From 645c18c981c46cb648a6795b477c36efb0fd8ca3 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Thu, 14 Jan 2016 23:54:11 +0100 Subject: [PATCH] [grep] use subparse feature --- modules/grep.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/modules/grep.py b/modules/grep.py index df1b794..6a26c02 100644 --- a/modules/grep.py +++ b/modules/grep.py @@ -14,13 +14,12 @@ from more import Response # MODULE CORE ######################################################### -def grep(fltr, cmd, args, msg, icase=False, only=False): +def grep(fltr, cmd, msg, icase=False, only=False): """Perform a grep like on known nemubot structures Arguments: fltr -- The filter regexp cmd -- The subcommand to execute - args -- subcommand arguments msg -- The original message icase -- like the --ignore-case parameter of grep only -- like the --only-matching parameter of grep @@ -28,11 +27,7 @@ def grep(fltr, cmd, args, msg, icase=False, only=False): fltr = re.compile(fltr, re.I if icase else 0) - for r in context.subtreat(Command(cmd, - args, - to_response=msg.to_response, - frm=msg.frm, - server=msg.server)): + for r in context.subtreat(context.subparse(msg, cmd)): if isinstance(r, Response): for i in range(len(r.messages) - 1, -1, -1): if isinstance(r.messages[i], list): @@ -79,8 +74,7 @@ def cmd_grep(msg): only = "only" in msg.kwargs l = [m for m in grep(msg.args[0] if msg.args[0][0] == "^" else ".*?(" + msg.args[0] + ").*?", - msg.args[1][1:] if msg.args[1][0] == "!" else msg.args[1], - msg.args[2:], + " ".join(msg.args[1:]), msg, icase="nocase" in msg.kwargs, only=only) if m is not None]