feat(moderation): resolving moderations now logs in the changes list
Some checks failed
Pylint / Pylint (3.10) (push) Failing after 46s

This commit is contained in:
Seaswimmer 2023-12-14 19:57:43 -05:00
parent d623622d3b
commit 8929a2c190
Signed by: cswimr
GPG key ID: 1EBC234EEDA901AE

View file

@ -374,6 +374,7 @@ class Moderation(commands.Cog):
- 'message' - 'message'
- 'log' - WIP - 'log' - WIP
- 'case' - 'case'
- 'changes'
Required arguments for 'message': Required arguments for 'message':
- guild - guild
@ -387,7 +388,7 @@ class Moderation(commands.Cog):
- case_dict - case_dict
- resolved (optional) - resolved (optional)
Required arguments for 'case': Required arguments for 'case' & 'changes':
- interaction - interaction
- case_dict""" - case_dict"""
if embed_type == 'message': if embed_type == 'message':
@ -1046,6 +1047,28 @@ class Moderation(commands.Cog):
if reason is None: if reason is None:
reason = "No reason given." reason = "No reason given."
changes: list = case['changes']
if len(changes) > 25:
await interaction.response.send_message(content="Due to limitations with Discord's embed system, you cannot edit a case more than 25 times.", ephemeral=True)
return
if not changes:
changes.append(
{
'type': "ORIGINAL",
'timestamp': case['timestamp'],
'reason': case['reason'],
'user_id': case['moderator_id']
}
)
changes.append(
{
'type': "RESOLVE",
'timestamp': int(time.time()),
'reason': reason,
'user_id': interaction.user.id
}
)
if case['moderation_type'] in ['UNMUTE', 'UNBAN']: if case['moderation_type'] in ['UNMUTE', 'UNBAN']:
await interaction.response.send_message(content="You cannot resolve this type of moderation!", ephemeral=True) await interaction.response.send_message(content="You cannot resolve this type of moderation!", ephemeral=True)
@ -1066,19 +1089,14 @@ class Moderation(commands.Cog):
except discord.NotFound: except discord.NotFound:
pass pass
resolve_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET resolved = 1, expired = 1, resolved_by = %s, resolve_reason = %s WHERE moderation_id = %s" resolve_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET resolved = 1, expired = 1, changes = %s, resolved_by = %s, resolve_reason = %s WHERE moderation_id = %s"
else: else:
resolve_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET resolved = 1, resolved_by = %s, resolve_reason = %s WHERE moderation_id = %s" resolve_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET resolved = 1, changes = %s, resolved_by = %s, resolve_reason = %s WHERE moderation_id = %s"
cursor.execute(resolve_query, (interaction.user.id, reason, case_number)) cursor.execute(resolve_query, (json.dumps(changes), interaction.user.id, reason, case_number))
database.commit() database.commit()
response_query = "SELECT * FROM moderation_%s WHERE moderation_id = %s;" embed = await self.embed_factory('case', interaction=interaction, case_dict=await self.fetch_case(case_number, interaction.guild.id))
cursor.execute(response_query, (interaction.guild.id, case_number))
result = cursor.fetchone()
case_dict = self.generate_dict(result)
embed = await self.embed_factory('case', interaction=interaction, case_dict=case_dict)
await interaction.response.send_message(content=f"✅ Moderation #{case_number} resolved!", embed=embed) await interaction.response.send_message(content=f"✅ Moderation #{case_number} resolved!", embed=embed)
await self.log(interaction, case_number, True) await self.log(interaction, case_number, True)
@ -1086,7 +1104,7 @@ class Moderation(commands.Cog):
database.close() database.close()
@app_commands.command(name="case") @app_commands.command(name="case")
async def case(self, interaction: discord.Interaction, case_number: int, ephemeral: bool = False): async def case(self, interaction: discord.Interaction, case_number: int, ephemeral: bool = False, changes: bool = False):
"""Check the details of a specific case. """Check the details of a specific case.
Parameters Parameters
@ -1103,7 +1121,10 @@ class Moderation(commands.Cog):
if case_number != 0: if case_number != 0:
case = await self.fetch_case(case_number, interaction.guild.id) case = await self.fetch_case(case_number, interaction.guild.id)
if case: if case:
embed = await self.embed_factory('case', interaction=interaction, case_dict=case) if changes:
embed = await self.embed_factory('changes', interaction=interaction, case_dict=case)
else:
embed = await self.embed_factory('case', interaction=interaction, case_dict=case)
await interaction.response.send_message(embed=embed, ephemeral=ephemeral) await interaction.response.send_message(embed=embed, ephemeral=ephemeral)
return return
await interaction.response.send_message(content=f"No case with case number `{case_number}` found.", ephemeral=True) await interaction.response.send_message(content=f"No case with case number `{case_number}` found.", ephemeral=True)
@ -1137,6 +1158,7 @@ class Moderation(commands.Cog):
if not changes: if not changes:
changes.append( changes.append(
{ {
'type': "ORIGINAL",
'timestamp': case['timestamp'], 'timestamp': case['timestamp'],
'reason': case['reason'], 'reason': case['reason'],
'user_id': case['moderator_id'] 'user_id': case['moderator_id']
@ -1144,6 +1166,7 @@ class Moderation(commands.Cog):
) )
changes.append( changes.append(
{ {
'type': "EDIT",
'timestamp': int(time.time()), 'timestamp': int(time.time()),
'reason': reason, 'reason': reason,
'user_id': interaction.user.id 'user_id': interaction.user.id