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

63 lines
1.6 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":
{
2011-11-21 00:04:39 +01:00
"test connection":
2011-11-20 10:23:31 +01:00
{
2011-11-21 00:04:39 +01:00
"server": "irc.esper.net",
"nick": "cloudbot_test",
"user": "cloudbot",
2011-11-21 05:55:39 +01:00
"realname": "CloudBot/DEV - http://j.mp/uS5Cvx",
2011-11-21 00:04:39 +01:00
"nickserv_password": "",
"channels": ["#mau5bot"]
2011-11-20 10:23:31 +01:00
}
},
"disabled_plugins": [],
"disabled_commands": [],
2011-11-21 05:50:26 +01:00
"prefix": ".",
2011-11-20 10:23:31 +01:00
"acls": {},
2011-11-21 07:41:07 +01:00
"api_keys":
{
"geoip": "INSERT KEY FROM ipinfodb.com HERE",
"bitly_user": "INSERT USERNAME FROM bitly.com HERE",
"bitly_api": "INSERT API KEY FROM bitly.com HERE"
},
2011-11-20 10:23:31 +01:00
"censored_strings":
[
"DCC SEND",
"1nj3ct",
"thewrestlinggame",
"startkeylogger",
"hybux",
"\\0",
"\\x01",
"!coz",
"!tell /x"
],
"admins": []
}''') + '\n')
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