From 3b410b5f902760f000e93b6b7b78e6d100313192 Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Tue, 12 Jul 2022 21:00:51 -0400 Subject: [PATCH] Redid configs to allow for unique categories on each table. --- cogs/post_highscores/__init__.py | 6 ++++-- utilities/data_storage.py | 15 ++++++--------- utilities/utils.py | 13 ++++--------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/cogs/post_highscores/__init__.py b/cogs/post_highscores/__init__.py index e8077ad..ea59fb7 100644 --- a/cogs/post_highscores/__init__.py +++ b/cogs/post_highscores/__init__.py @@ -37,8 +37,10 @@ class PostHighscores(commands.Cog, name="Post Highscores"): Register with "?register" command.' assert channel is not None, await ctx.send(error_response) - for boss in highscores_config["bosses"]: - message: nextcord.Message = await send_highscore_message(channel, boss["boss"]) + for boss, categories in highscores_config[ # pylint: disable=unused-variable + "highscore_table" + ].items(): + message: nextcord.Message = await send_highscore_message(channel, boss) await message.edit(view=SubmissionButton(self.bot)) save_highscores_data(highscores_data) diff --git a/utilities/data_storage.py b/utilities/data_storage.py index 51bf03c..466212d 100644 --- a/utilities/data_storage.py +++ b/utilities/data_storage.py @@ -29,17 +29,14 @@ def open_highscores_data(): else: # create the json object data = {"highscore_channel_id": -1, "verification_channel_id": -1} - config = open_highscores_config() - for boss in config["bosses"]: - data[boss["boss"]] = {"message_id": 0} + config: dict = open_highscores_config() + for boss, categories in config["highscore_table"].items(): + data[boss] = {"message_id": 0} boss_categories = {} - for key, value in config["categories"].items(): + for category, category_config in categories.items(): # pylint: disable=unused-variable rank_list = [] - boss_categories[key] = rank_list - if boss["hardmode"] and value["hardmode"]: - rank_list = [] - boss_categories["Hardmode " + key] = rank_list - data[boss["boss"]]["categories"] = boss_categories + boss_categories[category] = rank_list + data[boss]["categories"] = boss_categories return data diff --git a/utilities/utils.py b/utilities/utils.py index c761791..ffff488 100644 --- a/utilities/utils.py +++ b/utilities/utils.py @@ -74,13 +74,8 @@ async def submit_score( @param user: user who submitted score @param score: score to add """ - # TODO update user submission to not have dupe users - # hardmode category, must have different category variable for config access. - if category.find("Hardmode ") != -1: - config_category = category.replace("Hardmode ", "") - else: - config_category = category + boss_category_config = highscores_config["highscore_table"][boss_name][category] # capping to 12 characters because runescape names are 12 characters long. # Splitting on pipe. My discord has multiple names on account split by pipe. @@ -91,7 +86,7 @@ async def submit_score( # create score tuple for either time or int # define sort index - if highscores_config["categories"][config_category]["is_time_record"]: + if boss_category_config["is_time_record"]: if score.find(":") == -1: score_seconds = float(score) else: @@ -117,7 +112,7 @@ async def submit_score( # sort users_scores users_scores.sort( key=lambda x: x[sort_index], - reverse=not highscores_config["categories"][config_category]["ascending"], + reverse=not boss_category_config["ascending"], ) for index, tup in enumerate(users_scores): @@ -133,7 +128,7 @@ async def submit_score( # sort scores. scores.sort( key=lambda x: x[sort_index], - reverse=not highscores_config["categories"][config_category]["ascending"], + reverse=not boss_category_config["ascending"], ) # enforce highscore size