From 664619bab0350ce99a365821108703bb7ba3b075 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Fri, 10 May 2019 15:14:13 +0200 Subject: [PATCH] ReplyContains diversoins now have their own timing (defaults to 1.8s) Fix #44 --- hugvey/story.py | 39 ++++++++++++++++++++++++++++++++++----- www/js/hugvey_console.js | 11 +++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/hugvey/story.py b/hugvey/story.py index 71d9a06..994ae98 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -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) - \ No newline at end of file + + 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] \ No newline at end of file diff --git a/www/js/hugvey_console.js b/www/js/hugvey_console.js index 2515521..7d16bf3 100644 --- a/www/js/hugvey_console.js +++ b/www/js/hugvey_console.js @@ -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 )); }