1
0
Fork 0
mirror of synced 2024-06-28 03:00:55 +12:00

Using relative pathing; also adding failure messages upon attempting to run the bot without a valid config.yml file

This commit is contained in:
Phxntxm 2016-08-11 21:14:30 -05:00
parent 89ca7b0469
commit a65c1b8f9c

View file

@ -4,39 +4,51 @@ import json
loop = asyncio.get_event_loop()
with open("/home/phxntx5/public_html/Bonfire/config.yml", "r") as f:
global_config = yaml.load(f)
connection = None
try:
with open("config.yml", "r") as f:
global_config = yaml.load(f)
except FileNotFoundError:
print("You have no config file setup! Please use config.yml.sample to setup a valid config file")
quit()
botDescription = global_config.get("description")
commandPrefix = global_config.get("command_prefix", "!")
discord_bots_key = global_config.get('discord_bots_key')
discord_bots_key = global_config.get('discord_bots_key', "")
battleWins = global_config.get("battleWins", [])
defaultStatus = global_config.get("default_status", "")
botToken = global_config.get("bot_token", "")
owner_ids = global_config.get("owner_id", [])
try:
botToken = global_config["bot_token"]
except KeyError:
print("You have no bot_token saved, this is a requirement for running a bot.")
print("Please use config.yml.sample to setup a valid config file")
quit()
try:
owner_ids = global_config["owner_id"]
except KeyError:
print("You have no owner_id saved! You're not going to be able to run certain commands without this.")
print("Please use config.yml.sample to setup a valid config file")
quit()
def saveContent(key: str, content):
with open("/home/phxntx5/public_html/Bonfire/config.json", "r+") as jf:
data = json.load(jf)
jf.seek(0)
data[key] = content
with open("config.json", "a+") as jf:
try:
json.dumps(data)
except:
return False
else:
jf.truncate()
json.dump(data, jf, indent=4)
return True
data = json.load(jf)
except json.JSONDecodeError:
data = {}
data[key] = content
jf.seek(0)
jf.truncate()
json.dump(data, jf, indent=4)
def getContent(key: str):
try:
with open("/home/phxntx5/public_html/Bonfire/config.json", "r+") as jf:
with open("config.json", "r+") as jf:
return json.load(jf)[key]
except KeyError:
return None
except FileNotFoundError:
return None