Changed where submission views live.
This commit is contained in:
@@ -3,6 +3,9 @@ Bot command to post the highscores
|
||||
"""
|
||||
|
||||
from nextcord.ext import commands
|
||||
import nextcord
|
||||
|
||||
from cogs.submission.submission_views import SubmissionButton # pylint: disable=import-error
|
||||
from highscores import highscores_config # pylint: disable=import-error
|
||||
from highscores import highscores_data # pylint: disable=import-error
|
||||
from utilities.data_storage import save_highscores_data # pylint: disable=import-error
|
||||
@@ -15,6 +18,11 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
"""Called when cog is loaded"""
|
||||
self.bot.add_view(SubmissionButton())
|
||||
|
||||
@commands.command(name="post-scores")
|
||||
async def post_highscores(self, ctx: commands.Context):
|
||||
"""
|
||||
@@ -29,12 +37,13 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
|
||||
print(f"Printing out highscores information in channel {highscore_channel_id}")
|
||||
channel = self.bot.get_channel(highscore_channel_id)
|
||||
|
||||
error_response = 'Registered Highscores channel does not exist or was never registered. \
|
||||
error_response = 'Registered Highscores channel does not exist or was never registered. \n\
|
||||
Register with "?register" command.'
|
||||
assert channel is not None, await ctx.send(error_response)
|
||||
|
||||
for boss in highscores_config["bosses"]:
|
||||
await send_highscore_message(channel, boss["boss"])
|
||||
message: nextcord.Message = await send_highscore_message(channel, boss["boss"])
|
||||
await message.edit(view=SubmissionButton())
|
||||
|
||||
save_highscores_data(highscores_data)
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
"""
|
||||
Bot command to post the highscores
|
||||
"""
|
||||
|
||||
from nextcord.ext import commands
|
||||
|
||||
from .submission_views import SubmissionButton
|
||||
|
||||
|
||||
class SubmissionCog(commands.Cog, name="Submission Cog"):
|
||||
"""Posts Highscores."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
"""Called when cog is loaded"""
|
||||
self.bot.add_view(SubmissionButton())
|
||||
|
||||
|
||||
# This function will be called when this extension is loaded.
|
||||
# It is necessary to add these functions to the bot.
|
||||
def setup(bot: commands.Bot):
|
||||
"""Adds functon to bot"""
|
||||
bot.add_cog(SubmissionCog(bot))
|
||||
@@ -0,0 +1,70 @@
|
||||
"""Views used in highscores bot."""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
import nextcord
|
||||
|
||||
from utilities.data_storage import open_message_map # pylint: disable=import-error
|
||||
from highscores import highscores_data # pylint: disable=import-error
|
||||
|
||||
|
||||
class SubmissionButton(nextcord.ui.View):
|
||||
"""Defines view for score submission button."""
|
||||
|
||||
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"submission for {boss_name}")
|
||||
# await interaction.channel.send(
|
||||
# f"Submitting score for {boss_name}",
|
||||
# view=SubmissionView(self._category_select_options(interaction)),
|
||||
# )
|
||||
|
||||
async def _category_select_options(
|
||||
self, interaction: nextcord.Interaction
|
||||
) -> "list[nextcord.SelectOption]":
|
||||
highscores_message_map = open_message_map()
|
||||
boss_name = highscores_message_map[str(interaction.message.id)]
|
||||
options: list[nextcord.SelectOption] = [] # pylint: disable=unsubscriptable-object
|
||||
boss_dict = highscores_data[boss_name]
|
||||
for category in boss_dict["categories"].items():
|
||||
options.append(nextcord.SelectOption(label=category))
|
||||
|
||||
return options
|
||||
|
||||
|
||||
class SubmissionDropdown(nextcord.ui.Select):
|
||||
"""Defines dropdown menu for submission"""
|
||||
|
||||
def __init__(self, options: "list[nextcord.SelectOption]"):
|
||||
super().__init__(
|
||||
placeholder="Choose submission category.", min_values=1, max_values=1, options=options
|
||||
)
|
||||
|
||||
def callback(self, interaction: nextcord.Interaction):
|
||||
pass
|
||||
|
||||
|
||||
class SubmissionView(nextcord.ui.View):
|
||||
"""Defines entire submission process view"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
# button_view: SubmissionButtonView.submit_button,
|
||||
options: "list[nextcord.SelectOption]",
|
||||
*,
|
||||
timeout: Optional[float] = 180,
|
||||
):
|
||||
super().__init__(timeout=timeout)
|
||||
self.add_item(SubmissionDropdown(options))
|
||||
# self._button_view = button_view
|
||||
|
||||
# async def interaction_check(self, interaction: nextcord.Interaction) -> bool:
|
||||
# return self._button_view.interaction.user == interaction.user # unsure if works
|
||||
Reference in New Issue
Block a user