Add command to get a category's size.
This commit is contained in:
+40
-1
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user