Commit Graph

73 Commits

Author SHA1 Message Date
Cal Corum
29f2a8683f fix: rename evolution/ to refractor/ endpoint and remove misplaced notifs module
All checks were successful
Ruff Lint / lint (pull_request) Successful in 14s
- Change `evolution/evaluate-game/` API call to `refractor/evaluate-game/` in
  complete_game() hook (was calling the wrong endpoint path)
- Update all test assertions in test_complete_game_hook.py to match the
  corrected endpoint path and update docstrings to "refractor" naming
- Remove helpers/evolution_notifs.py and tests/test_evolution_notifications.py
  from this PR — they belong to PR #112 (WP-14 tier notifications). The
  notify_tier_completion stub in logic_gameplay.py remains as the WP-14
  integration target.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 15:22:25 -05:00
Cal Corum
b04219d208 feat: WP-13 post-game callback hook for season stats and evolution
After complete_game() saves the game result and posts rewards, fire two
non-blocking API calls in order:
  1. POST season-stats/update-game/{game_id}
  2. POST evolution/evaluate-game/{game_id}

Any failure in the evolution block is caught and logged as a warning —
the game is already persisted so evolution will self-heal on the next
evaluate pass. A notify_tier_completion stub is added as a WP-14 target.

Closes #78 on cal/paper-dynasty-database

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 14:52:36 -05:00
8740c65773 Merge branch 'main' into fix/batch-cleanup-group-a
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m27s
2026-03-23 04:24:25 +00:00
Cal Corum
740ea93b34 fix: batch cleanup — dead code, bare excepts, empty stubs (#25, #32, #37, #38)
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m26s
Fixes #25, Fixes #32, Fixes #37, Fixes #38

- Remove unused PLAYER_CACHE = {} from api_calls.py (issue #37)
- Remove dead select_speed_testing() and select_all_testing() functions
  with their debug print() statements from gameplay_models.py (issue #32)
- Remove empty if-pass stubs after db_post calls in logic_gameplay.py (issue #38)
- Replace 10 bare except: clauses with except Exception: in gameplay_queries.py (issue #25)
- Add ruff.toml to configure pre-commit hook for existing codebase patterns
  (F403/F405 from intentional star imports, F541/F401/F841/E712 cosmetic)
- Fix E713 in logic_gameplay.py (not x in [...] -> x not in [...]) required
  by the pre-commit hook on the file already being touched

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-22 23:23:09 -05:00
Cal Corum
678fa320df fix: guard db_game against NameError when db_post fails in complete_game (#27)
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m24s
Initialize db_game = None before try block and guard roll_back call
with `if db_game is not None:` to prevent NameError masking the
original exception when db_post("games") raises before assignment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 10:32:48 -05:00
Cal Corum
4fcc8ed269 fix: remove duplicate sheets.open_by_key() call in get_full_roster_from_sheets (#30)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 13:22:58 +00:00
Cal Corum
1eda66a06c fix: preserve batter at plate when half-inning ends on caught stealing
Some checks failed
Build Docker Image / build (pull_request) Failing after 15s
When a half-inning ended with a CS (or pickoff), the batter who was at
the plate was incorrectly skipped in the next inning. The side-switch
code unconditionally advanced the batting order by 1 without checking
whether the last play was a plate appearance. Now checks opponent_play.pa
before incrementing, matching the existing non-side-switch logic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 22:37:42 -06:00
Cal Corum
c4577ed46f fix: validate player positions in lineup before game start
Some checks failed
Build Docker Image / build (pull_request) Failing after 16s
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>
2026-02-07 19:32:27 -06:00
Cal Corum
89801e1d42 Fix circular import by moving play lock functions to separate module
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>
2026-02-04 09:33:37 -06:00
Cal Corum
ebf006e5c6 Fix play lock system to prevent permanent user lockouts
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>
2026-02-04 09:21:18 -06:00
Cal Corum
90d7345850 Implement play locking to prevent concurrent command processing
Adds idempotency guard to prevent race conditions when multiple users
submit commands for the same play simultaneously.

Changes:
- Add PlayLockedException for locked play detection
- Implement lock check in checks_log_interaction()
- Acquire lock (play.locked = True) before processing commands
- Release lock (play.locked = False) after play completion
- Add warning logs for rejected duplicate submissions
- Add /diagnostics endpoint to health server for debugging

This prevents database corruption and duplicate processing when users
spam commands like "log xcheck" while the first is still processing.

Tested successfully in Discord - duplicate commands now properly return
PlayLockedException with instructions to wait.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-03 23:13:40 -06:00
Cal Corum
f95afd8d5d Fix unawaited coroutine in singles() command (SPD hit result)
- Added missing await keyword on line 2981 in logic_gameplay.py
- SPD hit result was calling singles() without await, causing RuntimeWarning
- All groundball tests passing (24/24)
- Bump version to 1.7.7

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 22:37:51 -06:00
Cal Corum
563820fe93 Remove debug print from is_game_over() causing stdout spam
Bug: The is_game_over() function contained a debug print statement that was
printing "1: " to stdout on every call. This was causing massive log spam
in Docker container output (thousands of lines) and making it difficult to
diagnose actual issues.

Fix: Remove the print(f'1: ') statement from line 3251.

Bumps version to 1.7.4

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 07:11:10 -06:00
Cal Corum
0163f24000 Fix null card_id in RosterLink causing IntegrityError
Previously, if get_card_or_none returned None (when a card ID from the
Google Sheet doesn't exist in the database), the code would create a
RosterLink with card=None, causing card_id to be null which violates
the NOT NULL constraint on the primary key.

Now we check if this_card is None before creating the RosterLink and
raise a CardNotFoundException with a helpful error message to guide
the user to fix their roster sheet.

Fixes the error: null value in column "card_id" of relation "rosterlink"
violates not-null constraint

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-15 09:15:07 -06:00
Cal Corum
0e3b98eb65 S10 Updates + PR Bugfix 2025-11-09 06:12:46 -06:00
Cal Corum
80e94498fa CLAUDE: Add safe WPA lookup with fallback to prevent KeyError crashes
Implements defensive error handling for WPA (Win Probability Added) calculations when rare game states are missing from the static lookup table. The safe_wpa_lookup() function uses a three-tier fallback strategy: exact lookup, bases-empty fallback, and 0.0 default value.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-11 18:25:59 -05:00
Cal Corum
a4adf50ca1 Added discord bot object to complete game function 2025-06-01 09:44:16 -05:00
Cal Corum
b3fa68b80e Bug fixes for uncapped doubles 2025-05-30 21:16:51 -05:00
Cal Corum
17680a2348 Added /substitution defense 2025-05-30 01:19:45 -05:00
Cal Corum
e366564bef Adding gauntlet 8
Season 9 updates
Uncapped runs scored bug fixed
2025-05-29 21:54:16 -05:00
Cal Corum
cffc9380f1 Replacing 1998 Live with 1998 Season 2025-04-14 16:28:14 -05:00
Cal Corum
92c7f47692 Advance trail runner when thrown at and safe 2025-03-09 13:21:08 -05:00
Cal Corum
36fd848b62 Bug fix: pitchers auto-fatigue one out too late 2025-03-09 13:07:09 -05:00
Cal Corum
8b8fa65023 Add lineup embed field without links 2025-02-28 22:24:11 -06:00
Cal Corum
557404301a Fix fatigue bugs 2025-02-11 00:58:45 -06:00
Cal Corum
4d59247e5c Fix Steal + Overthrow on OBC 5 2025-02-11 00:10:53 -06:00
Cal Corum
b454912393 Remove 3B hold check for runner on 2nd 2025-02-10 23:51:56 -06:00
Cal Corum
50895fef90 Show charts on SPD checks
Fix gb chart with OBC 5, 7
Add 1998 to player command
2025-02-10 23:44:05 -06:00
Cal Corum
149c4f3ab9 Update play order to use play_num instead of id 2025-02-08 16:53:21 -06:00
Cal Corum
f6bae8c208 Local db to Postgresql 2025-02-08 04:11:04 -06:00
Cal Corum
8be5e94536 Fatigue logging 2025-02-06 15:47:07 -06:00
Cal Corum
db52625899 Day 1 Gauntlet Updates
Baserunner advancement bug fixes
Pitcher sub bug fixes
2025-02-06 10:00:56 -06:00
Cal Corum
282a7e7ac2 Added live scorecard functionality
Added new pitcher embed highlighting
2025-02-05 11:30:56 -06:00
Cal Corum
c9b5b45961 Reliever bug 2025-02-05 09:41:06 -06:00
Cal Corum
9700a9abd6 Runner on 3rd, gb checks updated 2025-02-03 13:46:58 -06:00
Cal Corum
3b6bcfb186 Beta day 1 bug fixes 2025-02-02 22:01:33 -06:00
Cal Corum
7d54d9ea34 Add unlimited new-game
Add pitcher substitution
Add AI pitcher subs
2025-02-01 21:32:40 -06:00
Cal Corum
e850ee5519 Allow manual override of xcheck 2025-01-26 11:50:33 -06:00
Cal Corum
4a76d59481 Check for AI fatigue 2025-01-26 02:20:29 -06:00
Cal Corum
36dbde848e new_game_checks refactor 2025-01-24 10:08:11 -06:00
Cal Corum
965ceebd35 Add responders check to dropdowns
Add colors and insults to helpers
Finish /set commands with helpers post /new-game
Add POW check for pitchers
2024-12-27 22:33:25 -06:00
Cal Corum
724b8922f2 Update gauntlet get SP for new objects
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
2024-12-27 16:12:25 -06:00
Cal Corum
3db25b177a Refactor new game checks
Trail batter-runner on uncapped hits
2024-12-26 14:36:04 -06:00
Cal Corum
fa109442c2 Added range embeds to uncapped hits
Update gbA with runner on 3rd
2024-12-26 07:04:00 -06:00
Cal Corum
c3c88af14a Fixed HR unearned bug
Added pitching statline
2024-12-25 19:30:23 -06:00
Cal Corum
f40347e0bb Fixed chaos button bug
Added batting statline to batter & OT to catchers
2024-12-25 16:10:24 -06:00
Cal Corum
9dbd7896c4 Add PB to catcher string
Fix chaos interaction bug
2024-12-25 15:00:22 -06:00
Cal Corum
ac7b564e67 Fixed extra innings wpa bug
Fix earned run bug
Fix HBP batter_final
Fixed poop line
2024-12-24 23:32:47 -06:00
Cal Corum
7015fb3125 Added baserunning ai notes
Added get_batter_card to gameplay_queries
2024-12-24 21:08:00 -06:00
Cal Corum
c7b45aecf4 Fixed only_forced bug
Fixed scouting caching bug
2024-12-24 16:11:28 -06:00