From 02e4d075dd2ce7d93b0f34d7ec469cd2a68a4335 Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Wed, 29 Jun 2022 22:52:50 -0400 Subject: [PATCH] Only sending boss name as a string, no dict objects. --- cogs/post_highscores/__init__.py | 3 +-- cogs/score/__init__.py | 6 ++++-- utils/highscore_manage.py | 4 +++- utils/highscore_message.py | 11 +++++------ 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cogs/post_highscores/__init__.py b/cogs/post_highscores/__init__.py index 19ecb06..5f29e4e 100644 --- a/cogs/post_highscores/__init__.py +++ b/cogs/post_highscores/__init__.py @@ -25,7 +25,6 @@ class PostHighscores(commands.Cog, name="Post Highscores"): ?post-scores ``` """ - # temporarily sending config data... channel_id = highscores_data["channel_id"] print(f"Printing out highscores information in channel {channel_id}") channel = self.bot.get_channel(channel_id) @@ -35,7 +34,7 @@ class PostHighscores(commands.Cog, name="Post Highscores"): await ctx.send(response) return for boss in highscores_config["bosses"]: - await highscore_message.send_highscore_message(channel, boss) + await highscore_message.send_highscore_message(channel, boss["boss"]) data_storage.save_highscores_data(highscores_data) diff --git a/cogs/score/__init__.py b/cogs/score/__init__.py index 19e7a2a..d4788fa 100644 --- a/cogs/score/__init__.py +++ b/cogs/score/__init__.py @@ -15,7 +15,7 @@ class RegisterHighscoreChannel(commands.Cog, name="Score"): self.bot = bot @commands.command(name="score") - async def score(self, ctx: commands.Context, boss: str, category: str, score): + async def score(self, ctx: commands.Context, boss_name: str, category: str, score): """A command which calls a function to submit the score to highscores. Gathers required information from command and passes on. Usage: @@ -23,7 +23,9 @@ class RegisterHighscoreChannel(commands.Cog, name="Score"): ?score "Boss Name" "Category" "score" ``` """ - highscore_manage.submit_score_int(boss, category, ctx.author.display_name, score) + await highscore_manage.submit_score_int( + self, ctx, boss_name, category, ctx.author.display_name, score + ) # This function will be called when this extension is loaded. diff --git a/utils/highscore_manage.py b/utils/highscore_manage.py index 06f94af..f210def 100644 --- a/utils/highscore_manage.py +++ b/utils/highscore_manage.py @@ -7,7 +7,9 @@ from highscores import highscores_data # pylint: disable=import-error from utils import data_storage # pylint: disable=import-error -def submit_score_int(boss: str, category: str, user: str, score: int): +async def submit_score_int( + self, ctx: commands.Context, boss_name: str, category: str, user: str, score: int +): """ Adds a score to the high scores and sorts. Removes a score if larger than size limit. @param boss: the boss to add score to diff --git a/utils/highscore_message.py b/utils/highscore_message.py index 75b1e59..bd3fff3 100644 --- a/utils/highscore_message.py +++ b/utils/highscore_message.py @@ -7,13 +7,12 @@ from highscores import highscores_config # pylint: disable=import-error from highscores import highscores_data # pylint: disable=import-error -def format_highscore_message(boss): +def format_highscore_message(boss_name: str): """ returns a formatted string for a boss's highscore @param boss: the dictionary object for the boss @return the formatted string """ - boss_name = boss["boss"] ret_string = f"**{boss_name}**\n" boss_data = highscores_data[boss_name] @@ -37,15 +36,15 @@ def format_highscore_message(boss): return ret_string -async def send_highscore_message(channel, boss): +async def send_highscore_message(channel, boss_name: str): """ Function takes care of checking if a message exists for a boss, then creating and sending/editing the message @param channel: the channel to send the message in/search for message id @param boss: the boss to send the message about """ - highscore_string = format_highscore_message(boss) + highscore_string = format_highscore_message(boss_name) - message_id = highscores_data[boss["boss"]]["message_id"] + message_id = highscores_data[boss_name]["message_id"] try: message = await channel.fetch_message(message_id) await message.edit(content=highscore_string) @@ -53,4 +52,4 @@ async def send_highscore_message(channel, boss): # message doesn't exist. message = await channel.send(highscore_string) message_id = message.id - highscores_data[boss["boss"]]["message_id"] = message_id + highscores_data[boss_name]["message_id"] = message_id