WIP: Moderation type registry #26
1 changed files with 7 additions and 7 deletions
|
@ -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])})"
|
||||||
|
|
Loading…
Reference in a new issue