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-15 09:03:44 +01:00
|
|
|
@cog_ext.cog_slash(
|
2021-07-17 13:56:04 +01:00
|
|
|
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']['bots'] = int(role.id)
|
|
|
|
yaml_dump(conf, configFile)
|
|
|
|
await ctx.send(f'```The `botrole` 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
|
|
|
|
)
|
|
|
|
]
|
2021-07-15 09:03:44 +01:00
|
|
|
)
|
2021-07-17 13:56:04 +01:00
|
|
|
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}`.```')
|
|
|
|
|
2021-07-15 09:03:44 +01:00
|
|
|
|
|
|
|
def setup(client):
|
|
|
|
client.add_cog(Configuration(client))
|