ReplyContains diversoins now have their own timing (defaults to 1.8s) Fix #44
This commit is contained in:
parent
0b6963359d
commit
664619bab0
2 changed files with 45 additions and 5 deletions
|
@ -692,16 +692,14 @@ class Diversion(object):
|
||||||
# if self.params['returnAfterStrand']:
|
# if self.params['returnAfterStrand']:
|
||||||
# await story.setCurrentMessage(self.returnMessage)
|
# 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)
|
Participant doesn't speak for x consecutive replies (has had timeout)
|
||||||
"""
|
"""
|
||||||
':type story: Story'
|
':type story: Story'
|
||||||
# TODO: disable check on msgFrom/msgTo to allow for own timing (2 sec)
|
|
||||||
# use story.currentReply.getTimeSinceLastUtterance() > 2
|
# 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
|
# don't do nested diversions
|
||||||
# if we remove this, don't forget to double check 'returnMessage'
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.hasHit:
|
if self.hasHit:
|
||||||
|
@ -711,6 +709,22 @@ class Diversion(object):
|
||||||
if story.currentReply is None or not self.regex:
|
if story.currentReply is None or not self.regex:
|
||||||
return
|
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())
|
r = self.regex.search(story.currentReply.getText())
|
||||||
if r is None:
|
if r is None:
|
||||||
return
|
return
|
||||||
|
@ -1536,3 +1550,18 @@ class Story(object):
|
||||||
|
|
||||||
return self.calculateFinishesForMsg(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]
|
|
@ -366,6 +366,7 @@ class Graph {
|
||||||
div['params']['returnAfterStrand'] = true;
|
div['params']['returnAfterStrand'] = true;
|
||||||
div['params']['msgId'] = "";
|
div['params']['msgId'] = "";
|
||||||
div['params']['notForColor'] = "";
|
div['params']['notForColor'] = "";
|
||||||
|
div['params']['waitTime'] = 1.8;
|
||||||
}
|
}
|
||||||
else if(type == 'interrupt') {
|
else if(type == 'interrupt') {
|
||||||
div['params']['msgId'] = "";
|
div['params']['msgId'] = "";
|
||||||
|
@ -574,6 +575,16 @@ class Graph {
|
||||||
'change': (e) => div['params']['msgId'] = e.target.value
|
'change': (e) => div['params']['msgId'] = e.target.value
|
||||||
}}, ...msgOptions)
|
}}, ...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
|
notAfterMsgIdEl
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue