From 95d6570436e578c22544696f4c48ce43433b57bf Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Tue, 1 Oct 2013 23:54:08 +1300 Subject: [PATCH] new config format --- cloudbot.default.json | 71 +++++++++++++++++++------------------------ core/bot.py | 23 ++++++++------ plugins/core_misc.py | 28 +++++++++-------- plugins/core_sieve.py | 12 +++++--- plugins/ignore.py | 2 +- 5 files changed, 68 insertions(+), 68 deletions(-) diff --git a/cloudbot.default.json b/cloudbot.default.json index 00b2446..ca53241 100644 --- a/cloudbot.default.json +++ b/cloudbot.default.json @@ -1,24 +1,41 @@ { "connections": - { - "esper": + [ { - "server": "irc.esper.net", + "name": "esper", + "connection": { + "server": "irc.esper.net", + "port": 6667, + "ssl": false, + "ignore_cert": true + }, "nick": "MyCloudBot", "user": "cloudbot", - "realname": "CloudBot - http://git.io/cloudbotirc", - "mode": "", - "nickserv_password": "", - "nickserv_user": "", + "real_name": "CloudBot - http://git.io/cloudbotirc", "channels": ["#cloudbot", "#cloudbot2"], - "invite_join": true, - "auto_rejoin": false, + "disabled_plugins": [], + "disabled_commands": [], + "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": "." } - }, - "disabled_plugins": [], - "disabled_commands": [], - "acls": {}, + ], "api_keys": { "tvdb": "", @@ -35,31 +52,5 @@ "rdio_key": "", "rdio_secret": "", "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" - ] + } } diff --git a/core/bot.py b/core/bot.py index 12201b9..828ed73 100644 --- a/core/bot.py +++ b/core/bot.py @@ -29,18 +29,23 @@ class Bot(object): def connect(self): """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 - name = clean_name(name) - self.logger.debug("({}) Creating connection to {}.".format(name, conf['server'])) - if conf.get('ssl'): - self.connections[name] = irc.SSLIRC(name, conf['server'], conf['nick'], conf=conf, - port=conf.get('port', 6667), channels=conf['channels'], - ignore_certificate_errors=conf.get('ignore_cert', True)) + name = clean_name(conf['name']) + nick = conf['nick'] + server = conf['connection']['server'] + port = conf['connection'].get('port', 6667) + + 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)) else: - self.connections[name] = irc.IRC(name, conf['server'], conf['nick'], conf=conf, - port=conf.get('port', 6667), channels=conf['channels']) + self.connections[name] = irc.IRC(name, server, nick, conf = conf, + port = port, channels = conf['channels']) self.logger.debug("({}) Created connection.".format(name)) def setup(self): diff --git a/plugins/core_misc.py b/plugins/core_misc.py index bd71870..6570891 100755 --- a/plugins/core_misc.py +++ b/plugins/core_misc.py @@ -20,19 +20,21 @@ def invite(paraml, conn=None): # Identify to NickServ (or other service) @hook.event('004') def onjoin(paraml, conn=None, bot=None): - nickserv_password = conn.conf.get('nickserv_password', '') - nickserv_name = conn.conf.get('nickserv_name', 'nickserv') - nickserv_account_name = conn.conf.get('nickserv_user', '') - nickserv_command = conn.conf.get('nickserv_command', 'IDENTIFY') - if nickserv_password: - if nickserv_password in bot.config['censored_strings']: - bot.config['censored_strings'].remove(nickserv_password) - if nickserv_account_name: - conn.msg(nickserv_name, "{} {} {}".format(nickserv_command, nickserv_account_name, nickserv_password)) - else: - conn.msg(nickserv_name, "{} {}".format(nickserv_command, nickserv_password)) - bot.config['censored_strings'].append(nickserv_password) - time.sleep(1) + nickserv = conn.conf.get('nickserv') + if nickserv: + nickserv_password = nickserv.get('nickserv_password', '') + 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 in bot.config['censored_strings']: + bot.config['censored_strings'].remove(nickserv_password) + if nickserv_account_name: + conn.msg(nickserv_name, "{} {} {}".format(nickserv_command, nickserv_account_name, nickserv_password)) + else: + conn.msg(nickserv_name, "{} {}".format(nickserv_command, nickserv_password)) + bot.config['censored_strings'].append(nickserv_password) + time.sleep(1) # Set bot modes mode = conn.conf.get('mode') diff --git a/plugins/core_sieve.py b/plugins/core_sieve.py index 3b00c4b..4dc623b 100755 --- a/plugins/core_sieve.py +++ b/plugins/core_sieve.py @@ -6,20 +6,22 @@ from fnmatch import fnmatch @hook.sieve def sieve_suite(bot, input, func, kind, args): + conn = input.conn if input.command == 'PRIVMSG' and \ input.nick.endswith('bot') and args.get('ignorebots', True): return None 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 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: return None - acl = bot.config.get('acls', {}).get(func.__name__) + acl = conn.conf.get('acls', {}).get(func.__name__) if acl: if 'deny-except' in acl: allowed_channels = map(unicode.lower, acl['deny-except']) @@ -35,7 +37,7 @@ def sieve_suite(bot, input, func, kind, args): args["permissions"] = ["adminonly"] if args.get('permissions', False): - groups = bot.config.get("permissions", []) + groups = conn.conf.get("permissions", []) allowed_permissions = args.get('permissions', []) allowed_groups = [] @@ -57,7 +59,7 @@ def sieve_suite(bot, input, func, kind, args): mask = input.mask.lower() 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] for pattern in group_users: if fnmatch(mask, pattern): diff --git a/plugins/ignore.py b/plugins/ignore.py index 9c5de16..a62d79e 100755 --- a/plugins/ignore.py +++ b/plugins/ignore.py @@ -3,7 +3,7 @@ from util import hook from fnmatch import fnmatch -@hook.sieve +#@hook.sieve def ignore_sieve(bot, input, func, type, args): """ blocks input from ignored channels/hosts """ ignorelist = bot.config["plugins"]["ignore"]["ignored"]