h/plugins/sieve.py

56 lines
1.8 KiB
Python
Raw Normal View History

import re
from util import hook
@hook.sieve
def sieve_suite(bot, input, func, kind, args):
if input.command == 'PRIVMSG' and \
bot.config.get('ignorebots', True) and \
2010-05-10 23:59:34 +00:00
input.nick.lower()[-3:] == 'bot' and args.get('ignorebots', True):
return None
2010-05-10 23:59:34 +00:00
if kind == "command":
if input.trigger in bot.config.get('disabled_commands', []):
return None
2011-04-14 01:45:07 +00:00
2011-05-11 20:40:04 +00:00
ignored = bot.config.get('ignored', [])
2010-11-26 00:37:04 +00:00
if input.host in ignored or input.nick in ignored:
return None
2011-04-14 01:45:07 +00:00
fn = re.match(r'^plugins.(.+).py$', func._filename)
disabled = bot.config.get('disabled_plugins', [])
if fn and fn.group(1).lower() in disabled:
return None
acls = bot.config.get('acls', {})
for acl in [acls.get(func.__name__), acls.get(input.chan), acls.get(input.conn.server)]:
if acl is None:
continue
if 'deny-except' in acl:
allowed_channels = map(unicode.lower, acl['deny-except'])
if input.chan.lower() not in allowed_channels:
return None
if 'allow-except' in acl:
denied_channels = map(unicode.lower, acl['allow-except'])
if input.chan.lower() in denied_channels:
return None
if 'whitelist' in acl:
if func.__name__ not in acl['whitelist']:
return None
if 'blacklist' in acl:
if func.__name__ in acl['whitelist']:
return None
2014-04-24 21:15:58 +00:00
if 'blacklist-nicks' in acl:
if input.nick.lower() in acl['blacklist-nicks']:
return None
admins = input.conn.conf.get('admins', [])
input.admin = input.host in admins or input.nick in admins
2010-10-26 04:13:27 +00:00
if args.get('adminonly', False):
if not input.admin:
2010-10-26 04:13:27 +00:00
return None
2011-04-14 01:45:07 +00:00
return input