From 173aeb2a3c1c787fb03767795315bf62da9109bd Mon Sep 17 00:00:00 2001 From: Vivek Santayana Date: Sat, 24 Jul 2021 13:15:01 +0100 Subject: [PATCH] Debug Pitch Menu --- app/cogs/slashcommands/config.py | 4 ++-- .../slashcommands/secondary/game_create.py | 2 +- .../slashcommands/secondary/game_management.py | 7 ++----- .../secondary/manipulate_timeslots.py | 2 +- app/cogs/slashcommands/secondary/pitch.py | 18 ++++++++++++------ 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/cogs/slashcommands/config.py b/app/cogs/slashcommands/config.py index 8805198..dd7e58d 100644 --- a/app/cogs/slashcommands/config.py +++ b/app/cogs/slashcommands/config.py @@ -119,7 +119,7 @@ class Configuration(commands.Cog, name='Configuration Commands'): if self.client.get_cog('Player Commands') is None: loadCog(f'./{cogsDir}/slashcommands/secondary/player_commands.py') flag = True - if self.client.get_cog('Pitch') is None: + if self.client.get_cog('Pitch Command') is None: loadCog(f'./{cogsDir}/slashcommands/secondary/pitch.py') flag = True if flag: await self.client.slash.sync_all_commands() @@ -297,7 +297,7 @@ class Configuration(commands.Cog, name='Configuration Commands'): if self.client.get_cog('Player Commands') is None: loadCog(f'./{cogsDir}/slashcommands/secondary/player_commands.py') Flag = True - if self.client.get_cog('Pitch') is None: + if self.client.get_cog('Pitch Command') is None: loadCog(f'./{cogsDir}/slashcommands/secondary/pitch.py') Flag = True if flag: await self.client.slash.sync_all_commands() diff --git a/app/cogs/slashcommands/secondary/game_create.py b/app/cogs/slashcommands/secondary/game_create.py index ced3459..8838e7d 100644 --- a/app/cogs/slashcommands/secondary/game_create.py +++ b/app/cogs/slashcommands/secondary/game_create.py @@ -290,7 +290,7 @@ class GameCreate(commands.Cog, name='Game Create'): if self.client.get_cog('Player Commands') is None: loadCog(f'./{cogsDir}/slashcommands/secondary/player_commands.py') flag = True - if self.client.get_cog('Pitch') is None: + if self.client.get_cog('Pitch Command') is None: loadCog(f'./{cogsDir}/slashcommands/secondary/pitch.py') flag = True if flag: await self.client.slash.sync_all_commands() diff --git a/app/cogs/slashcommands/secondary/game_management.py b/app/cogs/slashcommands/secondary/game_management.py index 8fe2028..aa22d38 100644 --- a/app/cogs/slashcommands/secondary/game_management.py +++ b/app/cogs/slashcommands/secondary/game_management.py @@ -17,10 +17,7 @@ class GameManagement(commands.Cog, name='Game Management'): def __init__(self, client): self.client = client - conf = yaml_load(configFile) lookup = yaml_load(lookupFile) - data = yaml_load(dataFile) - guild_ids= [ int(x) for x in list(lookup)] ### Move delete, Modify, and Reset commands to a separate secondary cog to enable when games exist? @@ -100,7 +97,7 @@ class GameManagement(commands.Cog, name='Game Management'): if not any([x for x in yaml_load(lookupFile).values()]): unloadCog(f'./{cogsDir}/slashcommands/secondary/game_management.py') if self.client.get_cog('Player Commands') is not None: unloadCog(f'./{cogsDir}/slashcommands/secondary/player_commands.py') - if self.client.get_cog('Pitch') is not None: unloadCog(f'./{cogsDir}/slashcommands/secondary/pitch.py') + if self.client.get_cog('Pitch Command') is not None: unloadCog(f'./{cogsDir}/slashcommands/secondary/pitch.py') await self.client.slash.sync_all_commands() @cog_ext.cog_subcommand( @@ -556,7 +553,7 @@ class GameManagement(commands.Cog, name='Game Management'): if not any([x for x in yaml_load(lookupFile).values()]): unloadCog(f'./{cogsDir}/slashcommands/secondary/game_management.py') if self.client.get_cog('Player Commands') is not None: unloadCog(f'./{cogsDir}/slashcommands/secondary/player_commands.py') - if self.client.get_cog('Pitch') is not None: unloadCog(f'./{cogsDir}/slashcommands/secondary/pitch.py') + if self.client.get_cog('Pitch Command') is not None: unloadCog(f'./{cogsDir}/slashcommands/secondary/pitch.py') await self.client.slash.sync_all_commands() def setup(client): diff --git a/app/cogs/slashcommands/secondary/manipulate_timeslots.py b/app/cogs/slashcommands/secondary/manipulate_timeslots.py index 02339d9..a404e42 100644 --- a/app/cogs/slashcommands/secondary/manipulate_timeslots.py +++ b/app/cogs/slashcommands/secondary/manipulate_timeslots.py @@ -97,7 +97,7 @@ class ManipulateTimeslots(commands.Cog, name='Manipulate Timeslots'): unloadCog(f'./{cogsDir}/slashcommands/secondary/game_create.py') if self.client.get_cog('Player Commands') is not None: unloadCog(f'./{cogsDir}/slashcommands/secondary/player_commands.py') - if self.client.get_cog('Pitch') is not None: + if self.client.get_cog('Pitch Command') is not None: unloadCog(f'./{cogsDir}/slashcommands/secondary/pitch.py') await self.client.slash.sync_all_commands() else: diff --git a/app/cogs/slashcommands/secondary/pitch.py b/app/cogs/slashcommands/secondary/pitch.py index 32cf3a4..11a5f73 100644 --- a/app/cogs/slashcommands/secondary/pitch.py +++ b/app/cogs/slashcommands/secondary/pitch.py @@ -85,6 +85,7 @@ class Pitch(commands.Cog, name='Pitch Command'): ) if guildStr not in pitches: pitches[guildStr] = {} if timeslot not in pitches[guildStr]: pitches[guildStr][timeslot] = {} + pitches[guildStr][timeslot]['indices'] = {} pitches[guildStr][timeslot]['entries'] = [x for x in data[guildStr][timeslot].values()] pitches[guildStr][timeslot]['entries'].sort(key= lambda x: x['game_title']) header_message = await ctx.channel.send( @@ -122,7 +123,9 @@ class Pitch(commands.Cog, name='Pitch Command'): ] ) pitches[guildStr][timeslot]['messages'].append(m) - pitches[guildStr][timeslot]['roles'][index] = discord.utils.find(lambda x: x.id == element['role'],ctx.guild.roles) + r = discord.utils.find(lambda x: x.id == element['role'],ctx.guild.roles) + pitches[guildStr][timeslot]['roles'][index] = r + pitches[guildStr][timeslot]['indices'][r.id] = index newcomer = returning_player = None if 'newcomer' in conf[guildStr]['roles']: newcomer = discord.utils.find(lambda x: x.id == conf[guildStr]['roles']['newcomer'], ctx.guild.roles) if 'returning_player' in conf[guildStr]['roles']: returning_player = discord.utils.find(lambda x: x.id == conf[guildStr]['roles']['returning_player'], ctx.guild.roles) @@ -191,12 +194,15 @@ class Pitch(commands.Cog, name='Pitch Command'): else: index = int(button_ctx.custom_id.split('_',1)[1]) if button_ctx.custom_id.startswith('join_'): - if set(button_ctx.author.roles) & set(pitches[guildStr][timeslot]['roles']): - for role in list(set(button_ctx.author.roles) & set(pitches[guildStr][timeslot]['roles'])): + if set(button_ctx.author.roles) & set(pitches[guildStr][timeslot]['roles'].values()): + print('Check 0') + for role in list(set(button_ctx.author.roles) & set(pitches[guildStr][timeslot]['roles'].values())): if role != pitches[guildStr][timeslot]['roles'][index]: + print('check 1') await button_ctx.author.remove_roles(role,reason=f'/pitch interaction by {button_ctx.author.display_name}') data[guildStr][timeslot][str(role.id)]['current_players'] -= 1 - element = pitches[guildStr][timeslot]['entries'][index] + i = pitches[guildStr][timeslot]['indices'][role.id] + element = pitches[guildStr][timeslot]['entries'][i] gm = await self.client.fetch_user(element['gm']) o = f'_ _\n***{element["game_title"]}*** (GM: {gm.mention})\n```\n' if element['system'] is not None: o = ''.join([o,f'System: {element["system"]}\n']) @@ -206,7 +212,7 @@ class Pitch(commands.Cog, name='Pitch Command'): o = ''.join([o,f'```']) spaces_remaining = element["max_players"] - element["current_players"] o = ''.join([o,f'~~Spaces Remaining: {str(0)}~~'])if spaces_remaining <= 0 else ''.join([o,f'Spaces Remaining: {str(spaces_remaining)}']) - await pitches[guildStr][timeslot]['messages'][index].edit(content=o) + await pitches[guildStr][timeslot]['messages'][i].edit(content=o) tc = discord.utils.find(lambda x: x.id == lookup[guildStr][str(role.id)]['text_channel'],ctx.guild.text_channels) if tc is None: c = discord.utils.find(lambda x: x.id == lookup[guildStr][str(role.id)]['category'],ctx.guild.categories) @@ -282,7 +288,7 @@ class Pitch(commands.Cog, name='Pitch Command'): for message in pitches[guildStr][timeslot]['messages']: await message.delete() await control.delete() await ctx.channel.edit(reason=f'/pitch command issued by {ctx.author.display_name}', overwrites={}) - await button_ctx.send('```Pitch menu cleared. Pitches have now concluded.```') + await button_ctx.channel.send('```Pitch menu cleared. Pitches have now concluded.```') def setup(client): client.add_cog(Pitch(client)) \ No newline at end of file