WIP: Refactor Aurora (3.0.0) #29

Draft
cswimr wants to merge 347 commits from aurora-pydantic into main
Showing only changes of commit be253b668b - Show all commits

View file

@ -11,7 +11,6 @@ import sqlite3
import time import time
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from math import ceil from math import ceil
from typing import List
import discord import discord
from discord import Object from discord import Object
@ -1114,35 +1113,14 @@ class Aurora(commands.Cog):
database.close() database.close()
return return
cursor = database.cursor()
if target: if target:
query = f"""SELECT * moderations = Moderation.find_by_target(interaction.client, interaction.guild.id, target.id)
FROM moderation_{interaction.guild.id}
WHERE target_id = ? AND moderation_id != 0
ORDER BY moderation_id DESC;"""
cursor.execute(query, (target.id,))
elif moderator: elif moderator:
query = f"""SELECT * moderations = Moderation.find_by_moderator(interaction.client, interaction.guild.id, moderator.id)
FROM moderation_{interaction.guild.id}
WHERE moderator_id = ? AND moderation_id != 0
ORDER BY moderation_id DESC;"""
cursor.execute(query, (moderator.id,))
else: else:
query = f"""SELECT * moderations = Moderation.get_all_cases(interaction.client, interaction.guild.id)
FROM moderation_{interaction.guild.id}
WHERE moderation_id != 0
ORDER BY moderation_id DESC;"""
cursor.execute(query)
results = cursor.fetchall() case_quantity = len(moderations)
moderation_list: List[Moderation] = []
for result in results:
moderation = Moderation.from_result(interaction.client, result, interaction.guild.id)
moderation_list.append(moderation)
case_quantity = len(moderation_list)
page_quantity = ceil(case_quantity / pagesize) page_quantity = ceil(case_quantity / pagesize)
start_index = (page - 1) * pagesize start_index = (page - 1) * pagesize
end_index = page * pagesize end_index = page * pagesize
@ -1155,7 +1133,7 @@ class Aurora(commands.Cog):
memory_dict = {} memory_dict = {}
for mod in moderation_list[start_index:end_index]: for mod in moderations[start_index:end_index]:
if mod.target_id not in memory_dict: if mod.target_id not in memory_dict:
memory_dict.update({ memory_dict.update({
str(mod.target_id): await mod.get_target() str(mod.target_id): await mod.get_target()