2021-07-15 22:54:09 +01:00
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 # Slash Command features
import logging
# logger and handler
2021-07-17 13:56:04 +01:00
from bot import checkConfig , clearConfig , configFile , parseConfigCheck , setConfig , yaml_dump , yaml_load , loadCogs , unloadCogs
2021-07-15 22:54:09 +01:00
#### Actions for the Bot to take once it is ready to interact with commands.
2021-07-16 23:53:31 +01:00
class on_ready ( commands . Cog , name = ' On Ready Events ' ) :
2021-07-15 22:54:09 +01:00
def __init__ ( self , client ) :
self . client = client
@commands.Cog.listener ( )
async def on_ready ( self ) :
#### Create any missing config entries for guilds
for guild in self . client . guilds :
setConfig ( guild )
#### Delete any extra config entries for guilds the bot is not in
conf = yaml_load ( configFile )
for key in list ( conf ) :
clearConfig ( key )
2021-07-16 23:53:31 +01:00
#### Check completeness of configurations
for guild in self . client . guilds :
status , output = checkConfig ( guild )
conf = yaml_load ( configFile )
if not status :
await guild . get_channel ( conf [ str ( guild . id ) ] [ ' channels ' ] [ ' mod ' ] ) . send ( f " ```The Bot ' s configurations are incomplete for the guild ` { guild . name } `. Some limited functions will still be available, but most features cannot be used until the configurations are complete. \n { parseConfigCheck ( output ) } \n You can set these configuration values using the `/config` command.``` " )
2021-07-17 13:56:04 +01:00
# #### Reload the /commands after the configs have finished loading.
# unloadCogs('slashcommands')
# loadCogs('slashcommands')
2021-07-15 22:54:09 +01:00
def setup ( client ) :
client . add_cog ( on_ready ( client ) )