feat(moderation): added resolved_by field to mysql tables
All checks were successful
Pylint / Pylint (push) Successful in 1m11s
All checks were successful
Pylint / Pylint (push) Successful in 1m11s
This commit is contained in:
parent
d1d5bec732
commit
8a3ed15ee0
1 changed files with 16 additions and 12 deletions
|
@ -134,8 +134,9 @@ class Moderation(commands.Cog):
|
|||
"end_timestamp": result[6],
|
||||
"reason": result[7],
|
||||
"resolved": result[8],
|
||||
"resolve_reason": result[9],
|
||||
"expired": result[10]
|
||||
"resolved_by": result[9],
|
||||
"resolve_reason": result[10],
|
||||
"expired": result[11]
|
||||
}
|
||||
return case
|
||||
|
||||
|
@ -157,6 +158,7 @@ class Moderation(commands.Cog):
|
|||
end_timestamp INT,
|
||||
reason LONGTEXT,
|
||||
resolved BOOL NOT NULL,
|
||||
resolved_by LONGTEXT,
|
||||
resolve_reason LONGTEXT,
|
||||
expired BOOL NOT NULL
|
||||
)
|
||||
|
@ -164,10 +166,10 @@ class Moderation(commands.Cog):
|
|||
cursor.execute(query)
|
||||
insert_query = 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)
|
||||
(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)
|
||||
"""
|
||||
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)
|
||||
database.commit()
|
||||
database.close()
|
||||
|
@ -194,12 +196,12 @@ class Moderation(commands.Cog):
|
|||
database = await self.connect()
|
||||
cursor = database.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)"
|
||||
val = (moderation_id, timestamp, moderation_type, target_id, author_id, duration, end_timestamp, f"{reason}", 0, "NULL", 0)
|
||||
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", "NULL", 0)
|
||||
cursor.execute(sql, val)
|
||||
database.commit()
|
||||
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):
|
||||
"""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.add_field(name='Reason', value=f"```{case_dict['reason']}```", inline=False)
|
||||
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
|
||||
|
||||
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}")
|
||||
except discord.NotFound:
|
||||
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:
|
||||
resolve_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET resolved = 1, resolve_reason = %s WHERE moderation_id = %s"
|
||||
cursor.execute(resolve_query, (reason, case_number))
|
||||
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, (interaction.user.id, reason, case_number))
|
||||
database.commit()
|
||||
response_query = "SELECT * FROM moderation_%s WHERE moderation_id = %s;"
|
||||
cursor.execute(response_query, (interaction.guild.id, case_number))
|
||||
|
|
Loading…
Reference in a new issue