From 9bb84ce2870978dba83f5526967e4e92e0a55208 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Sat, 12 Jul 2025 23:15:00 -0500 Subject: [PATCH] Post Draft fixes for season 12 --- .gitignore | 2 ++ api_calls/player.py | 10 +++++++++- cogs/draft.py | 36 +++++++++++++++++++++++++++++------- cogs/gameday.py | 6 +++--- cogs/players.py | 18 +++++++++--------- cogs/transactions.py | 8 ++++---- db_calls.py | 6 ++++++ helpers.py | 3 ++- 8 files changed, 64 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 6d35f5a..e5bd7e4 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,5 @@ card-creation/ .dockerignore docker-compose.yml venv/ +CLAUDE.md +/.claude** diff --git a/api_calls/player.py b/api_calls/player.py index 0dc152e..820b1ac 100644 --- a/api_calls/player.py +++ b/api_calls/player.py @@ -34,4 +34,12 @@ class Player(pydantic.BaseModel): strat_code: Optional[str] = None bbref_id: Optional[str] = None injury_rating: Optional[str] = None - sbaplayer_id: Optional[int] = None \ No newline at end of file + sbaplayer_id: Optional[int] = None + + +async def get_one_player(player_id: int) -> Player: + data = await db_get('players', object_id=player_id) + if not data: + log_exception(ApiException(f'No player found with ID {player_id}')) + + return Player(**data) diff --git a/cogs/draft.py b/cogs/draft.py index 3694d69..fce5fac 100644 --- a/cogs/draft.py +++ b/cogs/draft.py @@ -9,7 +9,7 @@ from api_calls.draft_pick import DraftPick, get_one_draftpick, patch_draftpick from api_calls.player import Player from exceptions import ApiException, log_exception from helpers import * -from db_calls import db_get, db_patch, put_player, db_post, get_player_by_name +from db_calls import db_delete, db_get, db_patch, put_player, db_post, get_player_by_name from discord.ext import commands, tasks from discord import TextChannel, app_commands @@ -449,6 +449,7 @@ class Draft(commands.Cog): f'{draft_pick.owner.lname} selects {player["name"]} with the #{draft_pick.overall} overall pick' ) draft_pick.player = Player(**player) + logger.info(f'draft_pick test: {draft_pick}') await patch_draftpick(draft_pick) # TODO: uncomment for live draft player['team']['id'] = draft_pick.owner.id @@ -780,13 +781,34 @@ class Draft(commands.Cog): temp_player['team'] = fa_team this_player = await put_player(temp_player) - - # this_player = await get_player_by_name(current.season, this_pick['player']['id']) - # this_player = await db_get('players', object_id=this_pick['player']['id']) - await interaction.edit_original_response( - content='Don\'t forget to delete the transaction from the database.', - embed=await get_player_embed(this_player, current) + + t_query = await db_get( + 'transactions', + params=[('season', 12), ('move_id', f'draft-overall-{this_pick.overall}')] ) + if not t_query or t_query.get('count', 0) == 0: + await interaction.edit_original_response( + content='I couldn\'t find the transaction record of this move so that\'s Cal\'s problem now. The pick is wiped, though.', + embed=await get_player_embed(this_player, current) + ) + else: + try: + del_query = await db_delete( + 'transactions', + object_id=t_query['transactions'][0]['moveid'] + ) + except ValueError as e: + logger.error(f'Could not delete draft transaction: {e}') + await interaction.edit_original_response( + content='I couldn\'t delete the transaction record of this move so that\'s Cal\'s problem now. The pick is wiped, though.', + embed=await get_player_embed(this_player, current) + ) + return + await interaction.edit_original_response( + content=f'[I gotchu]({random_gif("blows kiss")}) boo boo, like it never even happened.', + embed=await get_player_embed(this_player, current) + + ) return if pick_lock is not None: diff --git a/cogs/gameday.py b/cogs/gameday.py index 339d2c3..49349ef 100644 --- a/cogs/gameday.py +++ b/cogs/gameday.py @@ -800,7 +800,7 @@ class Gameday(commands.Cog): @commands.has_any_role(SBA_PLAYERS_ROLE_NAME, PD_PLAYERS_ROLE_NAME) async def new_game_command(self, ctx): current = await db_get('current') - this_team = await get_team_by_owner(current['season'], ctx.author.id) + this_team = await get_team_by_owner(current.season, ctx.author.id) await ctx.send('**Note:** Make sure this is the channel where you will be playing commands. Once this is set, ' 'I will only take gameplay commands here.') @@ -828,9 +828,9 @@ class Gameday(commands.Cog): try: this_matchup = await get_one_schedule( - season=current['season'], + season=current.season, team_abbrev1=this_team['abbrev'], - week=current['week'] + week=current.week ) except ValueError as e: home_team = await get_team('home') diff --git a/cogs/players.py b/cogs/players.py index 625df9d..328fc99 100644 --- a/cogs/players.py +++ b/cogs/players.py @@ -1191,19 +1191,19 @@ class Players(commands.Cog): async def get_division_standings(self, current) -> discord.Embed: d1_query = await db_get('standings', params=[ - ('season', current.season), ('division_abbrev', 'SD') + ('season', current.season), ('division_abbrev', 'TC') ]) div_one = d1_query['standings'] d2_query = await db_get('standings', params=[ - ('season', current.season), ('division_abbrev', 'DC') + ('season', current.season), ('division_abbrev', 'ETSOS') ]) div_two = d2_query['standings'] d3_query = await db_get('standings', params=[ - ('season', current.season), ('division_abbrev', 'FIP') + ('season', current.season), ('division_abbrev', 'APL') ]) div_three = d3_query['standings'] d4_query = await db_get('standings', params=[ - ('season', current.season), ('division_abbrev', 'DOC') + ('season', current.season), ('division_abbrev', 'BBC') ]) div_four = d4_query['standings'] @@ -1233,10 +1233,10 @@ class Players(commands.Cog): f'{progress["games_played"]}/{progress["game_count"]} games played', color=0xB70000) embed.add_field(name=f'**Full Standings**', value=SBA_STANDINGS_URL, inline=False) - embed.add_field(name=f'**Snow Day**', value=div_one_standings, inline=False) - embed.add_field(name=f'**Dinger Central**', value=div_two_standings, inline=False) - embed.add_field(name=f'**Just the FIP**', value=div_three_standings, inline=False) - embed.add_field(name=f'**Division of Cook**', value=div_four_standings, inline=False) + embed.add_field(name=f'**Traveling Circus**', value=div_one_standings, inline=False) + embed.add_field(name=f'**ETSOS**', value=div_two_standings, inline=False) + embed.add_field(name=f'**Apple**', value=div_three_standings, inline=False) + embed.add_field(name=f'**Big Chungus**', value=div_four_standings, inline=False) return embed @@ -1520,7 +1520,7 @@ class Players(commands.Cog): setup_tab = scorecard.worksheet_by_title('Setup') scorecard_version = setup_tab.get_value('V35') - if int(scorecard_version) != current.bet_week: + if scorecard_version != current.bet_week: await interaction.edit_original_response( content=f'It looks like this scorecard is out of date. Did you create a new card at the start of the ' f'game? If you did, let Cal know about this error. If not, I\'ll need you to use an up to ' diff --git a/cogs/transactions.py b/cogs/transactions.py index fd9b53c..d83cc6a 100644 --- a/cogs/transactions.py +++ b/cogs/transactions.py @@ -5,7 +5,7 @@ from helpers import * from api_calls.current import get_current from db_calls import db_get, db_patch, get_team_by_owner, get_team_by_abbrev, get_player_by_name, put_player, db_post from discord.ext import commands, tasks -OFFSEASON_FLAG = True +OFFSEASON_FLAG = False logger = logging.getLogger('discord_app') @@ -353,7 +353,7 @@ class Transactions(commands.Cog): # if now.weekday() == 0 and now.hour == 5 and not current.freeze: # Spring/Summer if now.weekday() == 0 and now.hour == 0 and not current.freeze: # Fall/Winter current.week += 1 - await db_patch('current', object_id=current['id'], params=[('week', current.week), ('freeze', True)]) + await db_patch('current', object_id=current.id, params=[('week', current.week), ('freeze', True)]) await self.run_transactions(current) logger.debug(f'Building freeze string') @@ -372,7 +372,7 @@ class Transactions(commands.Cog): # End Freeze # elif now.weekday() == 5 and now.hour == 5 and current.freeze: # Spring/Summer elif now.weekday() == 5 and now.hour == 0 and current.freeze: # Fall/Winter - await db_patch('current', object_id=current['id'], params=[('freeze', False)]) + await db_patch('current', object_id=current.id, params=[('freeze', False)]) week_num = f'Week {current.week}' stars = f'{"":*<30}' @@ -643,7 +643,7 @@ class Transactions(commands.Cog): await ctx.send(f'The trade deadline is **week {current.trade_deadline}**. Since it is currently **week ' f'{current.week}** I am just going to stop you right there.') return - if current.week < -2: + if current.week < -2 or current.week == -1: await ctx.send(await get_emoji(ctx, 'oof', False)) await ctx.send(f'Patience, grasshopper. Trades open soon.') return diff --git a/db_calls.py b/db_calls.py index fa65ebc..72789bb 100644 --- a/db_calls.py +++ b/db_calls.py @@ -160,6 +160,12 @@ async def db_delete(endpoint: str, object_id: int, api_ver: int = 3, timeout=3): raise ValueError(f'DB: {e}') +# async def db_delete_transaction(move_id: str): +# req_url = get_req_url('transactions', api_ver=3, object_id=move_id) +# log_string = f'delete:\n{endpoint} {object_id}' +# logger.info(log_string) if master_debug else logger.debug(log_string) + + async def get_team_by_abbrev(team_abbrev: str, season: int): t_query = await db_get('teams', params=[('season', season), ('team_abbrev', team_abbrev)]) if not t_query or t_query['count'] == 0: diff --git a/helpers.py b/helpers.py index 9d4b69c..20849f4 100644 --- a/helpers.py +++ b/helpers.py @@ -37,7 +37,8 @@ SBA_SEASON7_DRAFT_KEY = '1BgySsUlQf9K21_uOjQOY7O0GrRfF6zt1BBaEFlvBokY' SBA_SEASON8_DRAFT_KEY = '1FG4cAs8OeTdrreRqu8D-APxibjB3RiEzn34KTTBLLDk' SBA_SEASON9_DRAFT_KEY = '1eyHqaVU9rtmhG1p0ZktOrz7FMDp3c_unCcFyMMYceLc' DRAFT_KEY = { - 11: '1Fz3GcTb7b9tLe8vkpyn59wRwC6P2QzxnLKtp7371sUc' + 11: '1Fz3GcTb7b9tLe8vkpyn59wRwC6P2QzxnLKtp7371sUc', + 12: '1OF-sAFykebc_2BrcYCgxCR-4rJo0GaNmTstagV-PMBU' } SBA_STANDINGS_URL = f'{SBA_BASE_URL}/standings' SBA_SCHEDULE_URL = f'{SBA_BASE_URL}/schedule'