Finished abstraction of /config subcommands

This commit is contained in:
Vivek Santayana 2021-07-18 01:28:06 +01:00
parent 3d937fffea
commit c5be0002ac
3 changed files with 88 additions and 238 deletions

View File

@ -54,6 +54,8 @@
> - [x] student role (role group) > - [x] student role (role group)
> - [x] help notifications (notification group) > - [x] help notifications (notification group)
> - [x] signup notifications (notification group) > - [x] signup notifications (notification group)
- [ ] Set up timeslots
- [ ] Delete timeslots
- [ ] Set up command permissions - [ ] Set up command permissions
> - [ ] Slash Commands > - [ ] Slash Commands
>> - [x] Admin Commands >> - [x] Admin Commands

View File

@ -23,305 +23,150 @@ class Configuration(commands.Cog):
for admin in conf[guildStr]['roles']['admin']: for admin in conf[guildStr]['roles']['admin']:
permissions[int(guildStr)].append(create_permission(id=admin,id_type=SlashCommandPermissionType.ROLE,permission=True)) permissions[int(guildStr)].append(create_permission(id=admin,id_type=SlashCommandPermissionType.ROLE,permission=True))
@cog_ext.cog_slash( @cog_ext.cog_subcommand(
name='hello', base='config',
description='Test command to see if registration works.', # 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, guild_ids=guild_ids,
options=[ options=[
create_option( create_option(
name='input', name='key',
description='Choose a phrase that best goes with the opening Hello', description='The name of the role parameter being assigned.',
option_type=3, option_type=3,
required=True, required=True,
choices=[ choices=[
create_choice( create_choice(
name='...there', name='`Bot` role',
value='there' value='bot'
), ),
create_choice( create_choice(
name='...world!', name='`Committee` role',
value='world' value='committee'
), ),
create_choice( create_choice(
name='...beautiful!', name='`Newcomer` role',
value='beautiful' 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( create_option(
name='role', name='role',
description='The role assigned to dice bots to access game channels.', description='The role assigned to the parameter.',
option_type=8, option_type=8,
required=True 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) conf = yaml_load(configFile)
if 'roles' not in conf[str(ctx.guild.id)]: if 'roles' not in conf[str(ctx.guild.id)]:
conf[str(ctx.guild.id)]['roles'] = {} 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) 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( @cog_ext.cog_subcommand(
base='config', base='config',
subcommand_group='role', # subcommand_group='channel',
name='committee', name='channels',
description='Designate the role used by committee members.', 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 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.',
# base_description='Commands for configuring the various parameters of the Guild', # base_description='Commands for configuring the various parameters of the Guild',
# base_default_permission=False, # base_default_permission=False,
# base_permissions=permissions, # base_permissions=permissions,
# subcommand_group_description='Designates the various key Bot channels for the guild.', # subcommand_group_description='Designates the various key Bot channels for the guild.',
guild_ids=guild_ids, guild_ids=guild_ids,
options=[ 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( create_option(
name='channel', name='channel',
description='The channel assigned for moderation notifications.', description='The channel assigned to the parameter.',
option_type=7, option_type=7,
required=True 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) conf = yaml_load(configFile)
if 'channels' not in conf[str(ctx.guild.id)]: if 'channels' not in conf[str(ctx.guild.id)]:
conf[str(ctx.guild.id)]['channels'] = {} 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) 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( @cog_ext.cog_subcommand(
base='config', base='config',
subcommand_group='channel', # subcommand_group='notifications',
name='help', name='notifications',
description='Designate the hel channel which the bot will monitor for member queries.', description='Configure monitoring and notifications to Committee for member query channels.',
# base_description='Commands for configuring the various parameters of the Guild', # base_description='Commands for configuring the various parameters of the Guild',
# base_default_permission=False, # base_default_permission=False,
# base_permissions=permissions, # 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, guild_ids=guild_ids,
options=[ options=[
create_option( create_option(
name='channel', name='channel',
description='The channel monitored by the Bot for help queries.', description='Select which channel to change notifications for.',
option_type=7, option_type=3,
required=True required=True,
) choices=[
] create_choice(
) name='Help Channel',
async def _config_channel_help(self, ctx:SlashContext, channel:discord.TextChannel): value='help'
conf = yaml_load(configFile) ),
if 'channels' not in conf[str(ctx.guild.id)]: create_choice(
conf[str(ctx.guild.id)]['channels'] = {} name='Signup Channel',
conf[str(ctx.guild.id)]['channels']['help'] = int(channel.id) value='signup'
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=[
create_option( create_option(
name='notifications', 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, option_type=5,
required=True 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) conf = yaml_load(configFile)
if 'notifications' not in conf[str(ctx.guild.id)]: if 'notifications' not in conf[str(ctx.guild.id)]:
conf[str(ctx.guild.id)]['notifications'] = {} 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) 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}`.```') await ctx.send(f'```Notifications for posts in the `{channel}` channel for the guild `{ctx.guild.name}` have been set to `{notifications}`.```')
@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}`.```')
def setup(client): def setup(client):
client.add_cog(Configuration(client)) client.add_cog(Configuration(client))

View File

@ -1,16 +1,19 @@
'864651943820525609': '864651943820525609':
channels: channels:
help: 866110872584978443
mod: 865662560225067018 mod: 865662560225067018
signup: 866110421592965171
configured: false configured: false
membership: {} membership: {}
name: Test name: Test
notifications: notifications:
help: null help: true
signup: null signup: true
owner: 493694762210033664 owner: 493694762210033664
prefix: '-' prefix: '-'
roles: roles:
admin: admin:
- 864661232005939280 - 864661232005939280
bots: 864661167297527830 bot: 864661167297527830
committee: 864661232005939280
timeslots: [] timeslots: []