Generating message map on bot start.

This commit is contained in:
alwayscompiling
2022-07-22 21:18:01 -04:00
parent 7a261d56fc
commit a1a9fae9fa
3 changed files with 14 additions and 22 deletions
+10 -18
View File
@@ -5,7 +5,6 @@ import json
HIGHSCORES_CONFIG_FILE = "highscores_config.json"
HIGHSCORES_DATA_FILE = "highscores_data.json"
HIGHSCORES_MESSAGE_MAP_FILE = "highscores_message_map.json"
def open_highscores_config():
@@ -40,17 +39,19 @@ def open_highscores_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.
"""
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
@@ -61,12 +62,3 @@ def save_highscores_data(data):
"""
with open(HIGHSCORES_DATA_FILE, encoding="utf-8", mode="w") as file:
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))