-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwiml-simpsons-game.rb
More file actions
194 lines (181 loc) · 7.63 KB
/
Copy pathtwiml-simpsons-game.rb
File metadata and controls
194 lines (181 loc) · 7.63 KB
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
require 'rubygems'
require 'sinatra'
require 'twilio-ruby'
get '/' do
send_file File.join(settings.public_folder, 'index.html')
end
points = 0
q1_pool = [
{ mp3: "english", name: "Homer Simpson", answer: "466" },
{ mp3: "neddoodle", name: "Ned Flanders", answer: "633"},
{ mp3: "exports", name: "Bart Simpson", answer: "227"},
{ mp3: "whuptushie", name: "Marge Simpson", answer: "627"},
{ mp3: "phrases", name: "Lisa Simpson", answer: "547"},
]
q1 =""
q2_pool = [
{ mp3: "surgery", name: "Doctor Nick Riviera", answer: "642" },
{ mp3: "alcohol", name: "Mayor Joe Quimby", answer: "563" },
{ mp3: "nelsonhero", name: "Milhouse Van Houten", answer: "645" },
{ mp3: "aspirin", name: "Apu Nahasapeemapetilon", answer: "278" },
{ mp3: "olive", name: "Moe Szyslak", answer: "663" },
]
q2 = ""
q3_pool = [
{ mp3: "roof", name: "Cletus Spuckler", answer: "253" },
{ mp3: "game", name: "Chief Clancy Wiggum", answer: "252" },
{ mp3: "titpecker", name: "Principal Seymore Skinner", answer: "739" },
{ mp3: "lemonball", name: "Professor John Nerdelbaum Frink, Junior", answer: "564" },
{ mp3: "17stab", name: "Waylon Smithers", answer: "929" },
]
q3 = ""
caller_name = ""
get '/hello' do
people = {
'+14047180928' => 'Corinne Skott',
'+14043755575' => 'Mike Skott',
'+16786405495' => 'Myron Skott',
'+14042757666' => 'Doctor Richard Smiley',
'+18182926583' => 'Chunk Daddy',
'+16784882915' => 'Ben Skott',
}
caller_name = people[params['From']] || 'Simpsons fan'
Twilio::TwiML::Response.new do |r|
r.Say "Ahoy hoy #{caller_name}, Welcome to", voice: 'alice'
r.Say "Mike Skott's"
r.Say "Simpson's audio game", voice: 'alice'
r.Gather :numDigits => '1', :action => '/hello/simps', :method => 'get' do |g|
r.Play '/sounds/simpsons_intro.mp3'
r.Say 'Get ready to play the Simpsons audio game!', voice: 'alice'
r.Play '/sounds/hacker.mp3'
g.Say 'Press 1 to play.', voice: 'alice'
g.Say 'Press any other key to start over.', voice: 'alice'
end
end.text
end
get '/hello/simps' do
redirect '/hello' unless ['1'].include?(params['Digits'])
points = 0
q1 = q1_pool.sample
q2 = q2_pool.sample
q3 = q3_pool.sample
Twilio::TwiML::Response.new do |r|
r.Gather :numDigits => '1', :action => '/hello/simps/1', :method => 'get' do |g|
g.Say 'To skip these instructions and get straight to the game, press 1 at any time. Press any other number to repeat these instructions.', voice: 'alice'
g.Say 'In a moment, you will hear an audio clip from the Simpsons. You must try to determine the name of the character that you hear in the clip.', voice: 'alice'
g.Say 'If you hear more than one character, please respond with the first character you hear in the clip.', voice: 'alice'
g.Say 'You will enter your response by dialing the first three letters of the characters first name.', voice: 'alice'
g.Say 'There will be three audio quotes in each game. Good luck!', voice: 'alice'
g.Say 'Press 1 to begin the game, or any other number to repeat these instructions.', voice: 'alice'
end
end.text
end
get '/hello/simps/1' do
redirect '/hello/simps?Digits=1' unless ['1'].include?(params['Digits'])
Twilio::TwiML::Response.new do |r|
r.Play '/sounds/02-coin.mp3'
r.Say 'This first question is worth 10 points. Here we go.', voice: 'alice'
r.Gather :numDigits => '3', :action => '/hello/simps/2', :method => 'get' do |g|
g.Play "/sounds/#{q1[:mp3]}.mp3"
g.Pause(length: 2)
g.Say 'Dial the first three letters of the characters first name.', voice: 'alice'
end
end.text
end
get '/hello/simps/2' do
if params['Digits'] == q1[:answer]
points += 10
response = Twilio::TwiML::Response.new do |r|
r.Play '/sounds/woohoo.mp3'
r.Say "#{q1[:name]} is correct for 10 points!", voice: 'alice'
r.Play '/sounds/44-coin-2.mp3'
r.Say 'This next question is worth 20 points. Ready?', voice: 'alice'
r.Gather :numDigits => '3', :action => '/hello/simps/3', :method => 'get' do |g|
g.Play "/sounds/#{q2[:mp3]}.mp3"
g.Pause(length: 2)
g.Say 'Dial the first three letters of the characters first name.', voice: 'alice'
end
end
else
response = Twilio::TwiML::Response.new do |r|
r.Play '/sounds/doh.mp3'
r.Say "That is incorrect. The correct answer was #{q1[:name]} or #{q1[:answer].split('').join(', ')}.", voice: 'alice'
r.Say 'You have no points... May god have mercy upon your soul.', voice: 'alice'
r.Play '/sounds/44-coin-2.mp3'
r.Say 'This next question is worth 20 points. Ready?', voice: 'alice'
r.Gather :numDigits => '3', :action => '/hello/simps/3', :method => 'get' do |g|
g.Play "/sounds/#{q2[:mp3]}.mp3"
g.Pause(length: 2)
g.Say 'Dial the first three letters of the characters first name.', voice: 'alice'
end
end
end
response.text
end
get '/hello/simps/3' do
if params['Digits'] == q2[:answer]
points += 20
response = Twilio::TwiML::Response.new do |r|
r.Play '/sounds/woohoo.mp3'
r.Say "#{q2[:name]} is correct for 20 points, giving you #{points} total points!", voice: 'alice'
r.Play '/sounds/45-coin-3.mp3'
r.Say 'This next question is worth 30 points. Ready?', voice: 'alice'
r.Gather :numDigits => '3', :action => '/hello/simps/end', :method => 'get' do |g|
g.Play "/sounds/#{q3[:mp3]}.mp3"
g.Pause(length: 2)
g.Say 'Dial the first three letters of the characters first name.', voice: 'alice'
end
end
else
response = Twilio::TwiML::Response.new do |r|
r.Play '/sounds/doh.mp3'
r.Say "That is incorrect. The correct answer was #{q2[:name]} or #{q2[:answer].split('').join(', ')}.", voice: 'alice'
r.Say "You now have a total of #{points} points.", voice: 'alice'
r.Play '/sounds/45-coin-3.mp3'
r.Say 'This next question is worth 30 points. Ready?', voice: 'alice'
r.Gather :numDigits => '3', :action => '/hello/simps/end', :method => 'get' do |g|
g.Play "/sounds/#{q3[:mp3]}.mp3"
g.Pause(length: 2)
g.Say 'Dial the first three letters of the characters first name.', voice: 'alice'
end
end
end
response.text
end
get '/hello/simps/end' do
if params['Digits'] == q3[:answer]
points += 30
response = Twilio::TwiML::Response.new do |r|
r.Play '/sounds/woohoo.mp3'
r.Say "#{q3[:name]} is correct for 30 points!", voice: 'alice'
r.Say "Congratulations #{caller_name}! You finished the game with a total of #{points} points.", voice: 'alice'
r.Play '/sounds/43-game-over.mp3'
r.Gather :numDigits => '1', :action => '/hello/simps/end-menu', :method => 'get' do |g|
g.Say 'To play again, press 1 now.', voice: 'alice'
g.Say 'Press any other key to disconnect.', voice: 'alice'
end
end
else
response = Twilio::TwiML::Response.new do |r|
r.Play '/sounds/doh.mp3'
r.Say "That is incorrect. The correct answer was #{q3[:name]} or #{q3[:answer].split('').join(', ')}.", voice: 'alice'
r.Say "Congratulations #{caller_name}! You finished the game with a total of #{points} points.", voice: 'alice'
r.Play '/sounds/43-game-over.mp3'
r.Gather :numDigits => '1', :action => '/hello/simps/end-menu', :method => 'get' do |g|
g.Say 'To play again, press 1 now.', voice: 'alice'
g.Say 'Press any other key to disconnect.', voice: 'alice'
end
end
end
response.text
end
get '/hello/simps/end-menu' do
if params['Digits'] == '1'
redirect '/hello/simps?Digits=1'
else
Twilio::TwiML::Response.new do |r|
r.Say 'Goodbye.', voice: 'alice'
r.Play '/sounds/beep15.mp3'
end.text
end
end