cleaning up highscores imports a little.
This commit is contained in:
@@ -3,7 +3,8 @@ Bot command to post the highscores
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from nextcord.ext import commands
|
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 data_storage # pylint: disable=import-error
|
||||||
from utils import highscore_message # 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...
|
# 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}")
|
print(f"Printing out highscores information in channel {channel_id}")
|
||||||
channel = self.bot.get_channel(channel_id)
|
channel = self.bot.get_channel(channel_id)
|
||||||
if channel is None:
|
if channel is None:
|
||||||
@@ -33,11 +34,11 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
|
|||||||
Register with "?register" command.'
|
Register with "?register" command.'
|
||||||
await ctx.send(response)
|
await ctx.send(response)
|
||||||
return
|
return
|
||||||
for boss in highscores.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)
|
||||||
break
|
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.
|
# This function will be called when this extension is loaded.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ Bot command to register the highscores channel
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from nextcord.ext import commands
|
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
|
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}.")
|
print(f"Registering {ctx.channel.id}.")
|
||||||
# respond to the message
|
# respond to the message
|
||||||
await ctx.send(f"Registered <#{ctx.channel.id}> as channel to post highscores in.")
|
await ctx.send(f"Registered <#{ctx.channel.id}> as channel to post highscores in.")
|
||||||
highscores.highscores_data["channel_id"] = ctx.channel.id
|
highscores_data["channel_id"] = ctx.channel.id
|
||||||
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.
|
# This function will be called when this extension is loaded.
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ Contains various functions for sending/editing the highscore messages.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import nextcord
|
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):
|
def format_highscore_message(boss):
|
||||||
@@ -14,19 +15,19 @@ def format_highscore_message(boss):
|
|||||||
"""
|
"""
|
||||||
boss_name = boss["boss"]
|
boss_name = boss["boss"]
|
||||||
ret_string = f"**{boss_name}**\n"
|
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
|
# Gather all categories and add to string
|
||||||
for category in highscores.highscores_config["categories"]:
|
for category in highscores_config["categories"]:
|
||||||
category_name = category["category"]
|
category_name = category["category"]
|
||||||
ret_string += f"{category_name}".ljust(30, " ")
|
ret_string += f"{category_name}".ljust(30, " ")
|
||||||
ret_string += "\n"
|
ret_string += "\n"
|
||||||
|
|
||||||
highscore_size = highscores.highscores_config["highscore_size"]
|
highscore_size = highscores_config["highscore_size"]
|
||||||
|
|
||||||
# list rankings
|
# list rankings
|
||||||
for i in range(highscore_size):
|
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"]]
|
boss_category_scores = boss_data[category["category"]]
|
||||||
if len(boss_category_scores) > i:
|
if len(boss_category_scores) > i:
|
||||||
score = 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 is hardmode, repeat above for hardmode applicable categories
|
||||||
if boss["hardmode"]:
|
if boss["hardmode"]:
|
||||||
for category in highscores.highscores_config["categories"]:
|
for category in highscores_config["categories"]:
|
||||||
if category["hardmode"]:
|
if category["hardmode"]:
|
||||||
category_name = category["category"]
|
category_name = category["category"]
|
||||||
ret_string += f"Hardmode {category_name}".ljust(30, " ")
|
ret_string += f"Hardmode {category_name}".ljust(30, " ")
|
||||||
@@ -49,7 +50,7 @@ def format_highscore_message(boss):
|
|||||||
ret_string += "\n"
|
ret_string += "\n"
|
||||||
|
|
||||||
for i in range(highscore_size):
|
for i in range(highscore_size):
|
||||||
for category in highscores.highscores_config["categories"]:
|
for category in highscores_config["categories"]:
|
||||||
if category["hardmode"]:
|
if category["hardmode"]:
|
||||||
hardmode_category = category["category"]
|
hardmode_category = category["category"]
|
||||||
boss_category_scores = boss_data[f"{hardmode_category}_hardmode"]
|
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)
|
highscore_string = format_highscore_message(boss)
|
||||||
|
|
||||||
message_id = highscores.highscores_data[boss["boss"]]["message_id"]
|
message_id = highscores_data[boss["boss"]]["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)
|
||||||
@@ -79,4 +80,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.highscores_data[boss["boss"]]["message_id"] = message_id
|
highscores_data[boss["boss"]]["message_id"] = message_id
|
||||||
|
|||||||
Reference in New Issue
Block a user