fix(moderation): hopefully fixed history exports
This commit is contained in:
parent
7f0d2ae153
commit
dc9e755492
1 changed files with 25 additions and 15 deletions
|
@ -565,6 +565,31 @@ class Moderation(commands.Cog):
|
||||||
return
|
return
|
||||||
|
|
||||||
database = await connect()
|
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()
|
cursor = database.cursor()
|
||||||
|
|
||||||
if target:
|
if target:
|
||||||
|
@ -588,21 +613,6 @@ class Moderation(commands.Cog):
|
||||||
results = cursor.fetchall()
|
results = cursor.fetchall()
|
||||||
result_dict_list = []
|
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:
|
for result in results:
|
||||||
case_dict = generate_dict(result)
|
case_dict = generate_dict(result)
|
||||||
if case_dict['moderation_id'] == 0:
|
if case_dict['moderation_id'] == 0:
|
||||||
|
|
Loading…
Reference in a new issue