Fix #26 - Condition: Variable
This commit is contained in:
parent
d1efa68d4e
commit
15a3ddc5dd
2 changed files with 27 additions and 0 deletions
|
@ -140,6 +140,7 @@ class Message(object):
|
||||||
return self.audioFile
|
return self.audioFile
|
||||||
|
|
||||||
self.logger.debug(f"Fetching audio for {self.getText()}")
|
self.logger.debug(f"Fetching audio for {self.getText()}")
|
||||||
|
# return "test";
|
||||||
async with self.filenameFetchLock:
|
async with self.filenameFetchLock:
|
||||||
client = AsyncHTTPClient()
|
client = AsyncHTTPClient()
|
||||||
queryString = urllib.parse.urlencode({
|
queryString = urllib.parse.urlencode({
|
||||||
|
@ -227,6 +228,8 @@ class Condition(object):
|
||||||
condition.method = condition._hasMetReplyContains
|
condition.method = condition._hasMetReplyContains
|
||||||
if data['type'] == "timeout":
|
if data['type'] == "timeout":
|
||||||
condition.method = condition._hasMetTimeout
|
condition.method = condition._hasMetTimeout
|
||||||
|
if data['type'] == "variable":
|
||||||
|
condition.method = condition._hasVariable
|
||||||
|
|
||||||
if 'vars' in data:
|
if 'vars' in data:
|
||||||
condition.vars = data['vars']
|
condition.vars = data['vars']
|
||||||
|
@ -265,6 +268,20 @@ class Condition(object):
|
||||||
story.stats['consecutiveSilentTimeouts'] += 1
|
story.stats['consecutiveSilentTimeouts'] += 1
|
||||||
|
|
||||||
return True
|
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:
|
def _hasMetReplyContains(self, story) -> bool:
|
||||||
"""
|
"""
|
||||||
|
@ -569,8 +586,14 @@ class Story(object):
|
||||||
self.logger.warn(f"Set variable that is not needed in the story: {name}")
|
self.logger.warn(f"Set variable that is not needed in the story: {name}")
|
||||||
self.variableValues[name] = value
|
self.variableValues[name] = value
|
||||||
|
|
||||||
|
if name not in self.variables:
|
||||||
|
return
|
||||||
|
|
||||||
for message in self.variables[name]:
|
for message in self.variables[name]:
|
||||||
message.setVariable(name, value)
|
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):
|
def setStoryData(self, story_data):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -938,6 +938,10 @@ class Graph {
|
||||||
'delays.2.waitTime': { 'type': 'number', 'value': 0, 'min': 0, 'step': 0.1, 'label': 'Delay 3 - time', 'unit': "s" },
|
'delays.2.waitTime': { 'type': 'number', 'value': 0, 'min': 0, 'step': 0.1, 'label': 'Delay 3 - time', 'unit': "s" },
|
||||||
'regex': { 'value': '','placeholder': "match any input" },
|
'regex': { 'value': '','placeholder': "match any input" },
|
||||||
'instantMatch': { 'value': '', 'title': "When matched, don't wait for reply to finish. Instantly take this direction.", 'type':'checkbox' },
|
'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' },
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue