-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
56 lines (48 loc) · 2.03 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
from mycroft import MycroftSkill, intent_file_handler, intent_handler
from adapt.intent import IntentBuilder
import random
class MirrorMirror(MycroftSkill):
def __init__(self):
MycroftSkill.__init__(self)
def initialize(self):
self.gender_value = self.translate_namedvalues('gender.value')
@intent_handler(IntentBuilder("handlermirror").require("mirror").
one_of("beautiful", "bad").optionally("man").optionally("woman").optionally("location").build())
def handle_mirror_mirror(self, message):
location = ""
bad = ""
beautiful = ""
if message.data.get("location", False):
for word in message.data['utterance'].split(" "):
if self.voc_match(word, "location"):
location = word
break
location = ""
if message.data.get("beautiful", False):
for word in message.data['utterance'].split(" "):
if self.voc_match(word, "beautiful"):
beautiful = word
break
if message.data.get("bad", False):
for word in message.data['utterance'].split(" "):
if self.voc_match(word, "beautiful"):
bad = word
break
if message.data.get("man", False):
gender = "male"
elif message.data.get("woman", False):
gender = "female"
else:
gender = ""
gender = self.gender_value[gender]
if message.data.get("beautiful", False):
l = ["friendly"]
if self.settings.get('random', True):
l = ["friendly", "the.second"]
self.speak_dialog(random.choice(l), data={"gender":gender, "beautiful":beautiful, "location":location})
else:
self.speak_dialog('unfriendly', data={"gender":gender, "bad":bad, "location":location})
def shutdown(self):
super(MirrorMirror, self).shutdown()
def create_skill():
return MirrorMirror()