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.
pull/1280/head
penrods 2017-12-05 11:18:12 -06:00
parent 8a2595e85c
commit 553b95643e
1 changed files with 6 additions and 2 deletions

View File

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