2021-07-15 09:03:44 +01:00
|
|
|
import os # OS Locations
|
|
|
|
import yaml # YAML parser for Bot config files
|
2021-07-15 22:54:09 +01:00
|
|
|
import asyncio # Discord Py Dependency
|
2021-07-15 09:03:44 +01:00
|
|
|
import discord # Main Lib
|
|
|
|
from discord.ext import commands # Commands module
|
|
|
|
from discord_slash import SlashCommand, SlashContext, cog_ext, utils # Slash Command Library
|
2021-07-17 13:56:04 +01:00
|
|
|
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
|
2021-07-15 09:03:44 +01:00
|
|
|
|
|
|
|
##### Configuration Cog
|
|
|
|
class Configuration(commands.Cog):
|
|
|
|
def __init__(self, client):
|
|
|
|
self.client = client
|
|
|
|
|
2021-07-17 13:56:04 +01:00
|
|
|
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))
|
|
|
|
|
2021-07-18 01:28:06 +01:00
|
|
|
@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.',
|
2021-07-17 13:56:04 +01:00
|
|
|
guild_ids=guild_ids,
|
|
|
|
options=[
|
|
|
|
create_option(
|
2021-07-18 01:28:06 +01:00
|
|
|
name='key',
|
|
|
|
description='The name of the role parameter being assigned.',
|
2021-07-17 13:56:04 +01:00
|
|
|
option_type=3,
|
|
|
|
required=True,
|
|
|
|
choices=[
|
|
|
|
create_choice(
|
2021-07-18 01:28:06 +01:00
|
|
|
name='`Bot` role',
|
|
|
|
value='bot'
|
2021-07-17 13:56:04 +01:00
|
|
|
),
|
|
|
|
create_choice(
|
2021-07-18 01:28:06 +01:00
|
|
|
name='`Committee` role',
|
|
|
|
value='committee'
|
2021-07-17 13:56:04 +01:00
|
|
|
),
|
|
|
|
create_choice(
|
2021-07-18 01:28:06 +01:00
|
|
|
name='`Newcomer` role',
|
|
|
|
value='newcomer'
|
|
|
|
),
|
|
|
|
create_choice(
|
|
|
|
name='`Returning Player` role',
|
|
|
|
value='returning_player'
|
|
|
|
),
|
|
|
|
create_choice(
|
|
|
|
name='`Student` role',
|
|
|
|
value='student'
|
2021-07-17 13:56:04 +01:00
|
|
|
)
|
2021-07-18 01:28:06 +01:00
|
|
|
]
|
|
|
|
),
|
2021-07-18 00:43:44 +01:00
|
|
|
create_option(
|
|
|
|
name='role',
|
2021-07-18 01:28:06 +01:00
|
|
|
description='The role assigned to the parameter.',
|
2021-07-18 00:43:44 +01:00
|
|
|
option_type=8,
|
|
|
|
required=True
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
2021-07-18 01:28:06 +01:00
|
|
|
async def _config_roles(self, ctx:SlashContext, key:str, role:discord.Role):
|
2021-07-18 00:43:44 +01:00
|
|
|
conf = yaml_load(configFile)
|
|
|
|
if 'roles' not in conf[str(ctx.guild.id)]:
|
|
|
|
conf[str(ctx.guild.id)]['roles'] = {}
|
2021-07-18 01:28:06 +01:00
|
|
|
conf[str(ctx.guild.id)]['roles'][key] = int(role.id)
|
2021-07-18 00:43:44 +01:00
|
|
|
yaml_dump(conf, configFile)
|
2021-07-18 01:28:06 +01:00
|
|
|
await ctx.send(f'```The `{key}` role for the guild `{ctx.guild.name}` has been set to `{role.name}`.```')
|
2021-07-18 00:43:44 +01:00
|
|
|
|
|
|
|
@cog_ext.cog_subcommand(
|
|
|
|
base='config',
|
2021-07-18 01:28:06 +01:00
|
|
|
# subcommand_group='channel',
|
|
|
|
name='channels',
|
|
|
|
description='Designate the various key channels for the Bot to interact with.',
|
2021-07-17 13:56:04 +01:00
|
|
|
# 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(
|
2021-07-18 01:28:06 +01:00
|
|
|
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'
|
|
|
|
)
|
|
|
|
]
|
|
|
|
),
|
2021-07-17 13:56:04 +01:00
|
|
|
create_option(
|
|
|
|
name='channel',
|
2021-07-18 01:28:06 +01:00
|
|
|
description='The channel assigned to the parameter.',
|
2021-07-17 13:56:04 +01:00
|
|
|
option_type=7,
|
|
|
|
required=True
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
2021-07-18 01:28:06 +01:00
|
|
|
async def _config_channels(self, ctx:SlashContext, key:str, channel:discord.TextChannel):
|
2021-07-17 13:56:04 +01:00
|
|
|
conf = yaml_load(configFile)
|
|
|
|
if 'channels' not in conf[str(ctx.guild.id)]:
|
|
|
|
conf[str(ctx.guild.id)]['channels'] = {}
|
2021-07-18 01:28:06 +01:00
|
|
|
conf[str(ctx.guild.id)]['channels'][key] = int(channel.id)
|
2021-07-17 13:56:04 +01:00
|
|
|
yaml_dump(conf, configFile)
|
2021-07-18 01:28:06 +01:00
|
|
|
await ctx.send(f'```The `{key}` channel for the guild `{ctx.guild.name}` has been set to `{channel.name}`.```')
|
2021-07-17 13:56:04 +01:00
|
|
|
|
2021-07-18 00:43:44 +01:00
|
|
|
@cog_ext.cog_subcommand(
|
|
|
|
base='config',
|
2021-07-18 01:28:06 +01:00
|
|
|
# subcommand_group='notifications',
|
|
|
|
name='notifications',
|
|
|
|
description='Configure monitoring and notifications to Committee for member query channels.',
|
2021-07-18 00:43:44 +01:00
|
|
|
# base_description='Commands for configuring the various parameters of the Guild',
|
|
|
|
# base_default_permission=False,
|
|
|
|
# base_permissions=permissions,
|
2021-07-18 01:28:06 +01:00
|
|
|
# subcommand_group_description='Configures whether the bot monitors and responds to posts in key channels.',
|
2021-07-18 00:43:44 +01:00
|
|
|
guild_ids=guild_ids,
|
|
|
|
options=[
|
|
|
|
create_option(
|
2021-07-18 01:28:06 +01:00
|
|
|
name='channel',
|
|
|
|
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'
|
|
|
|
)
|
|
|
|
]
|
|
|
|
),
|
2021-07-18 00:43:44 +01:00
|
|
|
create_option(
|
|
|
|
name='notifications',
|
2021-07-18 01:28:06 +01:00
|
|
|
description='Whether or not the bot monitors the channel for posts.',
|
2021-07-18 00:43:44 +01:00
|
|
|
option_type=5,
|
|
|
|
required=True
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
2021-07-18 01:28:06 +01:00
|
|
|
async def _config_notifications(self, ctx:SlashContext, channel:str, notifications:bool):
|
2021-07-18 00:43:44 +01:00
|
|
|
conf = yaml_load(configFile)
|
|
|
|
if 'notifications' not in conf[str(ctx.guild.id)]:
|
|
|
|
conf[str(ctx.guild.id)]['notifications'] = {}
|
2021-07-18 01:28:06 +01:00
|
|
|
conf[str(ctx.guild.id)]['notifications'][channel] = notifications
|
2021-07-18 00:43:44 +01:00
|
|
|
yaml_dump(conf, configFile)
|
2021-07-18 01:28:06 +01:00
|
|
|
await ctx.send(f'```Notifications for posts in the `{channel}` channel for the guild `{ctx.guild.name}` have been set to `{notifications}`.```')
|
2021-07-15 09:03:44 +01:00
|
|
|
|
|
|
|
def setup(client):
|
|
|
|
client.add_cog(Configuration(client))
|