diff --git a/cogs/admins.py b/cogs/admins.py index d6c8830..6608625 100644 --- a/cogs/admins.py +++ b/cogs/admins.py @@ -138,38 +138,63 @@ class Admins(commands.Cog): @group_give.command(name='packs') async def give_packs_subcommand( - self, interaction: discord.Interaction, num_packs: int, pack_type: Literal['Standard', 'Premium', 'MVP'], - team_abbrevs: str): + self, interaction: discord.Interaction, team_abbrevs: str, num_packs: int, pack_type: Literal['Standard', 'Premium', 'MVP'], cardset_id: int = None): if not owner_only(interaction): await interaction.response.send_message(random_no_gif()) return current = await db_get('current') await interaction.response.defer() - p_query = await db_get('packtypes', params=[('name', pack_type)]) + p_query = await db_get('packtypes', params=[('name', pack_type)]) + if p_query['count'] == 0: + raise KeyError(f'Packtype not found') + this_packtype = p_query['packtypes'][0] + + c_id = None + if cardset_id is not None: + cardset = await db_get('cardsets', object_id=cardset_id, none_okay=False) + c_id = cardset['id'] + response = '' for x in team_abbrevs.split(' '): - t_query = await db_get('teams', params=[('abbrev', x), ('season', current['season'])]) - team = t_query['teams'][0] - - if team: - total_packs = await give_packs(team, num_packs, pack_type=p_query['packtypes'][0]) - response += f'Just gave {num_packs} {pack_type} pack{"s" if num_packs > 1 else ""} to the ' \ - f'{team["sname"]}. They now have {total_packs["count"]} ' \ - f'pack{"s" if total_packs["count"] > 1 else ""}.\n' - - elif x.upper() == 'LEAGUE': + if x.upper() == 'LEAGUE': all_teams = await db_get('teams', params=[('season', current['season'])]) + total_teams = 0 for y in all_teams['teams']: - logging.warning(f'Giving {num_packs} pack(s) to team: {y["abbrev"]}') - await give_packs(team, num_packs) - response = f'Just gave all {all_teams["count"]} teams {num_packs} ' \ - f'standard pack{"s" if num_packs > 1 else ""}!' + if not y['is_ai'] and 'gauntlet' not in y['abbrev'].lower(): + logging.warning(f'Giving {num_packs} pack(s) to team: {y["abbrev"]}') + await db_post( + 'packs', + payload={'packs': [{ + 'team_id': y['id'], + 'pack_type_id': this_packtype['id'], + 'pack_cardset_id': c_id + } for x in range(num_packs)]} + ) + total_teams += 1 + + response = f'Just gave all {total_teams} teams {num_packs} ' \ + f'{pack_type} pack{"s" if num_packs > 1 else ""}!' else: - await interaction.edit_original_response(content=f'Hmm...I\'m not sure who **{x.upper()}** is.') - return + t_query = await db_get('teams', params=[('abbrev', x), ('season', current['season'])]) + if t_query['count'] > 0: + team = t_query['teams'][0] + + await db_post( + 'packs', + payload={'packs': [{ + 'team_id': team['id'], + 'pack_type_id': this_packtype['id'], + 'pack_cardset_id': c_id + } for x in range(num_packs)]} + ) + response += f'Just gave {num_packs} {pack_type} pack{"s" if num_packs > 1 else ""} to the {team["sname"]}.' + + else: + await interaction.edit_original_response(content=f'Hmm...I\'m not sure who **{x.upper()}** is.') + return logging.info(f'give info: {response}') await interaction.edit_original_response(content=f'{response if len(response) > 0 else "All done!"}') diff --git a/cogs/economy.py b/cogs/economy.py index 4684da7..8252b33 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -16,25 +16,10 @@ from typing import Optional, Literal from discord.app_commands import Choice import datetime -import pygsheets +import in_game from db_calls import db_get, db_post, db_patch, db_delete, get_team_by_abbrev from help_text import * -# date = f'{datetime.datetime.now().year}-{datetime.datetime.now().month}-{datetime.datetime.now().day}' -# logging.basicConfig( -# filename=f'logs/{date}.log', -# format='%(asctime)s - %(levelname)s - %(message)s', -# level=logging.WARNING -# ) - - -# async def legal_channel(ctx): -# bad_channels = ['paper-dynasty-chat', 'pd-news-ticker'] -# if ctx.message.channel.name in bad_channels: -# raise discord.ext.commands.CheckFailure(f'Slide on down to the {get_channel(ctx, "pd-bot-hole").mention} ;)') -# else: -# return True - class Economy(commands.Cog): def __init__(self, bot): @@ -426,22 +411,22 @@ class Economy(commands.Cog): embed.description = 'Cardset Requirements' embed.add_field( name='Ranked Legal', - value='2024 Season + Promos, 2018 Season + Promos', + value='1998 Live + Promos, 2024 Season + Promos', inline=False ) embed.add_field( name='Minor League', - value='Humans: Unlimited\nAI: 2024 Season / 2018 Season as backup', + value='Humans: Unlimited\nAI: 1998 Live / 2008 Season as backup', inline=False ) embed.add_field( name='Major League', - value='Humans: Ranked Legal\nAI: 2024, 2018, 2016, 2008 Seasons / 2023 & 2022 as backup', + value='Humans: Ranked Legal\nAI: 1998 Live + Promos, 2024 + Promos, 2013, 2008 Seasons / 2019 & 2022 as backup', inline=False ) embed.add_field( - name='Flashback', - value='2016, 2013, 2012, 2008 Seasons', + name='Flashback (SBa Rerun)', + value='2019, 2021, 2022, 2023 Seasons', inline=False ) embed.add_field( @@ -1630,6 +1615,8 @@ class Economy(commands.Cog): team = await db_patch('teams', object_id=team['id'], params=[('gsheet', new_sheet.id)]) await refresh_sheet(team, self.bot, sheets) + in_game.data_cache.TEAM_CACHE = {} + conf_message = f'Alright, your sheet is linked to your team - good luck' if owner_team == team: conf_message += ' this season!' @@ -1638,58 +1625,6 @@ class Economy(commands.Cog): conf_message += f'\n\n{HELP_SHEET_SCRIPTS}' await response.edit(content=f'{conf_message}') - # @commands.hybrid_command(name='refresh', help='Refresh team data in Sheets') - # @commands.has_any_role(PD_PLAYERS) - # async def update_team(self, ctx): - # if not await legal_channel(ctx): - # await ctx.send(f'Slide on down to the {get_channel(ctx, "pd-bot-hole").mention} ;)') - # return - # - # team = await get_team_by_owner(ctx.author.id) - # if not team: - # await ctx.send( - # f'I don\'t see a team for you, yet. You can sign up with the `/newteam` command!' - # ) - # return - # - # await refresh_sheet(team, self.bot) - # await ctx.send(random_conf_gif()) - # - # # if abbrev and self.bot.is_owner(ctx.author): - # # team = Team.get_season(abbrev[0]) - # # else: - # # team = Team.get_by_owner(ctx.author.id) - # # if not team: - # # await ctx.send('Now you wait just a second. You don\'t have a team!') - # # return - # # - # # # Get data from Sheets - # # roster_data = await self.get_collection(ctx, team) - # # - # # # Cut any marked players - # # comp_trade = True - # # if len(roster_data['cut']) > 0: - # # comp_trade = await self.cut_players(ctx, team, roster_data['cut']) - # # - # # if not comp_trade: - # # return - # # - # # # Set new rostered list - # # self.set_rostered_players(team, roster_data['rostered']) - # # - # # # Send current data to Sheets - # # if not await self.write_collection(ctx, team, extra=len(roster_data['cut'])): - # # logging.error(f'There was an issue trying to update the {team.sname} roster.') - # # await helpers.pause_then_type(ctx, 'Yikes. I had an issue with Sheets. Send help.') - # # else: - # # await helpers.pause_then_type(ctx, 'Alrighty, your sheet is all up to date!') - # # if team.logo: - # # thumb = team.logo - # # else: - # # thumb = self.bot.get_user(team.gmid).avatar_url - # # await ctx.send(content=None, embed=helpers.get_active_roster(team, thumb)) - # # - # # db.close() @commands.hybrid_command(name='give-card', help='Mod: Give free card to team') # @commands.is_owner() diff --git a/cogs/owner.py b/cogs/owner.py index 53c338d..8706431 100644 --- a/cogs/owner.py +++ b/cogs/owner.py @@ -112,7 +112,7 @@ class Owner(commands.Cog): await ctx.send(f'Synced {len(fmt)} commands globally.') ctx.bot.tree.clear_commands(guild=ctx.guild) await ctx.send(f'Cleared all local commands.') - if fmt > 0: + if len(fmt) > 0: fmt = await ctx.bot.tree.sync(guild=ctx.guild) await ctx.send(f'Synced global commands to this guild.') else: diff --git a/cogs/players.py b/cogs/players.py index 1f66a4f..98b07b0 100644 --- a/cogs/players.py +++ b/cogs/players.py @@ -446,7 +446,7 @@ class Players(commands.Cog): @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) async def player_slash_command( self, interaction: discord.Interaction, player_name: str, - cardset: Literal['All', '2024 Season', '2024 Promos', '2023 Season', '2023 Promos', '2022 Season', + cardset: Literal['All', '1998 Live', '1998 Promos', '2024 Season', '2024 Promos', '2023 Season', '2023 Promos', '2022 Season', '2022 Promos', '2021 Season', '2019 Season', '2018 Season', '2018 Promos', '2016 Season', '2013 Season', '2012 Season', '2008 Season', 'Backyard Baseball', 'Mario Super Sluggers', 'Sams Choice'] = 'All'): # min_rarity: Literal['Replacement', 'Reserve', 'Starter', 'All-Star', 'MVP'] = None): diff --git a/db_calls.py b/db_calls.py index 3c4a4db..a4ef5fa 100644 --- a/db_calls.py +++ b/db_calls.py @@ -9,7 +9,7 @@ import os AUTH_TOKEN = {'Authorization': f'Bearer {os.environ.get("API_TOKEN")}'} DB_URL = 'https://pd.manticorum.com/api' master_debug = True -alt_database = 'dev' +alt_database = False PLAYER_CACHE = {} if alt_database == 'dev': diff --git a/gauntlets.py b/gauntlets.py index a234bca..8c6d5fe 100644 --- a/gauntlets.py +++ b/gauntlets.py @@ -551,7 +551,7 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra view=None ) - def get_embeds(include_links=True): + def get_embeds(include_links=True, round_num=1): top_embed = helpers.get_team_embed(f'{embed_title} - Round {round_num}') top_embed.description = f'Rarity Counts' bot_embed = helpers.get_team_embed(f'{embed_title} - Round {round_num}') @@ -619,11 +619,12 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra last_message = await interaction.channel.send(content=None, embeds=get_embeds(include_links=False)) async def draft_loop(): + round_num = 1 + counter = 0 while round_num <= 26 and counter < 50: counter += 1 params = copy.deepcopy(base_params) - logging.info(f'gauntlets.py - run_draft - event_id 5 / round_num: {round_num} / counter: {counter} ' - f'/ counts: {counts} / max_counts: {max_counts}') + logging.info(f'gauntlets.py - run_draft - event_id {this_event["id"]} / round_num: {round_num} / counter: {counter} / counts: {counts} / max_counts: {max_counts}') # Set rarity based on remaining counts if counts['Hall of Fame'] < max_counts['Hall of Fame']: @@ -772,7 +773,7 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra # Update roster embed round_num += 1 - await last_message.edit(content=None, embeds=get_embeds(include_links=False)) + await last_message.edit(content=None, embeds=get_embeds(include_links=False, round_num=round_num)) logging.info(f'going into draft') backyard_round = None diff --git a/help_text.py b/help_text.py index 8d820a6..9956ad4 100644 --- a/help_text.py +++ b/help_text.py @@ -37,6 +37,7 @@ HELP_NEWGAME = ( f'- Run `/new-game` and select a game mode:\n' f'** **- gauntlet: Draft a team and attempt to go 10-0 against the AI teams\n' f'** **- mlb-campaign: Progress from Minors -> Majors -> Hall of Fame by defeating all 30 MLB teams\n' + f'** **- exhibition: Play against the AI and choose the cardsets it uses to build a team\n' f'** **- ranked/unlimited: Play against another human player\n' f'- Set starting lineups with `/read-lineup` for each team\n\n' f'From here, the game scorebug will be posted and you are ready to start rolling dice!' @@ -49,7 +50,7 @@ HELP_PLAYGAME = ( f'nested commands (e.g. `/log flyball b`)\n' f'- When you mess up a result, run `/log undo-play` and it will roll back one play\n' f'- Run `/gamestate` to see the scorebug with both lineups\n' - f'- Run `/substitution` to make lineup changes (for you and the AI in single player)\n' + f'- Run `/substitution` to make lineup changes\n' f'- Run `/show-card` to see upcoming batters or the current defenders' ) diff --git a/helpers.py b/helpers.py index de4f677..beba1c7 100644 --- a/helpers.py +++ b/helpers.py @@ -225,6 +225,8 @@ RARITY = { 'Replacement': 0 } SELECT_CARDSET_OPTIONS = [ + discord.SelectOption(label='1998 Live', value='20'), + discord.SelectOption(label='1998 Promos', value='21'), discord.SelectOption(label='2024 Season', value='17'), discord.SelectOption(label='2024 Promos', value='18'), discord.SelectOption(label='2023 Season', value='9'), @@ -666,6 +668,7 @@ class SelectOpenPack(discord.ui.Select): class SelectPaperdexCardset(discord.ui.Select): def __init__(self): options = [ + discord.SelectOption(label='1998 Live'), discord.SelectOption(label='2024 Season'), discord.SelectOption(label='2023 Season'), discord.SelectOption(label='2022 Season'), @@ -710,6 +713,8 @@ class SelectPaperdexCardset(discord.ui.Select): cardset_id = 17 elif self.values[0] == '2024 Promos': cardset_id = 18 + elif self.values[0] == '1998 Live': + cardset_id = 20 c_query = await db_get('cardsets', object_id=cardset_id, none_okay=False) await interaction.response.edit_message(content=f'Okay, sifting through your cards...', view=None) @@ -837,6 +842,7 @@ class SelectPaperdexTeam(discord.ui.Select): class SelectBuyPacksCardset(discord.ui.Select): def __init__(self, team: dict, quantity: int, pack_type_id: int, pack_embed: discord.Embed, cost: int): options = [ + discord.SelectOption(label='1998 Live'), discord.SelectOption(label='2024 Season'), discord.SelectOption(label='2023 Season'), discord.SelectOption(label='2022 Season'), @@ -878,6 +884,8 @@ class SelectBuyPacksCardset(discord.ui.Select): cardset_id = 13 elif self.values[0] == '2024 Season': cardset_id = 17 + elif self.values[0] == '1998 Live': + cardset_id = 20 self.pack_embed.description = f'{self.pack_embed.description} - {self.values[0]}' view = Confirm(responders=[interaction.user], timeout=30) @@ -2217,12 +2225,14 @@ async def roll_for_cards(all_packs: list, extra_val=None) -> list: if counts[key]['count'] > 0: params = [ ('min_rarity', counts[key]['rarity']), ('max_rarity', counts[key]['rarity']), - ('limit', counts[key]['count']), ('in_packs', True) + ('limit', counts[key]['count']) ] if all_packs[0]['pack_team'] is not None: - params.append(('franchise', all_packs[0]['pack_team']['lname'])) + params.extend([('franchise', all_packs[0]['pack_team']['lname']), ('in_packs', True)]) elif all_packs[0]['pack_cardset'] is not None: params.append(('cardset_id', all_packs[0]['pack_cardset']['id'])) + else: + params.append(('in_packs', True)) pl = await db_get('players/random', params=params)