forked from viveksantayana/geas-bot
Vivek Santayana
3d937fffea
Prior to abstraction to generic /config commands with multiple keyed arguments
327 lines
12 KiB
Python
327 lines
12 KiB
Python
import os # OS Locations
|
|
import yaml # YAML parser for Bot config files
|
|
import asyncio # Discord Py Dependency
|
|
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 bot import configFile, yaml_load, yaml_dump
|
|
|
|
##### Configuration Cog
|
|
class Configuration(commands.Cog):
|
|
def __init__(self, client):
|
|
self.client = client
|
|
|
|
guild_ids=[int(guildKey) for guildKey in yaml_load(configFile)]
|
|
permissions = {}
|
|
conf = yaml_load(configFile)
|
|
for guildStr in conf:
|
|
permissions[int(guildStr)] = []
|
|
permissions[int(guildStr)].append(create_permission(id=conf[guildStr]['owner'],id_type=SlashCommandPermissionType.USER,permission=True))
|
|
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.',
|
|
guild_ids=guild_ids,
|
|
options=[
|
|
create_option(
|
|
name='input',
|
|
description='Choose a phrase that best goes with the opening Hello',
|
|
option_type=3,
|
|
required=True,
|
|
choices=[
|
|
create_choice(
|
|
name='...there',
|
|
value='there'
|
|
),
|
|
create_choice(
|
|
name='...world!',
|
|
value='world'
|
|
),
|
|
create_choice(
|
|
name='...beautiful!',
|
|
value='beautiful'
|
|
)
|
|
],
|
|
)
|
|
]
|
|
)
|
|
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.',
|
|
option_type=8,
|
|
required=True
|
|
)
|
|
]
|
|
)
|
|
async def _config_role_bot(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']['bot'] = 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}`.```')
|
|
|
|
@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.',
|
|
# 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 moderation notifications.',
|
|
option_type=7,
|
|
required=True
|
|
)
|
|
]
|
|
)
|
|
async def _config_channel_mod(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']['mod'] = 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}`.```')
|
|
|
|
@cog_ext.cog_subcommand(
|
|
base='config',
|
|
subcommand_group='channel',
|
|
name='help',
|
|
description='Designate the hel channel which the bot will monitor for member queries.',
|
|
# 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 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=[
|
|
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_help(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']['help'] = input
|
|
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}`.```')
|
|
|
|
def setup(client):
|
|
client.add_cog(Configuration(client)) |