post-scores command now populates the highscores channel with formatted messages.

This commit is contained in:
alwayscompiling
2022-06-26 18:01:09 -04:00
parent 17cb66870a
commit bd9a48cc1f
3 changed files with 24 additions and 14 deletions
+15 -4
View File
@@ -4,6 +4,8 @@ Bot command to post the highscores
from nextcord.ext import commands
import highscores # pylint: disable=import-error
from utils import data_storage # pylint: disable=import-error
from utils import message_formatter # pylint: disable=import-error
class PostHighscores(commands.Cog, name="Post Highscores"):
@@ -27,14 +29,23 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
f"Printing out highscores information in channel {channel_id}")
channel = self.bot.get_channel(channel_id)
for boss in highscores.highscores_config["bosses"]:
print(boss)
boss_name = boss["boss"]
highscore_string = f"**{boss_name}**"
await channel.send(highscore_string)
highscore_string = message_formatter.format_boss_highscore(
boss)
message = await channel.send(highscore_string)
message_id = message.id
# check if there is a dict for the boss in the highscores data
if not boss["boss"] in highscores.highscores_data:
highscores.highscores_data[boss["boss"]] = {}
highscores.highscores_data[boss["boss"]
]["message_id"] = message_id
else:
response = "Highscores channel is not registered. Register with \"?register\" command."
await ctx.send(response)
data_storage.save_highscores_data(highscores.highscores_data)
# This function will be called when this extension is loaded.
# It is necessary to add these functions to the bot.
+1 -5
View File
@@ -76,10 +76,6 @@
"boss": "Helwyr",
"hardmode": "true"
},
{
"boss": "IM Compiling",
"hardmode": "true"
},
{
"boss": "Kalphite King",
"hardmode": "false"
@@ -193,7 +189,7 @@
},
{
"category": "Kill Time",
"hardmore": true,
"hardmode": true,
"ascending": true
},
{
+8 -5
View File
@@ -12,19 +12,20 @@ def format_boss_highscore(boss):
@return the formatted string
"""
boss_name = boss["boss"]
ret_string = f"**{boss_name}**/n"
ret_string = f"**{boss_name}**\n"
# Gather all categories and add to string
for category in highscores.highscores_config["categories"]:
category_name = category["category"]
ret_string += f"{category_name}\t\t"
ret_string += "\n"
highscore_size = highscores.highscores_config["highscore_size"]
# list rankings
for x in range(highscore_size):
for i in range(highscore_size):
for category in highscores.highscores_config["categories"]:
ret_string += f"{x}: (name here)\t\t"
ret_string += f"{i+1}: (name here)\t\t"
ret_string += "\n"
# if boss is hardmode, repeat above for hardmode applicable categories
@@ -36,7 +37,9 @@ def format_boss_highscore(boss):
ret_string += "\n"
for x in range(highscore_size):
for i in range(highscore_size):
for category in highscores.highscores_config["categories"]:
ret_string += f"{x}: (name here)\t\t"
if category["hardmode"]:
ret_string += f"{i+1}: (name here)\t\t"
ret_string += "\n"
return ret_string