Add get is_ascending command and autocomplete functions.
This commit is contained in:
+59
-1
@@ -6,6 +6,7 @@ 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."):
|
||||
@@ -18,10 +19,40 @@ class GetCog(commands.Cog, name="Get command."):
|
||||
async def get(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash command for getting. Never called."""
|
||||
|
||||
@get.subcommand("Commands for getting category information.")
|
||||
@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 get size of.", 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 to register channel to. Is SlashOption.
|
||||
category_id (str): String representation of Category id to register channel to. 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 the size for a category.")
|
||||
async def size(
|
||||
self,
|
||||
@@ -52,3 +83,30 @@ class GetCog(commands.Cog, name="Get command."):
|
||||
@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."""
|
||||
|
||||
@is_ascending.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")
|
||||
@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))
|
||||
|
||||
Reference in New Issue
Block a user