From b7f0087e0d94879e00df95d69393efb9c75a0f14 Mon Sep 17 00:00:00 2001 From: urlbot Date: Wed, 17 Jun 2015 11:17:29 +0200 Subject: [PATCH] parse_moin_bye(): limit matching to full words --- plugins.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/plugins.py b/plugins.py index 051926a..71ca4e2 100644 --- a/plugins.py +++ b/plugins.py @@ -134,13 +134,23 @@ def parse_moin_bye(**args): for direction in [moin, bye]: for d in direction: - if d.lower() in args['data'].lower() and len(args['data'].split()) < 3: - logger('plugin', 'sent %s reply' % ( - 'moin' if direction is moin else 'bye' - )) - return { - 'msg': '''%s, %s''' % (random.choice(direction), args['reply_user']) - } + words = re.split(r'\W+', args['data']) + + # assumption: longer sentences are not greetings + if 3 < len(args['data'].split()): + continue + + for w in words: + if d.lower() == w.lower(): + logger('plugin', 'sent %s reply for %s' % ( + 'moin' if direction is moin else 'bye', w + )) + return { + 'msg': '''%s, %s''' % ( + random.choice(direction), + args['reply_user'] + ) + } @pluginfunction('latex', r'reacts on \LaTeX', ptypes_PARSE) def parse_latex(**args):