This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/core/config.py

70 lines
2 KiB
Python
Raw Normal View History

2011-11-20 10:23:31 +01:00
import inspect
import json
import os
def save(conf):
json.dump(conf, open('config', 'w'), sort_keys=True, indent=2)
if not os.path.exists('config'):
open('config', 'w').write(inspect.cleandoc(
r'''
{
"connections":
{
2012-02-29 01:30:47 +01:00
"EsperNet":
2011-11-20 10:23:31 +01:00
{
2012-02-29 01:30:47 +01:00
"server": "irc.esper.net",
"nick": "MyNewCloudBot",
2011-11-21 00:04:39 +01:00
"user": "cloudbot",
2012-02-28 08:46:16 +01:00
"realname": "CloudBot - http://git.io/cloudbot",
2011-11-21 00:04:39 +01:00
"nickserv_password": "",
2012-02-29 01:30:47 +01:00
"channels": ["#cloudbot"],
2012-02-29 00:11:30 +01:00
"invitejoin": "True",
2012-02-29 00:02:44 +01:00
"autorejoin": "False",
"command_prefix": ".",
"stayalive": "",
2012-02-17 01:35:01 +01:00
"stayalive_delay": "20"
2011-11-20 10:23:31 +01:00
}
},
"disabled_plugins": [],
"disabled_commands": [],
"acls": {},
2011-11-21 07:41:07 +01:00
"api_keys":
{
"geoip": "INSERT API KEY FROM ipinfodb.com HERE",
"tvdb": "INSERT API KEY FROM thetvdb.com HERE",
2011-11-21 07:41:07 +01:00
"bitly_user": "INSERT USERNAME FROM bitly.com HERE",
2011-11-21 07:44:34 +01:00
"bitly_api": "INSERT API KEY FROM bitly.com HERE",
2012-02-16 09:08:07 +01:00
"wolframalpha": "INSERT API KEY FROM wolframalpha.com HERE",
2012-02-16 11:30:06 +01:00
"lastfm": "INSERT API KEY FROM lastfm HERE",
2012-02-29 06:09:40 +01:00
"mc_user": "INSERT MINECRAFT USERNAME HERE",
"mc_pass": "INSERT MINECRAFT PASSWORD HERE"
2011-11-21 07:41:07 +01:00
},
2011-11-20 10:23:31 +01:00
"censored_strings":
[
2012-02-29 02:33:16 +01:00
"mypass",
"mysecret"
2011-11-20 10:23:31 +01:00
],
2012-02-28 08:54:36 +01:00
"admins": ["myname"]
2011-11-20 10:23:31 +01:00
}''') + '\n')
2012-02-28 08:49:44 +01:00
print "Config generated!"
2012-02-29 01:30:47 +01:00
print "Please edit the config now!"
2012-02-28 08:49:44 +01:00
print "For help, see http://git.io/cloudbotwiki"
print "Thank you for using CloudBot!"
sys.exit()
2011-11-20 10:23:31 +01:00
2012-02-29 06:09:40 +01:00
2011-11-20 10:23:31 +01:00
def config():
# reload config from file if file has changed
config_mtime = os.stat('config').st_mtime
if bot._config_mtime != config_mtime:
try:
bot.config = json.load(open('config'))
bot._config_mtime = config_mtime
except ValueError, e:
print 'ERROR: malformed config!', e
2011-11-21 00:04:39 +01:00
bot._config_mtime = 0