-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·147 lines (126 loc) · 4.89 KB
/
index.js
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
sessionRequests = []
exports.handler = function( event, context ) {
var http = require( 'http' );
var https = require( 'https' );
var current = 'no selection';
var alexa_output = 'Sorry we were not able to access the hub site.'
var output_continue = false
var PythonShell = require('python-shell');
var url = 'https://url.ngrok.io/';
if ( event.request.intent ) {
current = event.request.intent.slots.Reddit.value.toLowerCase();
var current_arr = current.split(" ");
}
if (current_arr[0].toLowerCase() == 'off'){
url = 'https://url.ngrok.io/';
url = url + 'lights/led_off';
alexa_output = 'Turning off lights'
}else{
alexa_output = 'Turned on scene ' + current_arr.join(" ");
url = 'https://url.ngrok.io/';
current = current_arr.join("_");
url = url + 'lights/' + current;
}
if (current_arr[0].toLowerCase() == 'yes' || current_arr[0].toLowerCase() == 'set'){
alexa_output = 'Created new scene ' + sessionRequests;
var scene_name = sessionRequests[0].replace(/\s+/g, '_').toLowerCase();
url = 'https://url.ngrok.io/';
url = url + 'scenes/new/' + scene_name;
sessionRequests=[];
}
if (current_arr[0].toLowerCase() == 'no'){
current_arr.shift();
alexa_output = 'Name scene ' + current_arr.join(" ");
sessionRequests.shift()
sessionRequests.push(current_arr.join("_"))
output_continue = true;
}
if (current_arr[0].toLowerCase() == 'welcome'){
alexa_output = "Oh Snap! Can you feel that? It's party time!";
url = 'https://url.ngrok.io/';
if(current_arr.length > 1){
current_arr.shift();
alexa_output = "Welcome! "+ current_arr.join(", ").replace(/\b./g, function(m){ return m.toUpperCase(); }) + ", and fellow niggas we about to turn up and go dumb. Time to pop a pill and get crunk!";
}
url = url + 'party'
}
if (current_arr[0].toLowerCase() == 'scene' || current_arr[0].toLowerCase() == 'seen' || current_arr[0].toLowerCase() == 'lights' || current_arr[0].toLowerCase() == 'scenes' || current_arr[0].toLowerCase() == 'seens' || current_arr[0].toLowerCase() == 'light' || current_arr[0].toLowerCase() == 'setting'){
url = 'https://url.ngrok.io/';
current_arr.shift();
if (current_arr[0].toLowerCase() == 'new' || current_arr[0].toLowerCase() == 'knew' || current_arr[0].toLowerCase() == 'build'){
current_arr.shift();
alexa_output = 'Name scene ' + current_arr.join(" ");
sessionRequests.push(current_arr.join("_"))
output_continue = true;
}else if(current_arr[0].toLowerCase() == 'off'){
url = url + 'lights/led_off';
alexa_output = 'Turning off lights'
}
else{
alexa_output = 'Turned on scene ' + current_arr.join(" ");
current = current_arr.join("_");
url = url + 'lights/' + current;
}
}
if (current_arr[0].toLowerCase() == 'brightness'){
url = 'https://url.ngrok.io/';
current_arr.shift();
if (current_arr[0].toLowerCase() == 'low'){
url = url + 'brightness/50';
alexa_output = 'Light brightness is 50'
}else if(current_arr[0].toLowerCase() == 'lower'){
url = url + 'brightness/100';
alexa_output = 'Light brightness is 100'
}else if(current_arr[0].toLowerCase() == 'medium' || current_arr[0].toLowerCase() == 'middle'){
url = url + 'brightness/150';
alexa_output = 'Light brightness is 150'
}else if(current_arr[0].toLowerCase() == 'high' || current_arr[0].toLowerCase() == 'hi'){
url = url + 'brightness/255';
alexa_output = 'Light brightness is 255'
}
}
if (current_arr[0].toLowerCase() == 'football'){
url = 'https://url.ngrok.io/';
url = url + 'nfl';
alexa_output = 'Switching to Seahawks!'
}
if (output_continue){
var text = alexa_output;
output2( text, context );
}else{
https.get( url, function( ) {
var text = alexa_output;
output( text, context );
} );
}
};
function output( text, context ) {
var response = {
outputSpeech: {
type: "PlainText",
text: text
},
card: {
type: "Simple",
title: "Reddit",
content: text
},
shouldEndSession: true
};
context.succeed( { response: response } );
}
function output2( text, context ) {
var response = {
outputSpeech: {
type: "PlainText",
text: text
},
card: {
type: "Simple",
title: "Reddit",
content: text
},
shouldEndSession: false
};
context.succeed( { response: response } );
}