WIP: Refactor Aurora (3.0.0) #29

Draft
cswimr wants to merge 347 commits from aurora-pydantic into main
3 changed files with 10 additions and 8 deletions
Showing only changes of commit cbd82f8572 - Show all commits

View file

@ -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."))

View file

@ -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

View file

@ -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