Started writing /commands.
Completed channel group of config subcommands Fixed bugs in config initialisation function
This commit is contained in:
58
app/cogs/devcommands/dev.py
Normal file
58
app/cogs/devcommands/dev.py
Normal file
@ -0,0 +1,58 @@
|
||||
import os
|
||||
from dotenv import load_dotenv # Import OS variables from Dotenv file.
|
||||
load_dotenv() # Load Dotenv. Delete this for production
|
||||
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 # Slash Command features
|
||||
from deepdiff import DeepDiff
|
||||
from pprint import pprint
|
||||
|
||||
from bot import loadCog, unloadCog, checkConfig, parseConfigCheck, yaml_load, configFile
|
||||
|
||||
##### Dev Cog
|
||||
class Dev(commands.Cog, name='Developer Commands'):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
|
||||
#### Check if user is an administrator
|
||||
async def cog_check(self, ctx):
|
||||
for role in ctx.author.roles:
|
||||
if role.permissions.administrator:
|
||||
return True
|
||||
return ctx.author.guild_permissions.administrator
|
||||
|
||||
@commands.command(
|
||||
name='debug',
|
||||
description='Toggles debug feature for the guild. Enter either `on` or `off`.',
|
||||
brief='Toggle debug features.'
|
||||
)
|
||||
async def _debug(self, ctx, toggle:str):
|
||||
if toggle.lower() == 'on':
|
||||
loadCog(f'./debug/debug.py')
|
||||
await ctx.reply(f'```Debug commands enabled. Use them carefully.```')
|
||||
elif toggle.lower() == 'off':
|
||||
unloadCog(f'./debug/debug.py')
|
||||
await ctx.reply(f'``Debug commands disabled.``')
|
||||
else:
|
||||
raise commands.CommandError(message='Invalid argument.')
|
||||
# await ctx.reply(f'```Invalid argument.```')
|
||||
|
||||
@commands.command(
|
||||
name='testconfig',
|
||||
description='Tests the completeness of the configuration values of the current guild by comparing it to a configuration blueprint.',
|
||||
brief='Tests config values for current guild.',
|
||||
aliases=['configtest']
|
||||
)
|
||||
async def _testconfig(self, ctx):
|
||||
checkConfig(ctx.guild)
|
||||
status, output = checkConfig(ctx.guild)
|
||||
conf = yaml_load(configFile)
|
||||
if not status:
|
||||
await ctx.reply(f"```The Bot's configurations are incomplete for the guild {ctx.guild.name}. Some limited functions will still be available, but most features cannot be used until the configurations are complete.\n{parseConfigCheck(output)}\nYou can set these configuration values using the `/config` command.```")
|
||||
elif status:
|
||||
await ctx.reply(f"```The Bot's configurations for the guild {ctx.guild.name} are in order. The Bot is ready to interact with the guild.```")
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(Dev(client))
|
Reference in New Issue
Block a user