feat(moderation): expired moderations are now automaticaly marked as such

This commit is contained in:
Seaswimmer 2023-10-05 13:48:11 -04:00
parent 4083e1890e
commit 11da49202d
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -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()