Updated data structure to have categories be lists of key value pairs. This will make sorting easier.
This commit is contained in:
@@ -17,7 +17,8 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
|
|||||||
@commands.command(name="post-scores")
|
@commands.command(name="post-scores")
|
||||||
async def post_highscores(self, ctx: commands.Context):
|
async def post_highscores(self, ctx: commands.Context):
|
||||||
"""
|
"""
|
||||||
A command which posts the highscore in the designated channel. Sends warning if no channel has been registered.
|
A command which posts the highscore in the designated channel. Sends warning if no channel
|
||||||
|
has been registered.
|
||||||
Usage:
|
Usage:
|
||||||
```
|
```
|
||||||
?post-scores
|
?post-scores
|
||||||
@@ -28,11 +29,13 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
|
|||||||
print(f"Printing out highscores information in channel {channel_id}")
|
print(f"Printing out highscores information in channel {channel_id}")
|
||||||
channel = self.bot.get_channel(channel_id)
|
channel = self.bot.get_channel(channel_id)
|
||||||
if channel is None:
|
if channel is None:
|
||||||
response = 'Registered Highscores channel does not exist or was never registered. Register with "?register" command.'
|
response = 'Registered Highscores channel does not exist or was never registered. \
|
||||||
|
Register with "?register" command.'
|
||||||
await ctx.send(response)
|
await ctx.send(response)
|
||||||
return
|
return
|
||||||
for boss in highscores.highscores_config["bosses"]:
|
for boss in highscores.highscores_config["bosses"]:
|
||||||
await highscore_message.send_highscore_message(channel, boss)
|
await highscore_message.send_highscore_message(channel, boss)
|
||||||
|
break
|
||||||
|
|
||||||
data_storage.save_highscores_data(highscores.highscores_data)
|
data_storage.save_highscores_data(highscores.highscores_data)
|
||||||
|
|
||||||
|
|||||||
@@ -21,20 +21,13 @@ def open_highscores_data():
|
|||||||
# create the json object
|
# create the json object
|
||||||
data = {"channel_id": -1}
|
data = {"channel_id": -1}
|
||||||
config = open_highscores_config()
|
config = open_highscores_config()
|
||||||
size = config["highscore_size"]
|
|
||||||
for boss in config["bosses"]:
|
for boss in config["bosses"]:
|
||||||
data[boss["boss"]] = {"message_id": -1}
|
data[boss["boss"]] = {"message_id": 0}
|
||||||
for category in config["categories"]:
|
for category in config["categories"]:
|
||||||
rank_list = []
|
rank_list = []
|
||||||
for i in range(size): # pylint: disable=unused-variable
|
|
||||||
rank = {"player": "", "score": -1}
|
|
||||||
rank_list.append(rank)
|
|
||||||
data[boss["boss"]][category["category"]] = rank_list
|
data[boss["boss"]][category["category"]] = rank_list
|
||||||
if boss["hardmode"] and category["hardmode"]:
|
if boss["hardmode"] and category["hardmode"]:
|
||||||
rank_list = []
|
rank_list = []
|
||||||
for i in range(size): # pylint: disable=unused-variable
|
|
||||||
rank = {"player": "", "score": -1}
|
|
||||||
rank_list.append(rank)
|
|
||||||
data[boss["boss"]][category["category"] + "_hardmode"] = rank_list
|
data[boss["boss"]][category["category"] + "_hardmode"] = rank_list
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,13 @@ import highscores # pylint: disable=import-error
|
|||||||
|
|
||||||
def format_highscore_message(boss):
|
def format_highscore_message(boss):
|
||||||
"""
|
"""
|
||||||
returns a formattedd string for a boss's highscore
|
returns a formatted string for a boss's highscore
|
||||||
@param boss: the dictionary object for the boss
|
@param boss: the dictionary object for the boss
|
||||||
@return the formatted string
|
@return the formatted string
|
||||||
"""
|
"""
|
||||||
boss_name = boss["boss"]
|
boss_name = boss["boss"]
|
||||||
ret_string = f"**{boss_name}**\n"
|
ret_string = f"**{boss_name}**\n"
|
||||||
|
boss_data = highscores.highscores_data[boss_name]
|
||||||
|
|
||||||
# Gather all categories and add to string
|
# Gather all categories and add to string
|
||||||
for category in highscores.highscores_config["categories"]:
|
for category in highscores.highscores_config["categories"]:
|
||||||
@@ -26,7 +27,16 @@ def format_highscore_message(boss):
|
|||||||
# list rankings
|
# list rankings
|
||||||
for i in range(highscore_size):
|
for i in range(highscore_size):
|
||||||
for category in highscores.highscores_config["categories"]:
|
for category in highscores.highscores_config["categories"]:
|
||||||
ret_string += f"{i+1}: submit your score".ljust(30, " ")
|
boss_category_scores = boss_data[category["category"]]
|
||||||
|
if len(boss_category_scores) > i:
|
||||||
|
score = boss_category_scores[i]
|
||||||
|
# this is the dumbest solution to a problem iv seen in a while...
|
||||||
|
# I just needed the key and this is the best way to get it without
|
||||||
|
# getting a list of 1 key and parsing that string.
|
||||||
|
for key, value in score.items():
|
||||||
|
ret_string += f"{i+1}: {key} - {value}".ljust(30, " ")
|
||||||
|
else:
|
||||||
|
ret_string += f"{i+1}: submit your score".ljust(30, " ")
|
||||||
ret_string += "\n"
|
ret_string += "\n"
|
||||||
|
|
||||||
# if boss is hardmode, repeat above for hardmode applicable categories
|
# if boss is hardmode, repeat above for hardmode applicable categories
|
||||||
@@ -34,14 +44,21 @@ def format_highscore_message(boss):
|
|||||||
for category in highscores.highscores_config["categories"]:
|
for category in highscores.highscores_config["categories"]:
|
||||||
if category["hardmode"]:
|
if category["hardmode"]:
|
||||||
category_name = category["category"]
|
category_name = category["category"]
|
||||||
ret_string += f"{category_name}".ljust(30, " ")
|
ret_string += f"Hardmode {category_name}".ljust(30, " ")
|
||||||
|
|
||||||
ret_string += "\n"
|
ret_string += "\n"
|
||||||
|
|
||||||
for i in range(highscore_size):
|
for i in range(highscore_size):
|
||||||
for category in highscores.highscores_config["categories"]:
|
for category in highscores.highscores_config["categories"]:
|
||||||
if category["hardmode"]:
|
if category["hardmode"]:
|
||||||
ret_string += f"{i+1}: (name here)".ljust(30, " ")
|
hardmode_category = category["category"]
|
||||||
|
boss_category_scores = boss_data[f"{hardmode_category}_hardmode"]
|
||||||
|
if len(boss_category_scores) > i:
|
||||||
|
score = boss_category_scores[i]
|
||||||
|
for key, value in score.items():
|
||||||
|
ret_string += f"{i+1}: {key} - {value}".ljust(30, " ")
|
||||||
|
else:
|
||||||
|
ret_string += f"{i+1}: submit your score".ljust(30, " ")
|
||||||
ret_string += "\n"
|
ret_string += "\n"
|
||||||
return ret_string
|
return ret_string
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user