Edit verification view to use the database for information.
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
"""View for verification buttons."""
|
"""View for verification buttons."""
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from database_setup.sql_data_classes import Submission, engine
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from utilities.utils import submit_score
|
from utilities.utils import submit_score
|
||||||
@@ -20,27 +24,24 @@ class VerificationView(nextcord.ui.View):
|
|||||||
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-button-submission")
|
@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) -> None: # noqa: ARG002
|
async def approve_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
|
||||||
"""Button for approving score submission."""
|
"""Button for approving score submission."""
|
||||||
for embed in interaction.message.embeds:
|
with Session(engine) as session:
|
||||||
content = embed.to_dict()
|
stmt = (
|
||||||
|
select(Submission)
|
||||||
|
.where(Submission.GuildId == interaction.guild_id)
|
||||||
|
.where(Submission.MessageId == interaction.message.id)
|
||||||
|
)
|
||||||
|
|
||||||
for field in content["fields"]:
|
submission = session.scalar(stmt)
|
||||||
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"]
|
|
||||||
|
|
||||||
# TODO: rework to get the information from database instead
|
if submission is None:
|
||||||
|
await interaction.response.send_message("Could not find submission data in database.", ephemeral=True)
|
||||||
|
await interaction.message.delete()
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
await submit_score(
|
||||||
await submit_score(interaction, group_id, category_id, user, score)
|
interaction, submission.GroupId, submission.CategoryId, submission.UserName, submission.Score
|
||||||
|
)
|
||||||
content = interaction.message.content
|
content = interaction.message.content
|
||||||
content += f"\nApproved by <@{interaction.user.id}>."
|
content += f"\nApproved by <@{interaction.user.id}>."
|
||||||
# remove the bot information embed. it should always be the first one.
|
# 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])
|
await interaction.message.edit(content=content, view=None)
|
||||||
except UnboundLocalError:
|
|
||||||
await interaction.send("Instruct user to submit with all fields.")
|
|
||||||
await interaction.message.edit(view=None)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user