new config format
This commit is contained in:
parent
2466c9fbb4
commit
95d6570436
5 changed files with 68 additions and 68 deletions
|
@ -1,24 +1,41 @@
|
||||||
{
|
{
|
||||||
"connections":
|
"connections":
|
||||||
|
[
|
||||||
{
|
{
|
||||||
"esper":
|
"name": "esper",
|
||||||
{
|
"connection": {
|
||||||
"server": "irc.esper.net",
|
"server": "irc.esper.net",
|
||||||
|
"port": 6667,
|
||||||
|
"ssl": false,
|
||||||
|
"ignore_cert": true
|
||||||
|
},
|
||||||
"nick": "MyCloudBot",
|
"nick": "MyCloudBot",
|
||||||
"user": "cloudbot",
|
"user": "cloudbot",
|
||||||
"realname": "CloudBot - http://git.io/cloudbotirc",
|
"real_name": "CloudBot - http://git.io/cloudbotirc",
|
||||||
"mode": "",
|
|
||||||
"nickserv_password": "",
|
|
||||||
"nickserv_user": "",
|
|
||||||
"channels": ["#cloudbot", "#cloudbot2"],
|
"channels": ["#cloudbot", "#cloudbot2"],
|
||||||
"invite_join": true,
|
|
||||||
"auto_rejoin": false,
|
|
||||||
"command_prefix": "."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"disabled_plugins": [],
|
"disabled_plugins": [],
|
||||||
"disabled_commands": [],
|
"disabled_commands": [],
|
||||||
"acls": {},
|
"acls": {},
|
||||||
|
"nickserv": {
|
||||||
|
"nickserv_password": "",
|
||||||
|
"nickserv_user": ""
|
||||||
|
},
|
||||||
|
"permissions": {
|
||||||
|
"admins": {
|
||||||
|
"perms": ["adminonly", "addfactoid", "delfactoid", "ignore", "botcontrol", "permissions_users", "op"],
|
||||||
|
"users": ["examplea!user@example.com", "exampleb!user@example.com"]
|
||||||
|
},
|
||||||
|
"moderators": {
|
||||||
|
"perms": ["addfactoid", "delfactoid", "ignore"],
|
||||||
|
"users": ["examplec!user@example.com"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"plugins": {
|
||||||
|
|
||||||
|
},
|
||||||
|
"command_prefix": "."
|
||||||
|
}
|
||||||
|
],
|
||||||
"api_keys":
|
"api_keys":
|
||||||
{
|
{
|
||||||
"tvdb": "",
|
"tvdb": "",
|
||||||
|
@ -35,31 +52,5 @@
|
||||||
"rdio_key": "",
|
"rdio_key": "",
|
||||||
"rdio_secret": "",
|
"rdio_secret": "",
|
||||||
"steam_key": ""
|
"steam_key": ""
|
||||||
},
|
|
||||||
"permissions": {
|
|
||||||
"admins": {
|
|
||||||
"perms": ["adminonly", "addfactoid", "delfactoid", "ignore", "botcontrol", "permissions_users", "op"],
|
|
||||||
"users": ["examplea!user@example.com", "exampleb!user@example.com"]
|
|
||||||
},
|
|
||||||
"moderators": {
|
|
||||||
"perms": ["addfactoid", "delfactoid", "ignore"],
|
|
||||||
"users": ["examplec!user@example.com"]
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"plugins":
|
|
||||||
{
|
|
||||||
"factoids":
|
|
||||||
{
|
|
||||||
"prefix": false
|
|
||||||
},
|
|
||||||
"ignore":
|
|
||||||
{
|
|
||||||
"ignored": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"censored_strings":
|
|
||||||
[
|
|
||||||
"mypass",
|
|
||||||
"mysecret"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
23
core/bot.py
23
core/bot.py
|
@ -29,18 +29,23 @@ class Bot(object):
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
"""connect to all the networks defined in the bot config"""
|
"""connect to all the networks defined in the bot config"""
|
||||||
for name, conf in self.config['connections'].iteritems():
|
for conf in self.config['connections']:
|
||||||
# strip all spaces and capitalization from the connection name
|
# strip all spaces and capitalization from the connection name
|
||||||
name = clean_name(name)
|
name = clean_name(conf['name'])
|
||||||
self.logger.debug("({}) Creating connection to {}.".format(name, conf['server']))
|
nick = conf['nick']
|
||||||
if conf.get('ssl'):
|
server = conf['connection']['server']
|
||||||
self.connections[name] = irc.SSLIRC(name, conf['server'], conf['nick'], conf=conf,
|
port = conf['connection'].get('port', 6667)
|
||||||
port=conf.get('port', 6667), channels=conf['channels'],
|
|
||||||
ignore_certificate_errors=conf.get('ignore_cert', True))
|
self.logger.debug("({}) Creating connection to {}.".format(name, server))
|
||||||
|
|
||||||
|
if conf['connection'].get('ssl'):
|
||||||
|
self.connections[name] = irc.SSLIRC(name, server, nick, conf = conf,
|
||||||
|
port = port, channels = conf['channels'],
|
||||||
|
ignore_certificate_errors=conf['connection'].get('ignore_cert', True))
|
||||||
self.logger.debug("({}) Created SSL connection.".format(name))
|
self.logger.debug("({}) Created SSL connection.".format(name))
|
||||||
else:
|
else:
|
||||||
self.connections[name] = irc.IRC(name, conf['server'], conf['nick'], conf=conf,
|
self.connections[name] = irc.IRC(name, server, nick, conf = conf,
|
||||||
port=conf.get('port', 6667), channels=conf['channels'])
|
port = port, channels = conf['channels'])
|
||||||
self.logger.debug("({}) Created connection.".format(name))
|
self.logger.debug("({}) Created connection.".format(name))
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
|
|
|
@ -20,10 +20,12 @@ def invite(paraml, conn=None):
|
||||||
# Identify to NickServ (or other service)
|
# Identify to NickServ (or other service)
|
||||||
@hook.event('004')
|
@hook.event('004')
|
||||||
def onjoin(paraml, conn=None, bot=None):
|
def onjoin(paraml, conn=None, bot=None):
|
||||||
nickserv_password = conn.conf.get('nickserv_password', '')
|
nickserv = conn.conf.get('nickserv')
|
||||||
nickserv_name = conn.conf.get('nickserv_name', 'nickserv')
|
if nickserv:
|
||||||
nickserv_account_name = conn.conf.get('nickserv_user', '')
|
nickserv_password = nickserv.get('nickserv_password', '')
|
||||||
nickserv_command = conn.conf.get('nickserv_command', 'IDENTIFY')
|
nickserv_name = nickserv.get('nickserv_name', 'nickserv')
|
||||||
|
nickserv_account_name = nickserv.get('nickserv_user', '')
|
||||||
|
nickserv_command = nickserv.get('nickserv_command', 'IDENTIFY')
|
||||||
if nickserv_password:
|
if nickserv_password:
|
||||||
if nickserv_password in bot.config['censored_strings']:
|
if nickserv_password in bot.config['censored_strings']:
|
||||||
bot.config['censored_strings'].remove(nickserv_password)
|
bot.config['censored_strings'].remove(nickserv_password)
|
||||||
|
|
|
@ -6,20 +6,22 @@ from fnmatch import fnmatch
|
||||||
|
|
||||||
@hook.sieve
|
@hook.sieve
|
||||||
def sieve_suite(bot, input, func, kind, args):
|
def sieve_suite(bot, input, func, kind, args):
|
||||||
|
conn = input.conn
|
||||||
if input.command == 'PRIVMSG' and \
|
if input.command == 'PRIVMSG' and \
|
||||||
input.nick.endswith('bot') and args.get('ignorebots', True):
|
input.nick.endswith('bot') and args.get('ignorebots', True):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if kind == "command":
|
if kind == "command":
|
||||||
if input.trigger in bot.config.get('disabled_commands', []):
|
disabled_commands = conn.conf.get('disabled_plugins', [])
|
||||||
|
if input.trigger in disabled_commands:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
fn = re.match(r'^plugins.(.+).py$', func._filename)
|
fn = re.match(r'^plugins.(.+).py$', func._filename)
|
||||||
disabled = bot.config.get('disabled_plugins', [])
|
disabled = conn.conf.get('disabled_plugins', [])
|
||||||
if fn and fn.group(1).lower() in disabled:
|
if fn and fn.group(1).lower() in disabled:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
acl = bot.config.get('acls', {}).get(func.__name__)
|
acl = conn.conf.get('acls', {}).get(func.__name__)
|
||||||
if acl:
|
if acl:
|
||||||
if 'deny-except' in acl:
|
if 'deny-except' in acl:
|
||||||
allowed_channels = map(unicode.lower, acl['deny-except'])
|
allowed_channels = map(unicode.lower, acl['deny-except'])
|
||||||
|
@ -35,7 +37,7 @@ def sieve_suite(bot, input, func, kind, args):
|
||||||
args["permissions"] = ["adminonly"]
|
args["permissions"] = ["adminonly"]
|
||||||
|
|
||||||
if args.get('permissions', False):
|
if args.get('permissions', False):
|
||||||
groups = bot.config.get("permissions", [])
|
groups = conn.conf.get("permissions", [])
|
||||||
|
|
||||||
allowed_permissions = args.get('permissions', [])
|
allowed_permissions = args.get('permissions', [])
|
||||||
allowed_groups = []
|
allowed_groups = []
|
||||||
|
@ -57,7 +59,7 @@ def sieve_suite(bot, input, func, kind, args):
|
||||||
mask = input.mask.lower()
|
mask = input.mask.lower()
|
||||||
|
|
||||||
for group in allowed_groups:
|
for group in allowed_groups:
|
||||||
group_users = bot.config.get("permissions", {}).get(group, [])["users"]
|
group_users = conn.conf.get("permissions", {}).get(group, [])["users"]
|
||||||
group_users = [_mask.lower() for _mask in group_users]
|
group_users = [_mask.lower() for _mask in group_users]
|
||||||
for pattern in group_users:
|
for pattern in group_users:
|
||||||
if fnmatch(mask, pattern):
|
if fnmatch(mask, pattern):
|
||||||
|
|
|
@ -3,7 +3,7 @@ from util import hook
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
|
|
||||||
|
|
||||||
@hook.sieve
|
#@hook.sieve
|
||||||
def ignore_sieve(bot, input, func, type, args):
|
def ignore_sieve(bot, input, func, type, args):
|
||||||
""" blocks input from ignored channels/hosts """
|
""" blocks input from ignored channels/hosts """
|
||||||
ignorelist = bot.config["plugins"]["ignore"]["ignored"]
|
ignorelist = bot.config["plugins"]["ignore"]["ignored"]
|
||||||
|
|
Reference in a new issue