WIP: Refactor Aurora (3.0.0) #29

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

View file

@ -44,7 +44,7 @@ class Aurora(commands.Cog):
This cog stores all of its data in an SQLite database."""
__author__ = ["SeaswimmerTheFsh"]
__version__ = "2.4.0"
__version__ = "2.4.1"
__documentation__ = "https://seacogs.coastalcommits.com/aurora/"
async def red_delete_data_for_user(self, *, requester, user_id: int):

View file

@ -315,16 +315,22 @@ class Moderation(AuroraGuildModel):
async def get_latest(cls, bot: Red, guild_id: int, before: datetime = None, after: datetime = None, limit: int | None = None, offset: int = 0, types: Iterable[Type] | None = None, cursor: Cursor | None = None) -> Tuple["Moderation"]:
params = []
query = f"SELECT * FROM moderation_{guild_id} ORDER BY moderation_id DESC"
conditions = []
if types:
query += f" WHERE moderation_type IN ({', '.join(['?' for _ in types])})"
conditions.append(f"moderation_type IN ({', '.join(['?' for _ in types])})")
for t in types:
params.append(t.key)
if before:
query += " WHERE timestamp < ?"
conditions.append("timestamp < ?")
params.append(int(before.timestamp()))
if after:
query += " WHERE timestamp > ?"
conditions.append("timestamp > ?")
params.append(int(after.timestamp()))
if conditions:
query += " WHERE " + " AND ".join(conditions)
if limit:
query += " LIMIT ? OFFSET ?"
params.extend((limit, offset))