From ed62836b7f2d340cd3f8691263465276d992c187 Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Tue, 28 Jun 2022 22:33:52 -0400 Subject: [PATCH] cleaning up highscores imports a little. --- cogs/post_highscores/__init__.py | 9 +++++---- cogs/register_highscore_channel/__init__.py | 6 +++--- utils/highscore_message.py | 19 ++++++++++--------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/cogs/post_highscores/__init__.py b/cogs/post_highscores/__init__.py index 98b6fce..406eb88 100644 --- a/cogs/post_highscores/__init__.py +++ b/cogs/post_highscores/__init__.py @@ -3,7 +3,8 @@ Bot command to post the highscores """ from nextcord.ext import commands -import highscores # pylint: disable=import-error +from highscores import highscores_config # pylint: disable=import-error +from highscores import highscores_data # pylint: disable=import-error from utils import data_storage # pylint: disable=import-error from utils import highscore_message # pylint: disable=import-error @@ -25,7 +26,7 @@ class PostHighscores(commands.Cog, name="Post Highscores"): ``` """ # temporarily sending config data... - channel_id = highscores.highscores_data["channel_id"] + channel_id = highscores_data["channel_id"] print(f"Printing out highscores information in channel {channel_id}") channel = self.bot.get_channel(channel_id) if channel is None: @@ -33,11 +34,11 @@ class PostHighscores(commands.Cog, name="Post Highscores"): Register with "?register" command.' await ctx.send(response) return - for boss in highscores.highscores_config["bosses"]: + for boss in highscores_config["bosses"]: await highscore_message.send_highscore_message(channel, boss) break - data_storage.save_highscores_data(highscores.highscores_data) + data_storage.save_highscores_data(highscores_data) # This function will be called when this extension is loaded. diff --git a/cogs/register_highscore_channel/__init__.py b/cogs/register_highscore_channel/__init__.py index 58043f3..2a5b740 100644 --- a/cogs/register_highscore_channel/__init__.py +++ b/cogs/register_highscore_channel/__init__.py @@ -3,7 +3,7 @@ Bot command to register the highscores channel """ from nextcord.ext import commands -import highscores # pylint: disable=import-error +from highscores import highscores_data # pylint: disable=import-error from utils import data_storage # pylint: disable=import-error @@ -24,8 +24,8 @@ class RegisterHighscoreChannel(commands.Cog, name="Register HighScore Channel"): print(f"Registering {ctx.channel.id}.") # respond to the message await ctx.send(f"Registered <#{ctx.channel.id}> as channel to post highscores in.") - highscores.highscores_data["channel_id"] = ctx.channel.id - data_storage.save_highscores_data(highscores.highscores_data) + highscores_data["channel_id"] = ctx.channel.id + data_storage.save_highscores_data(highscores_data) # This function will be called when this extension is loaded. diff --git a/utils/highscore_message.py b/utils/highscore_message.py index 0df5d8d..5ee6630 100644 --- a/utils/highscore_message.py +++ b/utils/highscore_message.py @@ -3,7 +3,8 @@ Contains various functions for sending/editing the highscore messages. """ import nextcord -import highscores # pylint: disable=import-error +from highscores import highscores_config # pylint: disable=import-error +from highscores import highscores_data # pylint: disable=import-error def format_highscore_message(boss): @@ -14,19 +15,19 @@ def format_highscore_message(boss): """ boss_name = boss["boss"] ret_string = f"**{boss_name}**\n" - boss_data = highscores.highscores_data[boss_name] + boss_data = highscores_data[boss_name] # Gather all categories and add to string - for category in highscores.highscores_config["categories"]: + for category in highscores_config["categories"]: category_name = category["category"] ret_string += f"{category_name}".ljust(30, " ") ret_string += "\n" - highscore_size = highscores.highscores_config["highscore_size"] + highscore_size = highscores_config["highscore_size"] # list rankings for i in range(highscore_size): - for category in highscores.highscores_config["categories"]: + for category in highscores_config["categories"]: boss_category_scores = boss_data[category["category"]] if len(boss_category_scores) > i: score = boss_category_scores[i] @@ -41,7 +42,7 @@ def format_highscore_message(boss): # if boss is hardmode, repeat above for hardmode applicable categories if boss["hardmode"]: - for category in highscores.highscores_config["categories"]: + for category in highscores_config["categories"]: if category["hardmode"]: category_name = category["category"] ret_string += f"Hardmode {category_name}".ljust(30, " ") @@ -49,7 +50,7 @@ def format_highscore_message(boss): ret_string += "\n" for i in range(highscore_size): - for category in highscores.highscores_config["categories"]: + for category in highscores_config["categories"]: if category["hardmode"]: hardmode_category = category["category"] boss_category_scores = boss_data[f"{hardmode_category}_hardmode"] @@ -71,7 +72,7 @@ async def send_highscore_message(channel, boss): """ highscore_string = format_highscore_message(boss) - message_id = highscores.highscores_data[boss["boss"]]["message_id"] + message_id = highscores_data[boss["boss"]]["message_id"] try: message = await channel.fetch_message(message_id) await message.edit(content=highscore_string) @@ -79,4 +80,4 @@ async def send_highscore_message(channel, boss): # message doesn't exist. message = await channel.send(highscore_string) message_id = message.id - highscores.highscores_data[boss["boss"]]["message_id"] = message_id + highscores_data[boss["boss"]]["message_id"] = message_id