50 lines
2.0 KiB
Python
50 lines
2.0 KiB
Python
"""View for verification buttons"""
|
|
|
|
import nextcord
|
|
|
|
# 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."""
|
|
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
|
|
"""Button for approving score submission."""
|
|
for embed in interaction.message.embeds:
|
|
content = embed.to_dict()
|
|
|
|
for field in content["fields"]:
|
|
if field["name"] == "GroupId":
|
|
group_id = int(field["value"])
|
|
elif field["name"] == "CategoryId":
|
|
category_id = int(field["value"])
|
|
elif field["name"] == "Score":
|
|
score = field["value"]
|
|
elif field["name"] == "User Name":
|
|
user = field["value"]
|
|
|
|
try:
|
|
|
|
await submit_score(interaction, group_id, category_id, user, score)
|
|
content = interaction.message.content
|
|
content += f"\nApproved by <@{interaction.user.id}>."
|
|
# remove the bot information embed. it should always be the first one.
|
|
await interaction.message.edit(content=content, view=None, embed=interaction.message.embeds[0])
|
|
except UnboundLocalError:
|
|
await interaction.send("Instruct user to submit with all fields.")
|
|
await interaction.message.edit(view=None)
|