55 lines
2.2 KiB
Python
55 lines
2.2 KiB
Python
"""View for verification buttons"""
|
|
|
|
import nextcord
|
|
from sqlalchemy import select
|
|
from sqlalchemy.orm import Session
|
|
|
|
from utilities.sql_data_classes import Submissions, engine
|
|
|
|
# pylint: disable=import-error
|
|
from utilities.utils import submit_score
|
|
|
|
|
|
class VerificationView(nextcord.ui.View):
|
|
"""Defines views for verifying score submissions"""
|
|
|
|
def __init__(self):
|
|
super().__init__(timeout=None)
|
|
|
|
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-button-submission")
|
|
async def deny_button(
|
|
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
|
): # pylint: disable=unused-argument
|
|
"""Button for denying score submission."""
|
|
with Session(engine) as session:
|
|
stmt = select(Submissions).where(Submissions.VerificationMessageId == interaction.message.id)
|
|
submission = session.scalar(stmt)
|
|
# let user know submission was denied
|
|
|
|
# TODO need to access bot here
|
|
|
|
# delete the submission
|
|
session.delete(stmt)
|
|
session.commit()
|
|
await interaction.message.delete()
|
|
|
|
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-button-submission")
|
|
async def approve_button(
|
|
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
|
): # pylint: disable=unused-argument
|
|
with Session(engine) as session:
|
|
stmt = select(Submissions).where(Submissions.VerificationMessageId == interaction.message.id)
|
|
submission = session.scalar(stmt)
|
|
|
|
try:
|
|
await submit_score(
|
|
interaction, submission.GroupId, submission.CategoryId, submission.UserName, submission.Score
|
|
)
|
|
content = interaction.message.content
|
|
content += f"\nApproved by <@{interaction.user.id}>."
|
|
await interaction.message.edit(content=content, view=None)
|
|
# TODO send message to let user know submission was accepted. Need access to bot here.
|
|
except UnboundLocalError:
|
|
await interaction.send("Instruct user to submit with all fields.")
|
|
await interaction.message.edit(view=None)
|