Start filling out create category.
This commit is contained in:
+31
-3
@@ -6,9 +6,12 @@ from typing import Optional
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
# pylint: disable=import-error
|
||||
from utilities.utils import autofill_groups, MAX_LINE_LENGTH
|
||||
from utilities.sql_data_classes import Category, CategoryGroup, engine
|
||||
from utilities.utils import MAX_LINE_LENGTH, autofill_groups
|
||||
|
||||
|
||||
class CreateCog(commands.Cog, name="Create Cog"):
|
||||
@@ -44,7 +47,29 @@ class CreateCog(commands.Cog, name="Create Cog"):
|
||||
description="How many scores to post in Category. Default is 3.", required=False, default=3, min_value=1
|
||||
),
|
||||
) -> None:
|
||||
pass
|
||||
|
||||
new_category = Category(
|
||||
CategoryName=category_name,
|
||||
GroupId=int(group_id),
|
||||
Size=size,
|
||||
IsAscending=is_ascending,
|
||||
IsTimeRecord=is_time_record,
|
||||
IsValidated=is_validated,
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
try:
|
||||
session.add(new_category)
|
||||
session.commit()
|
||||
# TODO get correct exception
|
||||
except Exception as ece:
|
||||
# Category name already exists in group
|
||||
print(ece)
|
||||
session.rollback()
|
||||
stmt = select(CategoryGroup.GroupName).where(CategoryGroup.GroupId == int(group_id))
|
||||
interaction.response.send_message(
|
||||
f"{category_name} already exists in {session.scalar(stmt)}. Please rename.", ephemeral=True
|
||||
)
|
||||
|
||||
@create.subcommand(description="Create a new Category Group. Must not exist already for Guild.")
|
||||
async def group(
|
||||
@@ -72,7 +97,10 @@ class CreateCog(commands.Cog, name="Create Cog"):
|
||||
default=None,
|
||||
),
|
||||
) -> None:
|
||||
pass
|
||||
|
||||
# if no channel provided, use current channel.
|
||||
if channel is None:
|
||||
channel = interaction.channel
|
||||
|
||||
@category.on_autocomplete("group_id")
|
||||
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str):
|
||||
|
||||
@@ -11,7 +11,7 @@ from sqlalchemy.orm import Session
|
||||
|
||||
# pylint: disable=import-error
|
||||
from utilities.sql_data_classes import CategoryGroup, Guild, engine
|
||||
from utilities.utils import autofill_groups, MAX_LINE_LENGTH
|
||||
from utilities.utils import MAX_LINE_LENGTH, autofill_groups
|
||||
|
||||
|
||||
class SetCog(commands.Cog, name="Set command."):
|
||||
|
||||
Reference in New Issue
Block a user