2010-01-25 00:30:00 +00:00
|
|
|
import os
|
2010-01-17 04:24:36 +00:00
|
|
|
import re
|
|
|
|
|
|
|
|
from util import hook
|
|
|
|
|
|
|
|
|
|
|
|
@hook.sieve
|
|
|
|
def sieve_suite(bot, input, func, args):
|
|
|
|
events = args.get('events', ['PRIVMSG'])
|
|
|
|
|
|
|
|
if input.command not in events and events != '*':
|
|
|
|
return None
|
|
|
|
|
|
|
|
if input.nick.lower()[-3:] == 'bot' and args.get('ignorebots', True):
|
|
|
|
return None
|
|
|
|
|
2010-02-13 21:03:19 +00:00
|
|
|
hook = args.get('hook', r'(.*)')
|
2010-01-17 04:24:36 +00:00
|
|
|
|
2010-02-13 21:03:19 +00:00
|
|
|
if args.get('prefix', True):
|
|
|
|
if input.chan == input.nick: # private message, prefix not required
|
|
|
|
prefix = r'^(?:[.!]?|'
|
|
|
|
else:
|
|
|
|
prefix = r'^(?:[.!]|'
|
|
|
|
hook = prefix + input.conn.nick + r'[:,]*\s)' + hook
|
2010-01-17 04:24:36 +00:00
|
|
|
|
2010-02-13 21:03:19 +00:00
|
|
|
input.re = re.match(hook, input.msg, flags=re.I)
|
2010-01-17 04:24:36 +00:00
|
|
|
if input.re is None:
|
|
|
|
return None
|
|
|
|
|
2010-01-25 00:30:00 +00:00
|
|
|
acl = bot.config.get('acls', {}).get(func.__name__)
|
|
|
|
if acl:
|
|
|
|
if 'deny-except' in acl:
|
2010-02-24 16:37:45 +00:00
|
|
|
allowed_channels = map(unicode.lower, acl['deny-except'])
|
2010-01-25 00:30:00 +00:00
|
|
|
if input.chan.lower() not in allowed_channels:
|
|
|
|
return None
|
|
|
|
if 'allow-except' in acl:
|
2010-02-24 16:37:45 +00:00
|
|
|
denied_channels = map(unicode.lower, acl['allow-except'])
|
2010-01-25 00:30:00 +00:00
|
|
|
if input.chan.lower() in denied_channels:
|
|
|
|
return None
|
|
|
|
|
2010-01-17 23:07:08 +00:00
|
|
|
input.inp_unstripped = ' '.join(input.re.groups())
|
|
|
|
input.inp = input.inp_unstripped.strip()
|
2010-01-17 04:24:36 +00:00
|
|
|
|
|
|
|
return input
|