Generating message map on bot start.
This commit is contained in:
@@ -7,7 +7,7 @@ import nextcord
|
|||||||
from nextcord import Embed
|
from nextcord import Embed
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
from utilities.data_storage import open_message_map # pylint: disable=import-error
|
from utilities.data_storage import create_message_map # pylint: disable=import-error
|
||||||
from highscores import highscores_data # pylint: disable=import-error
|
from highscores import highscores_data # pylint: disable=import-error
|
||||||
from highscores import submission_objects # pylint: disable=import-error
|
from highscores import submission_objects # pylint: disable=import-error
|
||||||
from .verification_view import VerificationView
|
from .verification_view import VerificationView
|
||||||
@@ -186,7 +186,7 @@ class SubmissionCreateButton(nextcord.ui.View):
|
|||||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||||
): # pylint: disable=unused-argument
|
): # pylint: disable=unused-argument
|
||||||
"""Button for score submission."""
|
"""Button for score submission."""
|
||||||
highscores_message_map = open_message_map()
|
highscores_message_map = create_message_map()
|
||||||
boss_name = highscores_message_map[str(interaction.message.id)]
|
boss_name = highscores_message_map[str(interaction.message.id)]
|
||||||
# embed = nextcord.Embed(title="Highscores Submission")
|
# embed = nextcord.Embed(title="Highscores Submission")
|
||||||
# embed.add_field(name="Boss", value=boss_name, inline=False)
|
# embed.add_field(name="Boss", value=boss_name, inline=False)
|
||||||
|
|||||||
+2
-2
@@ -11,7 +11,7 @@ from nextcord.ext import commands
|
|||||||
import config
|
import config
|
||||||
from utilities.data_storage import open_highscores_config
|
from utilities.data_storage import open_highscores_config
|
||||||
from utilities.data_storage import open_highscores_data
|
from utilities.data_storage import open_highscores_data
|
||||||
from utilities.data_storage import open_message_map
|
from utilities.data_storage import create_message_map
|
||||||
|
|
||||||
logger = logging.getLogger("nextcord")
|
logger = logging.getLogger("nextcord")
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
@@ -22,7 +22,7 @@ logger.addHandler(handler)
|
|||||||
|
|
||||||
highscores_config = open_highscores_config()
|
highscores_config = open_highscores_config()
|
||||||
highscores_data = open_highscores_data()
|
highscores_data = open_highscores_data()
|
||||||
highscores_message_map = open_message_map()
|
highscores_message_map = create_message_map()
|
||||||
|
|
||||||
submission_objects: dict = {}
|
submission_objects: dict = {}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import json
|
|||||||
|
|
||||||
HIGHSCORES_CONFIG_FILE = "highscores_config.json"
|
HIGHSCORES_CONFIG_FILE = "highscores_config.json"
|
||||||
HIGHSCORES_DATA_FILE = "highscores_data.json"
|
HIGHSCORES_DATA_FILE = "highscores_data.json"
|
||||||
HIGHSCORES_MESSAGE_MAP_FILE = "highscores_message_map.json"
|
|
||||||
|
|
||||||
|
|
||||||
def open_highscores_config():
|
def open_highscores_config():
|
||||||
@@ -40,17 +39,19 @@ def open_highscores_data():
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def open_message_map():
|
def create_message_map(data: dict):
|
||||||
"""
|
"""
|
||||||
Opens a highscore_message_map.json file if one exists. Otherwise returns empty dict.
|
Creates a message map from input highscores data.
|
||||||
|
|
||||||
|
@param data: highscores_data dict to create map from.
|
||||||
@return: dict message_map of message to boss.
|
@return: dict message_map of message to boss.
|
||||||
"""
|
"""
|
||||||
if os.path.exists(HIGHSCORES_MESSAGE_MAP_FILE):
|
|
||||||
with open(HIGHSCORES_MESSAGE_MAP_FILE, encoding="utf-8", mode="r") as file:
|
|
||||||
message_map = json.load(file)
|
|
||||||
else:
|
|
||||||
# create the json object
|
|
||||||
message_map = {}
|
message_map = {}
|
||||||
|
|
||||||
|
for boss, info in data["tables"].items():
|
||||||
|
message_map[info["message_id"]] = boss
|
||||||
|
|
||||||
return message_map
|
return message_map
|
||||||
|
|
||||||
|
|
||||||
@@ -61,12 +62,3 @@ def save_highscores_data(data):
|
|||||||
"""
|
"""
|
||||||
with open(HIGHSCORES_DATA_FILE, encoding="utf-8", mode="w") as file:
|
with open(HIGHSCORES_DATA_FILE, encoding="utf-8", mode="w") as file:
|
||||||
file.write(json.dumps(data, indent=4))
|
file.write(json.dumps(data, indent=4))
|
||||||
|
|
||||||
|
|
||||||
def save_message_map(message_map):
|
|
||||||
"""
|
|
||||||
Saves the highscores message mao data dict into a json file.
|
|
||||||
@param map: dict map of message to boss.
|
|
||||||
"""
|
|
||||||
with open(HIGHSCORES_MESSAGE_MAP_FILE, encoding="utf-8", mode="w") as file:
|
|
||||||
file.write(json.dumps(message_map, indent=4))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user