post-scores command now populates the highscores channel with formatted messages.
This commit is contained in:
@@ -4,6 +4,8 @@ Bot command to post the highscores
|
|||||||
|
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
import highscores # pylint: disable=import-error
|
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"):
|
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}")
|
f"Printing out highscores information in channel {channel_id}")
|
||||||
channel = self.bot.get_channel(channel_id)
|
channel = self.bot.get_channel(channel_id)
|
||||||
for boss in highscores.highscores_config["bosses"]:
|
for boss in highscores.highscores_config["bosses"]:
|
||||||
print(boss)
|
highscore_string = message_formatter.format_boss_highscore(
|
||||||
boss_name = boss["boss"]
|
boss)
|
||||||
highscore_string = f"**{boss_name}**"
|
message = await channel.send(highscore_string)
|
||||||
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:
|
else:
|
||||||
response = "Highscores channel is not registered. Register with \"?register\" command."
|
response = "Highscores channel is not registered. Register with \"?register\" command."
|
||||||
await ctx.send(response)
|
await ctx.send(response)
|
||||||
|
|
||||||
|
data_storage.save_highscores_data(highscores.highscores_data)
|
||||||
|
|
||||||
|
|
||||||
# This function will be called when this extension is loaded.
|
# This function will be called when this extension is loaded.
|
||||||
# It is necessary to add these functions to the bot.
|
# It is necessary to add these functions to the bot.
|
||||||
|
|||||||
@@ -76,10 +76,6 @@
|
|||||||
"boss": "Helwyr",
|
"boss": "Helwyr",
|
||||||
"hardmode": "true"
|
"hardmode": "true"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"boss": "IM Compiling",
|
|
||||||
"hardmode": "true"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"boss": "Kalphite King",
|
"boss": "Kalphite King",
|
||||||
"hardmode": "false"
|
"hardmode": "false"
|
||||||
@@ -193,7 +189,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"category": "Kill Time",
|
"category": "Kill Time",
|
||||||
"hardmore": true,
|
"hardmode": true,
|
||||||
"ascending": true
|
"ascending": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,19 +12,20 @@ def format_boss_highscore(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"
|
||||||
|
|
||||||
# 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"]:
|
||||||
category_name = category["category"]
|
category_name = category["category"]
|
||||||
ret_string += f"{category_name}\t\t"
|
ret_string += f"{category_name}\t\t"
|
||||||
|
ret_string += "\n"
|
||||||
|
|
||||||
highscore_size = highscores.highscores_config["highscore_size"]
|
highscore_size = highscores.highscores_config["highscore_size"]
|
||||||
|
|
||||||
# list rankings
|
# list rankings
|
||||||
for x 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"{x}: (name here)\t\t"
|
ret_string += f"{i+1}: (name here)\t\t"
|
||||||
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
|
||||||
@@ -36,7 +37,9 @@ def format_boss_highscore(boss):
|
|||||||
|
|
||||||
ret_string += "\n"
|
ret_string += "\n"
|
||||||
|
|
||||||
for x 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"{x}: (name here)\t\t"
|
if category["hardmode"]:
|
||||||
|
ret_string += f"{i+1}: (name here)\t\t"
|
||||||
ret_string += "\n"
|
ret_string += "\n"
|
||||||
|
return ret_string
|
||||||
|
|||||||
Reference in New Issue
Block a user