diff --git a/hugvey/central_command.py b/hugvey/central_command.py index 7308a23..ead87b0 100644 --- a/hugvey/central_command.py +++ b/hugvey/central_command.py @@ -27,6 +27,7 @@ from pythonosc import udp_client, osc_server, dispatcher import copy from pythonosc.osc_server import AsyncIOOSCUDPServer from hugvey.variablestore import VariableStore +import datetime mainLogger = logging.getLogger("hugvey") @@ -143,6 +144,22 @@ class CentralCommand(object): status['has_state'] = Story.hugveyHasSavedState(hv.lightId) status['variables'] = {} if not isSelected or not hv.story else hv.story.variableValues + if not hv.story: + status['time_since_hugvey_spoke'] = '-' + status['time_since_visitor_spoke'] = '-' + else: + if not hv.story.lastMsgStartTime: + status['time_since_hugvey_spoke'] = '?' + elif not hv.story.lastMsgFinishTime: + status['time_since_hugvey_spoke'] = 'speaking' + else: + status['time_since_hugvey_spoke'] = str(datetime.timedelta(seconds=int(hv.story.timer.getElapsed() - hv.story.lastMsgFinishTime))) + + if not hv.story.timer.hasMark('last_speech'): + status['time_since_visitor_spoke'] = 'never' + else: + status['time_since_visitor_spoke'] = str(datetime.timedelta(seconds=int(hv.story.timer.getElapsed('last_speech')))) + return status def getStatusSummary(self, selected_ids = []): diff --git a/hugvey/story.py b/hugvey/story.py index 7fd7429..820def5 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -74,6 +74,7 @@ class Message(object): self.uuid = None # Have a unique id each time the message is played back. self.color = None self.lightChange = None + self.didRepeat = False # Used by diversions, autogenerated directions should link to next chapter mark instead of the given msgTo self.generatedDirectionsJumpToChapter = False @@ -345,6 +346,9 @@ class Condition(object): if 'vars' in data: condition.vars = data['vars'] + + if 'regex' in condition.vars: + condition.vars['regex'] = condition.vars['regex'].rstrip() return condition @@ -669,7 +673,7 @@ class Diversion(object): self.method = self._divergeIfReplyContains self.finaliseMethod = self._returnAfterReplyContains if len(self.params['regex']) > 0: - self.regex = re.compile(self.params['regex']) + self.regex = re.compile(self.params['regex'].rstrip()) else: self.regex = None @@ -680,7 +684,7 @@ class Diversion(object): self.method = self._divergeIfCollectiveMoment if type == 'repeat': self.method = self._divergeIfRepeatRequest - self.regex = re.compile(self.params['regex']) + self.regex = re.compile(self.params['regex'].rstrip()) if type == 'interrupt': self.method = self._divergeIfInterrupted @@ -982,6 +986,10 @@ class Diversion(object): # Perhaps set isFinished when matching condition. if story.currentReply is None or story.currentReply.getTimeSinceLastUtterance() < 1.8: return + + if story.currentMessage.didRepeat: + # repeat only once + return r = self.regex.search(story.currentReply.getText()) if r is None: @@ -990,6 +998,7 @@ class Diversion(object): logger.info(f"Diverge: request repeat {self.id}") story.stats['diversions']['repeat'] += 1 await story.setCurrentMessage(story.currentMessage) + story.currentMessage.didRepeat = True return True async def _divergeIfTimeout(self, story, msgFrom, msgTo, direction): @@ -1505,6 +1514,7 @@ class Story(object): # if self.currentDiversion is not None: # await self.currentDiversion.finalise(self) # else: + # TODO: check if direction that exists are diversion returns, and if they are already taken. Otherwise story blocks self.logger.info("THE END!") self._finish() return diff --git a/www/js/hugvey_timeline.js b/www/js/hugvey_timeline.js index e52d869..f151438 100644 --- a/www/js/hugvey_timeline.js +++ b/www/js/hugvey_timeline.js @@ -99,7 +99,7 @@ checkbox.addEventListener('change', (event) => { console.log(hv['language'], hv['status']); let evenOdd = parseInt(hv['id'])%2 ? 'odd': 'even'; let availableClass = hv['available'] ? 'is-available' : 'is-not-available' - this.dataGroups.update({id: parseInt(hv['id']), content: 'Hugvey #'+hv['id'], className: `status-${hv['status']} ${availableClass} lang-${hv['language']} ${evenOdd}`}) + this.dataGroups.update({id: parseInt(hv['id']), content: `