From dc9e7554926e8c98c4a2506d0b725860c1655f86 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 18 Dec 2023 16:27:22 -0500 Subject: [PATCH] fix(moderation): hopefully fixed history exports --- moderation/moderation.py | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/moderation/moderation.py b/moderation/moderation.py index d289068..253ac76 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -565,6 +565,31 @@ class Moderation(commands.Cog): return database = await connect() + + if export: + cursor = database.cursor(dictionary=True) + + query = """SELECT * + FROM moderation_%s + ORDER BY moderation_id DESC;""" + cursor.execute(query, (interaction.guild.id,)) + + results = cursor.fetchall() + + try: + filename = str(data_manager.cog_data_path(cog_instance=self)) + str(os.sep) + f"moderation_{interaction.guild.id}.json" + + with open(filename, "w", encoding="utf-8") as f: + json.dump(results, f, indent=2) + + await interaction.followup.send(file=discord.File(filename, 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 + cursor = database.cursor() if target: @@ -588,21 +613,6 @@ class Moderation(commands.Cog): results = cursor.fetchall() result_dict_list = [] - if export: - try: - filename = str(data_manager.cog_data_path(cog_instance=self)) + str(os.sep) + f"moderation_{interaction.guild.id}.json" - - with open(filename, "w", encoding="utf-8") as f: - json.dump(results, f, indent=2) - - await interaction.followup.send(file=discord.File(filename, 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 - for result in results: case_dict = generate_dict(result) if case_dict['moderation_id'] == 0: