OSC required for server and better variable matching for unfinished sentences Fix #31
This commit is contained in:
parent
f24f11de23
commit
ffcd0d70c2
2 changed files with 21 additions and 7 deletions
|
@ -92,9 +92,9 @@ class Message(object):
|
||||||
|
|
||||||
self.variableValues[name] = value
|
self.variableValues[name] = value
|
||||||
|
|
||||||
self.logger.warn(f"Set variable, now fetch {name}")
|
self.logger.warn(f"Set variable, fetch {name}")
|
||||||
if not None in self.variableValues.values():
|
if not None in self.variableValues.values():
|
||||||
self.logger.warn(f"now fetch indeed {name}")
|
self.logger.warn(f"now fetch {name}")
|
||||||
asyncio.get_event_loop().create_task(self.getAudioFilePath())
|
asyncio.get_event_loop().create_task(self.getAudioFilePath())
|
||||||
# asyncio.get_event_loop().call_soon_threadsafe(self.getAudioFilePath)
|
# asyncio.get_event_loop().call_soon_threadsafe(self.getAudioFilePath)
|
||||||
self.logger.warn(f"started {name}")
|
self.logger.warn(f"started {name}")
|
||||||
|
@ -103,7 +103,7 @@ class Message(object):
|
||||||
# sort reverse to avoid replacing the wrong variable
|
# sort reverse to avoid replacing the wrong variable
|
||||||
self.variables.sort(key=len, reverse=True)
|
self.variables.sort(key=len, reverse=True)
|
||||||
text = self.text
|
text = self.text
|
||||||
self.logger.debug(f"Getting text for {self.id}")
|
# self.logger.debug(f"Getting text for {self.id}")
|
||||||
for var in self.variables:
|
for var in self.variables:
|
||||||
self.logger.debug(f"try replacing ${var} with {self.variableValues[var]} in {text}")
|
self.logger.debug(f"try replacing ${var} with {self.variableValues[var]} in {text}")
|
||||||
replacement = self.variableValues[var] if (self.variableValues[var] is not None) else "nothing" #TODO: translate nothing to each language
|
replacement = self.variableValues[var] if (self.variableValues[var] is not None) else "nothing" #TODO: translate nothing to each language
|
||||||
|
@ -319,6 +319,8 @@ class Condition(object):
|
||||||
if not r or not r.hasUtterances():
|
if not r or not r.hasUtterances():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
capturedVariables = None
|
||||||
|
|
||||||
if 'regex' in self.vars and len(self.vars['regex']):
|
if 'regex' in self.vars and len(self.vars['regex']):
|
||||||
if 'regexCompiled' not in self.vars:
|
if 'regexCompiled' not in self.vars:
|
||||||
# Compile once, as we probably run it more than once
|
# Compile once, as we probably run it more than once
|
||||||
|
@ -332,11 +334,12 @@ class Condition(object):
|
||||||
return False
|
return False
|
||||||
story.logger.debug('Got match on {}'.format(self.vars['regex']))
|
story.logger.debug('Got match on {}'.format(self.vars['regex']))
|
||||||
|
|
||||||
|
capturedVariables = result.groupdict()
|
||||||
|
|
||||||
if ('instantMatch' in self.vars and self.vars['instantMatch']) or not r.isSpeaking():
|
if ('instantMatch' in self.vars and self.vars['instantMatch']) or not r.isSpeaking():
|
||||||
# try to avoid setting variables for intermediate strings
|
# try to avoid setting variables for intermediate strings
|
||||||
results = result.groupdict()
|
for captureGroup in capturedVariables:
|
||||||
for captureGroup in results:
|
story.setVariableValue(captureGroup, capturedVariables[captureGroup])
|
||||||
story.setVariableValue(captureGroup, results[captureGroup])
|
|
||||||
|
|
||||||
if 'instantMatch' in self.vars and self.vars['instantMatch']:
|
if 'instantMatch' in self.vars and self.vars['instantMatch']:
|
||||||
story.logger.info(f"Instant match on {self.vars['regex']}, {self.vars}")
|
story.logger.info(f"Instant match on {self.vars['regex']}, {self.vars}")
|
||||||
|
@ -358,6 +361,11 @@ class Condition(object):
|
||||||
timeSinceReply = story.timer.getElapsed() - r.getLastUtterance().lastUpdateTime
|
timeSinceReply = story.timer.getElapsed() - r.getLastUtterance().lastUpdateTime
|
||||||
story.logger.log(LOG_BS, f"check delay duration is now {replyDuration}, already waiting for {timeSinceReply}, have to wait {delay['waitTime']}")
|
story.logger.log(LOG_BS, f"check delay duration is now {replyDuration}, already waiting for {timeSinceReply}, have to wait {delay['waitTime']}")
|
||||||
if timeSinceReply > float(delay['waitTime']):
|
if timeSinceReply > float(delay['waitTime']):
|
||||||
|
# if variables are captured, only set them the moment the condition matches
|
||||||
|
if capturedVariables is not None:
|
||||||
|
for captureGroup in capturedVariables:
|
||||||
|
story.setVariableValue(captureGroup, capturedVariables[captureGroup])
|
||||||
|
|
||||||
return True
|
return True
|
||||||
break # don't check other delays
|
break # don't check other delays
|
||||||
# wait for delay to match
|
# wait for delay to match
|
||||||
|
@ -610,6 +618,9 @@ class Story(object):
|
||||||
def setVariableValue(self, name, value):
|
def setVariableValue(self, name, value):
|
||||||
if name not in self.variables:
|
if name not in self.variables:
|
||||||
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}")
|
||||||
|
else:
|
||||||
|
self.logger.debug(f"Set variable {name} to {value}")
|
||||||
|
|
||||||
self.variableValues[name] = value
|
self.variableValues[name] = value
|
||||||
|
|
||||||
if name not in self.variables:
|
if name not in self.variables:
|
||||||
|
|
|
@ -7,4 +7,7 @@ requests-threads
|
||||||
fabric
|
fabric
|
||||||
cutelog
|
cutelog
|
||||||
tornado
|
tornado
|
||||||
shortuuid
|
shortuuid
|
||||||
|
python-osc
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue