fix(aurora): minor changes to the aurora importer and also fixed a bug in the Moderation.get_latest method
All checks were successful
Actions / Build Documentation (MkDocs) (pull_request) Successful in 29s
Actions / Lint Code (Ruff & Pylint) (pull_request) Successful in 42s

This commit is contained in:
Seaswimmer 2024-08-12 18:50:07 -04:00
parent 8822d1714e
commit cbd82f8572
Signed by: cswimr
GPG key ID: 3813315477F26F82
3 changed files with 10 additions and 8 deletions

View file

@ -1187,12 +1187,14 @@ class Aurora(commands.Cog):
and ctx.message.attachments[0].content_type and ctx.message.attachments[0].content_type
== "application/json; charset=utf-8" == "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( message = await ctx.send(
warning( 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.*" "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: else:
await ctx.send(error("Please provide a valid Aurora export file.")) await ctx.send(error("Please provide a valid Aurora export file."))

View file

@ -2,7 +2,7 @@
import json import json
import os import os
from time import time from time import time
from typing import Dict from typing import Dict, List
from discord import ButtonStyle, File, Interaction, Message, ui from discord import ButtonStyle, File, Interaction, Message, ui
from redbot.core import commands, data_manager 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): class ImportAuroraView(ui.View):
def __init__(self, timeout, ctx, message): def __init__(self, timeout, ctx, message, data: List[Dict[str, any]]):
super().__init__() super().__init__()
self.ctx: commands.Context = ctx self.ctx: commands.Context = ctx
self.message: Message = message self.message: Message = message
self.data: List[Dict[str, any]] = data
@ui.button(label="Yes", style=ButtonStyle.success) @ui.button(label="Yes", style=ButtonStyle.success)
async def import_button_y( async def import_button_y(
@ -38,12 +39,9 @@ class ImportAuroraView(ui.View):
await interaction.edit_original_response(content="Importing moderations...") 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 = [] failed_cases = []
for case in data: for case in self.data:
if case["moderation_id"] == 0: if case["moderation_id"] == 0:
continue continue

View file

@ -331,10 +331,12 @@ class Moderation(AuroraGuildModel):
if conditions: if conditions:
query += " WHERE " + " AND ".join(conditions) query += " WHERE " + " AND ".join(conditions)
query += " ORDER BY moderation_id DESC"
if limit: if limit:
query += " LIMIT ? OFFSET ?" query += " LIMIT ? OFFSET ?"
params.extend((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) return await cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=tuple(params) if params else (), cursor=cursor)
@classmethod @classmethod