Compare commits

...
2 Commits
Author SHA1 Message Date
imcompiling 4785271ebb Add command to get a category's size. 2025-03-07 16:10:42 -05:00
imcompiling f9d765ad92 Forgot to convert some ids to int. 2025-03-07 16:09:33 -05:00
2 changed files with 53 additions and 6 deletions
+40 -1
View File
@@ -2,6 +2,10 @@
import nextcord import nextcord
from nextcord.ext import commands 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."): 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)) @nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True))
async def get(self, interaction: nextcord.Interaction) -> None: 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."""
+13 -5
View File
@@ -45,7 +45,9 @@ class SetCog(commands.Cog, name="Set command."):
category_id (str): String representation of Category id to register channel to. Is SlashOption. category_id (str): String representation of Category id to register channel to. Is SlashOption.
size (int): Size to set. Is SlashOption. size (int): Size to set. Is SlashOption.
""" """
stmt = select(Category).where(col(CategoryGroup.id) == group_id).where(col(Category.id) == int(category_id)) stmt = (
select(Category).where(col(CategoryGroup.id) == int(group_id)).where(col(Category.id) == int(category_id))
)
with Session(engine) as session: with Session(engine) as session:
category = session.scalar(stmt) category = session.scalar(stmt)
@@ -91,7 +93,9 @@ class SetCog(commands.Cog, name="Set command."):
category_id (str): String representation of Category id to register channel to. Is SlashOption. category_id (str): String representation of Category id to register channel to. Is SlashOption.
ascending (bool): Boolean to set. Determines whether scores are sorted ascending or not. Is SlashOption. ascending (bool): Boolean to set. Determines whether scores are sorted ascending or not. Is SlashOption.
""" """
stmt = select(Category).where(col(CategoryGroup.id) == group_id).where(col(Category.id) == int(category_id)) stmt = (
select(Category).where(col(CategoryGroup.id) == int(group_id)).where(col(Category.id) == int(category_id))
)
with Session(engine) as session: with Session(engine) as session:
category = session.scalar(stmt) category = session.scalar(stmt)
@@ -139,7 +143,9 @@ class SetCog(commands.Cog, name="Set command."):
category_id (str): String representation of Category id to register channel to. Is SlashOption. category_id (str): String representation of Category id to register channel to. Is SlashOption.
validated (bool): Boolean to set. Determines whether scores are validated or not. Is SlashOption. validated (bool): Boolean to set. Determines whether scores are validated or not. Is SlashOption.
""" """
stmt = select(Category).where(col(CategoryGroup.id) == group_id).where(col(Category.id) == int(category_id)) stmt = (
select(Category).where(col(CategoryGroup.id) == int(group_id)).where(col(Category.id) == int(category_id))
)
with Session(engine) as session: with Session(engine) as session:
category = session.scalar(stmt) category = session.scalar(stmt)
@@ -184,7 +190,9 @@ class SetCog(commands.Cog, name="Set command."):
category_id (str): String representation of Category id to register channel to. Is SlashOption. category_id (str): String representation of Category id to register channel to. Is SlashOption.
name (str): The name to update the category's name to. Is SlashOption. name (str): The name to update the category's name to. Is SlashOption.
""" """
stmt = select(Category).where(col(CategoryGroup.id) == group_id).where(col(Category.id) == int(category_id)) stmt = (
select(Category).where(col(CategoryGroup.id) == int(group_id)).where(col(Category.id) == int(category_id))
)
with Session(engine) as session: with Session(engine) as session:
category = session.scalar(stmt) category = session.scalar(stmt)
@@ -229,7 +237,7 @@ class SetCog(commands.Cog, name="Set command."):
group_id (str): String representation of Group id to register channel to. Is SlashOption. group_id (str): String representation of Group id to register channel to. Is SlashOption.
name (str): The name to update the group's name to. Is SlashOption. name (str): The name to update the group's name to. Is SlashOption.
""" """
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == group_id) stmt = select(CategoryGroup).where(col(CategoryGroup.id) == int(group_id))
with Session(engine) as session: with Session(engine) as session:
group = session.scalar(stmt) group = session.scalar(stmt)