2010-02-23 03:32:09 +00:00
|
|
|
import inspect
|
|
|
|
import json
|
2009-11-18 00:19:26 +00:00
|
|
|
import os
|
|
|
|
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-02-23 03:32:09 +00:00
|
|
|
def save(conf):
|
|
|
|
json.dump(conf, open('config', 'w'), sort_keys=True, indent=2)
|
2009-11-18 00:19:26 +00:00
|
|
|
|
|
|
|
if not os.path.exists('config'):
|
2010-02-23 03:32:09 +00:00
|
|
|
open('config', 'w').write(inspect.cleandoc(
|
2010-12-31 19:01:54 +00:00
|
|
|
r'''
|
2010-02-23 03:32:09 +00:00
|
|
|
{
|
|
|
|
"connections":
|
|
|
|
{
|
|
|
|
"local irc":
|
|
|
|
{
|
|
|
|
"server": "localhost",
|
|
|
|
"nick": "skybot",
|
|
|
|
"channels": ["#test"]
|
2010-01-17 20:20:11 +00:00
|
|
|
}
|
2010-05-07 23:16:44 +00:00
|
|
|
},
|
|
|
|
"disabled_plugins": [],
|
|
|
|
"disabled_commands": [],
|
2010-12-31 19:01:54 +00:00
|
|
|
"acls": {},
|
2011-04-25 18:17:55 +00:00
|
|
|
"api_keys": {},
|
2010-12-31 19:01:54 +00:00
|
|
|
"censored_strings":
|
|
|
|
[
|
|
|
|
"DCC SEND",
|
|
|
|
"1nj3ct",
|
|
|
|
"thewrestlinggame",
|
|
|
|
"startkeylogger",
|
|
|
|
"hybux",
|
|
|
|
"\\0",
|
|
|
|
"\\x01",
|
|
|
|
"!coz",
|
|
|
|
"!tell /x"
|
|
|
|
]
|
2010-02-23 03:32:09 +00:00
|
|
|
}''') + '\n')
|
2009-11-18 00:19:26 +00:00
|
|
|
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2009-11-18 00:19:26 +00:00
|
|
|
def config():
|
|
|
|
# reload config from file if file has changed
|
2010-08-22 22:24:57 +00:00
|
|
|
config_mtime = os.stat('config').st_mtime
|
|
|
|
if bot._config_mtime != config_mtime:
|
2010-05-07 23:16:44 +00:00
|
|
|
try:
|
|
|
|
bot.config = json.load(open('config'))
|
2010-08-22 22:24:57 +00:00
|
|
|
bot._config_mtime = config_mtime
|
2014-04-30 20:16:16 +00:00
|
|
|
for name, conf in bot.config['connections'].iteritems():
|
|
|
|
if name in bot.conns:
|
|
|
|
bot.conns[name].set_conf(conf)
|
|
|
|
else:
|
|
|
|
if conf.get('ssl'):
|
|
|
|
bot.conns[name] = SSLIRC(conf)
|
|
|
|
else:
|
|
|
|
bot.conns[name] = IRC(conf)
|
2010-05-07 23:16:44 +00:00
|
|
|
except ValueError, e:
|
|
|
|
print 'ERROR: malformed config!', e
|
|
|
|
|
|
|
|
|
|
|
|
bot._config_mtime = 0
|