diff --git a/cogs/post_highscores/__init__.py b/cogs/post_highscores/__init__.py index b34aa28..fecf7c3 100644 --- a/cogs/post_highscores/__init__.py +++ b/cogs/post_highscores/__init__.py @@ -6,9 +6,7 @@ from nextcord.ext import commands import nextcord from cogs.submission.submission_views import SubmissionCreateButton # 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 from utilities.utils import send_highscore_message # pylint: disable=import-error @@ -29,24 +27,18 @@ class PostHighscores(commands.Cog, name="Post Highscores"): ?post-scores ``` """ - guild_data = highscores_data[str(ctx.guild.id)] - highscore_channel_id = guild_data["highscore_channel_id"] + highscore_channel_id = highscores_data.get_guild_channel_id(ctx.guild.id) print(f"Printing out highscores information in channel {highscore_channel_id}") channel = ctx.guild.get_channel(highscore_channel_id) - error_response = 'Registered Highscores channel does not exist or was never registered. \n\ - Register with "?register" command.' + error_response = "Registered Highscores channel does not exist or was never registered. " + error_response += 'Register with "?register" command.' assert channel is not None, await ctx.send(error_response) - for boss, categories in highscores_config[ # pylint: disable=unused-variable - "tables" - ].items(): - message: nextcord.Message = await send_highscore_message(channel, boss, guild_data) + for table in highscores_data.get_table_names(ctx.guild.id): + message: nextcord.Message = await send_highscore_message(channel, table, ctx.guild.id) await message.edit(view=SubmissionCreateButton(self.bot)) - # Saving in case new message was sent. - save_highscores_data(highscores_data) - # This function will be called when this extension is loaded. # It is necessary to add these functions to the bot. diff --git a/utilities/highscores_data.py b/utilities/highscores_data.py index f130dad..2b72bea 100644 --- a/utilities/highscores_data.py +++ b/utilities/highscores_data.py @@ -112,7 +112,7 @@ class HighscoresData: @param table: table to get category data from @returns: list of tuples containing all category and relative score data. """ - return self._data[str(guild_id)][table]["categories"].items() + return self._data[str(guild_id)]["tables"][table]["categories"].items() def get_config_highscore_size(self) -> int: """ @@ -149,6 +149,22 @@ class HighscoresData: """ return self._data[str(guild_id)]["tables"][table]["message_id"] + def get_table_names(self, guild_id) -> "list[str]": + """ + Returns a list of table names. + + @param guild_id: guild id to retrieve from. + @returns: list of table names + """ + tables: "list[str]" = [] + + for table, data in self._data[str(guild_id)][ # pylint: disable=unused-variable + "tables" + ].items(): + tables.append(table) + + return tables + def remove_guild(self, guild_id: int, guild_name: str) -> None: """ Removes a guild's data from object. Saves backup.