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()
|
|
|
|
|
2016-08-19 13:56:41 +12:00
|
|
|
# Ensure that the required config.yml file actually exists
|
2016-08-12 14:14:30 +12:00
|
|
|
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()
|
2016-07-11 09:57:52 +12:00
|
|
|
|
2016-08-19 13:56:41 +12:00
|
|
|
# Default bot's description
|
2016-07-09 13:27:19 +12:00
|
|
|
botDescription = global_config.get("description")
|
2016-08-19 13:56:41 +12:00
|
|
|
# Bot's default prefix for commands
|
2016-08-05 02:30:34 +12:00
|
|
|
commandPrefix = global_config.get("command_prefix", "!")
|
2016-08-19 13:56:41 +12:00
|
|
|
# The key for bots.discord.pw and carbonitex
|
2016-08-12 14:14:30 +12:00
|
|
|
discord_bots_key = global_config.get('discord_bots_key', "")
|
2016-08-19 13:56:41 +12:00
|
|
|
carbon_key = global_config.get('carbon_key', "")
|
|
|
|
# The invite link for the server made for the bot
|
2016-08-16 15:30:52 +12:00
|
|
|
dev_server = global_config.get("dev_server", "")
|
2016-07-09 13:27:19 +12:00
|
|
|
|
2016-08-19 13:56:41 +12:00
|
|
|
# A list of all the outputs for the battle command
|
2016-07-09 13:27:19 +12:00
|
|
|
battleWins = global_config.get("battleWins", [])
|
2016-08-19 13:56:41 +12:00
|
|
|
# The default status the bot will use
|
2016-07-09 13:27:19 +12:00
|
|
|
defaultStatus = global_config.get("default_status", "")
|
2016-08-19 13:56:41 +12:00
|
|
|
#
|
2016-08-12 14:14:30 +12:00
|
|
|
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()
|
2016-07-09 13:27:19 +12:00
|
|
|
|
2016-07-11 09:57:52 +12:00
|
|
|
|
2016-08-15 14:10:12 +12:00
|
|
|
def save_content(key: str, content):
|
2016-08-13 07:52:44 +12:00
|
|
|
try:
|
|
|
|
with open("config.json", "r+") as jf:
|
|
|
|
data = json.load(jf)
|
|
|
|
data[key] = content
|
|
|
|
jf.seek(0)
|
2016-08-14 15:52:55 +12:00
|
|
|
json.dumps(data)
|
2016-08-13 07:52:44 +12:00
|
|
|
jf.truncate()
|
|
|
|
json.dump(data, jf, indent=4)
|
|
|
|
except FileNotFoundError:
|
|
|
|
with open("config.json", "w+") as jf:
|
|
|
|
json.dump({key: content}, jf, indent=4)
|
2016-07-18 05:12:57 +12:00
|
|
|
|
2016-07-18 05:11:47 +12:00
|
|
|
|
2016-08-15 14:10:12 +12:00
|
|
|
def get_content(key: str):
|
2016-07-18 03:17:47 +12:00
|
|
|
try:
|
2016-08-12 14:14:30 +12:00
|
|
|
with open("config.json", "r+") as jf:
|
2016-07-18 23:53:32 +12:00
|
|
|
return json.load(jf)[key]
|
2016-07-18 03:17:47 +12:00
|
|
|
except KeyError:
|
|
|
|
return None
|
2016-08-12 14:14:30 +12:00
|
|
|
except FileNotFoundError:
|
|
|
|
return None
|