From c45606a7a414844e25214a9167ec9b330c5bda1a Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Wed, 29 Jun 2022 22:53:32 -0400 Subject: [PATCH] Add message edit to score command. --- utils/highscore_manage.py | 17 +++++++++++++++-- utils/highscore_message.py | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/utils/highscore_manage.py b/utils/highscore_manage.py index f210def..e1f7bec 100644 --- a/utils/highscore_manage.py +++ b/utils/highscore_manage.py @@ -2,8 +2,10 @@ Contains various functions for managing the highscores data """ +from nextcord.ext import commands from highscores import highscores_config # pylint: disable=import-error from highscores import highscores_data # pylint: disable=import-error +from utils import highscore_message # pylint: disable=import-error from utils import data_storage # pylint: disable=import-error @@ -18,14 +20,25 @@ async def submit_score_int( @param score: score (int) to add """ # TODO update user submission to not have dupe users - scores = highscores_data[boss][category] + scores = highscores_data[boss_name]["categories"][category] score_tuple = (user, score) scores.append(score_tuple) ascending = highscores_config["categories"][category] scores.sort(key=lambda x: x[1], reverse=not ascending) while len(scores) > highscores_config["highscore_size"]: scores.pop() - highscores_data[boss][category] = scores + highscores_data[boss_name]["categories"][category] = scores + + # edit message + channel_id = highscores_data["channel_id"] + print(f"Editting message {channel_id}") + channel = self.bot.get_channel(channel_id) + if channel is None: + response = 'Registered Highscores channel does not exist or was never registered. \ + Register with "?register" command.' + await ctx.send(response) + return + await highscore_message.send_highscore_message(channel, boss_name) # save data data_storage.save_highscores_data(highscores_data) diff --git a/utils/highscore_message.py b/utils/highscore_message.py index bd3fff3..0c4fe79 100644 --- a/utils/highscore_message.py +++ b/utils/highscore_message.py @@ -28,7 +28,7 @@ def format_highscore_message(boss_name: str): for key, value in boss_data["categories"].items(): if len(value) > i: score = value[i] - ret_string += f"{i+1}: {key} - {score}".ljust(30, " ") + ret_string += f"{i+1}: {score[0]} - {score[1]}".ljust(30, " ") else: ret_string += f"{i+1}: submit your score".ljust(30, " ") ret_string += "\n"