h/core/sieve.py

30 lines
690 B
Python
Raw Normal View History

2008-06-09 11:59:56 +00:00
import re
import hook
@hook.sieve
2009-03-16 18:57:06 +00:00
def sieve_suite(bot, input, func, args):
events = args.get('events', ['PRIVMSG'])
2008-06-09 11:59:56 +00:00
if input.command not in events and events != '*':
return None
if input.nick.lower()[-3:] == 'bot' and args.get('ignorebots', True):
return None
2008-06-09 11:59:56 +00:00
hook = args.get('hook', r'(.*)')
2008-06-09 11:59:56 +00:00
args.setdefault('prefix', True)
if args.get('prefix', True):
hook = (r'^(?:[.!]|' if input.chan != input.nick else r'^(?:[.!]?|') \
+ bot.nick +r'[:,]*\s*)' + hook
2009-04-01 23:09:06 +00:00
input.re = re.match(hook, input.msg, flags=re.I)
2009-03-15 03:06:36 +00:00
if input.re is None:
return None
2009-03-24 22:53:56 +00:00
input.inp = ' '.join(input.re.groups())
2009-03-15 03:06:36 +00:00
2008-06-09 11:59:56 +00:00
return input