feat(moderation): added resolved_by field to mysql tables
All checks were successful
Pylint / Pylint (push) Successful in 1m11s

This commit is contained in:
Seaswimmer 2023-10-06 10:07:52 -04:00
parent d1d5bec732
commit 8a3ed15ee0
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -134,8 +134,9 @@ class Moderation(commands.Cog):
"end_timestamp": result[6], "end_timestamp": result[6],
"reason": result[7], "reason": result[7],
"resolved": result[8], "resolved": result[8],
"resolve_reason": result[9], "resolved_by": result[9],
"expired": result[10] "resolve_reason": result[10],
"expired": result[11]
} }
return case return case
@ -157,6 +158,7 @@ class Moderation(commands.Cog):
end_timestamp INT, end_timestamp INT,
reason LONGTEXT, reason LONGTEXT,
resolved BOOL NOT NULL, resolved BOOL NOT NULL,
resolved_by LONGTEXT,
resolve_reason LONGTEXT, resolve_reason LONGTEXT,
expired BOOL NOT NULL expired BOOL NOT NULL
) )
@ -164,10 +166,10 @@ class Moderation(commands.Cog):
cursor.execute(query) cursor.execute(query)
insert_query = f""" insert_query = f"""
INSERT INTO `moderation_{guild.id}` 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, resolved_by, 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, %s)
""" """
insert_values = (0, 0, "NULL", 0, 0, "NULL", 0, "NULL", 0, "NULL", 0) insert_values = (0, 0, "NULL", 0, 0, "NULL", 0, "NULL", 0, "NULL", "NULL", 0)
cursor.execute(insert_query, insert_values) cursor.execute(insert_query, insert_values)
database.commit() database.commit()
database.close() database.close()
@ -194,12 +196,12 @@ class Moderation(commands.Cog):
database = await self.connect() database = await self.connect()
cursor = database.cursor() cursor = database.cursor()
moderation_id = await self.get_next_case_number(guild_id=guild_id, cursor=cursor) 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)" sql = f"INSERT INTO `moderation_{guild_id}` (moderation_id, timestamp, moderation_type, target_id, moderator_id, duration, end_timestamp, reason, resolved, resolved_by, resolve_reason, expired) VALUES (%s, %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", "NULL", 0)
cursor.execute(sql, val) cursor.execute(sql, val)
database.commit() database.commit()
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, NULL, 0", 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, cursor = None): 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."""
@ -276,7 +278,9 @@ class Moderation(commands.Cog):
embed.description = embed.description + f"\n**Duration:** {duration_embed}\n**Expired:** {bool(case_dict['expired'])}" embed.description = embed.description + f"\n**Duration:** {duration_embed}\n**Expired:** {bool(case_dict['expired'])}"
embed.add_field(name='Reason', value=f"```{case_dict['reason']}```", inline=False) embed.add_field(name='Reason', value=f"```{case_dict['reason']}```", inline=False)
if case_dict['resolved'] == 1: if case_dict['resolved'] == 1:
embed.add_field(name='Resolve Reason', value=f"```{case_dict['resolve_reason']}```", inline=False) resolved_user = await self.fetch_user_dict(interaction, case_dict['resolved_by'])
resolved_name = resolved_user['name'] if resolved_user['discriminator'] == "0" else f"{resolved_user['name']}#{resolved_user['discriminator']}"
embed.add_field(name='Resolve Reason', value=f"Resolved by {resolved_name} ({resolved_user['id']}) for:\n```{case_dict['resolve_reason']}```", inline=False)
return embed return embed
raise(TypeError("'type' argument is invalid!")) raise(TypeError("'type' argument is invalid!"))
@ -477,10 +481,10 @@ class Moderation(commands.Cog):
await interaction.guild.unban(user, reason=f"Case #{case_number} resolved by {interaction.user.id}") await interaction.guild.unban(user, reason=f"Case #{case_number} resolved by {interaction.user.id}")
except discord.NotFound: except discord.NotFound:
pass pass
resolve_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET resolved = 1, expired = 1, resolve_reason = %s WHERE moderation_id = %s" resolve_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET resolved = 1, expired = 1, resolved_by, resolve_reason = %s WHERE moderation_id = %s"
else: else:
resolve_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET resolved = 1, resolve_reason = %s WHERE moderation_id = %s" resolve_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET resolved = 1, resolved_by = %s, resolve_reason = %s WHERE moderation_id = %s"
cursor.execute(resolve_query, (reason, case_number)) cursor.execute(resolve_query, (interaction.user.id, reason, case_number))
database.commit() database.commit()
response_query = "SELECT * FROM moderation_%s WHERE moderation_id = %s;" response_query = "SELECT * FROM moderation_%s WHERE moderation_id = %s;"
cursor.execute(response_query, (interaction.guild.id, case_number)) cursor.execute(response_query, (interaction.guild.id, case_number))