Adding map to track message id to boss.
This commit is contained in:
+2
-1
@@ -131,4 +131,5 @@ dmypy.json
|
|||||||
nextcord.log
|
nextcord.log
|
||||||
|
|
||||||
# data file for bot
|
# data file for bot
|
||||||
highscores_data.json
|
highscores_data.json
|
||||||
|
highscores_message_map.json
|
||||||
+3
-1
@@ -11,6 +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
|
||||||
|
|
||||||
logger = logging.getLogger("nextcord")
|
logger = logging.getLogger("nextcord")
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
@@ -21,6 +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()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -30,7 +32,7 @@ def main():
|
|||||||
intents = nextcord.Intents.default()
|
intents = nextcord.Intents.default()
|
||||||
|
|
||||||
# Required in order to read messages (eg. prefix commands)
|
# Required in order to read messages (eg. prefix commands)
|
||||||
intents.message_content = True
|
intents.message_content = True # pylint: disable=assigning-non-slot
|
||||||
|
|
||||||
# To enable the guilds priveleged intent:
|
# To enable the guilds priveleged intent:
|
||||||
# intents.guilds = True
|
# intents.guilds = True
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ 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():
|
||||||
@@ -42,6 +43,20 @@ def open_highscores_data():
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def open_message_map():
|
||||||
|
"""
|
||||||
|
Opens a highscore_message_map.json file if one exists. Otherwise returns empty dict.
|
||||||
|
@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 = {}
|
||||||
|
return message_map
|
||||||
|
|
||||||
|
|
||||||
def save_highscores_data(data):
|
def save_highscores_data(data):
|
||||||
"""
|
"""
|
||||||
Saves the highscores data dict into a json file.
|
Saves the highscores data dict into a json file.
|
||||||
@@ -49,3 +64,12 @@ 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))
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ Contains various utlity functions for highscores bot
|
|||||||
import nextcord
|
import nextcord
|
||||||
from highscores import highscores_config # pylint: disable=import-error
|
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
|
||||||
|
from highscores import highscores_message_map # pylint: disable=import-error
|
||||||
from utilities.data_storage import save_highscores_data # pylint: disable=import-error
|
from utilities.data_storage import save_highscores_data # pylint: disable=import-error
|
||||||
|
from utilities.data_storage import save_message_map # pylint: disable=import-error
|
||||||
|
|
||||||
|
|
||||||
def format_highscore_message(boss_name: str):
|
def format_highscore_message(boss_name: str):
|
||||||
@@ -56,6 +58,10 @@ async def send_highscore_message(channel, boss_name: str):
|
|||||||
message_id = message.id
|
message_id = message.id
|
||||||
highscores_data[boss_name]["message_id"] = message_id
|
highscores_data[boss_name]["message_id"] = message_id
|
||||||
|
|
||||||
|
# save message -> boss_name in message_map
|
||||||
|
highscores_message_map[message_id] = boss_name
|
||||||
|
save_message_map(highscores_message_map)
|
||||||
|
|
||||||
|
|
||||||
async def submit_score(
|
async def submit_score(
|
||||||
interaction: nextcord.Interaction, user: str, boss_name: str, category: str, score: str
|
interaction: nextcord.Interaction, user: str, boss_name: str, category: str, score: str
|
||||||
|
|||||||
Reference in New Issue
Block a user