handle cfg defaults better

This commit is contained in:
Lynne 2019-04-29 13:59:37 +10:00
parent 48faf4d3b3
commit 99d1d13fbf
No known key found for this signature in database
GPG Key ID: FB7B970303ACE499

26
main.py
View File

@ -12,25 +12,19 @@ import requests
import functions
scopes = ["read:statuses", "read:accounts", "read:follows", "write:statuses", "read:notifications"]
#cfg defaults
cfg = {
"site": "https://botsin.space",
"cw": None,
"instance_blacklist": ["bofa.lol", "witches.town"],
"learn_from_cw": False
}
try:
cfg = json.load(open('config.json', 'r'))
cfg.update(json.load(open('config.json', 'r')))
except:
shutil.copy2("config.sample.json", "config.json")
cfg = json.load(open('config.json', 'r'))
#config.json should contain the instance URL, the instance blacklist (for dead/broken instances), and the CW text. if they're not provided, we'll fall back to defaults.
# TODO: this is pretty messy
if 'site' not in cfg:
cfg['website'] = "https://botsin.space"
if 'cw' not in cfg:
cfg['cw'] = None
if 'instance_blacklist' not in cfg:
cfg["instance_blacklist"] = [
"bofa.lol",
"witches.town"
]
if 'learn_from_cw' not in cfg:
cfg['learn_from_cw'] = False
shutil.copy2("config.sample.json", "config.json")
cfg.update(json.load(open('config.json', 'r')))
#if the user is using a (very!) old version that still uses the .secret files, migrate to the new method
if os.path.exists("clientcred.secret"):