From 553b95643e3b9c42ce75cefc9f83cd9b8d9814ba Mon Sep 17 00:00:00 2001 From: penrods Date: Tue, 5 Dec 2017 11:18:12 -0600 Subject: [PATCH] Add support for unnamed intents This allows skill writers to ignore naming intents. Combined with a forthcoming change to Adapt that creates a default of None for IntentBuilder() This allows the current: @intent_handler(IntentBuilder("CurrentWeatherIntent").require( "Weather").optionally("Location").build()) def handle_current_weather(self, message): ... To become: @intent_handler(IntentBuilder().require("Weather").optionally("Location")) def handle_current_weather(self, message): ... Which will automatically name the Intent "handle_current_weather". Also dropped the log message in the default initialize() method since it is common to not override it now. --- mycroft/skills/core.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mycroft/skills/core.py b/mycroft/skills/core.py index af7325b4d4..2e6a1d9d65 100644 --- a/mycroft/skills/core.py +++ b/mycroft/skills/core.py @@ -295,11 +295,11 @@ class MycroftSkill(object): def initialize(self): """ - Initialization function to be implemented by all Skills. + Initialization function, run after fully constructed Usually used to create intents rules and register them. """ - LOG.debug("No initialize function implemented") + pass def get_intro_message(self): """ @@ -459,6 +459,10 @@ class MycroftSkill(object): elif type(intent_parser) != Intent: raise ValueError('intent_parser is not an Intent') + if not intent_parser.name: + # Default to the handler's function name if None or "" + intent_parser.name = handler.__name__ + name = intent_parser.name intent_parser.name = str(self.skill_id) + ':' + intent_parser.name self.emitter.emit(Message("register_intent", intent_parser.__dict__))