Don't stop the conversation on hook match if the hook match was a priority one

This commit is contained in:
Fabio Manganiello 2018-01-05 10:09:02 +01:00
parent 5461bf532c
commit 109805fd8d
2 changed files with 5 additions and 2 deletions

View file

@ -28,7 +28,7 @@ def parse(msg):
class EventCondition(object): class EventCondition(object):
""" Event hook condition class """ """ Event hook condition class """
def __init__(self, type=Event.__class__, **kwargs): def __init__(self, type=Event.__class__, priority=None, **kwargs):
""" """
Rule constructor. Rule constructor.
Params: Params:
@ -40,6 +40,7 @@ class EventCondition(object):
self.type = type self.type = type
self.args = {} self.args = {}
self.parsed_args = {} self.parsed_args = {}
self.priority = priority
for (key, value) in kwargs.items(): for (key, value) in kwargs.items():
# TODO So far we only allow simple value match. If value is a dict # 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.condition = EventCondition.build(condition or {})
self.actions = actions self.actions = actions
self.priority = priority or 0 self.priority = priority or 0
self.condition.priority = self.priority
@classmethod @classmethod
@ -141,6 +143,7 @@ class EventHook(object):
condition = EventCondition.build(hook['if']) if 'if' in hook else None condition = EventCondition.build(hook['if']) if 'if' in hook else None
actions = [] actions = []
priority = hook['priority'] if 'priority' in hook else None priority = hook['priority'] if 'priority' in hook else None
condition.priority = priority
if 'then' in hook: if 'then' in hook:
if isinstance(hook['then'], list): if isinstance(hook['then'], list):

View file

@ -33,7 +33,7 @@ class SpeechRecognizedEvent(AssistantEvent):
def matches_condition(self, condition): def matches_condition(self, condition):
result = super().matches_condition(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() self._assistant.stop_conversation()
return result return result