From c5be0002ac4cb3f8808e571a33d4624b43ff55ea Mon Sep 17 00:00:00 2001 From: Vivek Santayana Date: Sun, 18 Jul 2021 01:28:06 +0100 Subject: [PATCH] Finished abstraction of /config subcommands --- TODO.md | 2 + app/cogs/slashcommands/config.py | 315 ++++++++----------------------- app/data/config.yml | 9 +- 3 files changed, 88 insertions(+), 238 deletions(-) diff --git a/TODO.md b/TODO.md index 52bf4e7..6d53b06 100644 --- a/TODO.md +++ b/TODO.md @@ -54,6 +54,8 @@ > - [x] student role (role group) > - [x] help notifications (notification group) > - [x] signup notifications (notification group) +- [ ] Set up timeslots +- [ ] Delete timeslots - [ ] Set up command permissions > - [ ] Slash Commands >> - [x] Admin Commands diff --git a/app/cogs/slashcommands/config.py b/app/cogs/slashcommands/config.py index 60705e0..e4da52c 100644 --- a/app/cogs/slashcommands/config.py +++ b/app/cogs/slashcommands/config.py @@ -23,305 +23,150 @@ class Configuration(commands.Cog): for admin in conf[guildStr]['roles']['admin']: permissions[int(guildStr)].append(create_permission(id=admin,id_type=SlashCommandPermissionType.ROLE,permission=True)) - @cog_ext.cog_slash( - name='hello', - description='Test command to see if registration works.', + @cog_ext.cog_subcommand( + base='config', + # subcommand_group='role', + name='roles', + description='Designates the various key roles referenced by the Bot.', + base_description='Commands for configuring the various parameters of the Guild.', + base_default_permission=False, + base_permissions=permissions, + # subcommand_group_description='Designates the various key command roles for the guild.', guild_ids=guild_ids, options=[ create_option( - name='input', - description='Choose a phrase that best goes with the opening Hello', + name='key', + description='The name of the role parameter being assigned.', option_type=3, required=True, choices=[ create_choice( - name='...there', - value='there' + name='`Bot` role', + value='bot' ), create_choice( - name='...world!', - value='world' + name='`Committee` role', + value='committee' ), create_choice( - name='...beautiful!', - value='beautiful' + name='`Newcomer` role', + value='newcomer' + ), + create_choice( + name='`Returning Player` role', + value='returning_player' + ), + create_choice( + name='`Student` role', + value='student' ) - ], - ) - ] - ) - async def _hello(self, ctx:SlashContext, input): - await ctx.send(f'{input}') - - @cog_ext.cog_subcommand( - base='config', - subcommand_group='role', - name='bot', - description='Designate the role on the guild which the dice bots use to access game text channels.', - base_description='Commands for configuring the various parameters of the Guild', - base_default_permission=False, - base_permissions=permissions, - subcommand_group_description='Designates the various key command roles for the guild.', - guild_ids=guild_ids, - options=[ + ] + ), create_option( name='role', - description='The role assigned to dice bots to access game channels.', + description='The role assigned to the parameter.', option_type=8, required=True ) ] ) - async def _config_role_bot(self, ctx:SlashContext, role:discord.Role): + async def _config_roles(self, ctx:SlashContext, key:str, role:discord.Role): conf = yaml_load(configFile) if 'roles' not in conf[str(ctx.guild.id)]: conf[str(ctx.guild.id)]['roles'] = {} - conf[str(ctx.guild.id)]['roles']['bot'] = int(role.id) + conf[str(ctx.guild.id)]['roles'][key] = int(role.id) yaml_dump(conf, configFile) - await ctx.send(f'```The `bot` role for the guild `{ctx.guild.name}` has been set to `{role.name}`.```') + await ctx.send(f'```The `{key}` role for the guild `{ctx.guild.name}` has been set to `{role.name}`.```') @cog_ext.cog_subcommand( base='config', - subcommand_group='role', - name='committee', - description='Designate the role used by committee members.', - # base_description='Commands for configuring the various parameters of the Guild', - # base_default_permission=False, - # base_permissions=permissions, - # subcommand_group_description='Designates the various key command roles for the guild.', - guild_ids=guild_ids, - options=[ - create_option( - name='role', - description='The role assigned to committee members.', - option_type=8, - required=True - ) - ] - ) - async def _config_role_committee(self, ctx:SlashContext, role:discord.Role): - conf = yaml_load(configFile) - if 'roles' not in conf[str(ctx.guild.id)]: - conf[str(ctx.guild.id)]['roles'] = {} - conf[str(ctx.guild.id)]['roles']['committee'] = int(role.id) - yaml_dump(conf, configFile) - await ctx.send(f'```The `committee` role for the guild `{ctx.guild.name}` has been set to `{role.name}`.```') - - @cog_ext.cog_subcommand( - base='config', - subcommand_group='role', - name='newcomer', - description='Role for members new to the guild.', - # base_description='Commands for configuring the various parameters of the Guild', - # base_default_permission=False, - # base_permissions=permissions, - # subcommand_group_description='Designates the various key command roles for the guild.', - guild_ids=guild_ids, - options=[ - create_option( - name='role', - description='The role assigned to new members.', - option_type=8, - required=True - ) - ] - ) - async def _config_role_newcomer(self, ctx:SlashContext, role:discord.Role): - conf = yaml_load(configFile) - if 'roles' not in conf[str(ctx.guild.id)]: - conf[str(ctx.guild.id)]['roles'] = {} - conf[str(ctx.guild.id)]['roles']['newcomer'] = int(role.id) - yaml_dump(conf, configFile) - await ctx.send(f'```The `newcomer` role for the guild `{ctx.guild.name}` has been set to `{role.name}`.```') - - @cog_ext.cog_subcommand( - base='config', - subcommand_group='role', - name='returning_player', - description='Role for returning players re-joining their game.', - # base_description='Commands for configuring the various parameters of the Guild', - # base_default_permission=False, - # base_permissions=permissions, - # subcommand_group_description='Designates the various key command roles for the guild.', - guild_ids=guild_ids, - options=[ - create_option( - name='role', - description='Role for returning players continuing in their games.', - option_type=8, - required=True - ) - ] - ) - async def _config_role_returning_player(self, ctx:SlashContext, role:discord.Role): - conf = yaml_load(configFile) - if 'roles' not in conf[str(ctx.guild.id)]: - conf[str(ctx.guild.id)]['roles'] = {} - conf[str(ctx.guild.id)]['roles']['returning_player'] = int(role.id) - yaml_dump(conf, configFile) - await ctx.send(f'```The `returning player` role for the guild `{ctx.guild.name}` has been set to `{role.name}`.```') - - @cog_ext.cog_subcommand( - base='config', - subcommand_group='role', - name='student', - description='Role for students.', - # base_description='Commands for configuring the various parameters of the Guild', - # base_default_permission=False, - # base_permissions=permissions, - # subcommand_group_description='Designates the various key command roles for the guild.', - guild_ids=guild_ids, - options=[ - create_option( - name='role', - description='The role assigned to students.', - option_type=8, - required=True - ) - ] - ) - async def _config_role_student(self, ctx:SlashContext, role:discord.Role): - conf = yaml_load(configFile) - if 'roles' not in conf[str(ctx.guild.id)]: - conf[str(ctx.guild.id)]['roles'] = {} - conf[str(ctx.guild.id)]['roles']['student'] = int(role.id) - yaml_dump(conf, configFile) - await ctx.send(f'```The `student` role for the guild `{ctx.guild.name}` has been set to `{role.name}`.```') - - @cog_ext.cog_subcommand( - base='config', - subcommand_group='channel', - name='signup', - description='Designate the channel where members can post their sign-up confirmation.', - # base_description='Commands for configuring the various parameters of the Guild', - # base_default_permission=False, - # base_permissions=permissions, - subcommand_group_description='Designates the various key Bot channels for the guild.', - guild_ids=guild_ids, - options=[ - create_option( - name='channel', - description='The channel assigned for members to verify their membership.', - option_type=7, - required=True - ) - ] - ) - async def _config_channel_signup(self, ctx:SlashContext, channel:discord.TextChannel): - conf = yaml_load(configFile) - if 'channels' not in conf[str(ctx.guild.id)]: - conf[str(ctx.guild.id)]['channels'] = {} - conf[str(ctx.guild.id)]['channels']['signup'] = int(channel.id) - yaml_dump(conf, configFile) - await ctx.send(f'```The `signup` channel for the guild `{ctx.guild.name}` has been set to `{channel.name}`.```') - - @cog_ext.cog_subcommand( - base='config', - subcommand_group='channel', - name='modlog', - description='Designate the channel for bot to post notifications for the admins.', + # subcommand_group='channel', + name='channels', + description='Designate the various key channels for the Bot to interact with.', # base_description='Commands for configuring the various parameters of the Guild', # base_default_permission=False, # base_permissions=permissions, # subcommand_group_description='Designates the various key Bot channels for the guild.', guild_ids=guild_ids, options=[ + create_option( + name='key', + description='The name of the channel parameter being assigned.', + option_type=3, + required=True, + choices=[ + create_choice( + name='Help Channel', + value='help' + ), + create_choice( + name='Mod Channel', + value='mod' + ), + create_choice( + name='SIgnup Channel', + value='signup' + ) + ] + ), create_option( name='channel', - description='The channel assigned for moderation notifications.', + description='The channel assigned to the parameter.', option_type=7, required=True ) ] ) - async def _config_channel_mod(self, ctx:SlashContext, channel:discord.TextChannel): + async def _config_channels(self, ctx:SlashContext, key:str, channel:discord.TextChannel): conf = yaml_load(configFile) if 'channels' not in conf[str(ctx.guild.id)]: conf[str(ctx.guild.id)]['channels'] = {} - conf[str(ctx.guild.id)]['channels']['mod'] = int(channel.id) + conf[str(ctx.guild.id)]['channels'][key] = int(channel.id) yaml_dump(conf, configFile) - await ctx.send(f'```The `moderation log` channel for the guild `{ctx.guild.name}` has been set to `{channel.name}`.```') + await ctx.send(f'```The `{key}` channel for the guild `{ctx.guild.name}` has been set to `{channel.name}`.```') @cog_ext.cog_subcommand( base='config', - subcommand_group='channel', - name='help', - description='Designate the hel channel which the bot will monitor for member queries.', + # subcommand_group='notifications', + name='notifications', + description='Configure monitoring and notifications to Committee for member query channels.', # base_description='Commands for configuring the various parameters of the Guild', # base_default_permission=False, # base_permissions=permissions, - # subcommand_group_description='Designates the various key Bot channels for the guild.', + # subcommand_group_description='Configures whether the bot monitors and responds to posts in key channels.', guild_ids=guild_ids, options=[ create_option( name='channel', - description='The channel monitored by the Bot for help queries.', - option_type=7, - required=True - ) - ] - ) - async def _config_channel_help(self, ctx:SlashContext, channel:discord.TextChannel): - conf = yaml_load(configFile) - if 'channels' not in conf[str(ctx.guild.id)]: - conf[str(ctx.guild.id)]['channels'] = {} - conf[str(ctx.guild.id)]['channels']['help'] = int(channel.id) - yaml_dump(conf, configFile) - await ctx.send(f'```The `help` channel for the guild `{ctx.guild.name}` has been set to `{channel.name}`.```') - - @cog_ext.cog_subcommand( - base='config', - subcommand_group='notifications', - name='help', - description='Configure whether the bot monitors the `help` channel and notifies Committee about posts.', - # base_description='Commands for configuring the various parameters of the Guild', - # base_default_permission=False, - # base_permissions=permissions, - subcommand_group_description='Configures whether the bot monitors and responds to posts in key channels.', - guild_ids=guild_ids, - options=[ + description='Select which channel to change notifications for.', + option_type=3, + required=True, + choices=[ + create_choice( + name='Help Channel', + value='help' + ), + create_choice( + name='Signup Channel', + value='signup' + ) + ] + ), create_option( name='notifications', - description='Whether or not the bot monitors the help channel for posts.', + description='Whether or not the bot monitors the channel for posts.', option_type=5, required=True ) ] ) - async def _config_notifications_help(self, ctx:SlashContext, input:bool): + async def _config_notifications(self, ctx:SlashContext, channel:str, notifications:bool): conf = yaml_load(configFile) if 'notifications' not in conf[str(ctx.guild.id)]: conf[str(ctx.guild.id)]['notifications'] = {} - conf[str(ctx.guild.id)]['notifications']['help'] = input + conf[str(ctx.guild.id)]['notifications'][channel] = notifications yaml_dump(conf, configFile) - await ctx.send(f'```Notifications for posts in the `help` channel for the guild `{ctx.guild.name}` has been set to `{input}`.```') - - @cog_ext.cog_subcommand( - base='config', - subcommand_group='notifications', - name='signup', - description='Configure whether the bot monitors the `signup` channel and notifies Committee about posts.', - # base_description='Commands for configuring the various parameters of the Guild', - # base_default_permission=False, - # base_permissions=permissions, - subcommand_group_description='Configures whether the bot monitors and responds to posts in key channels.', - guild_ids=guild_ids, - options=[ - create_option( - name='notifications', - description='Whether or not the bot monitors the help channel for posts.', - option_type=5, - required=True - ) - ] - ) - async def _config_notifications_signup(self, ctx:SlashContext, input:bool): - conf = yaml_load(configFile) - if 'notifications' not in conf[str(ctx.guild.id)]: - conf[str(ctx.guild.id)]['notifications'] = {} - conf[str(ctx.guild.id)]['notifications']['signup'] = input - yaml_dump(conf, configFile) - await ctx.send(f'```Notifications for posts in the `signup` channel for the guild `{ctx.guild.name}` has been set to `{input}`.```') + await ctx.send(f'```Notifications for posts in the `{channel}` channel for the guild `{ctx.guild.name}` have been set to `{notifications}`.```') def setup(client): client.add_cog(Configuration(client)) \ No newline at end of file diff --git a/app/data/config.yml b/app/data/config.yml index 4fb638a..9a2d40f 100644 --- a/app/data/config.yml +++ b/app/data/config.yml @@ -1,16 +1,19 @@ '864651943820525609': channels: + help: 866110872584978443 mod: 865662560225067018 + signup: 866110421592965171 configured: false membership: {} name: Test notifications: - help: null - signup: null + help: true + signup: true owner: 493694762210033664 prefix: '-' roles: admin: - 864661232005939280 - bots: 864661167297527830 + bot: 864661167297527830 + committee: 864661232005939280 timeslots: []