Redid configs to allow for unique categories on each table.

This commit is contained in:
alwayscompiling
2022-07-12 21:00:51 -04:00
parent d7bac2048f
commit 3b410b5f90
3 changed files with 14 additions and 20 deletions
+4 -2
View File
@@ -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)
+6 -9
View File
@@ -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
+4 -9
View File
@@ -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