forked from OpenVoiceOS/ovos-skill-easter-eggs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
200 lines (174 loc) · 7.61 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# pylint: disable=unused-import,missing-docstring,invalid-name
import random
from os import listdir
from os.path import dirname, join
from ovos_workshop.intents import IntentBuilder
from ovos_workshop.decorators import skill_api_method, intent_handler
from ovos_workshop.skills import OVOSSkill
from ovos_bus_client.apis.ocp import OCPInterface
from skill_easter_eggs.stardate import StarDate
from skill_easter_eggs.constants import SPICY_SOUNDS
class EasterEggsSkill(OVOSSkill):
def initialize(self):
self.ocp = OCPInterface(bus=self.bus) # pylint: disable=attribute-defined-outside-init
@property
def grandma_mode(self):
return self.settings.get("grandma_mode_enabled", True)
@intent_handler(IntentBuilder("grandma_mode_intent").require("grandma_mode_keyword").build())
def handle_grandma_mode(self, _):
self.settings["grandma_mode_enabled"] = True
self.speak("Ok, we'll tone it down a bit.")
@intent_handler(IntentBuilder("adult_mode_intent").require("adult_mode_keyword").build())
def handle_adult_mode(self, _):
self.settings["grandma_mode_enabled"] = False
self.speak("Do you feel lucky, punk?")
@intent_handler(IntentBuilder("stardate_intent").require("stardate_keyword").build())
def handle_stardate_intent(self, _):
spoken_stardate = self._create_spoken_stardate()
self.speak_dialog("stardate", {"stardate": spoken_stardate})
def _create_spoken_stardate(self):
spoken_stardate = ""
sd = str(StarDate().getStardate())
for x in sd:
if x.isnumeric():
spoken_stardate += f"{x} "
if x == ".":
spoken_stardate += "point "
return spoken_stardate
@intent_handler(IntentBuilder("pod_bay_doors_intent").require("pod_bay_doors_keyword").build())
def handle_pod_intent(self, _):
self.speak_dialog("pod")
@intent_handler(
IntentBuilder("robotics_laws_intent")
.require("robotics_keyword")
.require("law_keyword")
.optionally("LawOfRobotics")
.build()
)
def handle_robotic_laws_intent(self, message):
law = str(message.data.get("LawOfRobotics", "all"))
if law == "1":
self.speak_dialog("rule1")
elif law == "2":
self.speak_dialog("rule2")
elif law == "3":
self.speak_dialog("rule3")
else:
self.speak_dialog("rule1")
self.speak_dialog("rule2")
self.speak_dialog("rule3")
@intent_handler(
IntentBuilder("rock_paper_scissors_lizard_spock_intent")
.require("rock_paper_scissors_lizard_spock_keyword")
.build()
)
def handle_rock_paper_scissors_lizard_spock_intent(self, _):
self.speak_dialog("rock_paper_scissors_lizard_spock")
@intent_handler(IntentBuilder("languages_you_speak_intent").require("languages_you_speak_keyword").build())
def handle_number_of_languages_intent(self, _):
self.speak_dialog("languages")
@intent_handler(IntentBuilder("portal_intent").require("portal_keyword").build())
def handle_portal_intent(self, _):
path, files = self.get_reference_files("sounds/portal", "mp3")
if len(files):
mp3 = path + "/" + random.choice(files)
self._play_in_ocp(mp3, title="Portal Easter Egg")
else:
self.speak_dialog("bad_file")
def get_reference_files(self, path_ending: str, extension: str):
"""Get a list of files in a directory
If grandma mode is enabled, filter out spicy sounds
path_ending: str, path to directory, should not start with /
extension: str, file extension to filter by
"""
path_ending = path_ending.strip("/")
path = join(dirname(__file__), path_ending)
if self.grandma_mode:
files = [sound for sound in listdir(path) if f".{extension}" in sound and f"{path_ending}/{sound}" not in SPICY_SOUNDS]
else:
files = [sound for sound in listdir(path) if f".{extension}" in sound]
return path, files
@intent_handler(IntentBuilder("hal_intent").require("hal_keyword").build())
def handle_hal_intent(self, _):
path, files = self.get_reference_files("sounds/hal", "mp3")
if len(files):
mp3 = path + "/" + random.choice(files)
self.play_audio(mp3)
else:
self.speak_dialog("bad_file")
@intent_handler(IntentBuilder("duke_nukem_intent").require("duke_nukem_keyword").build())
def handle_dukenukem_intent(self, _):
if not self.grandma_mode:
path, files = self.get_reference_files("sounds/dukenukem", "wav")
if len(files):
wav = path + "/" + random.choice(files)
self.play_audio(wav)
else:
self.speak_dialog("bad_file")
else:
self.speak("Duke Who-Kem?")
@intent_handler(IntentBuilder("arnold_intent").require("arnold_keyword").build())
def handle_arnold_intent(self, _):
path, files = self.get_reference_files("sounds/arnold", "wav")
if len(files):
wav = path + "/" + random.choice(files)
self.play_audio(wav)
else:
self.speak_dialog("bad_file")
@intent_handler(IntentBuilder("bender_intent").require("bender_keyword").build())
def handle_bender_intent(self, _):
path, files = self.get_reference_files("sounds/bender", "mp3")
if len(files):
mp3 = path + "/" + random.choice(files)
self.play_audio(mp3)
else:
self.speak_dialog("bad_file")
@intent_handler(IntentBuilder("glados_intent").require("glados_keyword").build())
def handle_glados_intent(self, _):
path, files = self.get_reference_files("sounds/glados", "mp3")
if len(files):
mp3 = path + "/" + random.choice(files)
self._play_in_ocp(mp3, title="GlaDOS says...")
else:
self.speak_dialog("bad_file")
@intent_handler(IntentBuilder("conan_intent").require("conan_keyword").build())
def handle_conan_intent(self, _):
path, files = self.get_reference_files("sounds/conan", "mp3")
if len(files):
mp3 = path + "/" + random.choice(files)
self.play_audio(filename=mp3)
else:
self.speak_dialog("bad_file")
@intent_handler(IntentBuilder("bill_and_ted_intent").require("bill_and_ted_keyword").build())
def handle_bill_and_ted_intent(self, _):
path, files = self.get_reference_files("sounds/billandted", "mp3")
if len(files):
mp3 = path + "/" + random.choice(files)
self.play_audio(filename=mp3)
else:
self.speak_dialog("bad_file")
@intent_handler(IntentBuilder("malibu_stacey_intent").require("malibu_stacey_keyword").build())
def handle_malibu_stacey_intent(self, _):
path, files = self.get_reference_files("sounds/malibustacey", "mp3")
if len(files):
mp3 = path + "/" + random.choice(files)
self.play_audio(filename=mp3)
else:
self.speak_dialog("bad_file")
@skill_api_method
def get_display_date(self):
return StarDate().getStardate()
def _play_in_ocp(self, media, title="Easter Egg!"):
data = {
"match_confidence": 100,
"media_type": 1, # MediaType.AUDIO
"length": 0,
"uri": media,
"playback": 2, # PlaybackType.AUDIO
"image": "",
"bg_image": "",
"skill_icon": "",
"title": title,
"skill_id": self.skill_id,
}
self.ocp.play(tracks=[data])