forked from viveksantayana/geas-bot
Finished making purge command (untested)
Made all feedback from /commands hidden messages.
This commit is contained in:
parent
f80a37f949
commit
615e3fa169
@ -79,10 +79,10 @@ class Configuration(commands.Cog, name='Configuration Commands'):
|
||||
)
|
||||
async def _config_roles(self, ctx:SlashContext, key:str, role_exists:bool, role:discord.Role=None):
|
||||
if role_exists and role is None:
|
||||
await ctx.send(f'```If the role you want to assign to `{key}` already exists, you must assign it. If it does not exist, the Bot will create one.```')
|
||||
await ctx.send(f'```If the role you want to assign to `{key}` already exists, you must assign it. Please select a role to assign.```',hidden=True)
|
||||
return
|
||||
if not role_exists and role is not None:
|
||||
await ctx.send(f'```You have specified a role to assign to `{key}` but have also specified it does not exist. If a role already exists, indicate it. If it does not exist, do not assign a role.```')
|
||||
await ctx.send(f'```You have specified a role to assign to `{key}` but have also specified it does not exist. If a role does not exist, do not assign a role.```',hidden=True)
|
||||
return
|
||||
r = role
|
||||
if not role_exists:
|
||||
@ -105,7 +105,7 @@ class Configuration(commands.Cog, name='Configuration Commands'):
|
||||
conf[str(ctx.guild.id)]['roles'] = {}
|
||||
conf[str(ctx.guild.id)]['roles'][key] = int(r.id)
|
||||
yaml_dump(conf, configFile)
|
||||
await ctx.send(f'```The `{key}` role for the guild `{ctx.guild.name}` has been set to `{r.name}`.```\n{r.mention}')
|
||||
await ctx.send(f'```The `{key}` role for the guild `{ctx.guild.name}` has been set to `{r.name}`.```\n{r.mention}',hidden=True)
|
||||
if all(['bot' in yaml_load(configFile)[x]['roles'] for x in yaml_load(configFile)]):
|
||||
if all([len(yaml_load(configFile)[x]['timeslots']) > 0 for x in yaml_load(configFile)]):
|
||||
if self.client.get_cog('Game Setup') is None:
|
||||
@ -162,10 +162,10 @@ class Configuration(commands.Cog, name='Configuration Commands'):
|
||||
)
|
||||
async def _config_channels(self, ctx:SlashContext, key:str, channel_exists:bool, channel:discord.TextChannel=None):
|
||||
if channel_exists and channel is None:
|
||||
await ctx.send(f'```If the channel you want to assign to `{key}` already exists, you must assign it. If it does not exist, the Bot will create one.```')
|
||||
await ctx.send(f'```If the channel you want to assign to `{key}` already exists, you must assign it. Please select a role to assign.```',hidden=True)
|
||||
return
|
||||
if not channel_exists and channel is not None:
|
||||
await ctx.send(f'```You have specified a channel to assign to `{key}` but have also specified it does not exist. If a channel already exists, indicate it. If it does not exist, do not assign a channel.```')
|
||||
await ctx.send(f'```You have specified a channel to assign to `{key}` but have also specified it does not exist. If a channel does not exist, do not assign a channel.```',hidden=True)
|
||||
return
|
||||
c = channel
|
||||
if not channel_exists:
|
||||
@ -185,7 +185,7 @@ class Configuration(commands.Cog, name='Configuration Commands'):
|
||||
conf[str(ctx.guild.id)]['channels'] = {}
|
||||
conf[str(ctx.guild.id)]['channels'][key] = int(c.id)
|
||||
yaml_dump(conf, configFile)
|
||||
await ctx.send(f'```The `{key}` channel for the guild `{ctx.guild.name}` has been set to `{c.name}`.\n\nAll permission overrides for the channel have been reset. Remember to set the appropriate permissions for your guild.```\n{c.mention}')
|
||||
await ctx.send(f'```The `{key}` channel for the guild `{ctx.guild.name}` has been set to `{c.name}`.\n\nAll permission overrides for the channel have been reset. Remember to set the appropriate permissions for your guild.```\n{c.mention}',hidden=True)
|
||||
|
||||
@cog_ext.cog_subcommand(
|
||||
base='config',
|
||||
@ -228,7 +228,7 @@ class Configuration(commands.Cog, name='Configuration Commands'):
|
||||
conf[str(ctx.guild.id)]['notifications'] = {}
|
||||
conf[str(ctx.guild.id)]['notifications'][channel] = notifications
|
||||
yaml_dump(conf, configFile)
|
||||
await ctx.send(f'```Notifications for posts in the `{channel}` channel for the guild `{ctx.guild.name}` have been set to `{notifications}`.```')
|
||||
await ctx.send(f'```Notifications for posts in the `{channel}` channel for the guild `{ctx.guild.name}` have been set to `{notifications}`.```',hidden=True)
|
||||
|
||||
@cog_ext.cog_subcommand(
|
||||
base='config',
|
||||
@ -258,16 +258,16 @@ class Configuration(commands.Cog, name='Configuration Commands'):
|
||||
async def _config_timeslots_add(self, ctx:SlashContext, key:str, name:str):
|
||||
sanitisedKey = re.sub(r"\W+",'', key[:9].lower())
|
||||
if not key.isalnum():
|
||||
await ctx.send(f'```Key value {key} is not a valid alphanumeric time code. Sanitising to `{sanitisedKey}`.```')
|
||||
await ctx.send(f'```Key value {key} is not a valid alphanumeric time code. Sanitising to `{sanitisedKey}`.```',hidden=True)
|
||||
conf = yaml_load(configFile)
|
||||
if 'timeslots' not in conf[str(ctx.guild.id)]:
|
||||
conf[str(ctx.guild.id)]['timeslots'] = {}
|
||||
if sanitisedKey in conf[str(ctx.guild.id)]['timeslots']:
|
||||
await ctx.send(f'```Key value {sanitisedKey} has already been defined for guild `{ctx.guild.name}` for `{conf[str(ctx.guild.id)]["timeslots"][sanitisedKey]}`. Please use the `remove` or `modify` sub-commands to amend it.```')
|
||||
await ctx.send(f'```Key value {sanitisedKey} has already been defined for guild `{ctx.guild.name}` for `{conf[str(ctx.guild.id)]["timeslots"][sanitisedKey]}`. Please use the `remove` or `modify` sub-commands to amend it.```',hidden=True)
|
||||
return
|
||||
conf[str(ctx.guild.id)]['timeslots'][sanitisedKey] = name
|
||||
yaml_dump(conf, configFile)
|
||||
await ctx.send(f'```Timeslot `{name}` with the key `{sanitisedKey}` has been added for the guild `{ctx.guild.name}`.```')
|
||||
await ctx.send(f'```Timeslot `{name}` with the key `{sanitisedKey}` has been added for the guild `{ctx.guild.name}`.```',hidden=True)
|
||||
if all([len(yaml_load(configFile)[x]['timeslots']) > 0 for x in yaml_load(configFile)]):
|
||||
if self.client.get_cog('Manipulate Timeslots') is None:
|
||||
loadCog(f'./{cogsDir}/slashcommands/secondary/manipulate_timeslots.py')
|
||||
@ -316,17 +316,17 @@ class Configuration(commands.Cog, name='Configuration Commands'):
|
||||
await ctx.send(f'```If the role for membership type `{name}` already exists, you must assign it. If it does not exist, the Bot will create one.```')
|
||||
return
|
||||
if not role_exists and role is not None:
|
||||
await ctx.send(f'```You have specified a role for `{name}` does not already exist but have also specified a role to assign. Please either assign a role if it exists, or leave it blank if does not.```')
|
||||
await ctx.send(f'```You have specified a role for `{name}` does not already exist but have also specified a role to assign. Please either assign a role if it exists, or leave it blank if does not.```',hidden=True)
|
||||
return
|
||||
conf = yaml_load(configFile)
|
||||
if 'membership' not in conf[str(ctx.guild.id)]:
|
||||
conf[str(ctx.guild.id)]['membership'] = []
|
||||
if role is not None:
|
||||
if role.id in conf[str(ctx.guild.id)]['membership']:
|
||||
await ctx.send(f'```The role {name} has already been assigned to a membership type for guild `{ctx.guild.name}`. Please use the `remove` sub-command to delete it or assign a different role.```')
|
||||
await ctx.send(f'```The role {name} has already been assigned to a membership type for guild `{ctx.guild.name}`. Please use the `remove` sub-command to delete it or assign a different role.```',hidden=True)
|
||||
return
|
||||
if any([ctx.guild.get_role(m).name == name for m in conf[str(ctx.guild.id)]['membership']]):
|
||||
await ctx.send(f'```The membership type {name} has already been assigned a role for guild `{ctx.guild.name}`. Please use the `remove` sub-command to delete the role or assign a different membership type.```')
|
||||
await ctx.send(f'```The membership type {name} has already been assigned a role for guild `{ctx.guild.name}`. Please use the `remove` sub-command to delete the role or assign a different membership type.```',hidden=True)
|
||||
return
|
||||
if not role_exists:
|
||||
r = await ctx.guild.create_role(
|
||||
@ -344,7 +344,7 @@ class Configuration(commands.Cog, name='Configuration Commands'):
|
||||
)
|
||||
conf[str(ctx.guild.id)]['membership'].append(role.id) if role is not None else conf[str(ctx.guild.id)]['membership'].append(r.id)
|
||||
yaml_dump(conf, configFile)
|
||||
await ctx.send(f'```Membership type `{role.name if role is not None else r.name}` has been registered for the guild `{ctx.guild.name}`.```')
|
||||
await ctx.send(f'```Membership type `{role.name if role is not None else r.name}` has been registered for the guild `{ctx.guild.name}`.```',hidden=True)
|
||||
if all([len(yaml_load(configFile)[x]['membership']) > 0 for x in yaml_load(configFile)]):
|
||||
if self.client.get_cog('Edit Membership') is None:
|
||||
loadCog(f'./{cogsDir}/slashcommands/secondary/edit_membership.py')
|
||||
@ -382,7 +382,7 @@ class Configuration(commands.Cog, name='Configuration Commands'):
|
||||
not_required:str=None,
|
||||
optional:str=None
|
||||
):
|
||||
await ctx.send(f'```You entered: name = {required}, not_required = {not_required}, and optional = {optional}```')
|
||||
await ctx.send(f'```You entered: name = {required}, not_required = {not_required}, and optional = {optional}```',hidden=True)
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(Configuration(client))
|
@ -64,9 +64,9 @@ class EditMembership(commands.Cog, name='Edit Membership'):
|
||||
output = f'Role `{role.name}` is not a registered membership role in the guild `{ctx.guild.name}`. Please select a valid membership role.\n\n Eligible roles are:\n'
|
||||
for m in conf[str(ctx.guild.id)]['membership']:
|
||||
output = ''.join([output, f'\n{ctx.guild.get_role(m).name}'])
|
||||
await ctx.send(''.join(['```',output,'```']))
|
||||
await ctx.send(''.join(['```',output,'```']),hidden=True)
|
||||
else:
|
||||
await ctx.send(f'```No roles have been registered as membership types for the guild `{ctx.guild.name}`.```')
|
||||
await ctx.send(f'```No roles have been registered as membership types for the guild `{ctx.guild.name}`.```',hidden=True)
|
||||
|
||||
@cog_ext.cog_subcommand(
|
||||
base='config',
|
||||
@ -87,9 +87,9 @@ class EditMembership(commands.Cog, name='Edit Membership'):
|
||||
output = f'The following membership types have been registered for the guild {ctx.guild.name}:\n'
|
||||
for m in conf[str(ctx.guild.id)]['membership']:
|
||||
output = ''.join([output, f'\n{ctx.guild.get_role(m).name}'])
|
||||
await ctx.send(''.join(['```',output,'```']))
|
||||
await ctx.send(''.join(['```',output,'```']),hidden=True)
|
||||
else:
|
||||
await ctx.send(f'```No roles have been registered as membership types for the guild `{ctx.guild.name}`.```')
|
||||
await ctx.send(f'```No roles have been registered as membership types for the guild `{ctx.guild.name}`.```',hidden=True)
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(EditMembership(client))
|
@ -5,11 +5,13 @@ import discord # Main Lib
|
||||
from discord.ext import commands # Commands module
|
||||
from discord_slash import SlashCommand, SlashContext, cog_ext, utils # Slash Command Library
|
||||
from discord_slash.utils.manage_commands import create_choice, create_option, create_permission # Slash Command features
|
||||
from discord_slash.model import SlashCommandPermissionType
|
||||
from discord_slash.model import SlashCommandPermissionType, ButtonStyle
|
||||
from discord_slash.client import SlashCommand
|
||||
from discord_slash.utils.manage_components import create_select, create_select_option, create_actionrow, wait_for_component, create_button, create_actionrow
|
||||
|
||||
import re
|
||||
|
||||
from bot import configFile, yaml_load, yaml_dump, reloadCog, cogsDir, unloadCog, dataFile, lookupFile, gmFile
|
||||
from bot import configFile, yaml_load, yaml_dump, reloadCog, cogsDir, unloadCog, dataFile, lookupFile, gmFile, categoriesFile
|
||||
|
||||
class GameManagement(commands.Cog, name='Game Management'):
|
||||
def __init__(self, client):
|
||||
@ -48,15 +50,16 @@ class GameManagement(commands.Cog, name='Game Management'):
|
||||
gms = yaml_load(gmFile)
|
||||
lookup = yaml_load(lookupFile)
|
||||
guildStr = str(ctx.guild.id)
|
||||
if str(game_role.id) not in lookup[guildStr]:
|
||||
await ctx.send(f'```This is not a valid game role. Please mention a role that is associated with a game.```')
|
||||
rStr = str(game_role.id)
|
||||
if rStr not in lookup[guildStr]:
|
||||
await ctx.send(f'```This is not a valid game role. Please mention a role that is associated with a game.```', hidden=True)
|
||||
return
|
||||
game_title = lookup[guildStr][str(game_role.id)]['game_title']
|
||||
time = lookup[guildStr][str(game_role.id)]['time']
|
||||
c = ctx.guild.get_channel(lookup[guildStr][str(game_role.id)]['category'])
|
||||
gm = lookup[guildStr][str(game_role.id)]['gm']
|
||||
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][str(game_role.id)]
|
||||
del data[guildStr][time][rStr]
|
||||
if c is not None:
|
||||
channelsFound = True
|
||||
for t in ctx.guild.text_channels:
|
||||
@ -66,18 +69,18 @@ class GameManagement(commands.Cog, name='Game Management'):
|
||||
if v.category == c:
|
||||
await v.delete(reason=f'/game delete command issued by `{ctx.author.display_name}`')
|
||||
await c.delete(reason=f'/game delete command issued by `{ctx.author.display_name}`')
|
||||
lookup[guildStr].pop(str(game_role.id), None)
|
||||
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.'])
|
||||
await ctx.send(f'```{output}```')
|
||||
await ctx.send(f'```{output}```',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)]:
|
||||
gms[guildStr].pop(str(gm))
|
||||
del gms[guildStr][str(gm)]
|
||||
yaml_dump(lookup, lookupFile)
|
||||
yaml_dump(data, dataFile)
|
||||
yaml_dump(gms, gmFile)
|
||||
@ -167,7 +170,7 @@ class GameManagement(commands.Cog, name='Game Management'):
|
||||
):
|
||||
await ctx.channel.trigger_typing()
|
||||
if all(x is None for x in [timeslot, gm, max_players, game_title, min_players, current_players, system, platform]):
|
||||
await ctx.send(f'```No parameters have been entered to modify the game.```')
|
||||
await ctx.send(f'```No parameters have been entered to modify the game.```',hidden=True)
|
||||
return
|
||||
conf = yaml_load(configFile)
|
||||
data = yaml_load(dataFile)
|
||||
@ -190,16 +193,16 @@ class GameManagement(commands.Cog, name='Game Management'):
|
||||
return
|
||||
if timeslot is not None:
|
||||
if time not in conf[guildStr]['timeslots']:
|
||||
await ctx.send(f'```Time code `{timeslot}` is not recognised. Please enter a valid time code to register the game. use `/config timeslots list` to get a list of valid time codes.```')
|
||||
await ctx.send(f'```Time code `{timeslot}` is not recognised. Please enter a valid time code to register the game. use `/config timeslots list` to get a list of valid time codes.```',hidden=True)
|
||||
return
|
||||
if any(x is not None and x < 0 for x in [min_players, max_players, current_players]):
|
||||
await ctx.send(f'```You cannot enter negative integers for the number of players.```')
|
||||
await ctx.send(f'```You cannot enter negative integers for the number of players.```',hidden=True)
|
||||
return
|
||||
if min_players and max_players and min_players > max_players:
|
||||
await ctx.send(f'```The minimum number of players cannot exceed the maximum number of players.```')
|
||||
await ctx.send(f'```The minimum number of players cannot exceed the maximum number of players.```',hidden=True)
|
||||
return
|
||||
if current_players and max_players and current_players > max_players:
|
||||
await ctx.send(f'```The number of reserved spaces cannot exceed the maximum number of players.```')
|
||||
await ctx.send(f'```The number of reserved spaces cannot exceed the maximum number of players.```',hidden=True)
|
||||
return
|
||||
|
||||
# Infer Old Data
|
||||
@ -211,9 +214,11 @@ class GameManagement(commands.Cog, name='Game Management'):
|
||||
if time != old_time:
|
||||
result = ''.join([result,f"The game's time slot has changed from {conf[guildStr]['timeslots'][time]} to {conf[guildStr]['timeslots'][time]}.\n"])
|
||||
del data[guildStr][old_time][rStr]
|
||||
if not data[guildStr][old_time]:
|
||||
del data[guildStr][old_time]
|
||||
if game_title and game_title != old_data['game_title']:
|
||||
if game_title in [x['game_title'] for x in lookup[guildStr].values()] and time in [x['time'] for x in lookup[guildStr].values()]:
|
||||
await ctx.send(f'```The target game `{game_title}` has already been created for the time slot `{conf[guildStr]["timeslots"][time]}`. Please avoud duplicates, or use the `modify` sub-command to edit the existing game.```')
|
||||
await ctx.send(f'```The target game `{game_title}` has already been created for the time slot `{conf[guildStr]["timeslots"][time]}`. Please avoud duplicates, or use the `modify` sub-command to edit the existing game.```',hidden=True)
|
||||
return
|
||||
result = ''.join([result,f"The game's title has been updated to {game_title}\n"])
|
||||
game_title = old_data['game_title'] if not game_title else game_title
|
||||
@ -232,6 +237,8 @@ class GameManagement(commands.Cog, name='Game Management'):
|
||||
if gm and gm.id != old_data['gm']:
|
||||
result = ''.join([result,f"The GM has been updated to {gm.display_name}.\n"])
|
||||
gms[guildStr][str(old_data['gm'])].remove(r.id)
|
||||
if not gms[guildStr][str(old_data['gm'])]:
|
||||
del gms[guildStr][str(old_data['gm'])]
|
||||
gm = await ctx.guild.fetch_member(old_data['gm']) if not gm else gm
|
||||
if r not in gm.roles:
|
||||
await gm.add_roles(r)
|
||||
@ -332,9 +339,10 @@ class GameManagement(commands.Cog, name='Game Management'):
|
||||
output = ''.join([output,f'Min Players: {min_players}\n'if min_players is not None else ''])
|
||||
output = ''.join([output,f'Current Players: {current_players if current_players else "0"}\n'])
|
||||
output = ''.join([output,f'Platform: {platform}```' if platform is not None else '```'])
|
||||
await ctx.send(result)
|
||||
output = ''.join([output,f'\n\n{gm.mention} | {r.mention}'])
|
||||
await ctx.send(result,hidden=True)
|
||||
o = await t.send(output)
|
||||
await o.pin(reason=f'/game create command issued by `{ctx.author.display_name}`')
|
||||
await o.pin(reason=f'/game modify command issued by `{ctx.author.display_name}`')
|
||||
data[guildStr][time][rStr] = {
|
||||
'game_title': game_title,
|
||||
'gm': gm.id,
|
||||
@ -364,5 +372,122 @@ class GameManagement(commands.Cog, name='Game Management'):
|
||||
yaml_dump(lookup,lookupFile)
|
||||
yaml_dump(gms,gmFile)
|
||||
|
||||
@cog_ext.cog_subcommand(
|
||||
base='game',
|
||||
# subcommand_group='',
|
||||
name='purge',
|
||||
description='Delete all games in a given timeslot.',
|
||||
# base_description='Commands for setting up and removing games on the Guild.',
|
||||
# base_default_permission=False,
|
||||
# base_permissions=permissions,
|
||||
# subcommand_group_description='Adds a time slot available to the channel for games.',
|
||||
guild_ids=guild_ids,
|
||||
)
|
||||
async def _purge(
|
||||
self,
|
||||
ctx:SlashContext
|
||||
):
|
||||
await ctx.channel.trigger_typing()
|
||||
conf = yaml_load(configFile)
|
||||
data = yaml_load(dataFile)
|
||||
lookup = yaml_load(lookupFile)
|
||||
gms = yaml_load(gmFile)
|
||||
categories = yaml_load(categoriesFile)
|
||||
guildStr = str(ctx.guild.id)
|
||||
|
||||
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}`')
|
||||
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]
|
||||
|
||||
if 'timeslots' not in conf[guildStr]:
|
||||
conf[guildStr]['timeslots'] = {}
|
||||
tsDict = {k: conf[guildStr]['timeslots'][k] for k in conf[guildStr]['timeslots'] if data[k]}
|
||||
optionsList = [create_select_option(label=tsDict[x], value=x, description=x) for x in tsDict].insert(0, create_select_option(label='All Timeslots', value='--all', description='--all'))
|
||||
try:
|
||||
m = await ctx.send(
|
||||
content='```Select which time slot for which you would like to purge all games.```',
|
||||
delete_after=5,
|
||||
components=[
|
||||
create_actionrow(
|
||||
create_select(
|
||||
placeholder='Time Slot',
|
||||
options= optionsList,
|
||||
min_values=1,
|
||||
max_values=1
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
while True:
|
||||
select_ctx = await wait_for_component(self.client,messages=m, timeout=5)
|
||||
if select_ctx.author != ctx.author:
|
||||
await select_ctx.send(f'```Invalid response: you are not the person who issued the command.```', hidden=True)
|
||||
else:
|
||||
break
|
||||
await m.delete()
|
||||
[timeslot] = select_ctx.selected_options
|
||||
except asyncio.TimeoutError:
|
||||
await ctx.send(f'```Error: Command timed out.```', hidden=True)
|
||||
return
|
||||
if timeslot == '--all':
|
||||
m = await ctx.send(
|
||||
content=f'```You are attempting to purge games for all channels. This will delete every game currently running for guild {ctx.guild.name}. Are you sure?```',
|
||||
delete_after=5,
|
||||
components=[
|
||||
create_actionrow(
|
||||
create_button(
|
||||
style=ButtonStyle.green,
|
||||
label='Yes',
|
||||
emoji='👍',
|
||||
custom_id='purge_yes',
|
||||
),
|
||||
create_button(
|
||||
style=ButtonStyle.red,
|
||||
label='No',
|
||||
emoji='👎',
|
||||
custom_id='purge_no',
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
while True:
|
||||
button_ctx = await wait_for_component(self.client, messages=m, timeout=5)
|
||||
if button_ctx.author != ctx.author:
|
||||
await button_ctx.send(f'```Invalid response: you are not the person who issued the command.```', hidden=True)
|
||||
else:
|
||||
break
|
||||
await m.delete()
|
||||
if select_ctx.custom_id == 'purge_no':
|
||||
await ctx.send(f'```The action `/game purge --all` has been aborted.```',hidden=True)
|
||||
return
|
||||
await ctx.channel.trigger_typing()
|
||||
for t in data[guildStr]:
|
||||
await purgeGames(ctx=ctx, timeslot=t)
|
||||
await ctx.send(
|
||||
content = '```All games for all time slots have been purged.```',
|
||||
hidden=True
|
||||
)
|
||||
else:
|
||||
await purgeGames(ctx=ctx, timeslot=timeslot)
|
||||
await ctx.send(
|
||||
content = f'```All games for time slot `{conf[guildStr]["timeslots"][timeslot]}` have been purged.```',
|
||||
hidden=True
|
||||
)
|
||||
yaml_dump(gms,gmFile)
|
||||
yaml_dump(lookup,lookupFile)
|
||||
yaml_dump(data,dataFile)
|
||||
yaml_dump(categories,categoriesFile)
|
||||
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(GameManagement(client))
|
@ -114,26 +114,26 @@ class GameSetup(commands.Cog, name='Game Setup'):
|
||||
if 'roles' not in conf[guildStr]:
|
||||
conf[guildStr]['roles'] = {}
|
||||
if 'bot' not in conf[guildStr]['roles']:
|
||||
await ctx.send(f'```\`Bot` role for guild `{ctx.guild.name}` has not been defined. Cannot configure game.```')
|
||||
await ctx.send(f'```\`Bot` role for guild `{ctx.guild.name}` has not been defined. Cannot configure game.```',hidden=True)
|
||||
return
|
||||
if 'timeslots' not in conf[guildStr]:
|
||||
conf[guildStr]['timeslots'] = {}
|
||||
if time not in conf[guildStr]['timeslots']:
|
||||
await ctx.send(f'```Time code `{timeslot}` is not recognised. Please enter a valid time code to register the game. use `/config timeslots list` to get a list of valid time codes.```')
|
||||
await ctx.send(f'```Time code `{timeslot}` is not recognised. Please enter a valid time code to register the game. use `/config timeslots list` to get a list of valid time codes.```',hidden=True)
|
||||
return
|
||||
if min_players and min_players > max_players:
|
||||
await ctx.send(f'```The minimum number of players cannot exceed the maximum number of players.```')
|
||||
await ctx.send(f'```The minimum number of players cannot exceed the maximum number of players.```',hidden=True)
|
||||
return
|
||||
if current_players and current_players > max_players:
|
||||
await ctx.send(f'```The number of reserved spaces cannot exceed the maximum number of players.```')
|
||||
await ctx.send(f'```The number of reserved spaces cannot exceed the maximum number of players.```',hidden=True)
|
||||
return
|
||||
if any(x is not None and x < 0 for x in [min_players, max_players, current_players]):
|
||||
await ctx.send(f'```You cannot enter negative integers for the number of players.```')
|
||||
await ctx.send(f'```You cannot enter negative integers for the number of players.```',hidden=True)
|
||||
return
|
||||
if guildStr not in lookup:
|
||||
lookup[guildStr] = {}
|
||||
if game_title in [x['game_title'] for x in lookup[guildStr].values()] and time in [x['time'] for x in lookup[guildStr].values()]:
|
||||
await ctx.send(f'```Game `{game_title}` has already been created for the time slot `{conf[guildStr]["timeslots"][time]}`. Please avoud duplicates, or use the `modify` sub-command to edit the existing game.```')
|
||||
await ctx.send(f'```Game `{game_title}` has already been created for the time slot `{conf[guildStr]["timeslots"][time]}`. Please avoud duplicates, or use the `modify` sub-command to edit the existing game.```',hidden=True)
|
||||
return
|
||||
if guildStr not in data:
|
||||
data[guildStr] = {}
|
||||
@ -250,7 +250,8 @@ class GameSetup(commands.Cog, name='Game Setup'):
|
||||
output = ''.join([output,f'Min Players: {min_players}\n'if min_players is not None else ''])
|
||||
output = ''.join([output,f'Current Players: {current_players if current_players else "0"}\n'])
|
||||
output = ''.join([output,f'Platform: {platform}```' if platform is not None else '```'])
|
||||
await ctx.send(result)
|
||||
output = ''.join([output,f'\n\n{gm.mention} | {r.mention}'])
|
||||
await ctx.send(result,hidden=True)
|
||||
o = await t.send(output)
|
||||
await o.pin(reason=f'/game create command issued by `{ctx.author.display_name}`')
|
||||
data[guildStr][time][str(r.id)] = {
|
||||
|
@ -86,7 +86,7 @@ class ManipulateTimeslots(commands.Cog, name='Manipulate Timeslots'):
|
||||
await ctx.send(f'```Error: Command timed out.```', hidden=True)
|
||||
return
|
||||
if timeslot not in data[guildStr] or not data[guildStr][timeslot]:
|
||||
await ctx.send(f'```Timeslot {conf[guildStr]["timeslots"][timeslot]} with the key `{timeslot}` has been deleted for the guild `{ctx.guild.name}`.```')
|
||||
await ctx.send(f'```Timeslot {conf[guildStr]["timeslots"][timeslot]} with the key `{timeslot}` has been deleted for the guild `{ctx.guild.name}`.```',hidden=True)
|
||||
conf[guildStr]['timeslots'].pop(timeslot, None)
|
||||
yaml_dump(conf, configFile)
|
||||
if not all([x['timeslots'] for x in yaml_load(configFile).values()]):
|
||||
@ -97,7 +97,7 @@ class ManipulateTimeslots(commands.Cog, name='Manipulate Timeslots'):
|
||||
unloadCog(f'./{cogsDir}/slashcommands/secondary/game_setup.py')
|
||||
await self.client.slash.sync_all_commands()
|
||||
else:
|
||||
await ctx.send('```Error: You cannot delete a timeslot that has existing game entries. Please delete all games first.```')
|
||||
await ctx.send('```Error: You cannot delete a timeslot that has existing game entries. Please delete all games first.```',hidden=True)
|
||||
|
||||
@cog_ext.cog_subcommand(
|
||||
base='config',
|
||||
@ -130,16 +130,16 @@ class ManipulateTimeslots(commands.Cog, name='Manipulate Timeslots'):
|
||||
if 'timeslots' not in conf[guildStr]:
|
||||
conf[guildStr]['timeslots'] = {}
|
||||
if key in conf[guildStr]['timeslots']:
|
||||
await ctx.send(f'```Timeslot {conf[guildStr]["timeslots"][key]} with the key `{key}` has been renamed to {name} for the guild `{ctx.guild.name}`.```')
|
||||
await ctx.send(f'```Timeslot {conf[guildStr]["timeslots"][key]} with the key `{key}` has been renamed to {name} for the guild `{ctx.guild.name}`.```',hidden=True)
|
||||
conf[guildStr]['timeslots'][key] = name
|
||||
yaml_dump(conf, configFile)
|
||||
elif len(conf[guildStr]['timeslots']) > 0:
|
||||
output = f'```Timeslot `{key}` was not found in the guild `{ctx.guild.name}`. Please enter a valid key.\n\n Available timeslots are:\n(key): (timeslot name)'
|
||||
for c in conf[guildStr]['timeslots']:
|
||||
output = ''.join([output, f'\n {c}: {conf[guildStr]["timeslots"][c]}'])
|
||||
await ctx.send(''.join([output,'```']))
|
||||
await ctx.send(''.join([output,'```']),hidden=True)
|
||||
else:
|
||||
await ctx.send(f'```No timeslots have been defined for the guild `{ctx.guild.name}`.```')
|
||||
await ctx.send(f'```No timeslots have been defined for the guild `{ctx.guild.name}`.```',hidden=True)
|
||||
|
||||
@cog_ext.cog_subcommand(
|
||||
base='config',
|
||||
@ -163,7 +163,7 @@ class ManipulateTimeslots(commands.Cog, name='Manipulate Timeslots'):
|
||||
output = ''.join([output, f'\n {c}: {conf[guildStr]["timeslots"][c]}'])
|
||||
await ctx.send(''.join([output,'```']))
|
||||
else:
|
||||
await ctx.send(f'```No timeslots have been defined for the guild `{ctx.guild.name}`.```')
|
||||
await ctx.send(f'```No timeslots have been defined for the guild `{ctx.guild.name}`.```',hidden=True)
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(ManipulateTimeslots(client))
|
Loading…
Reference in New Issue
Block a user