Skip to content

Commit

Permalink
Rework of the template to reflect modern practices
Browse files Browse the repository at this point in the history
Now using intent decorators and better examples of
using dialog templates, etc.
  • Loading branch information
penrods committed Feb 19, 2018
1 parent 08a8371 commit da6066e
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 154 deletions.
29 changes: 14 additions & 15 deletions 00__skill_template/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# PROJECT_NAME skill
To submit your skill, replace this file with text from
https://rawgit.com/MycroftAI/mycroft-skills/master/meta_editor.html

This skill does ...

To get this done we need
- This
- That
- The other thing
## YOUR SKILL NAME
One line description of the skill

## Description
A more verbose description, including any extra instructions or
information that didn't fit in the one line.

## Current state
## Examples
* "Hello world"
* "Greetings planet earth"
* "Count up"
* "Count down"

Working features:
- ...

Known issues:
- ...

TODO:
- ...
## Credits
Your name
122 changes: 48 additions & 74 deletions 00__skill_template/__init__.py
Original file line number Diff line number Diff line change
@@ -1,91 +1,65 @@
# Copyright 2016 Mycroft AI, Inc.
#
# This file is part of Mycroft Core.
#
# Mycroft Core is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Mycroft Core is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>.
# TODO: Add an appropriate license to your skill before publishing. See
# the LICENSE file for more information.


# Visit https://docs.mycroft.ai/skill.creation for more detailed information
# on the structure of this skill and its containing folder, as well as
# instructions for designing your own skill based on this template.


# Import statements: the list of outside modules you'll be using in your
# skills, whether from other files in mycroft-core or from external libraries
from os.path import dirname
# Below is the list of outside modules you'll be using in your skill.
# They might be built-in to Python, from mycroft-core or from external
# libraries. If you use an external library, be sure to include it
# in the requirements.txt file so the library is installed properly
# when the skill gets installed later by a user.

from adapt.intent import IntentBuilder
from mycroft.skills.core import MycroftSkill
from mycroft.util.log import getLogger
from mycroft.skills.core import MycroftSkill, intent_handler
from mycroft.util.log import LOG

__author__ = 'eward'
# Each skill is contained within its own class, which inherits base methods
# from the MycroftSkill class. You extend this class as shown below.

# Logger: used for debug lines, like "LOGGER.debug(xyz)". These
# statements will show up in the command line when running Mycroft.
LOGGER = getLogger(__name__)

# The logic of each skill is contained within its own class, which inherits
# base methods from the MycroftSkill class with the syntax you can see below:
# "class ____Skill(MycroftSkill)"
class HelloWorldSkill(MycroftSkill):
# TODO: Change "Template" to a unique name for your skill
class TemplateSkill(MycroftSkill):

# The constructor of the skill, which calls MycroftSkill's constructor
def __init__(self):
super(HelloWorldSkill, self).__init__(name="HelloWorldSkill")

# This method loads the files needed for the skill's functioning, and
# creates and registers each intent that the skill uses
def initialize(self):
self.load_data_files(dirname(__file__))

thank_you_intent = IntentBuilder("ThankYouIntent").\
require("ThankYouKeyword").build()
self.register_intent(thank_you_intent, self.handle_thank_you_intent)

how_are_you_intent = IntentBuilder("HowAreYouIntent").\
require("HowAreYouKeyword").build()
self.register_intent(how_are_you_intent,
self.handle_how_are_you_intent)

hello_world_intent = IntentBuilder("HelloWorldIntent").\
require("HelloWorldKeyword").build()
self.register_intent(hello_world_intent,
self.handle_hello_world_intent)

# The "handle_xxxx_intent" functions define Mycroft's behavior when
# each of the skill's intents is triggered: in this case, he simply
# speaks a response. Note that the "speak_dialog" method doesn't
# actually speak the text it's passed--instead, that text is the filename
# of a file in the dialog folder, and Mycroft speaks its contents when
# the method is called.
def handle_thank_you_intent(self, message):
self.speak_dialog("welcome")

def handle_how_are_you_intent(self, message):
self.speak_dialog("how.are.you")

super(TemplateSkill, self).__init__(name="TemplateSkill")

# Initialize working variables used within the skill.
self.count = 0

# The "handle_xxxx_intent" function is triggered by Mycroft when the
# skill's intent is matched. The intent is defined by the IntentBuilder()
# pieces, and is triggered when the user's utterance matches the pattern
# defined by the keywords. In this case, the match occurs when one word
# is found from each of the files:
# vocab/en-us/Hello.voc
# vocab/en-us/World.voc
# In this example that means it would match on utterances like:
# 'Hello world'
# 'Howdy you great big world'
# 'Greetings planet earth'
@intent_handler(IntentBuilder("").require("Hello").require("World"))
def handle_hello_world_intent(self, message):
# In this case, respond by simply speaking a canned response.
# Mycroft will randomly speak one of the lines from the file
# dialogs/en-us/hello.world.dialog
self.speak_dialog("hello.world")

@intent_handler(IntentBuilder("").require("Count").require("Dir"))
def handle_count_intent(self, message):
if message.data["Dir"] == "up":
self.count += 1
else: # assume "down"
self.count -= 1
self.speak_dialog("count.is.now", data={"count": self.count})

# The "stop" method defines what Mycroft does when told to stop during
# the skill's execution. In this case, since the skill's functionality
# is extremely simple, the method just contains the keyword "pass", which
# does nothing.
def stop(self):
pass
# is extremely simple, there is no need to override it. If you DO
# need to implement stop, you should return True to indicate you handled
# it.
#
# def stop(self):
# return False

# The "create_skill()" method is used to create an instance of the skill.
# Note that it's outside the class itself.
def create_skill():
return HelloWorldSkill()
return TemplateSkill()
2 changes: 2 additions & 0 deletions 00__skill_template/dialog/en-us/count.is.now.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The count is now {{count}}
We are now up to {{count}}
3 changes: 1 addition & 2 deletions 00__skill_template/dialog/en-us/hello.world.dialog
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
Hello world
Hello
Hi to you too
Hi to you too
6 changes: 0 additions & 6 deletions 00__skill_template/dialog/en-us/how.are.you.dialog

This file was deleted.

6 changes: 0 additions & 6 deletions 00__skill_template/dialog/en-us/welcome.dialog

This file was deleted.

5 changes: 3 additions & 2 deletions 00__skill_template/requirements.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#This file is for any packages you need installed for your skill to run
sudo apt-get install the-best-packages ever
# The requirements.sh is an advanced mechanism an should rarely be needed.
# Be aware that it won't run with root permissions and 'sudo' won't work
# in most cases.
7 changes: 0 additions & 7 deletions 00__skill_template/test/intent/sample1.intent.json

This file was deleted.

7 changes: 0 additions & 7 deletions 00__skill_template/test/intent/sample2.intent.json

This file was deleted.

7 changes: 0 additions & 7 deletions 00__skill_template/test/intent/sample3.intent.json

This file was deleted.

7 changes: 0 additions & 7 deletions 00__skill_template/test/intent/sample4.intent.json

This file was deleted.

7 changes: 0 additions & 7 deletions 00__skill_template/test/intent/sample5.intent.json

This file was deleted.

7 changes: 0 additions & 7 deletions 00__skill_template/test/intent/sample6.intent.json

This file was deleted.

1 change: 1 addition & 0 deletions 00__skill_template/vocab/en-us/Count.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
count
2 changes: 2 additions & 0 deletions 00__skill_template/vocab/en-us/Dir.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
up
down
3 changes: 3 additions & 0 deletions 00__skill_template/vocab/en-us/Hello.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hello
greetings
howdy
2 changes: 0 additions & 2 deletions 00__skill_template/vocab/en-us/HelloWorldKeyword.voc

This file was deleted.

3 changes: 0 additions & 3 deletions 00__skill_template/vocab/en-us/HowAreYouKeyword.voc

This file was deleted.

2 changes: 0 additions & 2 deletions 00__skill_template/vocab/en-us/ThankYouKeyword.voc

This file was deleted.

2 changes: 2 additions & 0 deletions 00__skill_template/vocab/en-us/World.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
world
earth

0 comments on commit da6066e

Please sign in to comment.