-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
101 lines (70 loc) · 3.09 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
from mycroft import MycroftSkill, intent_file_handler
from mycroft.audio import wait_while_speaking
from mycroft.skills.context import *
from mycroft.util.log import LOG
from datetime import date
# TODO: Fallback Skill einrichten
class BarbaraSkill(MycroftSkill):
def __init__(self):
MycroftSkill.__init__(self)
# Aufstellungsdatum, für die Altersberechnung
self.initial_date = date(2020, 5, 28)
def initialize(self):
# Word entity ist Platzhalter für beliebieges Wort
self.register_entity_file("word.entity")
# self.parser = WiktionaryParser()
### normale Frage-Antwort-Intents ###
@intent_file_handler('barbara.what.is.name.intent')
def handle_barbara_name(self, message):
self.speak_dialog('barbara.name.introduction')
@intent_file_handler('barbara.how.are.you.intent')
def handle_barbara_how_are_you(self, message):
self.speak_dialog('barbara.I.feel.fine')
@intent_file_handler('barbara.who.are.you.intent')
def handle_barbara_who_are_you(self, message):
self.speak_dialog('barbara.I.am')
@intent_file_handler('barbara.why.are.you.here.intent')
def handle_barbara_why_are_you_here(self, message):
self.speak_dialog('barbara.I.am.here.because')
### komplexere Intents ###
@intent_file_handler('barbara.how.old.are.you.intent')
def handle_barbara_how_old(self, message):
age = date.today() - self.initial_date
self.speak_dialog('barbara.I.am.old', {'age': age.days})
# TODO: hier ask_yesno prüfen obs funktioniert
@intent_file_handler('barbara.what.can.you.do.intent')
def handle_barbara_what_can_you_do(self, message):
# Fragen ob Beispielfragen gegeben werden sollen
give_examples = self.ask_yesno('barbara.ask.example.questions')
# Falls ja
if give_examples == "yes":
self.speak_dialog('barbara.example.questions')
# Falls Nein
else:
# Anders weiterhelfen?
# Ja
if self.ask_yesno('barbara.ask.can.I.help.otherwise') == "yes":
# TODO: hier als Prompt implementieren
self.speak_dialog('barbara.ask.what.do.you.want.to.know')
# Nein
else:
self.speak_dialog('barbara.goodbye')
# @intent_file_handler('fallback.wiktionary.definition.intent')
# def handle_wiktionary_definition(self, message):
# #Get word to define from utterance
# word = message.data.get('word')
# #Lookup the word using Wiktionary
# get_word_info = self.parser.fetch(word)
# #Speak definition for requested word back to user
# try:
# # Get first definition from wiktionary response
# response = get_word_info[0]['definitions'][0]['text'][1]
# # Log the definition
# LOG.info(response)
# self.speak_dialog('fallback.wiktionary', {'word': word, 'definition': response})
# except:
# self.speak_dialog('error.wiktionary')
def stop(self):
pass
def create_skill():
return BarbaraSkill()