1
0
Fork 0
mirror of synced 2024-06-28 19:20:34 +12:00
Bonfire/cogs/utils/config.py

43 lines
1.1 KiB
Python
Raw Normal View History

2016-07-09 13:27:19 +12:00
import yaml
import asyncio
2016-07-17 08:26:30 +12:00
import json
2016-07-09 13:27:19 +12:00
loop = asyncio.get_event_loop()
with open("/home/phxntx5/public_html/Bonfire/config.yml", "r") as f:
global_config = yaml.load(f)
connection = None
2016-07-09 13:27:19 +12:00
botDescription = global_config.get("description")
commandPrefix = global_config.get("command_prefix", "!")
2016-08-02 01:06:11 +12:00
discord_bots_key = global_config.get('discord_bots_key')
2016-07-09 13:27:19 +12:00
battleWins = global_config.get("battleWins", [])
defaultStatus = global_config.get("default_status", "")
botToken = global_config.get("bot_token", "")
owner_ids = global_config.get("owner_id", [])
2016-07-09 13:27:19 +12:00
2016-07-17 08:26:30 +12:00
def saveContent(key: str, content):
2016-07-18 04:34:49 +12:00
with open("/home/phxntx5/public_html/Bonfire/config.json", "r+") as jf:
data = json.load(jf)
jf.seek(0)
data[key] = content
try:
json.dumps(data)
except:
return False
else:
jf.truncate()
json.dump(data, jf, indent=4)
return True
def getContent(key: str):
try:
2016-07-18 04:34:49 +12:00
with open("/home/phxntx5/public_html/Bonfire/config.json", "r+") as jf:
return json.load(jf)[key]
except KeyError:
return None