Fix lint smells and update model usage in submission.
This commit is contained in:
+36
-23
@@ -6,9 +6,11 @@ import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlmodel import col
|
||||
|
||||
from cogs.submission.verification_view import VerificationView
|
||||
from database.db import Category, CategoryGroup, Guild, Submission, engine
|
||||
from database.db import engine
|
||||
from database.models import Category, CategoryGroup, Guild, Submission
|
||||
from main import logger
|
||||
from utilities.utils import autofill_categories, autofill_groups, submit_score
|
||||
|
||||
@@ -19,8 +21,10 @@ class SubmissionCog(commands.Cog):
|
||||
def __init__(self) -> None:
|
||||
return
|
||||
|
||||
# TODO(imcompiling): fix too many return statements when reworking command.
|
||||
# https://gitea.cheezers.org/imcompiling/agon/issues/76
|
||||
@nextcord.slash_command()
|
||||
async def submit( # noqa: PLR0913
|
||||
async def submit( # noqa: PLR0911, PLR0913
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", required=True, description="Group to submit score to."),
|
||||
@@ -56,40 +60,49 @@ class SubmissionCog(commands.Cog):
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(Category).where(Category.GroupId == int(group_id)).where(Category.CategoryId == int(category_id))
|
||||
select(Category)
|
||||
.where(col(Category.group_id) == int(group_id))
|
||||
.where(col(Category.id) == int(category_id))
|
||||
)
|
||||
|
||||
category: Category = session.scalar(stmt)
|
||||
category: Category | None = session.scalar(stmt)
|
||||
|
||||
if category is None:
|
||||
await interaction.response.send_message("Category not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
# check if verification is required. if no picture, deny
|
||||
if category.IsValidated and proof is None:
|
||||
if category.is_validated and proof is None:
|
||||
await interaction.response.send_message(
|
||||
"This category required verification. Please attach a picture and re-submit.", ephemeral=True
|
||||
)
|
||||
return
|
||||
|
||||
# check with regex if score is in correct format
|
||||
verified_score = await self.verify_score(interaction, score, is_time_record=category.IsTimeRecord)
|
||||
verified_score = await self.verify_score(interaction, score, is_time_record=category.is_time_record)
|
||||
|
||||
# check if verify_score was successful. It replies with corrections required itself.
|
||||
if verified_score is None:
|
||||
return
|
||||
|
||||
# Create submission verification request or submit score if verification not needed.
|
||||
if not category.IsValidated:
|
||||
if not category.is_validated:
|
||||
await submit_score(interaction, int(group_id), int(category_id), username, verified_score)
|
||||
await interaction.response.send_message("Score has been submitted!", ephemeral=True)
|
||||
return
|
||||
|
||||
stmt = select(Guild).where(Guild.GuildId == interaction.guild_id)
|
||||
verification_channel_id: int = session.scalar(stmt).VerificationChannel
|
||||
stmt = select(col(Guild.verification_channel)).where(col(Guild.id) == interaction.guild_id)
|
||||
verification_channel_id: int | None = session.scalar(stmt)
|
||||
|
||||
if verification_channel_id is None:
|
||||
error_response = "No verification channel was registered. Contact server admins."
|
||||
await interaction.response.send_message(error_response, ephemeral=True)
|
||||
return
|
||||
|
||||
channel = interaction.guild.get_channel(verification_channel_id)
|
||||
|
||||
if channel is None:
|
||||
error_response = (
|
||||
"Registered Verification channel does not exist or was never registered. Contact server admins."
|
||||
)
|
||||
error_response = "Registered Verification channel does not exist. Contact server admins."
|
||||
await interaction.response.send_message(error_response, ephemeral=True)
|
||||
return
|
||||
|
||||
@@ -111,13 +124,13 @@ class SubmissionCog(commands.Cog):
|
||||
|
||||
# Save the submission data for later use.
|
||||
submission: Submission = Submission(
|
||||
CategoryId=category_id,
|
||||
GroupId=group_id,
|
||||
GuildId=interaction.guild_id,
|
||||
MessageId=verification_message.id,
|
||||
Score=verified_score,
|
||||
UserId=interaction.user.id,
|
||||
UserName=username,
|
||||
category_id=int(category_id),
|
||||
group_id=int(group_id),
|
||||
guild_id=interaction.guild_id,
|
||||
message_id=verification_message.id,
|
||||
score=verified_score,
|
||||
user_id=interaction.user.id,
|
||||
username=username,
|
||||
)
|
||||
|
||||
session.add(submission)
|
||||
@@ -151,15 +164,15 @@ class SubmissionCog(commands.Cog):
|
||||
|
||||
# Get group name from database
|
||||
stmt = (
|
||||
select(CategoryGroup.GroupName)
|
||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
.where(CategoryGroup.GroupId == group_id)
|
||||
select(col(CategoryGroup.name))
|
||||
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||
.where(col(CategoryGroup.id) == group_id)
|
||||
)
|
||||
embed.add_field(name="Group", value=session.scalar(stmt), inline=False)
|
||||
|
||||
# Get category name from database
|
||||
stmt = (
|
||||
select(Category.CategoryName).where(Category.GroupId == group_id).where(Category.CategoryId == category_id)
|
||||
select(col(Category.name)).where(col(Category.group_id) == group_id).where(col(Category.id) == category_id)
|
||||
)
|
||||
embed.add_field(name="Category", value=session.scalar(stmt), inline=False)
|
||||
embed.add_field(name="Score", value=score, inline=False)
|
||||
|
||||
Reference in New Issue
Block a user