From be2d97e19c0067479c37b9e2bebc79f52cd98a8f Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Thu, 5 Oct 2023 09:23:54 -0400 Subject: [PATCH] misc(moderation): cleaned up mysql_log method --- moderation/moderation.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/moderation/moderation.py b/moderation/moderation.py index 358b145..95b6c06 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -168,8 +168,7 @@ class Moderation(commands.Cog): end_timestamp = 0 database = await self.connect() cursor = database.cursor() - cursor.execute(f"SELECT moderation_id FROM `moderation_{guild_id}` ORDER BY moderation_id DESC LIMIT 1") - moderation_id = cursor.fetchone()[0] + 1 + moderation_id = await self.get_next_case_number(guild_id=guild_id, cursor=cursor) 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) cursor.execute(sql, val) @@ -177,10 +176,11 @@ class Moderation(commands.Cog): 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) - 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.""" - database = await self.connect() - cursor = database.cursor() + if not 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") return cursor.fetchone()[0] + 1