misc(aurora): use tuples instead of lists
All checks were successful
Actions / Build Documentation (MkDocs) (pull_request) Successful in 44s
Actions / Lint Code (Ruff & Pylint) (pull_request) Successful in 1m14s

This commit is contained in:
Seaswimmer 2024-06-03 00:55:09 -04:00
parent 99d95afe07
commit 499cfbe8a9
Signed by: cswimr
GPG key ID: 5D671B5D03D65A7F

View file

@ -2,7 +2,7 @@ import json
import sqlite3 import sqlite3
from datetime import datetime, timedelta from datetime import datetime, timedelta
from time import time from time import time
from typing import Dict, Iterable, List, Optional, Union from typing import Dict, Iterable, List, Optional, Tuple, Union
import discord import discord
from discord import NotFound from discord import NotFound
@ -202,7 +202,7 @@ class Moderation(AuroraGuildModel):
return cls.from_dict(bot=bot, data=case) return cls.from_dict(bot=bot, data=case)
@classmethod @classmethod
def execute(cls, bot: Red, guild_id: int, query: str, parameters: tuple | None = None) -> List["Moderation"]: def execute(cls, bot: Red, guild_id: int, query: str, parameters: tuple | None = None) -> Tuple["Moderation"]:
from ..utilities.database import connect from ..utilities.database import connect
if not parameters: if not parameters:
parameters = () parameters = ()
@ -218,8 +218,8 @@ class Moderation(AuroraGuildModel):
case = cls.from_result(bot=bot, result=result, guild_id=guild_id) case = cls.from_result(bot=bot, result=result, guild_id=guild_id)
if case.moderation_id != 0: if case.moderation_id != 0:
cases.append(case) cases.append(case)
return cases return tuple(iterable=cases)
return [] return ()
@classmethod @classmethod
def from_sql(cls, bot: Red, moderation_id: int, guild_id: int) -> "Moderation": def from_sql(cls, bot: Red, moderation_id: int, guild_id: int) -> "Moderation":
@ -234,7 +234,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
def find_by_target(cls, bot: Red, guild_id: int, target: int, types: list | None = None) -> List["Moderation"]: def find_by_target(cls, bot: Red, guild_id: int, target: int, types: list | None = None) -> Tuple["Moderation"]:
query = f"SELECT * FROM moderation_{guild_id} WHERE target_id = ?" query = f"SELECT * FROM moderation_{guild_id} WHERE target_id = ?"
if types: if types:
query += f" AND moderation_type IN ({', '.join(['?' for _ in types])})" query += f" AND moderation_type IN ({', '.join(['?' for _ in types])})"
@ -243,7 +243,7 @@ class Moderation(AuroraGuildModel):
return cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=(target, *types) if types else (target,)) return cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=(target, *types) if types else (target,))
@classmethod @classmethod
def find_by_moderator(cls, bot: Red, guild_id: int, moderator: int, types: list | None = None) -> List["Moderation"]: def find_by_moderator(cls, bot: Red, guild_id: int, moderator: int, types: list | None = None) -> Tuple["Moderation"]:
query = f"SELECT * FROM moderation_{guild_id} WHERE moderator_id = ?" query = f"SELECT * FROM moderation_{guild_id} WHERE moderator_id = ?"
if types: if types:
query += f" AND moderation_type IN ({', '.join(['?' for _ in types])})" query += f" AND moderation_type IN ({', '.join(['?' for _ in types])})"
@ -252,7 +252,7 @@ class Moderation(AuroraGuildModel):
return cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=(moderator, *types) if types else (moderator,)) return cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=(moderator, *types) if types else (moderator,))
@classmethod @classmethod
def get_all_cases(cls, bot: Red, guild_id: int, types: list | None = None) -> List["Moderation"]: def get_all_cases(cls, bot: Red, guild_id: int, types: list | None = None) -> Tuple["Moderation"]:
query = f"SELECT * FROM moderation_{guild_id}" query = f"SELECT * FROM moderation_{guild_id}"
if types: if types:
query += f" WHERE moderation_type IN ({', '.join(['?' for _ in types])})" query += f" WHERE moderation_type IN ({', '.join(['?' for _ in types])})"