def load_guild(self, guild): my_channels = dict() for row in ConfigChannel.select().where(ConfigChannel.serverid == guild.id): if validate_channel_name(row.configname): my_channels[row.configname] = row.channelid else: Logging.error(f"Misconfiguration in config channel: {row.configname}") self.bot.config_channels[guild.id] = my_channels
async def set_channel(self, ctx: commands.Context, channel_name: str, channel_id: int = 0): # Validate channel if channel_id != 0 and ctx.guild.get_channel(channel_id) is None: return False row: ConfigChannel = ConfigChannel.get_or_create(serverid=ctx.guild.id, configname=channel_name)[0] row.channelid = channel_id row.save() self.bot.config_channels[ctx.guild.id][channel_name] = channel_id return True
async def set_channel(self, ctx: commands.Context, channel_name: str, channel_id: int = 0): try: # Validate channel if ctx.guild.get_channel(channel_id) is None: return False row: ConfigChannel = ConfigChannel.get_or_none( serverid=ctx.guild.id, configname=channel_name) if row is None: ConfigChannel.create(serverid=ctx.guild.id, channelid=str(channel_id), configname=channel_name) else: row.channelid = channel_id row.save() self.bot.config_channels[ctx.guild.id][channel_name] = channel_id return True except Exception as ex: return False
async def startup_cleanup(self): # Load channels self.bot.config_channels = dict() for guild in self.bot.guilds: my_channels = dict() for row in ConfigChannel.select().where( ConfigChannel.serverid == guild.id): if validate_channel_name(row.configname): my_channels[row.configname] = row.channelid else: Logging.error( f"Misconfiguration in config channel: {row.configname}" ) self.bot.config_channels[guild.id] = my_channels
async def channel_config(self, ctx): """ Show channel configuration for guild """ embed = discord.Embed( timestamp=ctx.message.created_at, color=0x663399, title=Lang.get_locale_string("channel_config/info", ctx, server_name=ctx.guild.name)) embed.add_field(name='Configurable Channels', value=f"[{Utils.welcome_channel}|{Utils.rules_channel}|" f"{Utils.log_channel}|{Utils.ro_art_channel}|{Utils.entry_channel}]", inline=False) for row in ConfigChannel.select().where(ConfigChannel.serverid == ctx.guild.id): embed.add_field(name=row.configname, value=f"<#{row.channelid}>", inline=False) await ctx.send(embed=embed)
async def on_guild_remove(self, guild): del self.bot.config_channels[guild.id] for row in ConfigChannel.select().where(ConfigChannel.serverid == guild.id): row.delete_instance()