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":
|
||||
{
|
||||
"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"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
23
core/bot.py
23
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):
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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"]
|
||||
|
|
Reference in a new issue