Only sending boss name as a string, no dict objects.
This commit is contained in:
@@ -25,7 +25,6 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
|
|||||||
?post-scores
|
?post-scores
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
# temporarily sending config data...
|
|
||||||
channel_id = highscores_data["channel_id"]
|
channel_id = highscores_data["channel_id"]
|
||||||
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)
|
||||||
@@ -35,7 +34,7 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
|
|||||||
await ctx.send(response)
|
await ctx.send(response)
|
||||||
return
|
return
|
||||||
for boss in highscores_config["bosses"]:
|
for boss in highscores_config["bosses"]:
|
||||||
await highscore_message.send_highscore_message(channel, boss)
|
await highscore_message.send_highscore_message(channel, boss["boss"])
|
||||||
|
|
||||||
data_storage.save_highscores_data(highscores_data)
|
data_storage.save_highscores_data(highscores_data)
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class RegisterHighscoreChannel(commands.Cog, name="Score"):
|
|||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@commands.command(name="score")
|
@commands.command(name="score")
|
||||||
async def score(self, ctx: commands.Context, boss: str, category: str, score):
|
async def score(self, ctx: commands.Context, boss_name: str, category: str, score):
|
||||||
"""A command which calls a function to submit the score to highscores. Gathers required
|
"""A command which calls a function to submit the score to highscores. Gathers required
|
||||||
information from command and passes on.
|
information from command and passes on.
|
||||||
Usage:
|
Usage:
|
||||||
@@ -23,7 +23,9 @@ class RegisterHighscoreChannel(commands.Cog, name="Score"):
|
|||||||
?score "Boss Name" "Category" "score"
|
?score "Boss Name" "Category" "score"
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
highscore_manage.submit_score_int(boss, category, ctx.author.display_name, score)
|
await highscore_manage.submit_score_int(
|
||||||
|
self, ctx, boss_name, category, ctx.author.display_name, score
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# This function will be called when this extension is loaded.
|
# This function will be called when this extension is loaded.
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ from highscores import highscores_data # pylint: disable=import-error
|
|||||||
from utils import data_storage # pylint: disable=import-error
|
from utils import data_storage # pylint: disable=import-error
|
||||||
|
|
||||||
|
|
||||||
def submit_score_int(boss: str, category: str, user: str, score: int):
|
async def submit_score_int(
|
||||||
|
self, ctx: commands.Context, boss_name: str, category: str, user: str, score: int
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Adds a score to the high scores and sorts. Removes a score if larger than size limit.
|
Adds a score to the high scores and sorts. Removes a score if larger than size limit.
|
||||||
@param boss: the boss to add score to
|
@param boss: the boss to add score to
|
||||||
|
|||||||
@@ -7,13 +7,12 @@ 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
|
||||||
|
|
||||||
|
|
||||||
def format_highscore_message(boss):
|
def format_highscore_message(boss_name: str):
|
||||||
"""
|
"""
|
||||||
returns a formatted 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"]
|
|
||||||
ret_string = f"**{boss_name}**\n"
|
ret_string = f"**{boss_name}**\n"
|
||||||
boss_data = highscores_data[boss_name]
|
boss_data = highscores_data[boss_name]
|
||||||
|
|
||||||
@@ -37,15 +36,15 @@ def format_highscore_message(boss):
|
|||||||
return ret_string
|
return ret_string
|
||||||
|
|
||||||
|
|
||||||
async def send_highscore_message(channel, boss):
|
async def send_highscore_message(channel, boss_name: str):
|
||||||
"""
|
"""
|
||||||
Function takes care of checking if a message exists for a boss, then creating and sending/editing the message
|
Function takes care of checking if a message exists for a boss, then creating and sending/editing the message
|
||||||
@param channel: the channel to send the message in/search for message id
|
@param channel: the channel to send the message in/search for message id
|
||||||
@param boss: the boss to send the message about
|
@param boss: the boss to send the message about
|
||||||
"""
|
"""
|
||||||
highscore_string = format_highscore_message(boss)
|
highscore_string = format_highscore_message(boss_name)
|
||||||
|
|
||||||
message_id = highscores_data[boss["boss"]]["message_id"]
|
message_id = highscores_data[boss_name]["message_id"]
|
||||||
try:
|
try:
|
||||||
message = await channel.fetch_message(message_id)
|
message = await channel.fetch_message(message_id)
|
||||||
await message.edit(content=highscore_string)
|
await message.edit(content=highscore_string)
|
||||||
@@ -53,4 +52,4 @@ async def send_highscore_message(channel, boss):
|
|||||||
# message doesn't exist.
|
# message doesn't exist.
|
||||||
message = await channel.send(highscore_string)
|
message = await channel.send(highscore_string)
|
||||||
message_id = message.id
|
message_id = message.id
|
||||||
highscores_data[boss["boss"]]["message_id"] = message_id
|
highscores_data[boss_name]["message_id"] = message_id
|
||||||
|
|||||||
Reference in New Issue
Block a user