Backup file was checked in with unused imports (requests, pygsheets),
adding noise to git grep, IDEs, and code review.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Consolidate SCOUT_TOKENS_PER_DAY and get_scout_tokens_used() into
helpers/scouting.py (was duplicated across 3 files)
- Add midnight_timestamp() utility to helpers/utils.py
- Remove _build_scouted_ids() wrapper, use self.claims directly
- Fix build_scout_embed return type annotation
- Use Discord <t:UNIX:R> relative timestamps for scout window countdown
- Add 66-test suite covering helpers, ScoutView, and cog
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When a player opens a pack, a scout opportunity is posted to #pack-openings
with face-down card buttons. Other players can blind-pick one card using
daily scout tokens (2/day), receiving a copy. The opener keeps all cards.
New files:
- discord_ui/scout_view.py: ScoutView with dynamic buttons and claim logic
- helpers/scouting.py: create_scout_opportunity() and embed builder
- cogs/economy_new/scouting.py: /scout-tokens command and cleanup task
Modified:
- helpers/main.py: Hook into open_st_pr_packs() after display_cards()
- paperdynasty.py: Register scouting cog
Requires new API endpoints in paper-dynasty-database (scout_opportunities).
Tracks #44.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Early returns in log_chaos, log_sac_bunt, and log_stealing left play
locks permanently stuck because the lock was acquired but never released.
The new locked_play async context manager wraps checks_log_interaction()
and guarantees lock release on exception, early return, or normal exit.
Migrated all 18 locking commands in gameplay.py and removed redundant
double-locking in end_game_command.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Prevents PositionNotFoundException from crashing mlb-campaign when a
player is placed at a position they cannot play (e.g. an outfielder
listed at Catcher in the Google Sheet). Adds early validation in
get_lineups_from_sheets and proper error handling at all read_lineup
call sites so the user gets a clear message and the game is cleaned up.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
HOTFIX: Production bot failed to start due to circular import.
Root cause: utilities/dropdown.py importing from command_logic/logic_gameplay.py
while logic_gameplay.py imports from utilities/dropdown.py.
Solution: Created play_lock.py as standalone module containing:
- release_play_lock()
- safe_play_lock()
Both modules now import from play_lock.py instead of each other.
Error message:
ImportError: cannot import name 'release_play_lock' from partially
initialized module 'command_logic.logic_gameplay' (most likely due
to a circular import)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
CRITICAL BUG FIX: Play locks were never released on exceptions, causing
permanent user lockouts. Found 13 stuck plays in production.
Changes:
1. Added lock_play parameter to checks_log_interaction() (default True)
2. Removed unnecessary locks from read-only commands:
- /settings-ingame (game settings, not play state)
- /show-card defense (read-only display)
- /substitute commands (just show UI, lock in callback)
3. Added safe_play_lock() context manager for automatic lock release
4. Added play locking to substitution callbacks:
- SelectBatterSub.callback()
- SelectReliefPitcher.callback()
5. Global error handler now releases stuck locks automatically
Architecture:
- Commands that display UI or read data: No lock
- Commands that modify play state: Lock at last possible moment
- 3-layer defense: manual release, context manager, global handler
Resolves race condition from concurrent play modifications.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Previously p_group was only set if pack type already existed in p_data,
which would silently skip new pack types. Now properly initializes the
pack type list when encountering a new type.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add FRANCHISE_NORMALIZE dict and helper to constants.py
- Update economy.py to normalize team_choice and use sname
- Update helpers/main.py franchise queries to use sname
- Update selectors.py to normalize franchise on player updates
Part of cross-era player matching fix for AI rosters
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Bug: Several slash commands (@app_commands.command) were using prefix command
decorators (@commands.has_any_role, @commands.check) which don't work with
app_commands. This caused errors caught by the global error handler, resulting
in "Unknown interaction" (404) errors being displayed before the command executed.
Affected commands:
- /comeonmanineedthis: Both role and channel checks were wrong
- /selldupes: Channel check was wrong
- /team: Channel check was wrong
Fix:
- Created app_legal_channel() decorator in helpers.py for slash commands
- Changed @commands.has_any_role to @app_commands.checks.has_any_role
- Changed @commands.check(legal_channel) to @app_legal_channel()
Bumps version to 1.7.5
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Users reported that end-of-run messages to #pd-news-ticker were no longer
appearing when gauntlet teams lost their second game. The news-ticker
announcement was only happening for 10-win completions, not 2-loss endings.
Changes:
- Updated end_run() to accept bot and main_team parameters
- Added send_to_channel() call when losses == 2 (natural run end)
- Skips news-ticker for manual resets (force_end=True)
- Updated post_result() to pass bot and main_team to end_run()
- Updated manual reset calls to explicitly pass force_end=True
Now when a gauntlet team loses their second game, #pd-news-ticker will
show: "The **[Team]** have completed their **[Event]** Gauntlet run
with a final record of [wins]-[losses]."
The draft completion message to news-ticker was already working correctly
at cogs/players_new/gauntlet.py:178-183.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Created get_context_user() helper function to safely extract the user from
either Context or Interaction objects. This prevents AttributeError issues
when hybrid commands are invoked as slash commands.
Hybrid commands receive commands.Context (with .author) when invoked with
prefix commands, but discord.Interaction (with .user) when invoked as slash
commands. The helper function handles both cases transparently.
Updated all affected hybrid commands:
- /branding-pd (cogs/players.py, cogs/players_new/team_management.py)
- /pullroster (cogs/players.py, cogs/players_new/team_management.py)
- /newsheet (cogs/economy_new/team_setup.py)
- /lastpack (cogs/economy_new/packs.py)
This follows the same pattern as the owner_only() fix and provides a
consistent, maintainable solution for all hybrid commands.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Multiple fixes to resolve PlayNotFoundException and lineup initialization errors:
1. gauntlets.py:
- Fixed Team object subscriptable errors (use .id instead of ['id'])
- Added fallback cardsets (24, 25, 26) for Event 9 RP shortage
- Fixed draft_team type handling (can be Team object or dict)
2. cogs/gameplay.py:
- Fixed gauntlet game creation flow to read field player lineup from sheets
- Catches LineupsMissingException when SP not yet selected
- Instructs user to run /gamestate after SP selection
3. utilities/dropdown.py:
- Fixed SelectStartingPitcher to create own session instead of using closed session
- Store game/team IDs instead of objects to avoid detached session issues
- Added exception handling for failed legality check API calls
These changes fix the issue where gauntlet games would fail to initialize
because the SP lineup entry wasn't being committed to the database.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Handle gamestates without full lineups
Added /set command for lineup and SP
Fixed uncapped hit bugs
Added league_name property to Games
Fix get_team for gauntlets
Fixed SelectSP dropdown bug