Compare commits

...

2 commits

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
@ -387,9 +388,8 @@ class Moderation(commands.Cog):
embed = discord.Embed(title=f"📕 Case #{case['moderation_id']}", color=await self.bot.get_embed_color(None))
embed.description = f"**Type:** {str.title(case['moderation_type'])}\n**Target:** {target_name} ({target.id})\n**Moderator:** {moderator_name} ({moderator.id})\n**Resolved:** {bool(case['resolved'])}\n**Timestamp:** <t:{case['timestamp']}> | <t:{case['timestamp']}:R>"
if case['duration'] != 'NULL':
expired = True if case["end_timestamp"] <= time.time() or case['resolved'] == 1 else False
td = timedelta(**{unit: int(val) for unit, val in zip(["hours", "minutes", "seconds"], case["duration"].split(":"))})
embed.description = embed.description + f"\n**Duration:** {humanize.precisedelta(td)}\n**Expired:** {expired}"
embed.description = embed.description + f"\n**Duration:** {humanize.precisedelta(td)}\n**Expired:** {case['expired']}"
embed.add_field(name='Reason', value=f"```{case['reason']}```", inline=False)
if case['resolved'] == 1:
embed.add_field(name='Resolve Reason', value=f"```{case['resolve_reason']}```", inline=False)
@ -397,6 +397,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()