diff --git a/hugvey/central_command.py b/hugvey/central_command.py index ead87b0..5225d83 100644 --- a/hugvey/central_command.py +++ b/hugvey/central_command.py @@ -148,9 +148,9 @@ class CentralCommand(object): status['time_since_hugvey_spoke'] = '-' status['time_since_visitor_spoke'] = '-' else: - if not hv.story.lastMsgStartTime: + if not hasattr(hv.story, 'lastMsgStartTime') or not hv.story.lastMsgStartTime: status['time_since_hugvey_spoke'] = '?' - elif not hv.story.lastMsgFinishTime: + elif not hasattr(hv.story, 'lastMsgFinishTime') or 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))) diff --git a/hugvey/story.py b/hugvey/story.py index 2561e17..c8abc29 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -75,6 +75,7 @@ class Message(object): self.color = None self.lightChange = None self.didRepeat = False + self.fileError = False # Used by diversions, autogenerated directions should link to next chapter mark instead of the given msgTo self.generatedDirectionsJumpToChapter = False @@ -216,14 +217,17 @@ class Message(object): await s.send_json(info) filename = await s.recv_string() s.close() - + + # TODO: should this go trough the event Queue? risking a too long delay though + if filename == 'local/crash.wav' or len(filename) < 1: + self.logger.warning("Noting crash") + self.fileError = True # print(threading.enumerate()) self.logger.debug(f"Fetched audio for {text}: {filename}") return filename - - + class Reply(object): def __init__(self, message: Message): @@ -334,6 +338,8 @@ class Condition(object): condition.method = condition._hasVariable if data['type'] == "diversion": condition.method = condition._hasDiverged + if data['type'] == "audioError": + condition.method = condition._hasAudioError if data['type'] == "messagePlayed": condition.method = condition._hasPlayed if data['type'] == "variableEquals": @@ -464,6 +470,14 @@ class Condition(object): return r + def _hasAudioError(self, story) -> bool: + if not story.currentMessage or not story.currentMessage.fileError: + return False + + self.logInfo = f"Has error loading audio file for {story.currentMessage.id}" + + return True + def _hasPlayed(self, story) -> bool: if not story.lastMsgFinishTime: return False @@ -1324,6 +1338,10 @@ class Story(object): self.logger.warn(f"Set variable that is not needed in the story: {name}") else: self.logger.debug(f"Set variable {name} to {value}") + + if self.variableValues[name] == value: + self.logger.debug(f"Skip double setting of variable {name} to {value}") + return self.variableValues[name] = value if store: diff --git a/hugvey/voice.py b/hugvey/voice.py index 95c7aaf..abb3fa6 100644 --- a/hugvey/voice.py +++ b/hugvey/voice.py @@ -110,6 +110,7 @@ class LyrebirdVoiceFetcher(VoiceFetcher): try: logger.debug(f"Fetch Lyrebird voice file: POST {request.url} body: {request.body}") +# raise Exception("TEST FOR ERROR HANDLING") response = await http_client.fetch(request) logger.debug(f"Got Lyrebird voice file in {response.request_time:.3}s") except Exception as e: diff --git a/www/js/hugvey_console.js b/www/js/hugvey_console.js index a83702f..d9f315e 100644 --- a/www/js/hugvey_console.js +++ b/www/js/hugvey_console.js @@ -1696,7 +1696,9 @@ class Graph { 'messagePlayed': { 'msgId': { 'value': '', 'label':'Message ID', 'placeholder': "(eg. en-njsm9b0ni)" }, 'inverseMatch': { "label": "Match if not played", 'value': '', 'title': "Match if the message has _not_ been played.", 'type':'checkbox' }, - } + }, + // audioError has no parameters. Just checks if there was an error fetching the audio file + 'audioError': {} }; }