Commit Graph

57 Commits

Author SHA1 Message Date
Cal Corum
45d71c61e3 fix: address reviewer issues — rename evolution endpoints, add TIER_BADGES
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m32s
- Update module docstring: replace evolution/cards with refractor/cards,
  drop old tier names (Unranked/Initiate/Rising/Ascendant/Evolved), add
  correct tier names (Base Card/Base Chrome/Refractor/Gold Refractor/
  Superfractor)
- Fix API call: db_get("evolution/cards") → db_get("refractor/cards")
- Add TIER_BADGES dict {1:"[BC]", 2:"[R]", 3:"[GR]", 4:"[SF]"}
- Update format_refractor_entry to prepend badge label for T1-T4 (T0 has
  no badge)
- Add TestTierBadges test class (11 tests) asserting badge values and
  presence in formatted output
- Update test_player_name_in_output to accommodate badge-prefixed bold name

Dead utilities/evolution_notifications.py has no source file on this branch
(WP-14/PR #112 already delivered the replacement).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 15:08:39 -05:00
Cal Corum
5670cd6e88 fix: correct tier names and group variable convention
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m45s
Tier names updated per Cal's spec:
  T0=Base Card, T1=Base Chrome, T2=Refractor, T3=Gold Refractor, T4=Superfractor

Also renames refractor_group → group_refractor per project convention.
All 39 tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 10:30:47 -05:00
Cal Corum
6b4957ec70 refactor: rename Evolution to Refractor system
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m34s
- cogs/evolution.py → cogs/refractor.py (class, group, command names)
- Tier names: Base Chrome, Refractor, Gold Refractor, Superfractor
- Fix import: helpers.main.get_team_by_owner
- Fix shadowed builtin: type → card_type parameter
- Tests renamed and updated (39/39 pass)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 08:48:31 -05:00
Cal Corum
d12cdb8d97 feat: /evo status slash command and tests (WP-11) (#76)
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m37s
Closes #76

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-13 09:07:28 -05:00
Cal Corum
3e9c2f6564 fix: add missing week field to scout reward POST
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m15s
The rewards API requires a week field. The scout claim callback was
posting without it, causing a 422 validation error when a user
selected a card from a scout opportunity.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 10:20:23 -05:00
Cal Corum
8b0c82f687 fix: invoke actual cog callback in test_error_handling_and_logging (#39)
The previous test patched api_calls.db_get and pygsheets.authorize then
called those mocks directly—never invoking any cog method. The test
passed even when all cog code was deleted.

Replace with a test that retrieves the real pull_roster_command.callback
from the cog instance, patches dependencies at the correct module-level
names, calls the callback, and asserts ctx.send was called with the
expected error message. If the cog cannot be imported, the test skips
gracefully via pytest.skip.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 13:22:58 +00:00
Cal Corum
1b83be89bb feat: limit scouting to Standard/Premium packs, simplify scout view
- Add SCOUTABLE_PACK_TYPES env var (default: Standard,Premium) to control
  which pack types offer scout opportunities
- Unify embed construction into build_scout_embed() — removes 3 near-duplicate
  embed builders across scout_view.py and scouting.py
- Replace manual total_scouts counter with derived property from claims dict
- Remove redundant db_get("current") API call per scout click — use PD_SEASON
- Remove duplicate expiry computation in create_scout_opportunity
- Move send_to_channel to top-level import, remove redundant local import
- Update tests to match simplified code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 13:22:58 +00:00
Cal Corum
0432f9d3f4 fix: add missing pack, description, image fields to scouting test fixtures
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 13:22:58 +00:00
Cal Corum
755f74be92 fix: Address PR review findings — two bugs and cleanup
- Fix int_timestamp() no-arg path returning seconds instead of
  milliseconds, which would silently break the daily scout token cap
  against the real API
- Acknowledge double-click interactions with ephemeral message instead
  of silently returning (Discord requires all interactions to be acked)
- Reorder scout flow: create card copy before consuming token so a
  failure doesn't cost the player a token for nothing
- Move build_scouted_card_list import to top of scout_view.py
- Remove unused asyncio import from helpers/scouting.py
- Fix footer text inconsistency ("One scout per player" everywhere)
- Update tests for new operation order and double-click behavior

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 13:22:58 +00:00
Cal Corum
3c0fa133fd refactor: Consolidate scouting utilities, add test suite, use Discord timestamps
- 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>
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
1a9efa8f7e fix: add locked_play context manager to prevent stuck play locks
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>
2026-02-10 21:54:44 -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
00ed42befd Add tests for play lock release and cross-command racing
Adds two new test cases to test_play_locking.py to improve coverage:

1. test_lock_released_after_successful_completion
   - Verifies play.locked is set to False after complete_play()
   - Confirms play.complete is set to True
   - Validates database commit is called

2. test_different_commands_racing_on_locked_play
   - Tests that ANY command type is blocked on locked plays
   - Prevents race conditions between different command types
   - Tests multiple commands: walk, strikeout, single, xcheck

These tests ensure the play locking idempotency guard works correctly
for both lock acquisition and release, and prevents all command types
from racing (not just duplicate commands).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-03 17:13:57 -06:00
Cal Corum
4be6afb541 Add API timeout/retry logic and fix get_team_by_owner for PostgreSQL
- Add APITimeoutError exception and retry logic to db_get
- Add timeout handling to db_post, db_put, db_patch, db_delete
- Fix get_team_by_owner to prefer non-gauntlet team (PostgreSQL migration fix)
- Code formatting cleanup (black)
2026-01-31 15:52:14 -06:00
Cal Corum
af49704272 Catchup files 2025-11-11 13:22:06 -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
660c6ad904 Added search functionality to /player command 2025-10-08 14:45:41 -05:00
Cal Corum
b1d05309ef Cogs to Packages Groundwork 2025-08-17 08:46:55 -05:00
Cal Corum
3debfd6e82 Catchup commit
Includes discord_ui refactor, testing overhaul, addition of
2025-07-22 09:22:19 -05:00
Cal Corum
8118b4a691 Added PO/FO to fielding roll
Complete /log xcheck and /log groundball
2024-12-06 00:46:49 -06:00
Cal Corum
d6d3d7beb0 Log stealing done
Log xchecks started
2024-11-25 13:17:51 -06:00
Cal Corum
073bd04b4b Added RosterLinks to remove card_id from setup process
Add SelectStartingPitcher dropdown
New .sync function
2024-11-23 19:53:48 -06:00
Cal Corum
7a718d45f0 AbRoll and JumpRoll objects
Add handedness to pitcher/batter
2024-11-20 21:31:31 -06:00
Cal Corum
f7685ff0e3 Added AbRoll and JumpRoll
Added auto_roll and roll_buttons to Game
Added log chaos
2024-11-17 14:57:54 -06:00
Cal Corum
3d333dabc3 Update api logging
New Position exception
Pull scouting data with lineups
More bunt types
String validation on gameplay models
AI Defensive alignment
2024-11-16 00:31:54 -06:00
Cal Corum
bfd72ae0f5 Update logging to RotatingFileHandler
Add auto game end
Calculate stats and decisions
Support raising instantiated exceptions
2024-11-09 23:14:54 -06:00
Cal Corum
c3418c4dfd New show-card dropdown view
Added PlayInitException
Added complete_and_post_play for log commands
Added many more log plays
Add undo-play
Added query logging
2024-11-09 00:48:13 -06:00
Cal Corum
fc3b407f2d ask_confirm helper added to buttons
Singles are complete
Doubles are complete
Uncapped advance is complete
2024-11-08 10:10:30 -06:00
Cal Corum
0327b6af62 Added ThrowResponse as managerai response
Added /log single, all but uncapped complete
Added check_uncapped_advance, ai on defense complete
2024-11-07 11:38:45 -06:00
Cal Corum
6e4904282e Complete play is complete including re24 and wpa 2024-11-06 14:58:24 -06:00
Cal Corum
e399fec853 Calculating wpa for plays 2024-11-06 02:17:28 -06:00
Cal Corum
d0f635034b Continuing progress on complete_play plus tests 2024-11-05 18:09:18 -06:00
Cal Corum
736897efad Added tag_from_second decision for AI
Flyball A and B complete
2024-11-04 00:12:35 -06:00
Cal Corum
e70f101cf5 Elevate test factory up one directory 2024-11-03 21:53:40 -06:00
Cal Corum
ee685f1415 Updated scorebug embed
Added play initialization
2024-10-24 17:14:11 -05:00
Cal Corum
79efceb6dd refactor exceptions and continue gameplay cog rebuild 2024-10-24 15:32:07 -05:00
Cal Corum
10c68c02b1 Create ManagerAi model 2024-10-16 14:09:11 -05:00
Cal Corum
1b87bfdb92 Mage Game.game_type required 2024-10-15 01:26:23 -05:00
Cal Corum
19e781137e Complete /new-game campaign
Add scorebug function to Game
Add card links prop to players
Add scorebug prop to play
2024-10-15 01:23:04 -05:00
Cal Corum
5fc89b5ce4 Added play table 2024-10-14 23:24:13 -05:00
Cal Corum
46860fb3c0 /read-lineup logic is complete 2024-10-14 20:46:55 -05:00
Cal Corum
428afe048e Finish loading utilities
Push queries from _models to _queries
2024-10-14 12:22:05 -05:00
Cal Corum
c253ae90a3 Migrate Confirm class to utilities 2024-10-14 01:17:09 -05:00
Cal Corum
2db26e00f1 Mature Cards and Players 2024-10-14 00:44:20 -05:00
Cal Corum
b35b25615d Update get_<x> functions to return x or None 2024-10-13 20:39:58 -05:00
Cal Corum
a16ed26541 Refactor tests to common factory 2024-10-13 20:06:25 -05:00
Cal Corum
59fa207212 Add Card table
Updating factory to do all work in session fixture
2024-10-13 01:53:20 -05:00
Cal Corum
968a2ab609 Resolved intermittently failing game tests 2024-10-13 00:32:14 -05:00
Cal Corum
c66075f9a8 Update Game's first_message to jump_url
Refactor test directory
2024-10-12 23:05:17 -05:00