From b2c07a31f2a17e55aec27c1d0bd5ea66df999c40 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 24 Apr 2024 01:25:02 +0200 Subject: [PATCH] Fixed tests --- platypush/message/event/__init__.py | 2 +- platypush/message/event/assistant/__init__.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/platypush/message/event/__init__.py b/platypush/message/event/__init__.py index ff4c769042..465b981add 100644 --- a/platypush/message/event/__init__.py +++ b/platypush/message/event/__init__.py @@ -220,7 +220,7 @@ class Event(Message): :param condition: The platypush.event.hook.EventCondition object """ - result = EventMatchResult(is_match=False) + result = EventMatchResult(is_match=False, parsed_args=self.args) match_scores = [] if not isinstance(self, condition.type): diff --git a/platypush/message/event/assistant/__init__.py b/platypush/message/event/assistant/__init__.py index 41d0d229fa..942e2c1ea6 100644 --- a/platypush/message/event/assistant/__init__.py +++ b/platypush/message/event/assistant/__init__.py @@ -179,6 +179,7 @@ class SpeechRecognizedEvent(AssistantEvent): result.score = sys.maxsize return result + parsed_args = {} event_tokens = re.split(r'\s+', event_args.get(argname, '').strip().lower()) condition_tokens = re.split(r'\s+', condition_value.strip().lower()) @@ -201,11 +202,11 @@ class SpeechRecognizedEvent(AssistantEvent): m = re.match(r'[^\\]*\${(.+?)}', condition_token) if m: argname = m.group(1) - if argname not in result.parsed_args: - result.parsed_args[argname] = event_token + if argname not in parsed_args: + parsed_args[argname] = event_token result.score += 1.0 else: - result.parsed_args[argname] += ' ' + event_token + parsed_args[argname] += ' ' + event_token if (len(condition_tokens) == 1 and len(event_tokens) == 1) or ( len(event_tokens) > 1 @@ -223,6 +224,9 @@ class SpeechRecognizedEvent(AssistantEvent): # It's a match if all the tokens in the condition string have been satisfied result.is_match = len(condition_tokens) == 0 + if result.is_match: + result.parsed_args = parsed_args + return result