Merge pull request #1280 from MycroftAI/feature/default-intent-name

- Add support for unnamed intents.
- Add more debugging information for skill handler errors
- Clean up skill name for pronounciation
- Update docstring for initialize method
pull/1287/head
Åke 2017-12-06 11:08:27 +01:00 committed by GitHub
commit deb2b56464
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions

View File

@ -295,11 +295,10 @@ class MycroftSkill(object):
def initialize(self):
"""
Initialization function to be implemented by all Skills.
Usually used to create intents rules and register them.
Invoked after the skill is fully constructed and registered with the
system. Use to perform any final setup needed for the skill.
"""
LOG.debug("No initialize function implemented")
pass
def get_intro_message(self):
"""
@ -401,6 +400,8 @@ class MycroftSkill(object):
except TypeError:
handler(self)
else:
LOG.error("Unexpected argument count:" +
str(len(getargspec(handler).args)))
raise TypeError
else:
if len(getargspec(handler).args) == 2:
@ -408,13 +409,17 @@ class MycroftSkill(object):
elif len(getargspec(handler).args) == 1:
handler()
else:
LOG.error("Unexpected argument count:" +
str(len(getargspec(handler).args)))
raise TypeError
self.settings.store() # Store settings if they've changed
except Exception as e:
# Convert "MyFancySkill" to "My Fancy Skill" for speaking
name = re.sub("([a-z])([A-Z])", "\g<1> \g<2>", self.name)
# TODO: Localize
self.speak(
"An error occurred while processing a request in " +
self.name)
name)
LOG.error(
"An error occurred while processing a request in " +
self.name, exc_info=True)
@ -459,8 +464,9 @@ class MycroftSkill(object):
elif type(intent_parser) != Intent:
raise ValueError('intent_parser is not an Intent')
name = intent_parser.name
intent_parser.name = str(self.skill_id) + ':' + intent_parser.name
# Default to the handler's function name if none given
name = intent_parser.name or handler.__name__
intent_parser.name = str(self.skill_id) + ':' + name
self.emitter.emit(Message("register_intent", intent_parser.__dict__))
self.registered_intents.append((name, intent_parser))
self.add_event(intent_parser.name, handler, need_self)