Fix #26 - Condition: Variable

This commit is contained in:
Ruben van de Ven 2019-03-29 14:11:48 +01:00
parent d1efa68d4e
commit 15a3ddc5dd
2 changed files with 27 additions and 0 deletions

View file

@ -140,6 +140,7 @@ class Message(object):
return self.audioFile
self.logger.debug(f"Fetching audio for {self.getText()}")
# return "test";
async with self.filenameFetchLock:
client = AsyncHTTPClient()
queryString = urllib.parse.urlencode({
@ -227,6 +228,8 @@ class Condition(object):
condition.method = condition._hasMetReplyContains
if data['type'] == "timeout":
condition.method = condition._hasMetTimeout
if data['type'] == "variable":
condition.method = condition._hasVariable
if 'vars' in data:
condition.vars = data['vars']
@ -266,6 +269,20 @@ class Condition(object):
return True
def _hasVariable(self, story) -> bool:
if not story.lastMsgFinishTime:
return False
r = story.hasVariableSet(self.vars['variable'])
if r:
story.logger.debug(f"Variable {self.vars['variable']} is set.")
if 'notSet' in self.vars and self.vars['notSet']:
# inverse:
r = not r
return r
def _hasMetReplyContains(self, story) -> bool:
"""
Check the reply for specific characteristics:
@ -569,9 +586,15 @@ class Story(object):
self.logger.warn(f"Set variable that is not needed in the story: {name}")
self.variableValues[name] = value
if name not in self.variables:
return
for message in self.variables[name]:
message.setVariable(name, value)
def hasVariableSet(self, name) -> bool:
return name in self.variableValues and self.variableValues is not None
def setStoryData(self, story_data):
"""
Parse self.data into a working story engine

View file

@ -938,6 +938,10 @@ class Graph {
'delays.2.waitTime': { 'type': 'number', 'value': 0, 'min': 0, 'step': 0.1, 'label': 'Delay 3 - time', 'unit': "s" },
'regex': { 'value': '','placeholder': "match any input" },
'instantMatch': { 'value': '', 'title': "When matched, don't wait for reply to finish. Instantly take this direction.", 'type':'checkbox' },
},
'variable': {
'variable': { 'value': '','placeholder': "Variable name (without $)" },
'notSet': { "label": "Not set", 'value': '', 'title': "Match if the variable is _not_ set.", 'type':'checkbox' },
}
};
}