Correcting data storage and creating global variables for data and config. Post and register commands tested for theory.

This commit is contained in:
alwayscompiling
2022-06-26 16:20:05 -04:00
parent 3afa052a2b
commit 7152fe6d2c
5 changed files with 104 additions and 38 deletions
+7 -34
View File
@@ -2,14 +2,15 @@
main file for pvm-highscores bot
"""
import os
import logging
import json
import logging
import os
import nextcord
from nextcord.ext import commands
import config
from utils import data_storage
logger = logging.getLogger('nextcord')
logger.setLevel(logging.DEBUG)
@@ -19,8 +20,9 @@ handler.setFormatter(logging.Formatter(
'%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
highscores_config_file = "highscores_config.json"
highscores_data_file = "highscores_data.json"
highscores_config = data_storage.open_highscores_config()
highscores_data = data_storage.open_highscores_data()
def main():
@@ -63,34 +65,5 @@ def main():
bot.run(config.DISCORD_TOKEN)
def open_highscores_data():
"""Opens a highscores_data.json file if one exists, otherwise creates a skeleton of the data."""
if (os.path.exists(highscores_data_file)):
with open(highscores_data_file, encoding='utf-8', mode="r") as file:
data = json.load(file)
else:
# create the json object
x = {
"channel_id": 0
}
data = json.dumps(x)
return data
def open_highscores_config():
"""Opens the highscores config file as a json object and returns."""
# Load bot config
with open(highscores_config_file, encoding='utf-8', mode='r') as file:
highscores_config = json.load(file)
return highscores_config
def save_highscores_data(data):
"""Saves the highscores data into a json file."""
with open(highscores_data_file, encoding='utf-8', mode='w') as file:
file.write(json.dumps(data, indent=4))
if __name__ == "__main__":
main()