Message map has guild id as an int. Update submission view to use HighscoresData.

This commit is contained in:
alwayscompiling
2022-07-28 11:01:40 -04:00
parent 463ef48052
commit f136181216
5 changed files with 60 additions and 23 deletions
+15 -13
View File
@@ -7,7 +7,6 @@ import nextcord
from nextcord import Embed
from nextcord.ext import commands
from highscores import highscores_config # pylint: disable=import-error
from highscores import highscores_data # pylint: disable=import-error
from highscores import highscores_message_map # pylint: disable=import-error
from highscores import submission_objects # pylint: disable=import-error
@@ -53,10 +52,10 @@ def get_submission_embed(userid: int) -> nextcord.Embed:
return embed
def category_select_options(boss_name: str) -> "list[nextcord.SelectOption]":
def category_select_options(guild_id: int, boss_name: str) -> "list[nextcord.SelectOption]":
"""Returns list of categories for a given boss."""
options: "list[nextcord.SelectOption]" = []
category_list = highscores_config["tables"][boss_name]
category_list = highscores_data.get_table_categories(guild_id, boss_name)
for category in category_list:
options.append(nextcord.SelectOption(label=category))
@@ -149,9 +148,9 @@ class SubmitButton(nextcord.ui.Button):
self._bot = bot
async def callback(self, interaction: nextcord.Interaction):
verification_channel_id = highscores_data[str(interaction.guild.id)][
"verification_channel_id"
]
verification_channel_id = highscores_data.get_guild_verification_channel(
interaction.guild_id
)
channel = interaction.guild.get_channel(verification_channel_id)
error_response = "Registered Verification channel does not exist or was never registered. \
@@ -194,23 +193,23 @@ class SubmissionCreateButton(nextcord.ui.View):
await interaction.send("Please finish in progress submission first.", ephemeral=True)
return
guild_id_str = str(interaction.guild.id)
guild_data = highscores_data[guild_id_str]
boss_name = highscores_message_map[guild_id_str][interaction.message.id]
channel = interaction.guild.get_channel(guild_data["submission_channel_id"])
boss_name = highscores_message_map[interaction.guild.id][interaction.message.id]
channel = interaction.guild.get_channel(
highscores_data.get_guild_submission_channel(interaction.guild_id)
)
# a user should only have 1 submission active at once.
# submitting with dummy message_id until message created
# split username on pipe.
submission_objects[interaction.user.id] = {
"message_id": 0,
"guild_id": interaction.guild_id,
"submission_state": SubmissionState.CATEGORY,
"boss_name": boss_name,
"score": "",
"category": "",
"username": interaction.user.display_name.split("|")[0][
: guild_data["username_length"]
: highscores_data.get_guild_username_length(interaction.guild_id)
],
}
@@ -244,10 +243,13 @@ class SubmissionView(nextcord.ui.View):
self._bot = bot
self._state = submission_objects[self._submission_user]["submission_state"]
self._boss_name = submission_objects[self._submission_user]["boss_name"]
self._guild_id = submission_objects[self._submission_user]["guild_id"]
# add items depending on given state
if self._state is SubmissionState.CATEGORY:
self.add_item(SubmissionDropdown(bot, category_select_options(self._boss_name)))
self.add_item(
SubmissionDropdown(bot, category_select_options(self._guild_id, self._boss_name))
)
self.add_item(CancelButton())
self.add_item(NextButton(self._bot))
elif (