ReplyContains diversoins now have their own timing (defaults to 1.8s) Fix #44

This commit is contained in:
Ruben van de Ven 2019-05-10 15:14:13 +02:00
parent 0b6963359d
commit 664619bab0
2 changed files with 45 additions and 5 deletions

View file

@ -692,16 +692,14 @@ class Diversion(object):
# if self.params['returnAfterStrand']:
# await story.setCurrentMessage(self.returnMessage)
async def _divergeIfReplyContains(self, story, msgFrom, msgTo, direction):
async def _divergeIfReplyContains(self, story, msgFrom, msgTo, _):
"""
Participant doesn't speak for x consecutive replies (has had timeout)
"""
':type story: Story'
# TODO: disable check on msgFrom/msgTo to allow for own timing (2 sec)
# use story.currentReply.getTimeSinceLastUtterance() > 2
if story.currentDiversion or not msgFrom or not msgTo:
if story.currentDiversion: # or not msgFrom or not msgTo:
# don't do nested diversions
# if we remove this, don't forget to double check 'returnMessage'
return False
if self.hasHit:
@ -711,6 +709,22 @@ class Diversion(object):
if story.currentReply is None or not self.regex:
return
direction = story.getDefaultDirectionForMsg(story.currentMessage)
if not direction:
# ignore the direction argument, and only check if the current message has a valid default
return
msgTo = direction.msgTo
if not direction:
return
waitTime = 1.8 if 'waitTime' not in self.params else float(self.params['waitTime'])
timeSince = story.currentReply.getTimeSinceLastUtterance()
if timeSince < waitTime:
story.logger.log(LOG_BS, f"Waiting for replyContains: {timeSince} (needs {waitTime})")
return
r = self.regex.search(story.currentReply.getText())
if r is None:
return
@ -1535,4 +1549,19 @@ class Story(object):
return self.strands[msg.id]
return self.calculateFinishesForMsg(msg.id)
def getDefaultDirectionForMsg(self, msg):
"""
There is only a default direction (for reply contains diversion) if it has
one, and only one, direction to go. If there's more, it should do nothing.
"""
if not msg.id in self.directionsPerMsg:
# is finish
return None
if len(self.directionsPerMsg[msg.id]) > 1:
return None
# TODO: should the direction have at least a timeout condition set, or not perse?
return self.directionsPerMsg[msg.id][0]

View file

@ -366,6 +366,7 @@ class Graph {
div['params']['returnAfterStrand'] = true;
div['params']['msgId'] = "";
div['params']['notForColor'] = "";
div['params']['waitTime'] = 1.8;
}
else if(type == 'interrupt') {
div['params']['msgId'] = "";
@ -574,6 +575,16 @@ class Graph {
'change': (e) => div['params']['msgId'] = e.target.value
}}, ...msgOptions)
),
crel('label', 'Wait time',
crel('input', {
'type': 'number',
'step': 0.1,
'value': div['params']['waitTime'],
'on': {
'change': (e) => div['params']['waitTime'] = parseFloat(e.target.value)
}
})
),
notAfterMsgIdEl
));
}