Prevent stacked timeout diversion and fix request for repeat

This commit is contained in:
Ruben van de Ven 2019-05-07 14:30:57 +02:00
parent d4ce360e24
commit 02dcf17858
1 changed files with 15 additions and 5 deletions

View File

@ -243,6 +243,12 @@ class Reply(object):
return True
return False
def getTimeSinceLastUtterance(self):
if not self.hasUtterances():
return None
return self.forMessage.story.timer.getElapsed() - self.getLastUtterance().lastUpdateTime
class Condition(object):
"""
A condition, basic conditions are built in, custom condition can be given by
@ -408,7 +414,7 @@ class Condition(object):
delays = sorted(self.vars['delays'], key=lambda k: float(k['minReplyDuration']), reverse=True)
for delay in delays:
if replyDuration > float(delay['minReplyDuration']):
timeSinceReply = story.timer.getElapsed() - r.getLastUtterance().lastUpdateTime
timeSinceReply = r.getTimeSinceLastUtterance()
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 variables are captured, only set them the moment the condition matches
@ -738,21 +744,22 @@ class Diversion(object):
"""
Participant asks if message can be repeated.
"""
if not msgFrom or not msgTo:
return
# if not msgFrom or not msgTo:
# return
# TODO: how to handle this now we sometimes use different timings.
# Perhaps set isFinished when matching condition.
if story.currentReply is None or story.currentReply.isSpeaking():
if story.currentReply is None or story.currentReply.getTimeSinceLastUtterance() > 1:
return
r = self.regex.search(story.currentReply.getText())
print('repeat?', r)
if r is None:
return
logger.info(f"Diverge: request repeat {self.id}")
story.stats['diversions']['repeat'] += 1
await story.setCurrentMessage(msgFrom)
await story.setCurrentMessage(story.currentMessage)
return True
async def _divergeIfTimeout(self, story, msgFrom, msgTo, direction):
@ -760,6 +767,9 @@ class Diversion(object):
(1) last spoken at all
(2) or duration for this last reply only
"""
if story.currentDiversion:
return
if msgFrom or msgTo:
# not applicable a direction has been chosen
return