feat(moderation): added exporting cases

This commit is contained in:
Seaswimmer 2023-12-14 19:59:22 -05:00
parent 8929a2c190
commit eb9cb459fd
Signed by untrusted user: cswimr
GPG key ID: 1EBC234EEDA901AE

View file

@ -1104,7 +1104,7 @@ class Moderation(commands.Cog):
database.close() database.close()
@app_commands.command(name="case") @app_commands.command(name="case")
async def case(self, interaction: discord.Interaction, case_number: int, ephemeral: bool = False, changes: bool = False): async def case(self, interaction: discord.Interaction, case_number: int, ephemeral: bool = False, changes: bool = False, export: bool = False):
"""Check the details of a specific case. """Check the details of a specific case.
Parameters Parameters
@ -1121,6 +1121,16 @@ class Moderation(commands.Cog):
if case_number != 0: if case_number != 0:
case = await self.fetch_case(case_number, interaction.guild.id) case = await self.fetch_case(case_number, interaction.guild.id)
if case: if case:
if export:
filename = str(data_manager.cog_data_path(cog_instance=self)) + str(os.sep) + f"moderation_{interaction.guild.id}_case_{case_number}.json"
with open(filename, "w", encoding="utf-8") as f:
json.dump(case, f, indent=2)
await interaction.response.send_message(file=discord.File(filename, f"moderation_{interaction.guild.id}_case_{case_number}.json"), ephemeral=ephemeral)
os.remove(filename)
return
if changes: if changes:
embed = await self.embed_factory('changes', interaction=interaction, case_dict=case) embed = await self.embed_factory('changes', interaction=interaction, case_dict=case)
else: else: