feat(moderation): added ability to export moderation history
Some checks failed
Pylint / Pylint (3.10) (push) Failing after 1m2s
Some checks failed
Pylint / Pylint (3.10) (push) Failing after 1m2s
This commit is contained in:
parent
d4e0425e0a
commit
6681a7d938
1 changed files with 17 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
|||
import logging
|
||||
import json
|
||||
import time
|
||||
import os
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Union
|
||||
import discord
|
||||
|
@ -697,7 +699,7 @@ class Moderation(commands.Cog):
|
|||
await self.log(interaction, moderation_id)
|
||||
|
||||
@app_commands.command(name="history")
|
||||
async def history(self, interaction: discord.Interaction, target: discord.User = None, moderator: discord.User = None, pagesize: app_commands.Range[int, 1, 25] = 5, page: int = 1, ephemeral: bool = False):
|
||||
async def history(self, interaction: discord.Interaction, target: discord.User = None, moderator: discord.User = None, pagesize: app_commands.Range[int, 1, 25] = 5, page: int = 1, ephemeral: bool = False, export: bool = False):
|
||||
"""List previous infractions.
|
||||
|
||||
Parameters
|
||||
|
@ -711,7 +713,9 @@ class Moderation(commands.Cog):
|
|||
page: int
|
||||
Page to select
|
||||
epheremal: bool
|
||||
Hide the command response"""
|
||||
Hide the command response
|
||||
export: bool
|
||||
Exports the server's entire moderation history to a JSON file"""
|
||||
await interaction.response.defer(ephemeral=ephemeral)
|
||||
permissions = self.check_permissions(interaction.client.user, ['embed_links'], interaction)
|
||||
if permissions:
|
||||
|
@ -741,6 +745,17 @@ class Moderation(commands.Cog):
|
|||
for result in results:
|
||||
case_dict = self.generate_dict(result)
|
||||
result_dict_list.append(case_dict)
|
||||
if export:
|
||||
try:
|
||||
filename = f"moderation_{interaction.guild.id}.json"
|
||||
with open(filename, "w") as f:
|
||||
json.dump(result_dict_list, f)
|
||||
await interaction.followup.send(file=discord.File(f"moderation_{interaction.guild.id}.json"), ephemeral=ephemeral)
|
||||
os.remove(filename)
|
||||
return
|
||||
except json.JSONDecodeError as e:
|
||||
await interaction.followup.send(content=f"An error occured while exporting the moderation history.\nError:\n```{e}```", ephemeral=ephemeral)
|
||||
return
|
||||
if target or moderator:
|
||||
case_quantity = len(result_dict_list)
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue