Skip to content

Commit

Permalink
message.forward
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Sep 22, 2023
1 parent a73067d commit fb15069
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions ovos_workshop/skills/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,8 @@ def __get_response(self):
Returns:
str: user's response or None on a timeout
"""
srcm = dig_for_message() or Message("", context={"source": "skills",
"skill_id": self.skill_id})

# in ovos-core < 0.0.8 we reassign the converse method itself
is_old = False
Expand All @@ -1069,24 +1071,22 @@ def __get_response(self):
# standalone usage without core
pass

self.bus.emit(Message("skill.converse.get_response.enable",
{"skill_id": self.skill_id}))
self.bus.emit(srcm.forward("skill.converse.get_response.enable",
{"skill_id": self.skill_id}))

if is_old: # NOT SAFE for multiple users at same time
res = self.__get_response_v1()
self.bus.emit(Message("skill.converse.get_response.disable",
{"skill_id": self.skill_id}))
self.bus.emit(srcm.forward("skill.converse.get_response.disable",
{"skill_id": self.skill_id}))
return res

self._activate()
utterances = []
lang = self.lang # unused, but we get this info together with utterance if needed
# user could switch lang midway, maybe ignore response in this case (?)

sess = SessionManager.get()

def _handle_get_response(message):
nonlocal utterances, lang
nonlocal utterances

skill_id = message.data["skill_id"]
if skill_id != self.skill_id:
Expand All @@ -1099,7 +1099,6 @@ def _handle_get_response(message):
return # not for us!

utterances = message.data["utterances"]
lang = message.data["lang"]
# received get_response

self.bus.on("skill.converse.get_response", _handle_get_response)
Expand All @@ -1118,8 +1117,8 @@ def _handle_get_response(message):
utterances = [self.__response] # external override

self.bus.remove("skill.converse.get_response", _handle_get_response)
self.bus.emit(Message("skill.converse.get_response.disable",
{"skill_id": self.skill_id}))
self.bus.emit(srcm.forward("skill.converse.get_response.disable",
{"skill_id": self.skill_id}))

if utterances:
return utterances[0]
Expand Down

0 comments on commit fb15069

Please sign in to comment.