174 lines
7.6 KiB
Python
174 lines
7.6 KiB
Python
"""Get command hierarchy."""
|
|
|
|
import nextcord
|
|
from nextcord.ext import commands
|
|
from sqlmodel import Session, col, select
|
|
|
|
from database.db import engine
|
|
from database.models import Category, CategoryGroup
|
|
from utilities.utils import autofill_categories, autofill_groups
|
|
|
|
|
|
class GetCog(commands.Cog, name="Get command."):
|
|
"""Class holds commands for setting variables in guild's database."""
|
|
|
|
def __init__(self) -> None:
|
|
"""Default constructor for SetCog class. Does nothing."""
|
|
|
|
@nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True))
|
|
async def get(self, interaction: nextcord.Interaction) -> None:
|
|
"""Parent slash command for getting. Never called."""
|
|
|
|
@get.subcommand(description="Commands for getting category information.")
|
|
async def category(self, interaction: nextcord.Interaction) -> None:
|
|
"""Parent slash subcommand for getting category information. Never called."""
|
|
|
|
@category.subcommand(description="Get whether a category is sorted in ascending or descending order.")
|
|
async def is_ascending(
|
|
self,
|
|
interaction: nextcord.Interaction,
|
|
group_id: str = nextcord.SlashOption(name="group", description="Group that Category is in.", required=True),
|
|
category_id: str = nextcord.SlashOption(
|
|
name="category", description="Category to information from.", required=True
|
|
),
|
|
) -> None:
|
|
"""
|
|
Command to view how a category is sorted.
|
|
|
|
Args:
|
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
|
group_id (str): String representation of Group id get information from. Is SlashOption.
|
|
category_id (str): String representation of Category id to get information from. Is SlashOption.
|
|
"""
|
|
stmt = (
|
|
select(Category).where(col(CategoryGroup.id) == int(group_id)).where(col(Category.id) == int(category_id))
|
|
)
|
|
|
|
with Session(engine) as session:
|
|
category = session.scalar(stmt)
|
|
if category is None:
|
|
await interaction.response.send_message("Group or Category was not found.", ephemeral=True)
|
|
return
|
|
|
|
await interaction.response.send_message(
|
|
f"{category.name} is sorted in {'ascending' if category.is_ascending else 'descending'} order.",
|
|
ephemeral=True,
|
|
)
|
|
|
|
@category.subcommand(description="Get whether a category required validation.")
|
|
async def is_validated(
|
|
self,
|
|
interaction: nextcord.Interaction,
|
|
group_id: str = nextcord.SlashOption(name="group", description="Group that Category is in.", required=True),
|
|
category_id: str = nextcord.SlashOption(
|
|
name="category", description="Category to information from.", required=True
|
|
),
|
|
) -> None:
|
|
"""
|
|
Command to view if a category required photo validation.
|
|
|
|
Args:
|
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
|
group_id (str): String representation of Group id get information from. Is SlashOption.
|
|
category_id (str): String representation of Category id to get information from. Is SlashOption.
|
|
"""
|
|
stmt = (
|
|
select(Category).where(col(CategoryGroup.id) == int(group_id)).where(col(Category.id) == int(category_id))
|
|
)
|
|
|
|
with Session(engine) as session:
|
|
category = session.scalar(stmt)
|
|
if category is None:
|
|
await interaction.response.send_message("Group or Category was not found.", ephemeral=True)
|
|
return
|
|
|
|
await interaction.response.send_message(
|
|
f"{category.name} does {'not ' if not category.is_validated else ''} require validation.",
|
|
ephemeral=True,
|
|
)
|
|
|
|
@category.subcommand(description="Get the size for a category.")
|
|
async def size(
|
|
self,
|
|
interaction: nextcord.Interaction,
|
|
group_id: str = nextcord.SlashOption(name="group", description="Group that Category is in.", required=True),
|
|
category_id: str = nextcord.SlashOption(name="category", description="Category to get size of.", required=True),
|
|
) -> None:
|
|
"""
|
|
Command to view a category's size.
|
|
|
|
Args:
|
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
|
group_id (str): String representation of Group id get information from. Is SlashOption.
|
|
category_id (str): String representation of Category id to get information from. Is SlashOption.
|
|
"""
|
|
stmt = (
|
|
select(Category).where(col(CategoryGroup.id) == int(group_id)).where(col(Category.id) == int(category_id))
|
|
)
|
|
|
|
with Session(engine) as session:
|
|
category = session.scalar(stmt)
|
|
if category is None:
|
|
await interaction.response.send_message("Group or Category was not found.", ephemeral=True)
|
|
return
|
|
|
|
await interaction.response.send_message(f"{category.name} has a size of {category.size}.", ephemeral=True)
|
|
|
|
@get.subcommand(description="Commands for getting group information.")
|
|
async def group(self, interaction: nextcord.Interaction) -> None:
|
|
"""Parent slash subcommand for getting group information. Never called."""
|
|
|
|
@group.subcommand(description="Get the pad length of a group.")
|
|
async def pad_length(
|
|
self,
|
|
interaction: nextcord.Interaction,
|
|
group_id: str = nextcord.SlashOption(name="group", description="Group to get pad length of.", required=True),
|
|
) -> None:
|
|
"""
|
|
Command to view a group's pad length.
|
|
|
|
Args:
|
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
|
group_id (str): String representation of Group id get information from. Is SlashOption.
|
|
"""
|
|
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == int(group_id))
|
|
|
|
with Session(engine) as session:
|
|
group = session.scalar(stmt)
|
|
if group is None:
|
|
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
|
return
|
|
|
|
await interaction.response.send_message(
|
|
f"{group.name} has a pad length of {group.pad_length}.", ephemeral=True
|
|
)
|
|
|
|
@is_ascending.on_autocomplete("category_id")
|
|
@is_validated.on_autocomplete("category_id")
|
|
@size.on_autocomplete("category_id")
|
|
async def category_autocomplete(self, interaction: nextcord.Interaction, category_id: str, group_id: str) -> None:
|
|
"""
|
|
Autocomplete function for category names.
|
|
|
|
Args:
|
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
|
category_id (str): String to be autocompleted with Category name.
|
|
group_id (str): Group to find Category from.
|
|
"""
|
|
await interaction.response.send_autocomplete(
|
|
autofill_categories(interaction.guild_id, int(group_id), category_id)
|
|
)
|
|
|
|
@is_ascending.on_autocomplete("group_id")
|
|
@is_validated.on_autocomplete("group_id")
|
|
@size.on_autocomplete("group_id")
|
|
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
|
|
"""
|
|
Sends results from autofill_groups back to group_output_channel for autocompletion of group_id.
|
|
|
|
Args:
|
|
interaction (nextcord.Interaction): Interaction with command.
|
|
group_id (str): String to run autocompletion against.
|
|
"""
|
|
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|