feat(moderation): added edit command

This commit is contained in:
Seaswimmer 2023-12-14 19:38:35 -05:00
parent 621f29be5c
commit c7e84c40d1
Signed by untrusted user: cswimr
GPG key ID: 1EBC234EEDA901AE

View file

@ -1108,6 +1108,52 @@ class Moderation(commands.Cog):
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)
@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) @tasks.loop(minutes=1)
async def handle_expiry(self): async def handle_expiry(self):
conf = await self.check_conf(['mysql_database']) conf = await self.check_conf(['mysql_database'])