forked from blizzthewolf/SeaCogs
feat(moderation): added ability to edit durations
This commit is contained in:
parent
5b8f6823ef
commit
e9e2c20a58
1 changed files with 57 additions and 13 deletions
|
@ -1203,7 +1203,7 @@ class Moderation(commands.Cog):
|
|||
await interaction.response.send_message(content=f"No case with case number `{case}` found.", ephemeral=True)
|
||||
|
||||
@app_commands.command(name="edit")
|
||||
async def edit(self, interaction: discord.Interaction, case: int, reason: str):
|
||||
async def edit(self, interaction: discord.Interaction, case: int, reason: str, duration: str = None):
|
||||
"""Edit the reason of a specific case.
|
||||
|
||||
Parameters
|
||||
|
@ -1211,19 +1211,43 @@ class Moderation(commands.Cog):
|
|||
case: int
|
||||
What case are you editing?
|
||||
reason: str
|
||||
What is the new reason?"""
|
||||
What is the new reason?
|
||||
duration: str
|
||||
What is the new duration? Does not reapply the moderation if it has already expired."""
|
||||
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 != 0:
|
||||
parsed_time = None
|
||||
case_dict = await self.fetch_case(case, interaction.guild.id)
|
||||
if case_dict:
|
||||
conf = await self.check_conf(['mysql_database'])
|
||||
if conf:
|
||||
raise(LookupError)
|
||||
|
||||
if duration:
|
||||
try:
|
||||
parsed_time = parse(sval=duration, as_timedelta=True, raise_exception=True)
|
||||
except ValueError:
|
||||
await interaction.response.send_message("Please provide a valid duration!", ephemeral=True)
|
||||
return
|
||||
|
||||
end_timestamp = case_dict['timestamp'] + parsed_time.total_seconds()
|
||||
|
||||
if case_dict['type'] == 'MUTE':
|
||||
if (time.time() - case_dict['timestamp']) + parsed_time.total_seconds() > 2419200:
|
||||
await interaction.response.send_message("Please provide a duration that is less than 28 days from the initial moderation.")
|
||||
return
|
||||
|
||||
try:
|
||||
member = await interaction.guild.fetch_member(case_dict['target_id'])
|
||||
|
||||
await member.timeout(parsed_time, reason=f"Case #{case} edited by {interaction.user.id}")
|
||||
except discord.NotFound:
|
||||
pass
|
||||
|
||||
changes: list = case_dict['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)
|
||||
|
@ -1234,15 +1258,31 @@ class Moderation(commands.Cog):
|
|||
'type': "ORIGINAL",
|
||||
'timestamp': case_dict['timestamp'],
|
||||
'reason': case_dict['reason'],
|
||||
'user_id': case_dict['moderator_id']
|
||||
'user_id': case_dict['moderator_id'],
|
||||
'duration': case_dict['duration'],
|
||||
'end_timestamp': case_dict['end_timestamp']
|
||||
}
|
||||
)
|
||||
if parsed_time:
|
||||
changes.append(
|
||||
{
|
||||
'type': "EDIT",
|
||||
'timestamp': int(time.time()),
|
||||
'reason': reason,
|
||||
'user_id': interaction.user.id
|
||||
'user_id': interaction.user.id,
|
||||
'duration': parsed_time,
|
||||
'end_timestamp': end_timestamp
|
||||
}
|
||||
)
|
||||
else:
|
||||
changes.append(
|
||||
{
|
||||
'type': "EDIT",
|
||||
'timestamp': int(time.time()),
|
||||
'reason': reason,
|
||||
'user_id': interaction.user.id,
|
||||
'duration': case_dict['duration'],
|
||||
'end_timestamp': case_dict['end_timestamp']
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -1250,6 +1290,10 @@ class Moderation(commands.Cog):
|
|||
cursor = database.cursor()
|
||||
db = await self.config.mysql_database()
|
||||
|
||||
if parsed_time:
|
||||
update_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET changes = %s, reason = %s, duration = %s, end_timestamp = %s WHERE moderation_id = %s"
|
||||
cursor.execute(update_query, (json.dumps(changes), reason, parsed_time, end_timestamp, case))
|
||||
else:
|
||||
update_query = f"UPDATE `{db}`.`moderation_{interaction.guild.id}` SET changes = %s, reason = %s WHERE moderation_id = %s"
|
||||
cursor.execute(update_query, (json.dumps(changes), reason, case))
|
||||
database.commit()
|
||||
|
|
Loading…
Reference in a new issue