misc(aurora): adding typechecks to return values in utils
This commit is contained in:
parent
afb961799d
commit
db7c06b044
1 changed files with 9 additions and 9 deletions
|
@ -17,7 +17,7 @@ def check_permissions(
|
||||||
permissions: list,
|
permissions: list,
|
||||||
ctx: Union[commands.Context, Interaction] = None,
|
ctx: Union[commands.Context, Interaction] = None,
|
||||||
guild: Guild = None,
|
guild: Guild = None,
|
||||||
):
|
) -> Union[bool, str]:
|
||||||
"""Checks if a user has a specific permission (or a list of permissions) in a channel."""
|
"""Checks if a user has a specific permission (or a list of permissions) in a channel."""
|
||||||
if ctx:
|
if ctx:
|
||||||
member = ctx.guild.get_member(user.id)
|
member = ctx.guild.get_member(user.id)
|
||||||
|
@ -42,7 +42,7 @@ def check_permissions(
|
||||||
|
|
||||||
async def check_moddable(
|
async def check_moddable(
|
||||||
target: Union[User, Member], interaction: Interaction, permissions: list
|
target: Union[User, Member], interaction: Interaction, permissions: list
|
||||||
):
|
) -> bool:
|
||||||
"""Checks if a moderator can moderate a target."""
|
"""Checks if a moderator can moderate a target."""
|
||||||
if check_permissions(interaction.client.user, permissions, guild=interaction.guild):
|
if check_permissions(interaction.client.user, permissions, guild=interaction.guild):
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
|
@ -124,8 +124,8 @@ async def get_next_case_number(guild_id: str, cursor=None) -> int:
|
||||||
return (result[0] + 1) if result else 1
|
return (result[0] + 1) if result else 1
|
||||||
|
|
||||||
|
|
||||||
def generate_dict(result):
|
def generate_dict(result) -> dict:
|
||||||
case: dict = {
|
case = {
|
||||||
"moderation_id": result[0],
|
"moderation_id": result[0],
|
||||||
"timestamp": result[1],
|
"timestamp": result[1],
|
||||||
"moderation_type": result[2],
|
"moderation_type": result[2],
|
||||||
|
@ -146,7 +146,7 @@ def generate_dict(result):
|
||||||
return case
|
return case
|
||||||
|
|
||||||
|
|
||||||
async def fetch_user_dict(interaction: Interaction, user_id: str):
|
async def fetch_user_dict(interaction: Interaction, user_id: str) -> dict:
|
||||||
"""This function returns a dictionary containing either user information or a standard deleted user template."""
|
"""This function returns a dictionary containing either user information or a standard deleted user template."""
|
||||||
if user_id == "?":
|
if user_id == "?":
|
||||||
user_dict = {"id": "?", "name": "Unknown User", "discriminator": "0"}
|
user_dict = {"id": "?", "name": "Unknown User", "discriminator": "0"}
|
||||||
|
@ -173,7 +173,7 @@ async def fetch_user_dict(interaction: Interaction, user_id: str):
|
||||||
return user_dict
|
return user_dict
|
||||||
|
|
||||||
|
|
||||||
async def fetch_channel_dict(interaction: Interaction, channel_id: str):
|
async def fetch_channel_dict(interaction: Interaction, channel_id: str) -> dict:
|
||||||
"""This function returns a dictionary containing either channel information or a standard deleted channel template."""
|
"""This function returns a dictionary containing either channel information or a standard deleted channel template."""
|
||||||
try:
|
try:
|
||||||
channel = interaction.guild.get_channel(channel_id)
|
channel = interaction.guild.get_channel(channel_id)
|
||||||
|
@ -192,7 +192,7 @@ async def fetch_channel_dict(interaction: Interaction, channel_id: str):
|
||||||
return channel_dict
|
return channel_dict
|
||||||
|
|
||||||
|
|
||||||
async def fetch_role_dict(interaction: Interaction, role_id: str):
|
async def fetch_role_dict(interaction: Interaction, role_id: str) -> dict:
|
||||||
"""This function returns a dictionary containing either role information or a standard deleted role template."""
|
"""This function returns a dictionary containing either role information or a standard deleted role template."""
|
||||||
role = interaction.guild.get_role(role_id)
|
role = interaction.guild.get_role(role_id)
|
||||||
if not role:
|
if not role:
|
||||||
|
@ -203,7 +203,7 @@ async def fetch_role_dict(interaction: Interaction, role_id: str):
|
||||||
return role_dict
|
return role_dict
|
||||||
|
|
||||||
|
|
||||||
async def log(interaction: Interaction, moderation_id: int, resolved: bool = False):
|
async def log(interaction: Interaction, moderation_id: int, resolved: bool = False) -> None:
|
||||||
"""This function sends a message to the guild's configured logging channel when an infraction takes place."""
|
"""This function sends a message to the guild's configured logging channel when an infraction takes place."""
|
||||||
from .database import fetch_case
|
from .database import fetch_case
|
||||||
from .factory import log_factory
|
from .factory import log_factory
|
||||||
|
@ -223,7 +223,7 @@ async def log(interaction: Interaction, moderation_id: int, resolved: bool = Fal
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
async def send_evidenceformat(interaction: Interaction, case_dict: dict):
|
async def send_evidenceformat(interaction: Interaction, case_dict: dict) -> None:
|
||||||
"""This function sends an ephemeral message to the moderator who took the moderation action, with a pre-made codeblock for use in the mod-evidence channel."""
|
"""This function sends an ephemeral message to the moderator who took the moderation action, with a pre-made codeblock for use in the mod-evidence channel."""
|
||||||
from .factory import evidenceformat_factory
|
from .factory import evidenceformat_factory
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue