From 4785271ebbfe3a7e50161a3d347c01ce99b09188 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Fri, 7 Mar 2025 16:10:42 -0500 Subject: [PATCH] Add command to get a category's size. --- cogs/commands/get.py | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/cogs/commands/get.py b/cogs/commands/get.py index 0f557b5..c4f06ac 100644 --- a/cogs/commands/get.py +++ b/cogs/commands/get.py @@ -2,6 +2,10 @@ import nextcord from nextcord.ext import commands +from sqlmodel import Session, col, select + +from database.db import engine +from database.models import Category, CategoryGroup class GetCog(commands.Cog, name="Get command."): @@ -12,4 +16,39 @@ class GetCog(commands.Cog, name="Get command."): @nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True)) async def get(self, interaction: nextcord.Interaction) -> None: - """Parent slash command for setting settings. Never called.""" + """Parent slash command for getting. Never called.""" + + @get.subcommand("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 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 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} 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."""