From c7e84c40d1240c8e12042b4e37b57829a16cd6b8 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Thu, 14 Dec 2023 19:38:35 -0500 Subject: [PATCH] feat(moderation): added edit command --- moderation/moderation.py | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/moderation/moderation.py b/moderation/moderation.py index 6d9929f..7873d4a 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -1108,6 +1108,52 @@ class Moderation(commands.Cog): return await interaction.response.send_message(content=f"No case with case number `{case_number}` found.", ephemeral=True) + @app_commands.command(name="edit") + async def edit(self, interaction: discord.Interaction, case_number: int, reason: str): + """Edit the reason of a specific case. + + Parameters + ----------- + case_number: int + What case are you editing? + reason: str + What is the new reason?""" + permissions = self.check_permissions(interaction.client.user, ['embed_links'], interaction) + if permissions: + await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True) + return + + if case_number != 0: + case = await self.fetch_case(case_number, interaction.guild.id) + if case: + conf = await self.check_conf(['mysql_database']) + if conf: + raise(LookupError) + + changes: list = json.loads(case['changes']) + if not changes: + changes.append({'timestamp': case['timestamp'], 'reason': case['reason'], 'user_id': case['moderator_id']}) + changes.append({'timestamp': int(time.time()), 'reason': reason, 'user_id': interaction.user.id}) + + database = await self.connect() + cursor = database.cursor() + db = await self.config.mysql_database() + + update_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET changes = %s, reason = %s WHERE moderation_id = %s" + cursor.execute(update_query, (changes, reason, case_number)) + database.commit() + + new_case = await self.fetch_case(case_number, interaction.guild.id) + embed = await self.embed_factory('case', interaction=interaction, case_dict=new_case) + + await interaction.response.send_message(content=f"✅ Moderation #{case_number} edited!", embed=embed, ephemeral=True) + await self.log(interaction, case_number) + + cursor.close() + database.close() + return + await interaction.response.send_message(content=f"No case with case number `{case_number}` found.", ephemeral=True) + @tasks.loop(minutes=1) async def handle_expiry(self): conf = await self.check_conf(['mysql_database'])