From 11da49202d951663df3fecc875603af44ad5bfc2 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Thu, 5 Oct 2023 13:48:11 -0400 Subject: [PATCH] feat(moderation): expired moderations are now automaticaly marked as such --- moderation/moderation.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/moderation/moderation.py b/moderation/moderation.py index 5c1d5d9..4e943c7 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -4,6 +4,7 @@ from datetime import datetime, timedelta, timezone import discord import humanize import mysql.connector +from discord.ext import tasks from pytimeparse2 import disable_dateutil, parse from redbot.core import app_commands, checks, Config, commands from redbot.core.app_commands import Choice @@ -397,6 +398,18 @@ class Moderation(commands.Cog): else: await interaction.response.send_message(content=f"No case with case number `{case_number}` found.", ephemeral=True) + @tasks.loop(minutes=1) + async def handle_expiry(self): + conf = await self.check_conf(['mysql_database']) + if conf: + return + database = await self.connect() + cursor = database.cursor() + query = f"UPDATE {await self.config.mysql_database()}.* SET expired = 1 WHERE end_timestamp <= %s AND expired = 0" + cursor.execute(query, (time.time(),)) + database.commit() + cursor.close() + database.close() @commands.group(autohelp=True) @checks.admin()