forked from viveksantayana/geas-bot
33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
|
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
|
||
|
from dev import configFile, yaml_load, yaml_dump
|
||
|
|
||
|
##### Actions for the bot to take whenever a channel in a guild is deleted
|
||
|
class on_guild_channel_delete(commands.Cog):
|
||
|
def __init__(self, client):
|
||
|
self.client = client
|
||
|
|
||
|
#### What to do if a mod channel gets deleted: try and pull default system channel, and if not then top-most channel
|
||
|
@commands.Cog.listener()
|
||
|
async def on_guild_channel_delete(self, channel):
|
||
|
conf = yaml_load(configFile)
|
||
|
if conf[str(channel.guild.id)]['modchannel'] == channel.id:
|
||
|
if channel.guild.system_channel is None:
|
||
|
p = len(channel.guild.channels)
|
||
|
c = None
|
||
|
for t in channel.guild.text_channels:
|
||
|
if t.position < p:
|
||
|
p = t.position
|
||
|
conf[str(channel.guild.id)]['modchannel'] = t.id
|
||
|
else:
|
||
|
conf[str(channel.guild.id)]['modchannel'] = channel.guild.system_channel.id
|
||
|
yaml_dump(conf, configFile)
|
||
|
|
||
|
def setup(client):
|
||
|
client.add_cog(on_guild_channel_delete(client))
|