fix(moderation): fixed exporting cases
This commit is contained in:
parent
8c347dd1f0
commit
87703daaf4
1 changed files with 6 additions and 6 deletions
|
@ -1137,10 +1137,10 @@ class Moderation(commands.Cog):
|
||||||
|
|
||||||
@app_commands.command(name="case")
|
@app_commands.command(name="case")
|
||||||
@app_commands.choices(export=[
|
@app_commands.choices(export=[
|
||||||
Choice(name="Export as File", value=1),
|
Choice(name='Export as File', value='file'),
|
||||||
Choice(name='Export as Codeblock', value=2)
|
Choice(name='Export as Codeblock', value='codeblock')
|
||||||
])
|
])
|
||||||
async def case(self, interaction: discord.Interaction, case: int, ephemeral: bool = None, changes: bool = False, export: Choice[int] = None):
|
async def case(self, interaction: discord.Interaction, case: int, ephemeral: bool = None, changes: bool = False, export: Choice[str] = None):
|
||||||
"""Check the details of a specific case.
|
"""Check the details of a specific case.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
@ -1152,7 +1152,7 @@ class Moderation(commands.Cog):
|
||||||
changes: bool
|
changes: bool
|
||||||
List the changes made to the case
|
List the changes made to the case
|
||||||
export: bool
|
export: bool
|
||||||
Export the case to a JSON file"""
|
Export the case to a JSON file or codeblock"""
|
||||||
permissions = self.check_permissions(interaction.client.user, ['embed_links'], interaction)
|
permissions = self.check_permissions(interaction.client.user, ['embed_links'], interaction)
|
||||||
if permissions:
|
if permissions:
|
||||||
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
||||||
|
@ -1167,13 +1167,13 @@ class Moderation(commands.Cog):
|
||||||
case_dict = await self.fetch_case(case, interaction.guild.id)
|
case_dict = await self.fetch_case(case, interaction.guild.id)
|
||||||
if case_dict:
|
if case_dict:
|
||||||
if export:
|
if export:
|
||||||
if export == 1 or len(str(case_dict)) > 1800: # If exporting as file or if case is too large to export as codeblock
|
if export.value == 'file' or len(str(case_dict)) > 1800:
|
||||||
filename = str(data_manager.cog_data_path(cog_instance=self)) + str(os.sep) + f"moderation_{interaction.guild.id}_case_{case}.json"
|
filename = str(data_manager.cog_data_path(cog_instance=self)) + str(os.sep) + f"moderation_{interaction.guild.id}_case_{case}.json"
|
||||||
|
|
||||||
with open(filename, "w", encoding="utf-8") as f:
|
with open(filename, "w", encoding="utf-8") as f:
|
||||||
json.dump(case_dict, f, indent=2)
|
json.dump(case_dict, f, indent=2)
|
||||||
|
|
||||||
if export == 2: # If exporting as codeblock
|
if export.value == 'codeblock':
|
||||||
content = f"Case #{case} exported.\n*Case was too large to export as codeblock, so it has been uploaded as a `.json` file.*"
|
content = f"Case #{case} exported.\n*Case was too large to export as codeblock, so it has been uploaded as a `.json` file.*"
|
||||||
else:
|
else:
|
||||||
content = f"Case #{case} exported."
|
content = f"Case #{case} exported."
|
||||||
|
|
Loading…
Reference in a new issue