WIP: Refactor Aurora (3.0.0) #29
1 changed files with 15 additions and 17 deletions
|
@ -1085,47 +1085,45 @@ class Aurora(commands.Cog):
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
database = await Moderation.connect()
|
if target:
|
||||||
|
filename = "moderation_target_" + str(target.id) + "_" + str(interaction.guild.id) + ".json"
|
||||||
|
moderations = await Moderation.find_by_target(interaction.client, interaction.guild.id, target.id)
|
||||||
|
elif moderator:
|
||||||
|
filename = "moderation_moderator_" + str(moderator.id) + "_" + str(interaction.guild.id) + ".json"
|
||||||
|
moderations = await Moderation.find_by_moderator(interaction.client, interaction.guild.id, moderator.id)
|
||||||
|
else:
|
||||||
|
filename = "moderation_" + str(interaction.guild.id) + ".json"
|
||||||
|
moderations = await Moderation.get_latest(interaction.client, interaction.guild.id)
|
||||||
|
|
||||||
if export:
|
if export:
|
||||||
try:
|
try:
|
||||||
filename = (
|
filepath = (
|
||||||
str(data_manager.cog_data_path(cog_instance=self))
|
str(data_manager.cog_data_path(cog_instance=self))
|
||||||
+ str(os.sep)
|
+ str(os.sep)
|
||||||
+ f"moderation_{interaction.guild.id}.json"
|
+ filename
|
||||||
)
|
)
|
||||||
|
|
||||||
cases = await Moderation.get_latest(bot=interaction.client, guild_id=interaction.guild.id)
|
|
||||||
|
|
||||||
with open(filename, "w", encoding="utf-8") as f:
|
with open(filename, "w", encoding="utf-8") as f:
|
||||||
dump(obj=cases, fp=f, indent=2)
|
dump(obj=moderations, fp=f, indent=2)
|
||||||
|
|
||||||
await interaction.followup.send(
|
await interaction.followup.send(
|
||||||
file=discord.File(
|
file=discord.File(
|
||||||
filename, f"moderation_{interaction.guild.id}.json"
|
fp=filepath, filename=filename
|
||||||
),
|
),
|
||||||
ephemeral=ephemeral,
|
ephemeral=ephemeral,
|
||||||
)
|
)
|
||||||
|
|
||||||
os.remove(filename)
|
os.remove(filepath)
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
await interaction.followup.send(
|
await interaction.followup.send(
|
||||||
content=error(
|
content=error(
|
||||||
"An error occured while exporting the moderation history.\nError:\n"
|
"An error occured while exporting the moderation history.\nError:\n"
|
||||||
)
|
)
|
||||||
+ box(e, "py"),
|
+ box(text=e, lang="py"),
|
||||||
ephemeral=ephemeral,
|
ephemeral=ephemeral,
|
||||||
)
|
)
|
||||||
await database.close()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if target:
|
|
||||||
moderations = await Moderation.find_by_target(interaction.client, interaction.guild.id, target.id)
|
|
||||||
elif moderator:
|
|
||||||
moderations = await Moderation.find_by_moderator(interaction.client, interaction.guild.id, moderator.id)
|
|
||||||
else:
|
|
||||||
moderations = await Moderation.get_latest(interaction.client, interaction.guild.id)
|
|
||||||
|
|
||||||
case_quantity = len(moderations)
|
case_quantity = len(moderations)
|
||||||
page_quantity = ceil(case_quantity / pagesize)
|
page_quantity = ceil(case_quantity / pagesize)
|
||||||
start_index = (page - 1) * pagesize
|
start_index = (page - 1) * pagesize
|
||||||
|
|
Loading…
Reference in a new issue