From 564faeedf21e07df302ec6ee7cb589c9d4f6ea0d Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Thu, 5 Oct 2023 16:15:16 -0400 Subject: [PATCH] feat(moderation): tempbans will be handled by handle_expiry every 60 seconds --- moderation/moderation.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/moderation/moderation.py b/moderation/moderation.py index 32d8a0a..3e28cab 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -405,14 +405,22 @@ class Moderation(commands.Cog): async def handle_expiry(self): conf = await self.check_conf(['mysql_database']) if conf: - return + raise(LookupError) database = await self.connect() cursor = database.cursor() db = await self.config.mysql_database() guilds: list[discord.Guild] = self.bot.guilds for guild in guilds: - query = f"UPDATE `{db}`.`moderation_{guild.id}` SET expired = 1 WHERE (end_timestamp != 0 AND end_timestamp <= %s AND expired = 0) OR (expired = 0 AND resolved = 1)" - cursor.execute(query, (time.time(),)) + 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 resolved = 0" + cursor.execute(tempban_query, (time.time(),)) + result = cursor.fetchall() + target_ids = [row[0] for row in result] + moderation_ids = [row[1] for row in result] + for target_id, moderation_id in zip(target_ids, moderation_ids): + user = await self.bot.fetch_user(target_id) + await guild.unban(user, reason=f"Automatic unban from case #{moderation_id}") + expiry_query = f"UPDATE `{db}`.`moderation_{guild.id}` SET expired = 1 WHERE (end_timestamp != 0 AND end_timestamp <= %s AND expired = 0) OR (expired = 0 AND resolved = 1)" + cursor.execute(expiry_query, (time.time(),)) database.commit() cursor.close() database.close()