feat(moderation): added edit command
Some checks failed
Pylint / Pylint (3.10) (push) Failing after 46s
Some checks failed
Pylint / Pylint (3.10) (push) Failing after 46s
This commit is contained in:
parent
621f29be5c
commit
c7e84c40d1
1 changed files with 46 additions and 0 deletions
|
@ -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'])
|
||||
|
|
Loading…
Reference in a new issue