forked from MycroftAI/mycroft-skills
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
65 lines (55 loc) · 2.76 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# TODO: Add an appropriate license to your skill before publishing. See
# the LICENSE file for more information.
# 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, intent_handler
from mycroft.util.log import LOG
# Each skill is contained within its own class, which inherits base methods
# from the MycroftSkill class. You extend this class as shown below.
# 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(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, 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 TemplateSkill()