Verification button working.

This commit is contained in:
alwayscompiling
2022-07-03 17:11:06 -04:00
parent 445c77b012
commit 0834634cde
3 changed files with 46 additions and 12 deletions
+8 -4
View File
@@ -2,10 +2,10 @@
Bot command to submit a score
"""
from ast import AsyncFunctionDef
from nextcord.ext import commands
from utils import highscore_manage # pylint: disable=import-error
from highscores import highscores_data # pylint: disable=import-error
from utilities.utils import submit_score # pylint: disable=import-error
from .verification_view import VerificationView
class Score(commands.Cog, name="Score"):
@@ -14,6 +14,11 @@ class Score(commands.Cog, name="Score"):
def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
"""Called when the cog is loaded"""
self.bot.add_view(VerificationView())
@commands.command(name="score")
async def score(self, ctx: commands.Context, boss_name: str, category: str, score: str):
"""A command which calls a function to submit the score to highscores.
@@ -35,10 +40,9 @@ class Score(commands.Cog, name="Score"):
await channel.send(
content=verification_string,
files=[await attch.to_file() for attch in ctx.message.attachments],
view=VerificationView(),
)
# await highscore_manage.submit_score(self, ctx, boss_name, category, score)
# This function will be called when this extension is loaded.
# It is necessary to add these functions to the bot.
+28
View File
@@ -0,0 +1,28 @@
"""View for verification buttons"""
import nextcord
from utilities.utils import submit_score # pylint: disable=import-error
class VerificationView(nextcord.ui.View):
"""Defines views for verifying score submissions"""
def __init__(self):
super().__init__(timeout=None)
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve")
async def approve_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction):
"""Button for approving score submission."""
await interaction.response.send_message("Approved")
content = interaction.message.content.split(":")
user = content[0]
boss_name = content[1]
category = content[2]
score = content[3]
await submit_score(interaction, user, boss_name, category, score)
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny")
async def deny_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction):
"""Button for denying score submission."""
await interaction.response.send_message("Denied")
+10 -8
View File
@@ -58,7 +58,9 @@ async def send_highscore_message(channel, boss_name: str):
highscores_data[boss_name]["message_id"] = message_id
async def submit_score(self, ctx: commands.Context, boss_name: str, category: str, score: str):
async def submit_score(
interaction: nextcord.Interaction, user: str, boss_name: str, category: str, score: str
):
"""
Adds a score to the high scores and sorts. Removes a score if larger than size limit.
@param boss: the boss to add score to
@@ -75,11 +77,11 @@ async def submit_score(self, ctx: commands.Context, boss_name: str, category: st
minutes = score_list[0]
seconds = score_list[1]
score_seconds = int(minutes) * 60 + int(seconds)
score_tuple = (ctx.author.display_name, score, score_seconds)
score_tuple = (user, score, score_seconds)
sort_index = 2
else:
score_tuple = (ctx.author.display_name, int(score))
score_tuple = (user, int(score))
sort_index = 1
scores = highscores_data[boss_name]["categories"][category]
@@ -97,12 +99,12 @@ async def submit_score(self, ctx: commands.Context, boss_name: str, category: st
# edit message
highscore_channel_id = highscores_data["highscore_channel_id"]
print(f"Editting message {highscore_channel_id}")
channel = self.bot.get_channel(highscore_channel_id)
if channel is None:
response = 'Registered Highscores channel does not exist or was never registered. \
channel = interaction.guild.get_channel(highscore_channel_id)
error_response = 'Registered Highscores channel does not exist or was never registered. \
Register with "?register" command.'
await ctx.send(response)
return
assert channel is not None, await interaction.send(error_response)
await send_highscore_message(channel, boss_name)
# save data