cleaning up highscores imports a little.

This commit is contained in:
alwayscompiling
2022-06-28 22:33:52 -04:00
parent 2b5c49a896
commit ed62836b7f
3 changed files with 18 additions and 16 deletions
+5 -4
View File
@@ -3,7 +3,8 @@ Bot command to post the highscores
"""
from nextcord.ext import commands
import highscores # pylint: disable=import-error
from highscores import highscores_config # pylint: disable=import-error
from highscores import highscores_data # pylint: disable=import-error
from utils import data_storage # pylint: disable=import-error
from utils import highscore_message # pylint: disable=import-error
@@ -25,7 +26,7 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
```
"""
# temporarily sending config data...
channel_id = highscores.highscores_data["channel_id"]
channel_id = highscores_data["channel_id"]
print(f"Printing out highscores information in channel {channel_id}")
channel = self.bot.get_channel(channel_id)
if channel is None:
@@ -33,11 +34,11 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
Register with "?register" command.'
await ctx.send(response)
return
for boss in highscores.highscores_config["bosses"]:
for boss in highscores_config["bosses"]:
await highscore_message.send_highscore_message(channel, boss)
break
data_storage.save_highscores_data(highscores.highscores_data)
data_storage.save_highscores_data(highscores_data)
# This function will be called when this extension is loaded.
+3 -3
View File
@@ -3,7 +3,7 @@ Bot command to register the highscores channel
"""
from nextcord.ext import commands
import highscores # pylint: disable=import-error
from highscores import highscores_data # pylint: disable=import-error
from utils import data_storage # pylint: disable=import-error
@@ -24,8 +24,8 @@ class RegisterHighscoreChannel(commands.Cog, name="Register HighScore Channel"):
print(f"Registering {ctx.channel.id}.")
# respond to the message
await ctx.send(f"Registered <#{ctx.channel.id}> as channel to post highscores in.")
highscores.highscores_data["channel_id"] = ctx.channel.id
data_storage.save_highscores_data(highscores.highscores_data)
highscores_data["channel_id"] = ctx.channel.id
data_storage.save_highscores_data(highscores_data)
# This function will be called when this extension is loaded.
+10 -9
View File
@@ -3,7 +3,8 @@ Contains various functions for sending/editing the highscore messages.
"""
import nextcord
import highscores # pylint: disable=import-error
from highscores import highscores_config # pylint: disable=import-error
from highscores import highscores_data # pylint: disable=import-error
def format_highscore_message(boss):
@@ -14,19 +15,19 @@ def format_highscore_message(boss):
"""
boss_name = boss["boss"]
ret_string = f"**{boss_name}**\n"
boss_data = highscores.highscores_data[boss_name]
boss_data = highscores_data[boss_name]
# Gather all categories and add to string
for category in highscores.highscores_config["categories"]:
for category in highscores_config["categories"]:
category_name = category["category"]
ret_string += f"{category_name}".ljust(30, " ")
ret_string += "\n"
highscore_size = highscores.highscores_config["highscore_size"]
highscore_size = highscores_config["highscore_size"]
# list rankings
for i in range(highscore_size):
for category in highscores.highscores_config["categories"]:
for category in highscores_config["categories"]:
boss_category_scores = boss_data[category["category"]]
if len(boss_category_scores) > i:
score = boss_category_scores[i]
@@ -41,7 +42,7 @@ def format_highscore_message(boss):
# if boss is hardmode, repeat above for hardmode applicable categories
if boss["hardmode"]:
for category in highscores.highscores_config["categories"]:
for category in highscores_config["categories"]:
if category["hardmode"]:
category_name = category["category"]
ret_string += f"Hardmode {category_name}".ljust(30, " ")
@@ -49,7 +50,7 @@ def format_highscore_message(boss):
ret_string += "\n"
for i in range(highscore_size):
for category in highscores.highscores_config["categories"]:
for category in highscores_config["categories"]:
if category["hardmode"]:
hardmode_category = category["category"]
boss_category_scores = boss_data[f"{hardmode_category}_hardmode"]
@@ -71,7 +72,7 @@ async def send_highscore_message(channel, boss):
"""
highscore_string = format_highscore_message(boss)
message_id = highscores.highscores_data[boss["boss"]]["message_id"]
message_id = highscores_data[boss["boss"]]["message_id"]
try:
message = await channel.fetch_message(message_id)
await message.edit(content=highscore_string)
@@ -79,4 +80,4 @@ async def send_highscore_message(channel, boss):
# message doesn't exist.
message = await channel.send(highscore_string)
message_id = message.id
highscores.highscores_data[boss["boss"]]["message_id"] = message_id
highscores_data[boss["boss"]]["message_id"] = message_id