Update the verification view to use database.
This commit is contained in:
@@ -193,10 +193,9 @@ class Submission:
|
|||||||
|
|
||||||
embed = Embed(title="Highscores Submission", description=description)
|
embed = Embed(title="Highscores Submission", description=description)
|
||||||
embed.add_field(name="User Name", value=self.username, inline=False)
|
embed.add_field(name="User Name", value=self.username, inline=False)
|
||||||
embed.add_field(name="Table", value=self.group_id, inline=False)
|
embed.add_field(name="GroupId", value=self.group_id, inline=False)
|
||||||
if self.category_id:
|
if self.category_id:
|
||||||
stmt = select(Category.CategoryName).where(Category.CategoryId == self.category_id)
|
embed.add_field(name="CategoryId", value=self.category_id, inline=False)
|
||||||
embed.add_field(name="Category", value=session.scalar(stmt), inline=False)
|
|
||||||
if self.score:
|
if self.score:
|
||||||
embed.add_field(name="Score", value=self.score, inline=False)
|
embed.add_field(name="Score", value=self.score, inline=False)
|
||||||
return embed
|
return embed
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
"""View for verification buttons"""
|
"""View for verification buttons"""
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from classes.score import Score, ScoreTime # pylint: disable=import-error
|
|
||||||
|
|
||||||
from highscores import highscores_data # pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from utilities.utils import submit_score # pylint: disable=import-error
|
from utilities.utils import submit_score
|
||||||
|
|
||||||
|
|
||||||
class VerificationView(nextcord.ui.View):
|
class VerificationView(nextcord.ui.View):
|
||||||
@@ -13,18 +12,14 @@ class VerificationView(nextcord.ui.View):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(timeout=None)
|
super().__init__(timeout=None)
|
||||||
|
|
||||||
@nextcord.ui.button(
|
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-button-submission")
|
||||||
label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-button-submission"
|
|
||||||
)
|
|
||||||
async def deny_button(
|
async def deny_button(
|
||||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||||
): # pylint: disable=unused-argument
|
): # pylint: disable=unused-argument
|
||||||
"""Button for denying score submission."""
|
"""Button for denying score submission."""
|
||||||
await interaction.message.delete()
|
await interaction.message.delete()
|
||||||
|
|
||||||
@nextcord.ui.button(
|
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-button-submission")
|
||||||
label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-button-submission"
|
|
||||||
)
|
|
||||||
async def approve_button(
|
async def approve_button(
|
||||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||||
): # pylint: disable=unused-argument
|
): # pylint: disable=unused-argument
|
||||||
@@ -32,33 +27,18 @@ class VerificationView(nextcord.ui.View):
|
|||||||
content = interaction.message.embeds[0].to_dict()
|
content = interaction.message.embeds[0].to_dict()
|
||||||
|
|
||||||
for field in content["fields"]:
|
for field in content["fields"]:
|
||||||
if field["name"] == "Table":
|
if field["name"] == "GroupId":
|
||||||
table = field["value"]
|
group_id = int(field["value"])
|
||||||
elif field["name"] == "Category":
|
elif field["name"] == "CategoryId":
|
||||||
category = field["value"]
|
category_id = int(field["value"])
|
||||||
elif field["name"] == "Score":
|
elif field["name"] == "Score":
|
||||||
score = field["value"]
|
score = float(field["value"])
|
||||||
elif field["name"] == "User Name":
|
elif field["name"] == "User Name":
|
||||||
user = field["value"]
|
user = field["value"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
submission_guild = highscores_data.get_guild(interaction.guild_id)
|
|
||||||
submission_table = submission_guild.get_table(table)
|
|
||||||
submission_category = submission_table.get_category(category)
|
|
||||||
if submission_category.time_record:
|
|
||||||
submission_score: ScoreTime = ScoreTime(user)
|
|
||||||
submission_score.set_value_str(score)
|
|
||||||
else:
|
|
||||||
submission_score: Score = Score(user)
|
|
||||||
submission_score.set_value_str(score)
|
|
||||||
|
|
||||||
await submit_score(
|
await submit_score(interaction, group_id, category_id, user, score)
|
||||||
interaction,
|
|
||||||
submission_guild,
|
|
||||||
submission_table,
|
|
||||||
submission_category,
|
|
||||||
submission_score,
|
|
||||||
)
|
|
||||||
content = interaction.message.content
|
content = interaction.message.content
|
||||||
content += f"\nApproved by <@{interaction.user.id}>."
|
content += f"\nApproved by <@{interaction.user.id}>."
|
||||||
await interaction.message.edit(content=content, view=None)
|
await interaction.message.edit(content=content, view=None)
|
||||||
|
|||||||
Reference in New Issue
Block a user