diff --git a/aurora/aurora.py b/aurora/aurora.py index 629f62e..3966949 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -1187,12 +1187,14 @@ class Aurora(commands.Cog): and ctx.message.attachments[0].content_type == "application/json; charset=utf-8" ): + file = await ctx.message.attachments[0].read() + data: list[dict] = sorted(json.loads(file), key=lambda x: x["moderation_id"]) message = await ctx.send( warning( "Are you sure you want to import moderations from another bot?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*" ) ) - await message.edit(view=ImportAuroraView(60, ctx, message)) + await message.edit(view=ImportAuroraView(60, ctx, message, data)) else: await ctx.send(error("Please provide a valid Aurora export file.")) diff --git a/aurora/importers/aurora.py b/aurora/importers/aurora.py index 9bd4f4b..f34a7b3 100644 --- a/aurora/importers/aurora.py +++ b/aurora/importers/aurora.py @@ -2,7 +2,7 @@ import json import os from time import time -from typing import Dict +from typing import Dict, List from discord import ButtonStyle, File, Interaction, Message, ui from redbot.core import commands, data_manager @@ -15,10 +15,11 @@ from ..utilities.utils import create_guild_table, timedelta_from_string class ImportAuroraView(ui.View): - def __init__(self, timeout, ctx, message): + def __init__(self, timeout, ctx, message, data: List[Dict[str, any]]): super().__init__() self.ctx: commands.Context = ctx self.message: Message = message + self.data: List[Dict[str, any]] = data @ui.button(label="Yes", style=ButtonStyle.success) async def import_button_y( @@ -38,12 +39,9 @@ class ImportAuroraView(ui.View): await interaction.edit_original_response(content="Importing moderations...") - file = await self.ctx.message.attachments[0].read() - data: list[dict] = sorted(json.loads(file), key=lambda x: x["moderation_id"]) - failed_cases = [] - for case in data: + for case in self.data: if case["moderation_id"] == 0: continue diff --git a/aurora/models/moderation.py b/aurora/models/moderation.py index c586a66..e2217c4 100644 --- a/aurora/models/moderation.py +++ b/aurora/models/moderation.py @@ -331,10 +331,12 @@ class Moderation(AuroraGuildModel): if conditions: query += " WHERE " + " AND ".join(conditions) + query += " ORDER BY moderation_id DESC" + if limit: query += " LIMIT ? OFFSET ?" params.extend((limit, offset)) - query += " ORDER BY moderation_id DESC;" + query += ";" return await cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=tuple(params) if params else (), cursor=cursor) @classmethod