misc(moderation): changed table naming scheme

This commit is contained in:
Seaswimmer 2023-10-04 16:37:59 -04:00
parent 2b0e24a4e9
commit 6fba47ea56
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -5,7 +5,7 @@ import discord
import humanize import humanize
import mysql.connector import mysql.connector
from pytimeparse2 import disable_dateutil, parse 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): class Moderation(commands.Cog):
@ -115,11 +115,11 @@ class Moderation(commands.Cog):
database = await self.connect() database = await self.connect()
cursor = database.cursor() cursor = database.cursor()
try: 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) logging.info("MySQL Table exists for server %s (%s)", guild.name, guild.id)
except mysql.connector.errors.ProgrammingError: except mysql.connector.errors.ProgrammingError:
query = f""" query = f"""
CREATE TABLE `{guild.id}_moderation` ( CREATE TABLE `moderation_{guild.id}` (
moderation_id INT UNIQUE PRIMARY KEY NOT NULL, moderation_id INT UNIQUE PRIMARY KEY NOT NULL,
timestamp INT NOT NULL, timestamp INT NOT NULL,
moderation_type LONGTEXT NOT NULL, moderation_type LONGTEXT NOT NULL,
@ -135,7 +135,7 @@ class Moderation(commands.Cog):
""" """
cursor.execute(query) cursor.execute(query)
insert_query = f""" 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) (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) 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) cursor.execute(insert_query, insert_values)
database.commit() database.commit()
database.close() 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: else:
database.close() database.close()
return return
@ -165,14 +165,14 @@ 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 `{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 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) 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)
database.commit() database.commit()
database.close() 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.hybrid_command(name="mute", aliases=['timeout'])
@commands.mod() @commands.mod()