Verification button working.
This commit is contained in:
@@ -2,10 +2,10 @@
|
|||||||
Bot command to submit a score
|
Bot command to submit a score
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ast import AsyncFunctionDef
|
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
from utils import highscore_manage # pylint: disable=import-error
|
|
||||||
from highscores import highscores_data # 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"):
|
class Score(commands.Cog, name="Score"):
|
||||||
@@ -14,6 +14,11 @@ class Score(commands.Cog, name="Score"):
|
|||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = 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")
|
@commands.command(name="score")
|
||||||
async def score(self, ctx: commands.Context, boss_name: str, category: str, score: str):
|
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.
|
"""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(
|
await channel.send(
|
||||||
content=verification_string,
|
content=verification_string,
|
||||||
files=[await attch.to_file() for attch in ctx.message.attachments],
|
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.
|
# This function will be called when this extension is loaded.
|
||||||
# It is necessary to add these functions to the bot.
|
# It is necessary to add these functions to the bot.
|
||||||
|
|||||||
@@ -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
@@ -58,7 +58,9 @@ async def send_highscore_message(channel, boss_name: str):
|
|||||||
highscores_data[boss_name]["message_id"] = message_id
|
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.
|
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
|
@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]
|
minutes = score_list[0]
|
||||||
seconds = score_list[1]
|
seconds = score_list[1]
|
||||||
score_seconds = int(minutes) * 60 + int(seconds)
|
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
|
sort_index = 2
|
||||||
|
|
||||||
else:
|
else:
|
||||||
score_tuple = (ctx.author.display_name, int(score))
|
score_tuple = (user, int(score))
|
||||||
sort_index = 1
|
sort_index = 1
|
||||||
|
|
||||||
scores = highscores_data[boss_name]["categories"][category]
|
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
|
# edit message
|
||||||
highscore_channel_id = highscores_data["highscore_channel_id"]
|
highscore_channel_id = highscores_data["highscore_channel_id"]
|
||||||
print(f"Editting message {highscore_channel_id}")
|
print(f"Editting message {highscore_channel_id}")
|
||||||
channel = self.bot.get_channel(highscore_channel_id)
|
channel = interaction.guild.get_channel(highscore_channel_id)
|
||||||
if channel is None:
|
|
||||||
response = 'Registered Highscores channel does not exist or was never registered. \
|
error_response = 'Registered Highscores channel does not exist or was never registered. \
|
||||||
Register with "?register" command.'
|
Register with "?register" command.'
|
||||||
await ctx.send(response)
|
assert channel is not None, await interaction.send(error_response)
|
||||||
return
|
|
||||||
await send_highscore_message(channel, boss_name)
|
await send_highscore_message(channel, boss_name)
|
||||||
|
|
||||||
# save data
|
# save data
|
||||||
|
|||||||
Reference in New Issue
Block a user