feat(moderation): do not run tasks or catch events for guilds that have the cog disabled
This commit is contained in:
parent
1c247636d1
commit
3d2960b37a
1 changed files with 64 additions and 60 deletions
|
@ -11,7 +11,7 @@ from redbot.core.app_commands import Choice
|
||||||
|
|
||||||
|
|
||||||
class Moderation(commands.Cog):
|
class Moderation(commands.Cog):
|
||||||
"""Custom cog moderation cog, meant to copy GalacticBot.
|
"""Custom moderation cog.
|
||||||
Developed by SeaswimmerTheFsh."""
|
Developed by SeaswimmerTheFsh."""
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
|
@ -45,6 +45,7 @@ class Moderation(commands.Cog):
|
||||||
guilds: list[discord.Guild] = self.bot.guilds
|
guilds: list[discord.Guild] = self.bot.guilds
|
||||||
try:
|
try:
|
||||||
for guild in guilds:
|
for guild in guilds:
|
||||||
|
if not await self.bot.cog_disabled_in_guild(self, guild):
|
||||||
await self.create_guild_table(guild)
|
await self.create_guild_table(guild)
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
return
|
return
|
||||||
|
@ -55,6 +56,7 @@ class Moderation(commands.Cog):
|
||||||
@commands.Cog.listener('on_guild_join')
|
@commands.Cog.listener('on_guild_join')
|
||||||
async def db_generate_guild_join(self, guild: discord.Guild):
|
async def db_generate_guild_join(self, guild: discord.Guild):
|
||||||
"""This method prepares the database schema whenever the bot joins a 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([
|
conf = await self.check_conf([
|
||||||
'mysql_address',
|
'mysql_address',
|
||||||
'mysql_database',
|
'mysql_database',
|
||||||
|
@ -72,6 +74,7 @@ class Moderation(commands.Cog):
|
||||||
@commands.Cog.listener('on_audit_log_entry_create')
|
@commands.Cog.listener('on_audit_log_entry_create')
|
||||||
async def autologger(self, entry: discord.AuditLogEntry):
|
async def autologger(self, entry: discord.AuditLogEntry):
|
||||||
"""This method automatically logs moderations done by users manually ("right clicks")."""
|
"""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 await self.config.guild(entry.guild.id).ignore_other_bots() is True:
|
||||||
if entry.user.bot or entry.target.bot:
|
if entry.user.bot or entry.target.bot:
|
||||||
return
|
return
|
||||||
|
@ -679,6 +682,7 @@ class Moderation(commands.Cog):
|
||||||
db = await self.config.mysql_database()
|
db = await self.config.mysql_database()
|
||||||
guilds: list[discord.Guild] = self.bot.guilds
|
guilds: list[discord.Guild] = self.bot.guilds
|
||||||
for guild in 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"
|
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:
|
try:
|
||||||
cursor.execute(tempban_query, (time.time(),))
|
cursor.execute(tempban_query, (time.time(),))
|
||||||
|
|
Loading…
Reference in a new issue