From 109805fd8de22137e52906d1442c1823fddce5a8 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 5 Jan 2018 10:09:02 +0100 Subject: [PATCH] Don't stop the conversation on hook match if the hook match was a priority one --- platypush/event/hook.py | 5 ++++- platypush/message/event/assistant/__init__.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/platypush/event/hook.py b/platypush/event/hook.py index 2886041e4f..ca2bb68073 100644 --- a/platypush/event/hook.py +++ b/platypush/event/hook.py @@ -28,7 +28,7 @@ def parse(msg): class EventCondition(object): """ Event hook condition class """ - def __init__(self, type=Event.__class__, **kwargs): + def __init__(self, type=Event.__class__, priority=None, **kwargs): """ Rule constructor. Params: @@ -40,6 +40,7 @@ class EventCondition(object): self.type = type self.args = {} self.parsed_args = {} + self.priority = priority for (key, value) in kwargs.items(): # TODO So far we only allow simple value match. If value is a dict @@ -127,6 +128,7 @@ class EventHook(object): self.condition = EventCondition.build(condition or {}) self.actions = actions self.priority = priority or 0 + self.condition.priority = self.priority @classmethod @@ -141,6 +143,7 @@ class EventHook(object): condition = EventCondition.build(hook['if']) if 'if' in hook else None actions = [] priority = hook['priority'] if 'priority' in hook else None + condition.priority = priority if 'then' in hook: if isinstance(hook['then'], list): diff --git a/platypush/message/event/assistant/__init__.py b/platypush/message/event/assistant/__init__.py index 44cf61148e..528e6803da 100644 --- a/platypush/message/event/assistant/__init__.py +++ b/platypush/message/event/assistant/__init__.py @@ -33,7 +33,7 @@ class SpeechRecognizedEvent(AssistantEvent): def matches_condition(self, condition): result = super().matches_condition(condition) - if result.is_match and self._assistant: + if result.is_match and self._assistant and not condition.priority: self._assistant.stop_conversation() return result