|
|
|
@ -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?
|
|
|
|
@ -63,45 +60,11 @@ class GameManagement(commands.Cog, name='Game Management'):
|
|
|
|
|
return
|
|
|
|
|
game_title = lookup[guildStr][rStr]['game_title']
|
|
|
|
|
time = lookup[guildStr][rStr]['time']
|
|
|
|
|
c = ctx.guild.get_channel(lookup[guildStr][rStr]['category'])
|
|
|
|
|
gm = lookup[guildStr][rStr]['gm']
|
|
|
|
|
channelsFound = False
|
|
|
|
|
del data[guildStr][time][rStr]
|
|
|
|
|
if c is not None:
|
|
|
|
|
channelsFound = True
|
|
|
|
|
for t in ctx.guild.text_channels:
|
|
|
|
|
if t.category == c:
|
|
|
|
|
await t.delete(reason=f'/game delete command issued by `{ctx.author.display_name}`')
|
|
|
|
|
for v in ctx.guild.voice_channels:
|
|
|
|
|
if v.category == c:
|
|
|
|
|
await v.delete(reason=f'/game delete command issued by `{ctx.author.display_name}`')
|
|
|
|
|
del categories[guildStr][str(c.id)]
|
|
|
|
|
await c.delete(reason=f'/game delete command issued by `{ctx.author.display_name}`')
|
|
|
|
|
lookup[guildStr].pop(rStr, None)
|
|
|
|
|
gm_m = await ctx.guild.fetch_member(gm)
|
|
|
|
|
output = f'The game `{game_title}` for timeslot `{conf[guildStr]["timeslots"][time]}` and with GM `{gm_m.display_name}` has been deleted.'
|
|
|
|
|
if channelsFound:
|
|
|
|
|
output = ''.join([output,' All associated text, voice, and category channels have been deleted.'])
|
|
|
|
|
else:
|
|
|
|
|
output = ''.join([output,' No associated text, voice, or category channels were found. Please delete them manually if they still persist.'])
|
|
|
|
|
if 'mod' in conf[guildStr]['channels'] and 'committee' in conf[guildStr]['roles']:
|
|
|
|
|
c = discord.utils.find(lambda x: x.id == conf[guildStr]['channels']['mod'], ctx.guild.channels)
|
|
|
|
|
await c.send(
|
|
|
|
|
content = f'```{output}```'
|
|
|
|
|
)
|
|
|
|
|
gm = await ctx.guild.fetch_member(lookup[guildStr][rStr]['gm'])
|
|
|
|
|
output = f'The game `{game_title}` for timeslot `{conf[guildStr]["timeslots"][time]}` and with GM `{gm.display_name}` has been deleted.'
|
|
|
|
|
await ctx.send(f'```Game `{game_title}` has been deleted.```', hidden=True)
|
|
|
|
|
await game_role.delete(reason=f'/game delete command issued by `{ctx.author.display_name}`')
|
|
|
|
|
gms[guildStr][str(gm)].remove(game_role.id)
|
|
|
|
|
if not gms[guildStr][str(gm)]: del gms[guildStr][str(gm)]
|
|
|
|
|
if not data[guildStr][time]: del data[guildStr][time]
|
|
|
|
|
yaml_dump(lookup, lookupFile)
|
|
|
|
|
yaml_dump(data, dataFile)
|
|
|
|
|
yaml_dump(gms, gmFile)
|
|
|
|
|
yaml_dump(categories, categoriesFile)
|
|
|
|
|
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')
|
|
|
|
|
await self.client.slash.sync_all_commands()
|
|
|
|
|
#### Bot will delete the game role. The on_guild_role_delete event listener will then recognise this deletion and synchronise the categories and data files accordingly.
|
|
|
|
|
|
|
|
|
|
@cog_ext.cog_subcommand(
|
|
|
|
|
base='game',
|
|
|
|
@ -197,12 +160,9 @@ class GameManagement(commands.Cog, name='Game Management'):
|
|
|
|
|
rStr = str(r.id)
|
|
|
|
|
old_time = lookup[guildStr][rStr]['time']
|
|
|
|
|
time = re.sub(r"\W+",'', timeslot[:9].lower()) if timeslot else old_time
|
|
|
|
|
if guildStr not in lookup:
|
|
|
|
|
lookup[guildStr] = {}
|
|
|
|
|
if guildStr not in data:
|
|
|
|
|
data[guildStr] = {}
|
|
|
|
|
if time not in data[guildStr]:
|
|
|
|
|
data[guildStr][time] = {}
|
|
|
|
|
if guildStr not in lookup: lookup[guildStr] = {}
|
|
|
|
|
if guildStr not in data: data[guildStr] = {}
|
|
|
|
|
if time not in data[guildStr]: data[guildStr][time] = {}
|
|
|
|
|
# Command Validation Checks
|
|
|
|
|
if rStr not in lookup[guildStr]:
|
|
|
|
|
await ctx.send(f'```Error: This is not a valid game role. Please mention a role that is associated with a game.```',hidden=True)
|
|
|
|
@ -416,18 +376,9 @@ class GameManagement(commands.Cog, name='Game Management'):
|
|
|
|
|
|
|
|
|
|
async def purgeGames(ctx:SlashContext, timeslot:str):
|
|
|
|
|
for g in list(data[guildStr][timeslot].values()):
|
|
|
|
|
c = discord.utils.find(lambda x: x.id == g['category'], ctx.guild.categories)
|
|
|
|
|
r = discord.utils.find(lambda x: x.id == g['role'], ctx.guild.roles)
|
|
|
|
|
for x in c.channels:
|
|
|
|
|
await x.delete(reason=f'/game purge command issued by `{ctx.author.display_name}`')
|
|
|
|
|
del categories[guildStr][str(c.id)]
|
|
|
|
|
await c.delete(reason=f'/game purge command issued by `{ctx.author.display_name}`')
|
|
|
|
|
await r.delete(reason=f'/game purge command issued by `{ctx.author.display_name}`')
|
|
|
|
|
gms[guildStr][str(g['gm'])].remove(r.id)
|
|
|
|
|
if not gms[guildStr][str(g['gm'])]:
|
|
|
|
|
del gms[guildStr][str(g['gm'])]
|
|
|
|
|
del lookup[guildStr][str(r.id)]
|
|
|
|
|
del data[guildStr][timeslot]
|
|
|
|
|
#### Bot will delete the game role. The on_guild_role_delete event listener will then recognise this deletion and synchronise the categories and data files accordingly.
|
|
|
|
|
|
|
|
|
|
if 'timeslots' not in conf[guildStr]: conf[guildStr]['timeslots'] = {}
|
|
|
|
|
tsDict = {k: conf[guildStr]['timeslots'][k] for k in data[guildStr] if data[guildStr][k]}
|
|
|
|
@ -549,15 +500,6 @@ class GameManagement(commands.Cog, name='Game Management'):
|
|
|
|
|
await c.send(
|
|
|
|
|
content = f'```All games for time slot `{conf[guildStr]["timeslots"][timeslot]}` have been purged.```'
|
|
|
|
|
)
|
|
|
|
|
yaml_dump(gms,gmFile)
|
|
|
|
|
yaml_dump(lookup,lookupFile)
|
|
|
|
|
yaml_dump(data,dataFile)
|
|
|
|
|
yaml_dump(categories,categoriesFile)
|
|
|
|
|
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')
|
|
|
|
|
await self.client.slash.sync_all_commands()
|
|
|
|
|
|
|
|
|
|
def setup(client):
|
|
|
|
|
client.add_cog(GameManagement(client))
|