From 6fba47ea5696d2d9d10a6c87e32becb634a34636 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Wed, 4 Oct 2023 16:37:59 -0400 Subject: [PATCH] misc(moderation): changed table naming scheme --- moderation/moderation.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/moderation/moderation.py b/moderation/moderation.py index 6575c69..267d66f 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -5,7 +5,7 @@ import discord import humanize import mysql.connector from pytimeparse2 import disable_dateutil, parse -from redbot.core import Config, checks, commands +from redbot.core import Config, checks, commands, tasks class Moderation(commands.Cog): @@ -115,11 +115,11 @@ class Moderation(commands.Cog): database = await self.connect() cursor = database.cursor() try: - cursor.execute(f"SELECT * FROM `{guild.id}_moderation`") + cursor.execute(f"SELECT * FROM `moderation_{guild.id}`") logging.info("MySQL Table exists for server %s (%s)", guild.name, guild.id) except mysql.connector.errors.ProgrammingError: query = f""" - CREATE TABLE `{guild.id}_moderation` ( + CREATE TABLE `moderation_{guild.id}` ( moderation_id INT UNIQUE PRIMARY KEY NOT NULL, timestamp INT NOT NULL, moderation_type LONGTEXT NOT NULL, @@ -135,7 +135,7 @@ class Moderation(commands.Cog): """ cursor.execute(query) insert_query = f""" - INSERT INTO `{guild.id}_moderation` + 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) """ @@ -143,7 +143,7 @@ class Moderation(commands.Cog): cursor.execute(insert_query, insert_values) database.commit() database.close() - logging.info("MySQL Table created for %s (%s)\n%s_moderation", guild.name, guild.id, guild.id) + logging.info("MySQL Table created for %s (%s)\nmoderation_%s", guild.name, guild.id, guild.id) else: database.close() return @@ -165,14 +165,14 @@ class Moderation(commands.Cog): end_timestamp = 0 database = await self.connect() cursor = database.cursor() - cursor.execute(f"SELECT moderation_id FROM `{guild_id}_moderation` ORDER BY moderation_id DESC LIMIT 1") + cursor.execute(f"SELECT moderation_id FROM `moderation_{guild_id}` ORDER BY moderation_id DESC LIMIT 1") moderation_id = cursor.fetchone()[0] + 1 - sql = f"INSERT INTO `{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)" + 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) database.commit() database.close() - logging.debug("MySQL row inserted into %s_moderation!\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) @commands.hybrid_command(name="mute", aliases=['timeout']) @commands.mod()