Changed where submission views live.

This commit is contained in:
alwayscompiling
2022-07-06 21:05:04 -04:00
parent d0428afb3f
commit c4261fc7f4
6 changed files with 113 additions and 29 deletions
+6 -4
View File
@@ -39,7 +39,7 @@ def format_highscore_message(boss_name: str):
return ret_string + "```"
async def send_highscore_message(channel, boss_name: str):
async def send_highscore_message(channel, boss_name: str) -> nextcord.Message:
"""
Function takes care of checking if a message exists for a boss, then
creating and sending/editing the message
@@ -50,17 +50,19 @@ async def send_highscore_message(channel, boss_name: str):
message_id = highscores_data[boss_name]["message_id"]
try:
message = await channel.fetch_message(message_id)
await message.edit(content=highscore_string, view=SubmissionView())
message: nextcord.Message = await channel.fetch_message(message_id)
await message.edit(content=highscore_string)
except nextcord.NotFound:
# message doesn't exist.
message = await channel.send(highscore_string, view=SubmissionView())
message: nextcord.Message = await channel.send(highscore_string)
message_id = message.id
highscores_data[boss_name]["message_id"] = message_id
# save message -> boss_name in message_map
highscores_message_map[str(message_id)] = boss_name
save_message_map(highscores_message_map)
return message
async def submit_score(
interaction: nextcord.Interaction, user: str, boss_name: str, category: str, score: str
-20
View File
@@ -1,20 +0,0 @@
"""Views used in highscores bot."""
import nextcord
from utilities.data_storage import open_message_map # pylint: disable=import-error
class SubmissionButtonView(nextcord.ui.View):
"""Defines view for score submission."""
def __init__(self):
super().__init__(timeout=None)
@nextcord.ui.button(label="Submit", style=nextcord.ButtonStyle.green, custom_id="submit")
async def submit_button(
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
): # pylint: disable=unused-argument
"""Button for score submission."""
highscores_message_map = open_message_map()
boss_name = highscores_message_map[str(interaction.message.id)]
await interaction.channel.send(f"Submitting score for {boss_name}")