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