fix(aurora): fixed Moderation.get_latest() breaking when using only before and after, and no other kwargs
Some checks failed
Actions / Build Documentation (MkDocs) (pull_request) Failing after 27s
Actions / Lint Code (Ruff & Pylint) (pull_request) Successful in 39s

This commit is contained in:
Seaswimmer 2024-08-10 13:42:15 -04:00
parent 14750787b2
commit f3246366ff
Signed by: cswimr
GPG key ID: 3813315477F26F82
2 changed files with 10 additions and 4 deletions

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