fix(moderation): hopefully fixed exports not exporting as files

This commit is contained in:
SeaswimmerTheFsh 2023-12-15 10:35:55 -05:00
parent e91cd10ce6
commit af9db8cc58
Signed by untrusted user: cswimr
GPG key ID: 1EBC234EEDA901AE

View file

@ -1137,10 +1137,10 @@ class Moderation(commands.Cog):
@app_commands.command(name="case")
@app_commands.choices(export=[
Choice(name="Export as File", value='file'),
Choice(name='Export as Codeblock', value='codeblock')
Choice(name="Export as File", value=1),
Choice(name='Export as Codeblock', value=2)
])
async def case(self, interaction: discord.Interaction, case: int, ephemeral: bool = None, changes: bool = False, export: Choice[str] = None):
async def case(self, interaction: discord.Interaction, case: int, ephemeral: bool = None, changes: bool = False, export: Choice[int] = None):
"""Check the details of a specific case.
Parameters
@ -1167,13 +1167,13 @@ class Moderation(commands.Cog):
case_dict = await self.fetch_case(case, interaction.guild.id)
if case_dict:
if export:
if export == 'file' or len(str(case)) > 1800:
if export == 1 or len(str(case_dict)) > 1800: # If exporting as file or if case is too large to export as codeblock
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:
json.dump(case_dict, f, indent=2)
if export == 'codeblock':
if export == 2: # If exporting as codeblock
content = f"Case #{case} exported.\n*Case was too large to export as codeblock, so it has been uploaded as a `.json` file.*"
else:
content = f"Case #{case} exported."