feat(aurora): added expired argument to the /history command
Some checks failed
Actions / Build Documentation (MkDocs) (pull_request) Successful in 28s
Actions / Lint Code (Ruff & Pylint) (pull_request) Failing after 41s

This commit is contained in:
Seaswimmer 2024-08-13 14:25:03 -04:00
parent 448ac6792e
commit 233e6ac908
Signed by: cswimr
GPG key ID: 3813315477F26F82
2 changed files with 22 additions and 8 deletions

View file

@ -47,7 +47,7 @@ class Aurora(commands.Cog):
This cog stores all of its data in an SQLite database.""" This cog stores all of its data in an SQLite database."""
__author__ = ["Seaswimmer"] __author__ = ["Seaswimmer"]
__version__ = "3.0.0-indev3" __version__ = "3.0.0-indev4"
__documentation__ = "https://seacogs.coastalcommits.com/aurora/" __documentation__ = "https://seacogs.coastalcommits.com/aurora/"
async def red_delete_data_for_user(self, *, requester, user_id: int): async def red_delete_data_for_user(self, *, requester, user_id: int):
@ -530,6 +530,7 @@ class Aurora(commands.Cog):
on: str | None = None, on: str | None = None,
before: str | None = None, before: str | None = None,
after: str | None = None, after: str | None = None,
expired: bool | None = None,
types: str | None = None, types: str | None = None,
ephemeral: bool | None = None, ephemeral: bool | None = None,
inline: bool | None = None, inline: bool | None = None,
@ -553,7 +554,9 @@ class Aurora(commands.Cog):
List infractions before a certain date List infractions before a certain date
after: str after: str
List infractions after a certain date List infractions after a certain date
types: bool expired: bool
List expired or unexpired infractions
types: str
List infractions of specific types, comma separated List infractions of specific types, comma separated
ephemeral: bool ephemeral: bool
Hide the command response Hide the command response
@ -674,13 +677,13 @@ class Aurora(commands.Cog):
if target: if target:
filename = f"moderation_target_{str(target.id)}_{str(interaction.guild.id)}.json" 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: elif moderator:
filename = f"moderation_moderator_{str(moderator.id)}_{str(interaction.guild.id)}.json" 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: else:
filename = f"moderation_{str(interaction.guild.id)}.json" 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: if export:
try: try:

View file

@ -312,7 +312,7 @@ class Moderation(AuroraGuildModel):
return results return results
@classmethod @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 = [] params = []
query = f"SELECT * FROM moderation_{guild_id}" query = f"SELECT * FROM moderation_{guild_id}"
conditions = [] conditions = []
@ -327,6 +327,9 @@ class Moderation(AuroraGuildModel):
if after: if after:
conditions.append("timestamp > ?") conditions.append("timestamp > ?")
params.append(int(after.timestamp())) params.append(int(after.timestamp()))
if expired is not None:
conditions.append("expired = ?")
params.append(int(expired))
if conditions: if conditions:
query += " WHERE " + " AND ".join(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}!") raise ValueError(f"Case {moderation_id} not found in moderation_{guild_id}!")
@classmethod @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 = ?" query = f"SELECT * FROM moderation_{guild_id} WHERE target_id = ?"
params = [target] params = [target]
if types: if types:
@ -366,12 +369,16 @@ class Moderation(AuroraGuildModel):
if after: if after:
query += " AND timestamp > ?" query += " AND timestamp > ?"
params.append(int(after.timestamp())) params.append(int(after.timestamp()))
if expired is not None:
query += " AND expired = ?"
params.append(int(expired))
query += " ORDER BY moderation_id DESC;" query += " ORDER BY moderation_id DESC;"
return await cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=params, cursor=cursor) return await cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=params, cursor=cursor)
@classmethod @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 = ?" query = f"SELECT * FROM moderation_{guild_id} WHERE moderator_id = ?"
params = [moderator] params = [moderator]
if types: if types:
@ -384,6 +391,10 @@ class Moderation(AuroraGuildModel):
if after: if after:
query += " AND timestamp > ?" query += " AND timestamp > ?"
params.append(int(after.timestamp())) params.append(int(after.timestamp()))
if expired is not None:
query += " AND expired = ?"
params.append(int(expired))
query += " ORDER BY moderation_id DESC;" query += " ORDER BY moderation_id DESC;"
return await cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=params, cursor=cursor) return await cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=params, cursor=cursor)