-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
128 lines (99 loc) · 4.4 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# 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.skills.context import adds_context, removes_context
from mycroft.skills.core import FallbackSkill
from mycroft.util.log import LOG
from mycroft.util import play_wav as play
from time import sleep
import os
import sys
skill_path = "/opt/mycroft/skills/skill-Walking/"
sys.path.append(skill_path)
# This was my first test based on the default skill template
# See the 2nd class below for more sophisticated dialog control
# ToDo: delete
class WalkSkillBasic(MycroftSkill):
# The constructor of the skill, which calls MycroftSkill's constructor
def __init__(self):
super(WalkSkillBasic, self).__init__(name="WalkSkill")
self.finished = False
# 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 thewhat 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("WWeather"))
def handle_WWeather_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
# def no_response():
# self.speak_dialog("tragedy5")
# finished = True
# return
# choice = self.get_response('tragedy1')
# if not choice:
# no_response()
# else:
# choice = self.get_response('tragedy2')
# if not choice:
# no_response()
# else:
# choice = self.get_response('tragedy3')
# if not choice:
# no_response()
# else:
# choice = self.get_response('tragedy4')
# if not choice:
# no_response()
# else:
# self.speak_dialog("tragedy5")
self.finished = True
# look at converse
# 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 True
class WalkSkillContext(MycroftSkill):
def __init__(self, mode='tts'):
super(WalkSkillContext, self).__init__(name='WalkSkill')
self.started = False
LOG("WalkSkill").debug("Walking skill loaded")
@intent_handler(IntentBuilder('WWeatherIntent').require('query').require('WWeather'))
def handle_WWeather_intent(self, message):
self.started = True
self.speak_dialog("It.is.raining.cats.and.dogs!")
# ToDo: find a better way to move to the next line if there is no response
# the blank dialog below does not work with the Google TTS, so removed
# '''
# response = self.get_response('blank')
# if response == "yes" or response == "yeah":
# self.speak("Not from a Jedi")
# self.remove_context('PlagueisContext')
# else:
# self.story()
# '''
@intent_handler(IntentBuilder('WalkOpportunityIntent').require('query').require('save_death'))
def handle_Walk_Opportunity_intent(self, message):
self.started = True
self.speak_dialog("Yes!.Now.is.a.good.time..but.it.is.cold.outside..bring.me.a.sweater.")
self.speak_dialog("No!.We.went.for.a.walk.recently.")
def stop(self):
pass