feat(moderation): tempbans will be handled by handle_expiry every 60 seconds
Some checks failed
Pylint / Pylint (push) Failing after 1m12s
Some checks failed
Pylint / Pylint (push) Failing after 1m12s
This commit is contained in:
parent
f8bc67fe48
commit
564faeedf2
1 changed files with 11 additions and 3 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue