Condition for failure of Lyrebird (and MS)

This commit is contained in:
Ruben van de Ven 2019-11-11 19:27:20 +01:00
parent 9df1d77b4f
commit a99c2dcfbf
4 changed files with 27 additions and 6 deletions

View file

@ -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)))

View file

@ -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
@ -217,6 +218,10 @@ class Message(object):
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())
@ -224,7 +229,6 @@ class Message(object):
return filename
class Reply(object):
def __init__(self, message: Message):
self.forMessage = None
@ -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
@ -1325,6 +1339,10 @@ class Story(object):
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:
self.hugvey.command.variableStore.addVariable(self.runId, name, value, self.hugvey.id, self.language_code)

View file

@ -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:

View file

@ -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': {}
};
}