feat(moderation): added mysql_log method
Some checks reported warnings
Pylint / Pylint (push) Has been cancelled

This commit is contained in:
Seaswimmer 2023-10-04 11:04:36 -04:00
parent 43e1aebbbe
commit c17f004c03
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -1,10 +1,11 @@
import datetime
import logging
import time
import discord
import mysql.connector
from pytimeparse2 import disable_dateutil
from pytimeparse2 import disable_dateutil, parse
from redbot.core import Config, checks, commands
class Moderation(commands.Cog):
"""Custom cog moderation cog, meant to copy GalacticBot.
Developed by SeaswimmerTheFsh."""
@ -122,6 +123,24 @@ class Moderation(commands.Cog):
not_found_list.append(item)
return not_found_list
async def mysql_log(self, ctx: commands.Context, moderation_type: str, target_id: int, duration, reason:str ):
timestamp = int(time.time())
if duration != "NULL":
end_timedelta = datetime.fromtimestamp(timestamp) + duration
end_timestamp = int(end_timedelta.timestamp())
else:
end_timestamp = 0
database = await self.connect()
cursor = database.cursor()
cursor.execute(f"SELECT moderation_id FROM `{ctx.guild.id}_moderation` ORDER BY moderation_id DESC LIMIT 1")
moderation_id = cursor.fetchone()[0] + 1
sql = f"INSERT INTO `{ctx.guild.id}_moderation` (moderation_id, timestamp, moderation_type, target_id, moderator_id, duration, end_timestamp, reason, resolved, resolve_reason, expired) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
val = (moderation_id, timestamp, moderation_type, target_id, ctx.author.id, duration, end_timestamp, f"{reason}", 0, "NULL", 0)
cursor.execute(sql, val)
database.commit()
database.close()
logging.debug("MySQL row inserted into %s_moderation!\n%s, %s, %s, %s, %s, %s, %s, %s, 0, NULL", ctx.guild.id, moderation_id, timestamp, moderation_type, target_id, ctx.author.id, duration, end_timestamp, reason)
@commands.group(autohelp=True)
@checks.admin()
async def moderationset(self, ctx: commands.Context):