From ea9d8fb201b2d52d2631407a7c1cedf3acd966ce Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Thu, 14 Dec 2023 20:06:57 -0500 Subject: [PATCH] feat(moderation): case exports will now export as codeblocks instead of files if they are less than 1,800 characters in length --- moderation/moderation.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/moderation/moderation.py b/moderation/moderation.py index b83efd6..6c046ef 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -1124,15 +1124,19 @@ class Moderation(commands.Cog): case = await self.fetch_case(case_number, interaction.guild.id) 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" + if len(str(case)) > 1800: + 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) + 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) + await interaction.response.send_message(file=discord.File(filename, f"moderation_{interaction.guild.id}_case_{case_number}.json"), ephemeral=ephemeral) - os.remove(filename) - return + os.remove(filename) + return + else: + await interaction.response.send_message(content=f"```json\n{json.dumps(case, indent=2)}```", ephemeral=ephemeral) + return if changes: embed = await self.embed_factory('changes', interaction=interaction, case_dict=case) else: