fix: implement paperdex dupe-detection logic (#23) #70

Closed
cal wants to merge 13 commits from ai/paper-dynasty-discord#23 into main
Owner

Summary

Implements the dupe-detection logic that was stubbed out as a TODO in get_card_embeds().

  • Queries the cards API endpoint filtered by player_id + team_id to count how many copies of the card the viewing team owns
  • Displays the dupe count as a # Dupes embed field (e.g. "0 dupes", "1 dupe", "3 dupes") for non-Paper-Dynasty teams
  • Applied identically to both helpers/main.py and helpers.py

Files Changed

  • helpers/main.py — removed TODO comment block, implemented dupe detection
  • helpers.py — same change (legacy file, kept in sync)

Notes

The paperdex data already fetched via db_get("paperdex", flat=True) tracks "has ever collected" (one entry per player-team pair), so it cannot yield dupe counts on its own. A separate cards API call per card embed is required. The original commented-out approach was correct.

The count - 1 logic from the original stub was replaced with dupe_count = 0 if not team_dex["count"] else team_dex["count"] - 1 to correctly handle the edge case where count is 0 (team has no cards of this player — shouldn't appear in practice but avoids -1 dupes display).

Other observations

  • helpers.py (top-level) appears to be a legacy duplicate of helpers/ package — it still exists on main branch. PRs #62 and #65 on next-release address this.
  • The ruff formatter automatically reformatted 3 cosmetic lines in paperdex_team_embed in each file (string split across line change) — functional code is unchanged.
## Summary Implements the dupe-detection logic that was stubbed out as a TODO in `get_card_embeds()`. - Queries the `cards` API endpoint filtered by `player_id` + `team_id` to count how many copies of the card the viewing team owns - Displays the dupe count as a `# Dupes` embed field (e.g. "0 dupes", "1 dupe", "3 dupes") for non-Paper-Dynasty teams - Applied identically to both `helpers/main.py` and `helpers.py` ## Files Changed - `helpers/main.py` — removed TODO comment block, implemented dupe detection - `helpers.py` — same change (legacy file, kept in sync) ## Notes The `paperdex` data already fetched via `db_get("paperdex", flat=True)` tracks "has ever collected" (one entry per player-team pair), so it cannot yield dupe counts on its own. A separate `cards` API call per card embed is required. The original commented-out approach was correct. The `count - 1` logic from the original stub was replaced with `dupe_count = 0 if not team_dex["count"] else team_dex["count"] - 1` to correctly handle the edge case where `count` is 0 (team has no cards of this player — shouldn't appear in practice but avoids -1 dupes display). ## Other observations - `helpers.py` (top-level) appears to be a legacy duplicate of `helpers/` package — it still exists on `main` branch. PRs #62 and #65 on `next-release` address this. - The ruff formatter automatically reformatted 3 cosmetic lines in `paperdex_team_embed` in each file (string split across line change) — functional code is unchanged.
cal added 1 commit 2026-03-05 21:35:41 +00:00
fix: implement paperdex dupe-detection logic (#23)
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m20s
37041b028e
Queries cards API by player_id + team_id to count copies owned,
displays dupe count in card embed for non-Paper-Dynasty teams.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
cal added the
ai-reviewing
label 2026-03-05 21:47:20 +00:00
cal reviewed 2026-03-05 21:48:22 +00:00
cal left a comment
Author
Owner

AI Code Review

Files Reviewed

  • helpers/main.py (modified)
  • helpers.py (modified — legacy duplicate, kept in sync)

Findings

Correctness

  • Dupe count logic: dupe_count = 0 if not team_dex["count"] else team_dex["count"] - 1 is correct. Handles count=0 (→ 0 dupes, avoids -1), count=1 (→ 0 dupes, single copy), count=N (→ N-1 dupes). The PR's fix over the original stub's count = 1 if not team_dex['count'] else team_dex['count'] approach is cleaner.
  • Guard condition: if card["team"]["lname"] != "Paper Dynasty": matches the identical guard already used for "Collected By" display above (line 157), ensuring consistent behavior.
  • API call pattern: db_get("cards", params=[("player_id", ...), ("team_id", ...)]) mirrors the exact same pattern used at line 153 for db_get("paperdex", ...) — consistent with the existing code.
  • No error handling: team_dex["count"] could raise if db_get returns None. However, the surrounding code (all_dex["count"] at line 156) has the same assumption, so this is consistent with project patterns — not a blocker.

Security

  • No issues. player_id and team_id are sourced from API response data and passed as HTTP query params, not raw SQL. No injection risk.

Style & Conventions

  • Code style follows existing patterns in the function. Singular/plural handling (dupe/dupes) is consistent with the other embed fields in this function.
  • Second hunk in each file is ruff cosmetic reformat of paperdex_team_embed — functionally unchanged.

Suggestions

  • None that block merging. The implementation is minimal and correct.

Verdict: APPROVED

Clean implementation of the stubbed TODO. Logic is correct, edge cases handled, follows existing project patterns. The helpers.py sync is noted as intentional (legacy file, addressed by PRs #62/#65 on next-release).


Automated review by Claude PR Reviewer

## AI Code Review ### Files Reviewed - `helpers/main.py` (modified) - `helpers.py` (modified — legacy duplicate, kept in sync) ### Findings #### Correctness - **Dupe count logic**: `dupe_count = 0 if not team_dex["count"] else team_dex["count"] - 1` is correct. Handles count=0 (→ 0 dupes, avoids -1), count=1 (→ 0 dupes, single copy), count=N (→ N-1 dupes). The PR's fix over the original stub's `count = 1 if not team_dex['count'] else team_dex['count']` approach is cleaner. - **Guard condition**: `if card["team"]["lname"] != "Paper Dynasty":` matches the identical guard already used for "Collected By" display above (line 157), ensuring consistent behavior. - **API call pattern**: `db_get("cards", params=[("player_id", ...), ("team_id", ...)])` mirrors the exact same pattern used at line 153 for `db_get("paperdex", ...)` — consistent with the existing code. - **No error handling**: `team_dex["count"]` could raise if `db_get` returns `None`. However, the surrounding code (`all_dex["count"]` at line 156) has the same assumption, so this is consistent with project patterns — not a blocker. #### Security - No issues. `player_id` and `team_id` are sourced from API response data and passed as HTTP query params, not raw SQL. No injection risk. #### Style & Conventions - Code style follows existing patterns in the function. Singular/plural handling (`dupe`/`dupes`) is consistent with the other embed fields in this function. - Second hunk in each file is ruff cosmetic reformat of `paperdex_team_embed` — functionally unchanged. #### Suggestions - None that block merging. The implementation is minimal and correct. ### Verdict: APPROVED Clean implementation of the stubbed TODO. Logic is correct, edge cases handled, follows existing project patterns. The `helpers.py` sync is noted as intentional (legacy file, addressed by PRs #62/#65 on `next-release`). --- *Automated review by Claude PR Reviewer*
cal added
ai-reviewed
and removed
ai-reviewing
labels 2026-03-05 21:48:51 +00:00
cal changed target branch from main to next-release 2026-03-07 07:32:50 +00:00
cal force-pushed ai/paper-dynasty-discord#23 from 37041b028e to 174c485c85 2026-03-07 07:34:10 +00:00 Compare
cal changed target branch from next-release to main 2026-03-23 04:14:33 +00:00
Author
Owner

Closing — will re-implement fresh against main. Original PR had unrebaseable conflicts from the scouting refactor.

Closing — will re-implement fresh against `main`. Original PR had unrebaseable conflicts from the scouting refactor.
cal closed this pull request 2026-03-23 04:15:43 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/paper-dynasty-discord#70
No description provided.