-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
40 lines (34 loc) · 1.58 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
from mycroft import MycroftSkill, intent_file_handler
class Polite(MycroftSkill):
def __init__(self):
super().__init__()
# Keep track of how many impolite utterances have been made.
# This is only to change dialog later in the Skill.
self.impolite_count = 0
def initialize(self):
""" Call make_active each time the wakeword is heard.
converse() can only trigger if a Skill is active. """
self.add_event("recognizer_loop:wakeword", self.make_active)
def converse(self, utterances, lang=None):
""" The converse method is able to inspect utterances before
they are passed to the normal intent handling service. """
utt = utterances[0]
# Check if utt contains any words in vocab/lang-code/RudeWords.voc
if self.voc_match(utt, "RudeWords"):
self.log.debug("Impolite utterance detected")
self.impolite_count += 1
self.log.debug("counter: " + str(self.impolite_count))
# Speak different dialog based on the state of this Skill
if self.impolite_count < 3:
self.speak_dialog("not.polite")
else:
self.speak_dialog("you.have.detention")
# return True to tell Mycroft that we have handled the utterance
return True
else:
# If no RudeWord found, return False to pass this utterance on
# to the normal intent handling process.
self.log.debug("No rude words detected")
return False
def create_skill():
return Polite()