feat(aurora): converted /history to use the new Moderation sql queries

This commit is contained in:
Seaswimmer 2024-06-03 01:07:00 -04:00
parent 22f9ce52d1
commit be253b668b
Signed by untrusted user: cswimr
GPG key ID: 5D671B5D03D65A7F

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()