From 463ef48052c83c6eea2e98f49661dd38ac77ccaa Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Thu, 28 Jul 2022 10:40:23 -0400 Subject: [PATCH] Move message map creation to highscores.py. Was a circular import. --- highscores.py | 9 +++++++-- utilities/highscores_data.py | 13 +++++++++++++ utilities/utils.py | 19 ------------------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/highscores.py b/highscores.py index bad4380..6cc103a 100644 --- a/highscores.py +++ b/highscores.py @@ -10,7 +10,6 @@ from nextcord.ext import commands import config from utilities.highscores_data import HighscoresData -from utilities.utils import create_message_map logger = logging.getLogger("nextcord") logger.setLevel(logging.DEBUG) @@ -20,7 +19,13 @@ logger.addHandler(handler) highscores_data: HighscoresData = HighscoresData() -highscores_message_map = create_message_map(highscores_data) +highscores_message_map = {} + +for guild in highscores_data.get_guilds(): + highscores_message_map[guild] = {} + for table in highscores_data.get_table_names(guild): + message_id = highscores_data.get_table_message_id(guild, table) + highscores_message_map[guild][message_id] = table submission_objects: dict = {} diff --git a/utilities/highscores_data.py b/utilities/highscores_data.py index f40cdf4..120ab11 100644 --- a/utilities/highscores_data.py +++ b/utilities/highscores_data.py @@ -122,6 +122,19 @@ class HighscoresData: """ return self._config["highscore_size"] + def get_guilds(self) -> "list[int]": + """ + Gets a list of guilds tracked by data + + @returns: list of ints representing guild ids + """ + guilds: "list[int]" = [] + + for guild, data in self._data: # pylint: disable=unused-variable + guilds.append(int(guild)) + + return guilds + def get_guild_channel_id(self, guild_id: int) -> int: """ Returns the channel id to post highscore messages to. diff --git a/utilities/utils.py b/utilities/utils.py index 3131e2f..84ed136 100644 --- a/utilities/utils.py +++ b/utilities/utils.py @@ -7,25 +7,6 @@ from highscores import highscores_data # pylint: disable=import-error from highscores import highscores_message_map # pylint: disable=import-error -def create_message_map(data: dict): - """ - Creates a message map from input highscores data. - - @param data: highscores_data dict to create map from. - @return: dict message_map of message to boss. - """ - - message_map = {} - - # guild id will be a string. Json object keys are strings. - for guild, guild_scores in data.items(): - message_map[guild] = {} - for boss, info in guild_scores["tables"].items(): - message_map[guild][info["message_id"]] = boss - - return message_map - - def format_highscore_message(boss_name: str, guild_id: int): """ returns a formatted string for a boss's highscore