Entire submission process works somehow.

This commit is contained in:
alwayscompiling
2022-07-09 11:24:29 -04:00
parent 6a7207d710
commit 7854be890f
7 changed files with 78 additions and 23 deletions
+1 -1
View File
@@ -22,5 +22,5 @@ class HelpCog(commands.Cog):
# setup functions for bot # setup functions for bot
def setup(bot: commands.Bot): def setup(bot: commands.Bot):
"""Adds functon to bot""" """Adds function to bot"""
bot.add_cog(HelpCog(bot)) bot.add_cog(HelpCog(bot))
+1 -6
View File
@@ -18,11 +18,6 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
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 cog is loaded"""
self.bot.add_view(SubmissionButton())
@commands.command(name="post-scores") @commands.command(name="post-scores")
async def post_highscores(self, ctx: commands.Context): async def post_highscores(self, ctx: commands.Context):
""" """
@@ -51,5 +46,5 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
# 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.
def setup(bot: commands.Bot): def setup(bot: commands.Bot):
"""Adds functon to bot""" """Adds function to bot"""
bot.add_cog(PostHighscores(bot)) bot.add_cog(PostHighscores(bot))
+1 -1
View File
@@ -31,5 +31,5 @@ class RegisterHighscoreChannel(commands.Cog, name="Register HighScore Channel"):
# 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.
def setup(bot: commands.Bot): def setup(bot: commands.Bot):
"""Adds functon to bot""" """Adds function to bot"""
bot.add_cog(RegisterHighscoreChannel(bot)) bot.add_cog(RegisterHighscoreChannel(bot))
@@ -31,5 +31,5 @@ class RegisterVerificationChannel(commands.Cog, name="Register Verify Channel"):
# 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.
def setup(bot: commands.Bot): def setup(bot: commands.Bot):
"""Adds functon to bot""" """Adds function to bot"""
bot.add_cog(RegisterVerificationChannel(bot)) bot.add_cog(RegisterVerificationChannel(bot))
+1 -1
View File
@@ -47,5 +47,5 @@ class Score(commands.Cog, name="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.
def setup(bot: commands.Bot): def setup(bot: commands.Bot):
"""Adds functon to bot""" """Adds function to bot"""
bot.add_cog(Score(bot)) bot.add_cog(Score(bot))
+4 -4
View File
@@ -1,5 +1,5 @@
""" """
Bot command to post the highscores Cog for creating submission process.
""" """
from nextcord.ext import commands from nextcord.ext import commands
@@ -8,7 +8,7 @@ from .submission_views import SubmissionButton
class SubmissionCog(commands.Cog, name="Submission Cog"): class SubmissionCog(commands.Cog, name="Submission Cog"):
"""Posts Highscores.""" """Constructs submission method."""
def __init__(self, bot: commands.Bot): def __init__(self, bot: commands.Bot):
self.bot = bot self.bot = bot
@@ -16,11 +16,11 @@ class SubmissionCog(commands.Cog, name="Submission Cog"):
@commands.Cog.listener() @commands.Cog.listener()
async def on_ready(self): async def on_ready(self):
"""Called when cog is loaded""" """Called when cog is loaded"""
self.bot.add_view(SubmissionButton()) self.bot.add_view(SubmissionButton(self.bot))
# 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.
def setup(bot: commands.Bot): def setup(bot: commands.Bot):
"""Adds functon to bot""" """Adds function to bot"""
bot.add_cog(SubmissionCog(bot)) bot.add_cog(SubmissionCog(bot))
+69 -9
View File
@@ -3,31 +3,52 @@
from typing import Optional from typing import Optional
import nextcord import nextcord
from nextcord.ext import commands
from utilities.data_storage import open_message_map # pylint: disable=import-error from utilities.data_storage import open_message_map # pylint: disable=import-error
from highscores import highscores_data # pylint: disable=import-error from highscores import highscores_data # pylint: disable=import-error
from .verification_view import VerificationView
class SubmissionButton(nextcord.ui.View): class SubmissionButton(nextcord.ui.View):
"""Defines view for score submission button.""" """Defines view for score submission button."""
def __init__(self): def __init__(self, bot: commands.Bot):
super().__init__(timeout=None) super().__init__(timeout=None)
self._bot = bot
@nextcord.ui.button(label="Submit", style=nextcord.ButtonStyle.green, custom_id="submit") @nextcord.ui.button(label="Submit", style=nextcord.ButtonStyle.primary, custom_id="submit")
async def submit_button( async def submit_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 score submission.""" """Button for score submission."""
highscores_message_map = open_message_map() highscores_message_map = open_message_map()
boss_name = highscores_message_map[str(interaction.message.id)] boss_name = highscores_message_map[str(interaction.message.id)]
await interaction.channel.send( embed = nextcord.Embed(title="Highscores Submission")
f"<@{interaction.user.id}> Submitting score for {boss_name}", embed.add_field(name="Boss", value=boss_name, inline=False)
embed.add_field(name="User", value=interaction.user.display_name, inline=False)
submission_message = await interaction.channel.send( # TODO change channel
f"<@{interaction.user.id}>",
view=SubmissionDropdownView( view=SubmissionDropdownView(
interaction, await self._category_select_options(boss_name) self._bot, interaction, await self._category_select_options(boss_name)
), ),
embed=embed,
) )
def wait_check(check_message: nextcord.Message):
return (
interaction.user.id == check_message.author.id
and interaction.channel == check_message.channel
) # unsure if comparison is correct
proof_message = await self._bot.wait_for("message", check=wait_check)
embed = submission_message.embeds[0]
embed.add_field(name="Score", value=proof_message.content, inline=False)
await submission_message.edit(
files=[await attch.to_file() for attch in proof_message.attachments], embed=embed
)
await proof_message.delete()
async def _category_select_options(self, boss_name: str) -> "list[nextcord.SelectOption]": async def _category_select_options(self, boss_name: str) -> "list[nextcord.SelectOption]":
options: list[nextcord.SelectOption] = [] # pylint: disable=unsubscriptable-object options: list[nextcord.SelectOption] = [] # pylint: disable=unsubscriptable-object
boss_dict = highscores_data[boss_name] boss_dict = highscores_data[boss_name]
@@ -40,15 +61,22 @@ class SubmissionButton(nextcord.ui.View):
class SubmissionDropdown(nextcord.ui.Select): class SubmissionDropdown(nextcord.ui.Select):
"""Defines dropdown menu for submission""" """Defines dropdown menu for submission"""
def __init__(self, options: "list[nextcord.SelectOption]"): def __init__(
self,
bot: commands.Bot,
options: "list[nextcord.SelectOption]",
):
super().__init__( super().__init__(
placeholder="Choose submission category.", min_values=1, max_values=1, options=options placeholder="Choose submission category.", min_values=1, max_values=1, options=options
) )
self._bot = bot
async def callback(self, interaction: nextcord.Interaction): async def callback(self, interaction: nextcord.Interaction):
embed = interaction.message.embeds[0]
embed.add_field(name="Category", value=self.values[0], inline=False)
await interaction.message.edit( await interaction.message.edit(
content=f"submitting for {self.values[0]}", embed=embed,
) # TODO create embed and then wait for response message. )
class SubmissionDropdownView(nextcord.ui.View): class SubmissionDropdownView(nextcord.ui.View):
@@ -56,14 +84,46 @@ class SubmissionDropdownView(nextcord.ui.View):
def __init__( def __init__(
self, self,
bot: commands.Bot,
prev_interaction: nextcord.Interaction, prev_interaction: nextcord.Interaction,
options: "list[nextcord.SelectOption]", options: "list[nextcord.SelectOption]",
*, *,
timeout: Optional[float] = 180, timeout: Optional[float] = 180,
): ):
super().__init__(timeout=timeout) super().__init__(timeout=timeout)
self.add_item(SubmissionDropdown(options)) self.add_item(SubmissionDropdown(bot, options))
self._prev_interaction = prev_interaction self._prev_interaction = prev_interaction
self.bot = bot
async def interaction_check(self, interaction: nextcord.Interaction) -> bool: async def interaction_check(self, interaction: nextcord.Interaction) -> bool:
return self._prev_interaction.user == interaction.user return self._prev_interaction.user == interaction.user
@nextcord.ui.button(
label="Submit Score", style=nextcord.ButtonStyle.green, custom_id="submit-score"
)
async def submit_button(
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
): # pylint: disable=unused-argument
"""Defines button to submit a user's score."""
verification_channel_id = highscores_data["verification_channel_id"]
channel = self.bot.get_channel(verification_channel_id)
error_response = "Registered Verification channel does not exist or was never registered. \
Contact server admins."
assert channel is not None, await channel.send(error_response)
await channel.send(
files=[await attch.to_file() for attch in interaction.message.attachments],
view=VerificationView(),
embed=interaction.message.embeds[0],
)
await interaction.message.edit(content=f"<@{interaction.user.id}> Submitted!", view=None)
@nextcord.ui.button(
label="Cancel", style=nextcord.ButtonStyle.red, custom_id="cancel-submission"
)
async def cancel_button(
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
): # pylint: disable=unused-argument
"""Deletes message to cancel interaction."""
await interaction.message.delete()