From 233e6ac90844e0cae4122066c22486b37f0f94c7 Mon Sep 17 00:00:00 2001 From: Seaswimmer Date: Tue, 13 Aug 2024 14:25:03 -0400 Subject: [PATCH] feat(aurora): added `expired` argument to the `/history` command --- aurora/aurora.py | 13 ++++++++----- aurora/models/moderation.py | 17 ++++++++++++++--- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index 94e9247..19a99c8 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -47,7 +47,7 @@ class Aurora(commands.Cog): This cog stores all of its data in an SQLite database.""" __author__ = ["Seaswimmer"] - __version__ = "3.0.0-indev3" + __version__ = "3.0.0-indev4" __documentation__ = "https://seacogs.coastalcommits.com/aurora/" async def red_delete_data_for_user(self, *, requester, user_id: int): @@ -530,6 +530,7 @@ class Aurora(commands.Cog): on: str | None = None, before: str | None = None, after: str | None = None, + expired: bool | None = None, types: str | None = None, ephemeral: bool | None = None, inline: bool | None = None, @@ -553,7 +554,9 @@ class Aurora(commands.Cog): List infractions before a certain date after: str List infractions after a certain date - types: bool + expired: bool + List expired or unexpired infractions + types: str List infractions of specific types, comma separated ephemeral: bool Hide the command response @@ -674,13 +677,13 @@ class Aurora(commands.Cog): if target: filename = f"moderation_target_{str(target.id)}_{str(interaction.guild.id)}.json" - moderations = await Moderation.find_by_target(bot=interaction.client, guild_id=interaction.guild.id, target=target.id, before=before, after=after, types=type_list) + moderations = await Moderation.find_by_target(bot=interaction.client, guild_id=interaction.guild.id, target=target.id, before=before, after=after, types=type_list, expired=expired) elif moderator: filename = f"moderation_moderator_{str(moderator.id)}_{str(interaction.guild.id)}.json" - moderations = await Moderation.find_by_moderator(bot=interaction.client, guild_id=interaction.guild.id, moderator=moderator.id, before=before, after=after, types=type_list) + moderations = await Moderation.find_by_moderator(bot=interaction.client, guild_id=interaction.guild.id, moderator=moderator.id, before=before, after=after, types=type_list, expired=expired) else: filename = f"moderation_{str(interaction.guild.id)}.json" - moderations = await Moderation.get_latest(bot=interaction.client, guild_id=interaction.guild.id, before=before, after=after, types=type_list) + moderations = await Moderation.get_latest(bot=interaction.client, guild_id=interaction.guild.id, before=before, after=after, types=type_list, expired=expired) if export: try: diff --git a/aurora/models/moderation.py b/aurora/models/moderation.py index e2217c4..0014cda 100644 --- a/aurora/models/moderation.py +++ b/aurora/models/moderation.py @@ -312,7 +312,7 @@ class Moderation(AuroraGuildModel): return results @classmethod - 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"]: + async def get_latest(cls, bot: Red, guild_id: int, before: datetime | None = None, after: datetime | None = None, limit: int | None = None, offset: int = 0, types: Iterable[Type] | None = None, expired: bool | None = None, cursor: Cursor | None = None) -> Tuple["Moderation"]: params = [] query = f"SELECT * FROM moderation_{guild_id}" conditions = [] @@ -327,6 +327,9 @@ class Moderation(AuroraGuildModel): if after: conditions.append("timestamp > ?") params.append(int(after.timestamp())) + if expired is not None: + conditions.append("expired = ?") + params.append(int(expired)) if conditions: query += " WHERE " + " AND ".join(conditions) @@ -353,7 +356,7 @@ class Moderation(AuroraGuildModel): raise ValueError(f"Case {moderation_id} not found in moderation_{guild_id}!") @classmethod - async def find_by_target(cls, bot: Red, guild_id: int, target: int, before: datetime = None, after: datetime = None, types: Iterable[Type] | None = None, cursor: Cursor | None = None) -> Tuple["Moderation"]: + async def find_by_target(cls, bot: Red, guild_id: int, target: int, before: datetime = None, after: datetime = None, types: Iterable[Type] | None = None, expired: bool | None = None, cursor: Cursor | None = None) -> Tuple["Moderation"]: query = f"SELECT * FROM moderation_{guild_id} WHERE target_id = ?" params = [target] if types: @@ -366,12 +369,16 @@ class Moderation(AuroraGuildModel): if after: query += " AND timestamp > ?" params.append(int(after.timestamp())) + if expired is not None: + query += " AND expired = ?" + params.append(int(expired)) + query += " ORDER BY moderation_id DESC;" return await cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=params, cursor=cursor) @classmethod - async def find_by_moderator(cls, bot: Red, guild_id: int, moderator: int, before: datetime = None, after: datetime = None, types: Iterable[Type] | None = None, cursor: Cursor | None = None) -> Tuple["Moderation"]: + async def find_by_moderator(cls, bot: Red, guild_id: int, moderator: int, before: datetime = None, after: datetime = None, types: Iterable[Type] | None = None, expired: bool | None = None, cursor: Cursor | None = None) -> Tuple["Moderation"]: query = f"SELECT * FROM moderation_{guild_id} WHERE moderator_id = ?" params = [moderator] if types: @@ -384,6 +391,10 @@ class Moderation(AuroraGuildModel): if after: query += " AND timestamp > ?" params.append(int(after.timestamp())) + if expired is not None: + query += " AND expired = ?" + params.append(int(expired)) + query += " ORDER BY moderation_id DESC;" return await cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=params, cursor=cursor)