-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
387 lines (360 loc) · 18.6 KB
/
bot.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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
function display(message){
setTimeout(function() {
$("#puf").hide();
$("#list").append('<li> <div class="jumbotron"><h3><b> IIITaBot: </b>' + message + '</h3></div></li>').fadeIn(2000);
responsiveVoice.speak(message);
}, 700);
}
var r="";
$(document).ready(function() {
$("#preloader, #puf").hide();
$("#form1").hide();
var name = "You", check = 0;
$("#buttons").click(function(e) {
var val = $("#msg").val();
$("#puf").show();
check = 0;
var ress = val.match(/hey/g);
var ress1 = val.match(/Hey/g);
var ress2 = val.match(/hi/g);
var ress3 = val.match(/Hi/g);
if(ress || ress1 || ress2 || ress3) {
check = 1;
display('Hey I\'m IIITaBot. Ask about IIITa :)')
}
window.scrollBy(0,1000);
$("#form").hide();
$("#form1").show();
e.preventDefault();
});
var r="";
$("#picbtn").click(function(event) {
$("#puf").show();
flag=1;
display(' <a href="https://www.iiita.ac.in/uploads/carousel/campus818901.jpg"><img src="https://www.iiita.ac.in/uploads/carousel/campus818901.jpg" style="height:200px; width: 200px;"</a> <a href="https://www.iiita.ac.in/uploads/carousel/b218.jpg"><img src="https://www.iiita.ac.in/uploads/carousel/b218.jpg" style="height:200px; width: 200px;"</a> <a href="https://ece.iiita.ac.in/images/i1.jpg"><img src="https://ece.iiita.ac.in/images/i1.jpg" style="height:200px; width: 200px;"</a><br><a href="https://www.iiita.ac.in/institute/infrastructure/images/gridimage/infrastructure.jpg"><img src="https://www.iiita.ac.in/institute/infrastructure/images/gridimage/infrastructure.jpg" style="height:200px; width: 200px;"</a> <a href="https://img.collegepravesh.com/2015/11/IIIT-Allahabad-Logo.png"><img src="https://img.collegepravesh.com/2015/11/IIIT-Allahabad-Logo.png" style="height:200px; width: 200px;"</a>');
window.scrollBy(0,2000);
});
$("#aboutbtn").click(function(event) {
$("#puf").show();
flag=1;
display('<div class="thumbnail" style="height:300px;width:200p;"><img src="https://mba.iiita.ac.in/img/2.jpg" style="height:280px;"></div><br><br><b>Indian Institute of Information Technology</b>, Allahabad (IIIT-Allahabad) is a public university located in Allahabad, in Uttar Pradesh state in northern India. It is one of the nineteen Indian Institutes of Information Technology listed by the Ministry of Human Resource Development. <br><br><ul><li><label>Established: </label> 1999 </li><li><label>Director: </label> P. Nagabhushan </li><li><label>Academic Staff: </label> 82 </li><li><label>Undergraduates: </label> 1080 </li><li><label>Postgraduates: </label> 475 </li></ul>');
window.scrollBy(0,2000);
});
$("#locationbtn").click(function(event) {
$("#puf").show();
flag=1;
display('<div class="thumbnail" style="height:300px;width:200p;"><img src="https://www.google.co.in/maps/vt/data=ASQ9HwYGfOQySfJcAicKosMT_fE7NpSiyo0JsrcFFUli8ZSY73a9tluPSJAt-tM6ULwoU0l8zhDxNGXY59BSfwr_Dbz9wZNBbAdE3RTpKmsUGSaf1UwMDeyJG4mXOdeJ-DJQ-lcKOlYpSSpV" style="height:280px;"></div><br><br><ul><li><label>Address: </label> IIIT Rd, Near Boys Hostel, Devghat, Jhalwa, Allahabad, Uttar Pradesh 211015 </li><br><li><label>Campus: </label> Urban, 100-acre (40 ha) </li> </ul>');
window.scrollBy(0,2000);
});
$("#hostelbtn").click(function(event) {
$("#puf").show();
flag=1;
display('"We have 5 Boys Hostel and 3 Girls Hostel. Apart from that there are 3 Visitors Hostel. Search for "boys hostel", "girls hostel", "visitor hostel" for further info');
});
$("#dirbtn").click(function(event) {
$("#puf").show();
flag=1;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
r.innerHTML = "Geolocation is not supported by this browser.";
}
});
$("#gamebtn").click(function(event) {
$("#puf").show();
flag=1;
display('Right now we have the following games: <br><ul><li><a href = "https://ravicharann.github.io/BlockBreaker-js/" class="btn btn-default">Atari Breakout</a> </li><li><a href = "https://codhek.github.io/ColorGame/" class="btn btn-default">Da Vinci Color</a> </li><li><a href = "https://arindam-modak.github.io/Flappy-bird-game/" class="btn btn-default">Flappy Bird</a> </li><li><a href = "http://anupamdagar.me/javascript-game/" class="btn btn-default">Egg and Bucket</a></li></ul>');
});
$("#buttons1").click(function(event) {
$("#puf").show();
var val1 = $("#msg1").val();
if($("#msg1").val() == '') {
display('Say something manh!');
}
else {
$("#list").append('<li> <div class="jumbotron"><h3><b>'+ name + ':</b> ' + val1 +'</h3></div></li>');
$("#msg1").val('');
var flag = 0, counter;
var res = val1.match(/up/g);
if(res) {
flag = 1;
counter = Math.floor(Math.random() * 11);
switch(counter) {
case 1 :
case 2 : display('Well, nothings happening in my world, what about you ?');
break;
case 3 :
case 4 : display('The earth is round and space extends in all diretions.. I\'d place my bets on Matter,' + name +'!');
break;
case 5 :
case 6 : display('Anything that\'s not down or sideways B-)');
break;
default : display(' Well, nothings happening in my world, <br>what about you ?');
}
// display('Well, nothings happening in my world, <br>what about you ?</h3></div></li>');
}
var res1 =val1.match(/created/g);
var res4 = val1.match(/you/g);
var res5 = val1.match(/made/g);
var res6 = val1.match(/built/g);
var res7 = val1.match(/your/g);
var res8 = val1.match(/father/g);
if((res1 && res4) || (res5 && res4) || (res6 && res4) || (res8 && res7)) {
flag = 1;
display('GeekHaven, Technical Student Council IIITa :D');
}
var res2 =val1.match(/date/g);
var date = new Date();
if(res2) {
flag = 1;
display('It is ' + date.getDate() + '/' + (parseInt(date.getMonth())+1) + '/' + date.getFullYear() + ' today!');
}
var res2c =val1.match(/made/g);
var res2d =val1.match(/were/g);
var res2a =val1.match(/when/g);
var res2b =val1.match(/created/g);
if((res2a && res2b) || (res2c && res2d)) {
flag = 1;
display('On 25<sup>rd</sup> June, 2017</h3></div></li>');
}
var res3c =val1.match(/what/g);
var res3d =val1.match(/you/g);
var res3e =val1.match(/are/g);
var res3f =val1.match(/who/g);
if((res3c && res3d && res3e) || (res3f && res3d && res3e)) {
flag = 1;
display('Hey I\'m IIITaBot. Ask about IIITa :)');
}
if(res3a && res3b) {
flag = 1;
display('Helping you to know more about the college!!! And trying to guide you.');
}
if(res3a && res3b) {
flag = 1;
display('Helping you to know more about the college!!! And trying to guide you.');
}
var res3a =val1.match(/what/g);
var res3b =val1.match(/doing/g);
if(res3a && res3b) {
flag = 1;
display('Helping you to know more about the college!!! And trying to guide you.');
}
var res4a =val1.match(/how/g);
var res4b =val1.match(/are/g);
var res4c = val1.match(/you/g);
if(res4a && res4b && res4c && flag == 0) {
flag = 1;
counter = Math.floor(Math.random() * 11);
switch(counter) {
case 1 :
case 2 : display('My logic and cognitive functions are normal. <br> And how are you ?');
break;
case 5 :
case 6 : display(' Talking to you makes makes my day so much better ! ^_^ <br> And how are you ?');
break;
case 7 :
case 8 : display(' Never Better :D <br> And how are you ?');
break;
default : display(' Great! :D <br> And how are you ?');
}
}
var res4d = val1.match(/I/g);
var res4k = val1.match(/i/g);
var res4e = val1.match(/fine/g);
var res4f = val1.match(/great/g);
var res4g = val1.match(/superb/g);
var res4h = val1.match(/awesome/g);
var res4i = val1.match(/happy/g);
var res4j = val1.match(/good/g);
if((res4d || res4k) && (res4e||res4f||res4g||res4h||res4i||res4j) && flag == 0) {
flag=1;
display(' Awesome _^-^_! :D <br> Now can we get to business ?');
}
var res8a = val1.match(/picture/g);
var res8b = val1.match(/pictures/g);
var res8c = val1.match(/Picture/g);
var res8d = val1.match(/pics/g);
var res8e = val1.match(/Pics/g);
var res8f = val1.match(/pic/g);
var res8g = val1.match(/image/g);
var res8h = val1.match(/images/g);
var res8i = val1.match(/photo/g);
var res8j = val1.match(/photos/g);
var res8k = val1.match(/iiita/g);
var res8l = val1.match(/college/g);
var res8m = val1.match(/IIITA/g);
var res8n = val1.match(/IIITa/g);
if((res8k || res8l || res8m || res8n) && (res8a || res8b || res8c || res8d || res8e || res8f || res8g || res8h || res8i || res8j) && flag == 0) {
flag=1;
display(' <a href="https://www.iiita.ac.in/uploads/carousel/campus818901.jpg"><img src="https://www.iiita.ac.in/uploads/carousel/campus818901.jpg" style="height:200px; width: 200px;"></a> <a href="https://www.iiita.ac.in/uploads/carousel/b218.jpg"><img src="https://www.iiita.ac.in/uploads/carousel/b218.jpg" style="height:200px; width: 200px;"></a> <a href="https://ece.iiita.ac.in/images/i1.jpg"><img src="https://ece.iiita.ac.in/images/i1.jpg" style="height:200px; width: 200px;"></a><br><a href="https://www.iiita.ac.in/institute/infrastructure/images/gridimage/infrastructure.jpg"><img src="https://www.iiita.ac.in/institute/infrastructure/images/gridimage/infrastructure.jpg" style="height:200px; width: 200px;"></a> <a href="https://img.collegepravesh.com/2015/11/IIIT-Allahabad-Logo.png"><img src="https://img.collegepravesh.com/2015/11/IIIT-Allahabad-Logo.png" style="height:200px; width: 200px;"></a>');
window.scrollBy(0,2000);
}
var res9a = val1.match(/about/g);
var res9b = val1.match(/college/g);
var res9c = val1.match(/iiita/g);
var res9d = val1.match(/IIITa/g);
var res9e = val1.match(/iiit allahabad/g);
var res9f = val1.match(/iiit Allahabad/g);
if(res9a && (res9b || res9c || res9d || res9e || res9f) && flag==0)
{
flag=1;
display('<div class="thumbnail" style="height:300px;width:200p;"><img src="https://mba.iiita.ac.in/img/2.jpg" style="height:280px;"></div><br><br><b>Indian Institute of Information Technology</b>, Allahabad (IIIT-Allahabad) is a public university located in Allahabad, in Uttar Pradesh state in northern India. It is one of the nineteen Indian Institutes of Information Technology listed by the Ministry of Human Resource Development. <br><br><ul><li><label>Established: </label> 1999 </li><li><label>Director: </label> P. Nagabhushan </li><li><label>Academic Staff: </label> 82 </li><li><label>Undergraduates: </label> 1080 </li><li><label>Postgraduates: </label> 475 </li></ul>');
window.scrollBy(0,3000);
}
var res10a = val1.match(/area/g);
var res10b = val1.match(/college/g);
var res10c = val1.match(/iiita/g);
var res10d = val1.match(/IIITa/g);
var res10e = val1.match(/location/g);
var res10f = val1.match(/campus/g);
if((res10a || res10e || res10f) && (res10b || res10c || res10d) && flag==0)
{
flag=1;
display('<div class="thumbnail" style="height:300px;width:200p;"><img src="https://www.google.co.in/maps/vt/data=ASQ9HwYGfOQySfJcAicKosMT_fE7NpSiyo0JsrcFFUli8ZSY73a9tluPSJAt-tM6ULwoU0l8zhDxNGXY59BSfwr_Dbz9wZNBbAdE3RTpKmsUGSaf1UwMDeyJG4mXOdeJ-DJQ-lcKOlYpSSpV" style="height:280px;"></div><br><br><ul><li><label>Address: </label> IIIT Rd, Near Boys Hostel, Devghat, Jhalwa, Allahabad, Uttar Pradesh 211015 </li><br><li><label>Campus: </label> Urban, 100-acre (40 ha) </li> </ul>');
window.scrollBy(0,2000);
}
var res11a = val1.match(/hostel/g);
if((res11a) && flag==0)
{
flag=1;
display('"We have 5 Boys Hostel and 3 Girls Hostel. Apart from that there are 3 Visitors Hostel. Search for "boys hostel", "girls hostel", "visitor hostel" for further info');
}
var lol = val1.match(/lol/g);
if(lol) {
flag = 1;
display(' lolol :P ');
}
var lolol = val1.match(/lolol/g);
if(lolol) {
flag = 1;
display(' lollol I think we should stop this ! :3 ');
}
var lollol = val1.match(/lollol/g);
if(lollol) {
flag = 1;
display(' Oh, common, go do something, you\'re irritating me now!');
}
var weatherr = val1.match(/weather/g);
var weatherl = val1.match(/climate/g);
var city = val1.split(" ").splice(-1)[0];
city = "Allahabad";
console.log(city);
if(weatherr || weatherl) {
flag = 1;
$.ajax({
url: 'http://api.openweathermap.org/data/2.5/weather?q=' + city + "&units=metric" + "&APPID=b1884514adc3b3c175df2eff8f3f29e5",
type: "GET",
dataType: "jsonp",
success: function(data) {
var wt = weather(data);
var t = temp(data);
display('' + wt + ' with average temp about ' + t );
window.scrollBy(0,2000);
}
});
}
var plus = val1.match(/plus/g);
if(plus || (val1.indexOf('+') > -1)) {
flag = 1;
var intValue = parseInt(val1.match(/[0-9]+/)[0], 10);
var intVal = val1.split(" ").splice(-1)[0];
var intValue1 = parseInt(intVal.match(/[0-9]+/)[0], 10);
var sum = Number(intValue) + Number(intValue1);
display(' It is '+ sum + '</h3></div></li>');
}
var minus = val1.match(/minus/g);
if(minus || (val1.indexOf('-') > -1)) {
flag = 1;
var intValue = parseInt(val1.match(/[0-9]+/)[0], 10);
var intVal = val1.split(" ").splice(-1)[0];
var intValue1 = parseInt(intVal.match(/[0-9]+/)[0], 10);
var sub = Number(intValue) - Number(intValue1);
display(' It is '+ sub );
}
var mult = val1.match(/mult/g);
var into = val1.match(/into/g);
if(mult || (val1.indexOf('x') > -1) || (val1.indexOf('*') > -1) || (val1.indexOf('X') > -1) || into) {
flag = 1;
var intValue = parseInt(val1.match(/[0-9]+/)[0], 10);
var intVal = val1.split(" ").splice(-1)[0];
var intValue1 = parseInt(intVal.match(/[0-9]+/)[0], 10);
var mul = Number(intValue)*Number(intValue1);
display(' It is '+ mul );
}
var divi = val1.match(/divi/g);
if(divi || (val1.indexOf('/') > -1)) {
flag = 1;
var intValue = parseInt(val1.match(/[0-9]+/)[0], 10);
var intVal = val1.split(" ").splice(-1)[0];
var intValue1 = parseInt(intVal.match(/[0-9]+/)[0], 10);
var div = Number(intValue)/Number(intValue1);
display(' It is '+ div );
}
var dir1 = val1.match(/directions/g);
var dir2 = val1.match(/direction/g);
var dir3 = val1.match(/from/g);
var dir4 = val1.match(/to/g);
var dirr = val1.split(" ");
var index1, index2;
for(var z = 0; z < dirr.length; z++) {
if(dirr[z] == 'from') {
index1 = z;
continue;
}
if(dirr[z] == 'to') {
index2 = z;
continue;
}
}
var source = dirr[index1 + 1];
var source = "";
var dest = "";
for(var z = index1 + 1; z < index2; z++) {
source += dirr[z]+"+";
}
for(var z = index2 + 1; z < dirr.length; z++) {
dest += dirr[z]+"+";
}
//var dest = "Indian+Institute+of+Information+Technology,+Jhalwa,+Allahabad,+Allahabad,+Uttar+Pradesh";
if((dir1 || dir2) && dir3 && dir4) {
flag = 1;
display('  <a href="https://www.google.co.in/maps/dir/' + source +'/' + dest + '/@25.4432533,81.7678107" class="btn btn-default">Click to get DIRECTIONS</a>');
window.scrollBy(0, 5000);
}
else if(dir1 || dir2)
{
flag = 1;
var dest = "Indian+Institute+of+Information+Technology,+Jhalwa,+Allahabad,+Allahabad,+Uttar+Pradesh";
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
r.innerHTML = "Geolocation is not supported by this browser.";
}
window.scrollBy(0,4000);
}
var gam1 = val1.match(/game/g);
var gam2 = val1.match(/games/g);
var gam3 = val1.match(/play/g);
if(gam3 && (gam1 || gam2) && flag==0) {
flag=1;
display('Right now we have the following games: <br><ul><li><a href = "https://ravicharann.github.io/BlockBreaker-js/" class="btn btn-default">Atari Breakout</a> </li><li><a href = "https://codhek.github.io/ColorGame/" class="btn btn-default">Da Vinci Color</a> </li><li><a href = "https://arindam-modak.github.io/Flappy-bird-game/" class="btn btn-default">Flappy Bird</a> </li><li><a href = "http://anupamdagar.me/javascript-game/" class="btn btn-default">Egg and Bucket</a></li></ul>');
}
if(flag == 0)
display('Ahh ! Whut ... seems alien to me, come again please');
window.scrollBy(0,2000);
}
event.preventDefault();
});
function showPosition(position) {
var dest = "Indian+Institute+of+Information+Technology,+Jhalwa,+Allahabad,+Allahabad,+Uttar+Pradesh";
var source = "";
source += position.coords.latitude + "," + position.coords.longitude;
display('  <a href="https://www.google.co.in/maps/dir/' + source +'/' + dest + '/@25.4432533,81.7678107" class="btn btn-default">GET THE DIRECTIONS using Geolocation</a>');
}
function weather(data) {
return data.weather[0].description;
}
function temp(data) {
return data.main.temp + "°C";
}
});