Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed May 2, 2024
1 parent 18f4e11 commit c7a900e
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ def _register_system_event_handlers(self):
self.add_event("skill.converse.request", self._handle_converse_request,
speak_errors=False)
self.add_event(f"{self.skill_id}.converse.request", self._handle_converse_request,
speak_errors=False)
speak_errors=False, activation=True)
self.add_event(f"{self.skill_id}.activate", self.handle_activate,
speak_errors=False)
self.add_event(f"{self.skill_id}.deactivate", self.handle_deactivate,
Expand All @@ -1103,7 +1103,8 @@ def _register_system_event_handlers(self):

# TODO: deprecate 0.0.9
self.add_event("skill.converse.get_response", self.__handle_get_response, speak_errors=False)
self.add_event(f"{self.skill_id}.converse.get_response", self.__handle_get_response, speak_errors=False)
self.add_event(f"{self.skill_id}.converse.get_response", self.__handle_get_response,
speak_errors=False, activation=True)

def _send_public_api(self, message: Message):
"""
Expand Down Expand Up @@ -1418,7 +1419,8 @@ def register_intent_file(self, intent_file: str, handler: callable):
filename = str(resource_file.file_path)
self.intent_service.register_padatious_intent(name, filename, lang)
if handler:
self.add_event(name, handler, 'mycroft.skill.handler')
self.add_event(name, handler, 'mycroft.skill.handler',
activation=True)

def register_entity_file(self, entity_file: str):
"""
Expand Down Expand Up @@ -1514,15 +1516,21 @@ def handle_remove_cross_context(self, message: Message):
self.remove_context(context)

def _on_event_start(self, message: Message, handler_info: str,
skill_data: dict):
skill_data: dict, activation: Optional[bool] = None):
"""
Indicate that the skill handler is starting.
activation (bool, optional): activate skill if True, deactivate if False, do nothing if None
"""
if handler_info:
# Indicate that the skill handler is starting if requested
msg_type = handler_info + '.start'
message.context["skill_id"] = self.skill_id
self.bus.emit(message.forward(msg_type, skill_data))
if activation is True:
self.activate()
elif activation is False:
self.deactivate()

def _on_event_end(self, message: Message, handler_info: str,
skill_data: dict):
Expand Down Expand Up @@ -1591,7 +1599,8 @@ def _register_adapt_intent(self,
self.intent_service.register_adapt_intent(name, intent_parser)
if handler:
self.add_event(intent_parser.name, handler,
'mycroft.skill.handler')
'mycroft.skill.handler',
activation=True)

# skill developer facing utils
def speak(self, utterance: str, expect_response: bool = False,
Expand Down Expand Up @@ -2219,7 +2228,7 @@ def remove_voc(self, utt: str, voc_filename: str,
# event related skill developer facing utils
def add_event(self, name: str, handler: callable,
handler_info: Optional[str] = None, once: bool = False,
speak_errors: bool = True):
speak_errors: bool = True, activation: Optional[bool] = None):
"""
Create event handler for executing intent or other event.
Expand All @@ -2233,6 +2242,7 @@ def add_event(self, name: str, handler: callable,
speak_errors (bool, optional): Determines if an error dialog should be
spoken to inform the user whenever
an exception happens inside the handler
activation (bool, optional): activate skill if True, deactivate if False, do nothing if None
"""
skill_data = {'name': get_handler_name(handler)}

Expand All @@ -2245,7 +2255,8 @@ def on_error(error, message):
speak_errors)

def on_start(message):
self._on_event_start(message, handler_info, skill_data)
self._on_event_start(message, handler_info,
skill_data, activation)

def on_end(message):
self._on_event_end(message, handler_info, skill_data)
Expand Down

0 comments on commit c7a900e

Please sign in to comment.