diff --git a/cogs/admins.py b/cogs/admins.py index 60b4c76..54f6c1d 100644 --- a/cogs/admins.py +++ b/cogs/admins.py @@ -173,9 +173,13 @@ class Admins(commands.Cog): @commands.is_owner() async def post_guide_command(self, ctx, gm: Member): team = await get_team_by_owner(gm.id) - await db_patch('teams', object_id=team['id'], params=[('has_guide', True)]) + t_query = await db_get('teams', params=[('gm_id', gm.id)]) - post_ratings_guide(team, self.bot) + if t_query['count'] == 0: + await ctx.send(f'Huh...I don\'t see any teams for {gm.name}') + + for x in t_query['teams']: + await db_patch('teams', object_id=x['id'], params=[('has_guide', True)]) await ctx.send(random_conf_gif()) diff --git a/cogs/economy.py b/cogs/economy.py index 1680fee..f23e3a5 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -596,7 +596,7 @@ class Economy(commands.Cog): elif pack['pack_type']['name'] == 'All Star': p_group = f'MVP-Cardset-{pack["pack_cardset"]["id"]}-{pack["pack_cardset"]["name"]}' - logging.debug(f'p_group: {p_group}') + logging.info(f'p_group: {p_group}') if p_group is not None: p_count += 1 if p_group not in p_data: @@ -630,7 +630,7 @@ class Economy(commands.Cog): embed.add_field(name=pretty_name, value=f'Qty: {len(p_data[key])}') select_options.append(discord.SelectOption(label=pretty_name, value=key)) - view = SelectView(select_objects=[SelectOpenPack(select_options)], timeout=15) + view = SelectView(select_objects=[SelectOpenPack(select_options, owner_team)], timeout=15) await interaction.response.send_message(embed=embed, view=view) group_buy = app_commands.Group(name='buy', description='Make a purchase from the marketplace') diff --git a/cogs/gameplay.py b/cogs/gameplay.py index f106893..f05a3ca 100644 --- a/cogs/gameplay.py +++ b/cogs/gameplay.py @@ -71,8 +71,17 @@ class Gameplay(commands.Cog): f'Batter: {gs["batter"]["name"]}\n' \ f'Location: {channel.mention if channel is not None else "Your Butt"}\n' \ f'-------------------------' + gt_string = 'Unlimited' + if x.game_type == 'minor-league': + gt_string = 'Minor League' + elif x.game_type == 'major-league': + gt_string = 'Major League' + elif x.game_type == 'hall-of-fame': + gt_string = 'Hall of Fame' + elif 'gauntlet' in x.game_type: + gt_string = 'Gauntlet Game' # Adding spacing; discord is collapsing markdown on itself embed.add_field( - name=f'{gs["away_team"]["sname"]} @ {gs["home_team"]["sname"]}', + name=f'{gs["away_team"]["sname"]} @ {gs["home_team"]["sname"]} - {gt_string}', value=g_message, inline=False ) @@ -1705,6 +1714,9 @@ class Gameplay(commands.Cog): elif abs(latest_play.home_score - latest_play.away_score) >= 10 and latest_play.inning_half.lower() == 'bot': logging.info(f'bottom half and it is a mercy') valid_end = True + elif latest_play.inning_num >= 9 and latest_play.inning_half.lower() == 'bot' and \ + latest_play.home_score > latest_play.away_score: + valid_end = True # valid_end = True # TODO: REMOVE THIS BEFORE GO-LIVE if not valid_end: @@ -2818,7 +2830,7 @@ class Gameplay(commands.Cog): make_sub(await ai_manager.get_relief_pitcher(this_play, ai_team, this_game.game_type)) await interaction.edit_original_response( content=None, - embed=await self.get_game_state_embed(this_game) + embed=await self.get_game_state_embed(this_game, full_length=False) ) @group_log.command(name='flyball', description='Flyballs: a, b, ballpark, bq, c') diff --git a/cogs/players.py b/cogs/players.py index ce63026..0710f91 100644 --- a/cogs/players.py +++ b/cogs/players.py @@ -164,7 +164,7 @@ def get_ai_records(short_games, long_games): return all_results -def get_record_embed(embed: discord.Embed, results: dict, league: str): +def get_record_embed_legacy(embed: discord.Embed, results: dict, league: str): ale_points = results["BAL"][league]["points"] + results["BOS"][league]["points"] + \ results["NYY"][league]["points"] + results["TBR"][league]["points"] + results["TOR"][league]["points"] alc_points = results["CLE"][league]["points"] + results["CHW"][league]["points"] + \ @@ -230,6 +230,60 @@ def get_record_embed(embed: discord.Embed, results: dict, league: str): return embed +def get_record_embed(team: dict, results: dict, league: str): + embed = get_team_embed(league, team) + embed.add_field( + name=f'AL East', + value=f'BAL: {results["BAL"][0]} - {results["BAL"][1]} ({results["BAL"][2]} RD)\n' + f'BOS: {results["BOS"][0]} - {results["BOS"][1]} ({results["BOS"][2]} RD)\n' + f'NYY: {results["NYY"][0]} - {results["NYY"][1]} ({results["NYY"][2]} RD)\n' + f'TBR: {results["TBR"][0]} - {results["TBR"][1]} ({results["TBR"][2]} RD)\n' + f'TOR: {results["TOR"][0]} - {results["TOR"][1]} ({results["TOR"][2]} RD)\n' + ) + embed.add_field( + name=f'AL Central', + value=f'CLE: {results["CLE"][0]} - {results["CLE"][1]} ({results["CLE"][2]} RD)\n' + f'CHW: {results["CHW"][0]} - {results["CHW"][1]} ({results["CHW"][2]} RD)\n' + f'DET: {results["DET"][0]} - {results["DET"][1]} ({results["DET"][2]} RD)\n' + f'KCR: {results["KCR"][0]} - {results["KCR"][1]} ({results["KCR"][2]} RD)\n' + f'MIN: {results["MIN"][0]} - {results["MIN"][1]} ({results["MIN"][2]} RD)\n' + ) + embed.add_field( + name=f'AL West', + value=f'HOU: {results["HOU"][0]} - {results["HOU"][1]} ({results["HOU"][2]} RD)\n' + f'LAA: {results["LAA"][0]} - {results["LAA"][1]} ({results["LAA"][2]} RD)\n' + f'OAK: {results["OAK"][0]} - {results["OAK"][1]} ({results["OAK"][2]} RD)\n' + f'SEA: {results["SEA"][0]} - {results["SEA"][1]} ({results["SEA"][2]} RD)\n' + f'TEX: {results["TEX"][0]} - {results["TEX"][1]} ({results["TEX"][2]} RD)\n' + ) + embed.add_field( + name=f'NL East', + value=f'ATL: {results["ATL"][0]} - {results["ATL"][1]} ({results["ATL"][2]} RD)\n' + f'MIA: {results["MIA"][0]} - {results["MIA"][1]} ({results["MIA"][2]} RD)\n' + f'NYM: {results["NYM"][0]} - {results["NYM"][1]} ({results["NYM"][2]} RD)\n' + f'PHI: {results["PHI"][0]} - {results["PHI"][1]} ({results["PHI"][2]} RD)\n' + f'WSN: {results["WSN"][0]} - {results["WSN"][1]} ({results["WSN"][2]} RD)\n' + ) + embed.add_field( + name=f'NL Central', + value=f'CHC: {results["CHC"][0]} - {results["CHC"][1]} ({results["CHC"][2]} RD)\n' + f'CHW: {results["CIN"][0]} - {results["CIN"][1]} ({results["CIN"][2]} RD)\n' + f'MIL: {results["MIL"][0]} - {results["MIL"][1]} ({results["MIL"][2]} RD)\n' + f'PIT: {results["PIT"][0]} - {results["PIT"][1]} ({results["PIT"][2]} RD)\n' + f'STL: {results["STL"][0]} - {results["STL"][1]} ({results["STL"][2]} RD)\n' + ) + embed.add_field( + name=f'NL West', + value=f'ARI: {results["ARI"][0]} - {results["ARI"][1]} ({results["ARI"][2]} RD)\n' + f'COL: {results["COL"][0]} - {results["COL"][1]} ({results["COL"][2]} RD)\n' + f'LAD: {results["LAD"][0]} - {results["LAD"][1]} ({results["LAD"][2]} RD)\n' + f'SDP: {results["SDP"][0]} - {results["SDP"][1]} ({results["SDP"][2]} RD)\n' + f'SFG: {results["SFG"][0]} - {results["SFG"][1]} ({results["SFG"][2]} RD)\n' + ) + + return embed + + class Players(commands.Cog): def __init__(self, bot): self.bot = bot @@ -393,6 +447,10 @@ class Players(commands.Cog): all_params = [('name', this_player)] all_players = await db_get('players', params=all_params) + if all_players['count'] == 0: + await interaction.edit_original_response(content='No players found') + return + all_cards = [get_blank_team_card(x) for x in all_players['players']] all_cards.sort(key=lambda x: x['player']['rarity']['value'], reverse=True) @@ -473,7 +531,6 @@ class Players(commands.Cog): t_query = await db_get('teams', params=[('abbrev', team_abbrev)]) else: t_query = await db_get('teams', params=[('gm_id', interaction.user.id)]) - current = await db_get('current') if t_query['count'] == 0: await interaction.response.send_message( @@ -481,53 +538,61 @@ class Players(commands.Cog): ) return team = t_query['teams'][0] + current = await db_get('current') await interaction.response.send_message( f'I\'m tallying the {team["lname"]} results now...', ephemeral=ephemeral ) - rs_query = await db_get( - 'results', - params=[('team_one_id', team['id']), ('season', current['season']), ('short_game', True)] - ) - rl_query = await db_get( - 'results', - params=[('team_one_id', team['id']), ('season', current['season']), ('short_game', False)] - ) + st_query = await db_get(f'teams/{team["id"]}/season-record', object_id=current["season"]) - logging.debug(f'getting ai records...') - all_results = get_ai_records(rs_query['results'], rl_query['results']) - logging.debug(f'received ai records') + minor_embed = get_record_embed(team, st_query['minor-league'], 'Minor League') + major_embed = get_record_embed(team, st_query['major-league'], 'Major League') + hof_embed = get_record_embed(team, st_query['hall-of-fame'], 'Hall of Fame') - logging.debug(f'getting embeds...') - short_embed = get_team_embed(team['lname'], team) - short_embed.description = '3-Inning Games' - minor_embed = get_team_embed(team['lname'], team) - minor_embed.description = 'Minor League Record' - major_embed = get_team_embed(team['lname'], team) - major_embed.description = 'Major League Record' - hof_embed = get_team_embed(team['lname'], team) - hof_embed.description = 'Hall of Fame Record' - logging.debug(f'received embeds') - - logging.debug(f'getting short game embed...') - short_embed = get_record_embed(short_embed, all_results, 'short') - minor_embed = get_record_embed(minor_embed, all_results, 'minor') - major_embed = get_record_embed(major_embed, all_results, 'major') - hof_embed = get_record_embed(hof_embed, all_results, 'hof') - logging.debug(f'received short game embed') + # rs_query = await db_get( + # 'games', + # params=[('team_one_id', team['id']), ('season', current['season']), ('short_game', True)] + # ) + # rl_query = await db_get( + # 'results', + # params=[('team_one_id', team['id']), ('season', current['season']), ('short_game', False)] + # ) + # + # logging.debug(f'getting ai records...') + # all_results = get_ai_records(rs_query['results'], rl_query['results']) + # logging.debug(f'received ai records') + # + # logging.debug(f'getting embeds...') + # short_embed = get_team_embed(team['lname'], team) + # short_embed.description = '3-Inning Games' + # minor_embed = get_team_embed(team['lname'], team) + # minor_embed.description = 'Minor League Record' + # major_embed = get_team_embed(team['lname'], team) + # major_embed.description = 'Major League Record' + # hof_embed = get_team_embed(team['lname'], team) + # hof_embed.description = 'Hall of Fame Record' + # logging.debug(f'received embeds') + # + # logging.debug(f'getting short game embed...') + # short_embed = get_record_embed(short_embed, all_results, 'short') + # minor_embed = get_record_embed(minor_embed, all_results, 'minor') + # major_embed = get_record_embed(major_embed, all_results, 'major') + # hof_embed = get_record_embed(hof_embed, all_results, 'hof') + # logging.debug(f'received short game embed') if league == 'All': start_page = 0 elif league == 'Minor League': - start_page = 1 + start_page = 0 elif league == 'Major League': - start_page = 2 + start_page = 1 else: - start_page = 3 + start_page = 2 + await interaction.edit_original_response(content=f'Here are the {team["lname"]} campaign records') await embed_pagination( - [short_embed, minor_embed, major_embed, hof_embed], + [minor_embed, major_embed, hof_embed], interaction.channel, interaction.user, timeout=20, diff --git a/db_calls_gameplay.py b/db_calls_gameplay.py index 4c26cdd..9834ea9 100644 --- a/db_calls_gameplay.py +++ b/db_calls_gameplay.py @@ -1,3 +1,4 @@ +import asyncio import datetime import logging import random @@ -784,6 +785,7 @@ def undo_subs(game: StratGame, new_play_num: int): async def get_player(game, lineup_member) -> dict: + # await asyncio.sleep(0.1) if isinstance(game, Game): if game.is_pd: this_card = await db_get(f'cards', object_id=lineup_member.card_id) diff --git a/helpers.py b/helpers.py index 727bc37..b339984 100644 --- a/helpers.py +++ b/helpers.py @@ -568,7 +568,8 @@ class SelectChoicePackTeam(discord.ui.Select): class SelectOpenPack(discord.ui.Select): - def __init__(self, options: list): + def __init__(self, options: list, team: dict): + self.owner_team = team super().__init__(placeholder='Select a Pack Type', options=options) async def callback(self, interaction: discord.Interaction): @@ -576,11 +577,8 @@ class SelectOpenPack(discord.ui.Select): pack_vals = self.values[0].split('-') logging.info(f'pack_vals: {pack_vals}') - # Get the owner's team - owner_team = await get_team_by_owner(interaction.user.id) - # Get the selected packs - params = [('team_id', owner_team['id']), ('opened', False), ('limit', 5), ('exact_match', True)] + params = [('team_id', self.owner_team['id']), ('opened', False), ('limit', 5), ('exact_match', True)] open_type = 'standard' if 'Standard' in pack_vals: @@ -607,21 +605,22 @@ class SelectOpenPack(discord.ui.Select): raise KeyError(f'Cannot identify pack details: {pack_vals}') # If team isn't already set on team choice pack, make team pack selection now + await interaction.response.edit_message(view=None) + cardset_id = None - if 'Team Choice' in pack_vals: - if 'Cardset' in pack_vals: - cardset_id = pack_vals[2] - await interaction.response.edit_message(view=None) - view = SelectView( - [SelectChoicePackTeam('AL', owner_team, cardset_id), - SelectChoicePackTeam('NL', owner_team, cardset_id)], - timeout=30 - ) - await interaction.channel.send( - content=None, - view=view - ) - return + if 'Team Choice' in pack_vals and 'Cardset' in pack_vals: + cardset_id = pack_vals[2] + if 'Team' not in pack_vals: + view = SelectView( + [SelectChoicePackTeam('AL', self.owner_team, cardset_id), + SelectChoicePackTeam('NL', self.owner_team, cardset_id)], + timeout=30 + ) + await interaction.channel.send( + content=None, + view=view + ) + return elif 'Team' in pack_vals: params.append(('pack_team_id', pack_vals[2])) elif 'Cardset' in pack_vals: @@ -633,13 +632,11 @@ class SelectOpenPack(discord.ui.Select): logging.error(f'open-packs - no packs found with params: {params}') raise ValueError(f'Unable to open packs') - await interaction.response.edit_message(view=None) - # Open the packs if open_type == 'standard': - await open_st_pr_packs(p_query['packs'], owner_team, interaction) + await open_st_pr_packs(p_query['packs'], self.owner_team, interaction) elif open_type == 'choice': - await open_choice_pack(p_query['packs'][0], owner_team, interaction, cardset_id) + await open_choice_pack(p_query['packs'][0], self.owner_team, interaction, cardset_id) class SelectPaperdexCardset(discord.ui.Select):