Message map has guild id as an int. Update submission view to use HighscoresData.
This commit is contained in:
@@ -7,7 +7,6 @@ from nextcord.ext import commands
|
||||
|
||||
from highscores import highscores_data # pylint: disable=import-error
|
||||
from utilities.highscores_data import save_highscores_data # pylint: disable=import-error
|
||||
from utilities.highscores_data import create_highscore_skeleton # pylint: disable=import-error
|
||||
|
||||
|
||||
class DeleteScores(commands.Cog, name="Delete Scores"):
|
||||
|
||||
@@ -27,7 +27,7 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
|
||||
?post-scores
|
||||
```
|
||||
"""
|
||||
highscore_channel_id = highscores_data.get_guild_channel_id(ctx.guild.id)
|
||||
highscore_channel_id = highscores_data.get_guild_highscores_channel(ctx.guild.id)
|
||||
print(f"Printing out highscores information in channel {highscore_channel_id}")
|
||||
channel = ctx.guild.get_channel(highscore_channel_id)
|
||||
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -130,19 +130,29 @@ class HighscoresData:
|
||||
"""
|
||||
guilds: "list[int]" = []
|
||||
|
||||
for guild, data in self._data: # pylint: disable=unused-variable
|
||||
for guild, data in self._data.items(): # pylint: disable=unused-variable
|
||||
guilds.append(int(guild))
|
||||
|
||||
return guilds
|
||||
|
||||
def get_guild_channel_id(self, guild_id: int) -> int:
|
||||
def get_guild_highscores_channel(self, guild_id: int) -> int:
|
||||
"""
|
||||
Returns the channel id to post highscore messages to.
|
||||
|
||||
@param guild_id: guild id to retrieve from
|
||||
@param guild_id: guild id to retrieve from.
|
||||
@returns: channel id of highscores channel.
|
||||
"""
|
||||
return self._data[str(guild_id)]["highscore_channel_id"]
|
||||
|
||||
def get_guild_submission_channel(self, guild_id: int) -> int:
|
||||
"""
|
||||
Returns the channel id to post submission messages to.
|
||||
|
||||
@param guild_id: guild id to retrieve from.
|
||||
@returns: channel id of submission channel.
|
||||
"""
|
||||
return self._data[str(guild_id)]["submission_channel_id"]
|
||||
|
||||
def get_guild_username_length(self, guild_id: int) -> int:
|
||||
"""
|
||||
Returns username length as set by each guild.
|
||||
@@ -152,12 +162,38 @@ class HighscoresData:
|
||||
"""
|
||||
return self._data[str(guild_id)]["username_length"]
|
||||
|
||||
def get_guild_verification_channel(self, guild_id: int) -> int:
|
||||
"""
|
||||
Returns the channel id to post verification messages to.
|
||||
|
||||
@param guild_id: guild id to retrieve from.
|
||||
@returns: channel id of verification channel.
|
||||
"""
|
||||
return self._data[str(guild_id)]["verification_channel_id"]
|
||||
|
||||
def get_table_categories(self, guild_id: int, table: str) -> "list[str]":
|
||||
"""
|
||||
Returns list of categories for a guild's table
|
||||
|
||||
@param guild_id: guild id to retrieve from.
|
||||
@param table: the table to retreive from.
|
||||
@returns: string list of categories in given table.
|
||||
"""
|
||||
categories: "list[str]" = []
|
||||
|
||||
for category, data in self._data[str(guild_id)][ # pylint: disable=unused-variable
|
||||
"tables"
|
||||
][table]["categories"].items():
|
||||
categories.append(category)
|
||||
|
||||
return categories
|
||||
|
||||
def get_table_message_id(self, guild_id: int, table: str) -> int:
|
||||
"""
|
||||
Returns the message id for given guild's table.
|
||||
|
||||
@param guild_id: guild id to retrieve from.
|
||||
@param table: the table to retreive from.
|
||||
@param table: the table to retrieve from.
|
||||
@returns: int id of message for table's highscores.
|
||||
"""
|
||||
return self._data[str(guild_id)]["tables"][table]["message_id"]
|
||||
|
||||
+4
-4
@@ -78,9 +78,9 @@ async def send_highscore_message(
|
||||
# get guild id from channel
|
||||
# channel should come from the guild that is requesting this highscores message anyways.
|
||||
# check if guild is in message map already
|
||||
if not str(channel.guild.id) in highscores_message_map:
|
||||
highscores_message_map[str(channel.guild.id)] = {}
|
||||
highscores_message_map[str(channel.guild.id)][message_id] = boss_name
|
||||
if not channel.guild.id in highscores_message_map:
|
||||
highscores_message_map[channel.guild.id] = {}
|
||||
highscores_message_map[channel.guild.id][message_id] = boss_name
|
||||
|
||||
return message
|
||||
|
||||
@@ -99,7 +99,7 @@ async def submit_score(
|
||||
highscores_data.add_score(interaction.guild_id, boss_name, category, user, score)
|
||||
|
||||
# edit message
|
||||
highscore_channel_id = highscores_data.get_guild_channel_id(interaction.guild_id)
|
||||
highscore_channel_id = highscores_data.get_guild_highscores_channel(interaction.guild_id)
|
||||
print(f"Editting message {highscore_channel_id}")
|
||||
channel = interaction.guild.get_channel(highscore_channel_id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user