Fix lint smells and update model usage.

This commit is contained in:
2025-03-04 11:04:10 -05:00
parent a99b488ae1
commit d7e44d3a22
+17 -15
View File
@@ -4,8 +4,10 @@ import nextcord
from nextcord.ext import commands from nextcord.ext import commands
from sqlalchemy import exc, select from sqlalchemy import exc, select
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from sqlmodel import col
from database.db import Category, CategoryGroup, engine from database.db import engine
from database.models import Category, CategoryGroup
from utilities.utils import MAX_LINE_LENGTH, autofill_groups, send_highscore_message from utilities.utils import MAX_LINE_LENGTH, autofill_groups, send_highscore_message
@@ -52,30 +54,30 @@ class CreateCog(commands.Cog, name="Create Cog"):
size (int): How many sores to show in the category message. Is SlashOption. size (int): How many sores to show in the category message. Is SlashOption.
""" """
new_category = Category( new_category = Category(
CategoryName=category_name, name=category_name,
GroupId=int(group_id), group_id=int(group_id),
Size=size, size=size,
IsAscending=is_ascending, is_ascending=is_ascending,
IsTimeRecord=is_time_record, is_time_record=is_time_record,
IsValidated=is_validated, is_validated=is_validated,
) )
# Open connection to engine and add new category. # Open connection to engine and add new category.
with Session(engine) as session: with Session(engine) as session:
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == int(group_id)) stmt = select(CategoryGroup).where(col(CategoryGroup.id) == int(group_id))
group = session.scalar(stmt) group = session.scalar(stmt)
try: try:
session.add(new_category) session.add(new_category)
session.commit() session.commit()
await send_highscore_message(session, interaction.guild, group) await send_highscore_message(session, interaction.guild, group)
await interaction.response.send_message( await interaction.response.send_message(
f'"{category_name}" has been added to "{group.GroupName}"!', ephemeral=True f'"{category_name}" has been added to "{group.name}"!', ephemeral=True
) )
except exc.IntegrityError: except exc.IntegrityError:
# Category name already exists in group # Category name already exists in group
session.rollback() session.rollback()
await interaction.response.send_message( await interaction.response.send_message(
f'"{category_name}" already exists in "{group.GroupName}". Please rename.', ephemeral=True f'"{category_name}" already exists in "{group.name}". Please rename.', ephemeral=True
) )
@create.subcommand(description="Create a new Category Group. Must not exist already for Guild.") @create.subcommand(description="Create a new Category Group. Must not exist already for Guild.")
@@ -123,11 +125,11 @@ class CreateCog(commands.Cog, name="Create Cog"):
channel_id: int = channel.id channel_id: int = channel.id
new_group = CategoryGroup( new_group = CategoryGroup(
GroupName=group_name, name=group_name,
ChannelId=channel_id, channel_id=channel_id,
GuildId=interaction.guild_id, guild_id=interaction.guild_id,
PadLength=pad_length, pad_length=pad_length,
UsernameLength=username_length, username_length=username_length,
) )
with Session(engine) as session: with Session(engine) as session: