Add message edit to score command.
This commit is contained in:
@@ -2,8 +2,10 @@
|
|||||||
Contains various functions for managing the highscores data
|
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_config # pylint: disable=import-error
|
||||||
from highscores import highscores_data # 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
|
from utils import data_storage # pylint: disable=import-error
|
||||||
|
|
||||||
|
|
||||||
@@ -18,14 +20,25 @@ async def submit_score_int(
|
|||||||
@param score: score (int) to add
|
@param score: score (int) to add
|
||||||
"""
|
"""
|
||||||
# TODO update user submission to not have dupe users
|
# 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)
|
score_tuple = (user, score)
|
||||||
scores.append(score_tuple)
|
scores.append(score_tuple)
|
||||||
ascending = highscores_config["categories"][category]
|
ascending = highscores_config["categories"][category]
|
||||||
scores.sort(key=lambda x: x[1], reverse=not ascending)
|
scores.sort(key=lambda x: x[1], reverse=not ascending)
|
||||||
while len(scores) > highscores_config["highscore_size"]:
|
while len(scores) > highscores_config["highscore_size"]:
|
||||||
scores.pop()
|
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
|
# save data
|
||||||
data_storage.save_highscores_data(highscores_data)
|
data_storage.save_highscores_data(highscores_data)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ def format_highscore_message(boss_name: str):
|
|||||||
for key, value in boss_data["categories"].items():
|
for key, value in boss_data["categories"].items():
|
||||||
if len(value) > i:
|
if len(value) > i:
|
||||||
score = 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:
|
else:
|
||||||
ret_string += f"{i+1}: submit your score".ljust(30, " ")
|
ret_string += f"{i+1}: submit your score".ljust(30, " ")
|
||||||
ret_string += "\n"
|
ret_string += "\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user