misc(moderation): cleaned up mysql_log method
Some checks failed
Pylint / Pylint (push) Failing after 1m20s

This commit is contained in:
Seaswimmer 2023-10-05 09:23:54 -04:00
parent 5136a492f8
commit be2d97e19c
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -168,8 +168,7 @@ class Moderation(commands.Cog):
end_timestamp = 0 end_timestamp = 0
database = await self.connect() database = await self.connect()
cursor = database.cursor() cursor = database.cursor()
cursor.execute(f"SELECT moderation_id FROM `moderation_{guild_id}` ORDER BY moderation_id DESC LIMIT 1") moderation_id = await self.get_next_case_number(guild_id=guild_id, cursor=cursor)
moderation_id = cursor.fetchone()[0] + 1
sql = f"INSERT INTO `moderation_{guild_id}` (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)" sql = f"INSERT INTO `moderation_{guild_id}` (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, author_id, duration, end_timestamp, f"{reason}", 0, "NULL", 0) val = (moderation_id, timestamp, moderation_type, target_id, author_id, duration, end_timestamp, f"{reason}", 0, "NULL", 0)
cursor.execute(sql, val) cursor.execute(sql, val)
@ -177,10 +176,11 @@ class Moderation(commands.Cog):
database.close() database.close()
logging.debug("MySQL row inserted into moderation_%s!\n%s, %s, %s, %s, %s, %s, %s, %s, 0, NULL", guild_id, moderation_id, timestamp, moderation_type, target_id, author_id, duration, end_timestamp, reason) logging.debug("MySQL row inserted into moderation_%s!\n%s, %s, %s, %s, %s, %s, %s, %s, 0, NULL", guild_id, moderation_id, timestamp, moderation_type, target_id, author_id, duration, end_timestamp, reason)
async def get_next_case_number(self, guild_id: str): async def get_next_case_number(self, guild_id: str, cursor = None):
"""This method returns the next case number from the MySQL table for a specific guild.""" """This method returns the next case number from the MySQL table for a specific guild."""
database = await self.connect() if not cursor:
cursor = database.cursor() database = await self.connect()
cursor = database.cursor()
cursor.execute(f"SELECT moderation_id FROM `moderation_{guild_id}` ORDER BY moderation_id DESC LIMIT 1") cursor.execute(f"SELECT moderation_id FROM `moderation_{guild_id}` ORDER BY moderation_id DESC LIMIT 1")
return cursor.fetchone()[0] + 1 return cursor.fetchone()[0] + 1