feat(moderation): do not run tasks or catch events for guilds that have the cog disabled

This commit is contained in:
Seaswimmer 2023-10-22 13:28:50 -04:00
parent 1c247636d1
commit 3d2960b37a
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -11,7 +11,7 @@ from redbot.core.app_commands import Choice
class Moderation(commands.Cog):
"""Custom cog moderation cog, meant to copy GalacticBot.
"""Custom moderation cog.
Developed by SeaswimmerTheFsh."""
def __init__(self, bot):
@ -45,6 +45,7 @@ class Moderation(commands.Cog):
guilds: list[discord.Guild] = self.bot.guilds
try:
for guild in guilds:
if not await self.bot.cog_disabled_in_guild(self, guild):
await self.create_guild_table(guild)
except ConnectionRefusedError:
return
@ -55,6 +56,7 @@ class Moderation(commands.Cog):
@commands.Cog.listener('on_guild_join')
async def db_generate_guild_join(self, guild: discord.Guild):
"""This method prepares the database schema whenever the bot joins a guild."""
if not await self.bot.cog_disabled_in_guild(self, guild):
conf = await self.check_conf([
'mysql_address',
'mysql_database',
@ -72,6 +74,7 @@ class Moderation(commands.Cog):
@commands.Cog.listener('on_audit_log_entry_create')
async def autologger(self, entry: discord.AuditLogEntry):
"""This method automatically logs moderations done by users manually ("right clicks")."""
if not await self.bot.cog_disabled_in_guild(self, entry.guild):
if await self.config.guild(entry.guild.id).ignore_other_bots() is True:
if entry.user.bot or entry.target.bot:
return
@ -679,6 +682,7 @@ class Moderation(commands.Cog):
db = await self.config.mysql_database()
guilds: list[discord.Guild] = self.bot.guilds
for guild in guilds:
if not await self.bot.cog_disabled_in_guild(self, guild):
tempban_query = f"SELECT target_id, moderation_id FROM moderation_{guild.id} WHERE end_timestamp != 0 AND end_timestamp <= %s AND moderation_type = 'TEMPBAN' AND expired = 0"
try:
cursor.execute(tempban_query, (time.time(),))