-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
832 lines (608 loc) · 25.2 KB
/
index.js
File metadata and controls
832 lines (608 loc) · 25.2 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
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
require('dotenv').config();
const Discord = require("discord.js")
const client = new Discord.Client()
const request = require('request');
var axios = require('axios');
var crypto = require('crypto');
var firebase = require('firebase');
const moment = require('moment');
const cron = require('node-cron');
var firebaseConfig = {
apiKey: "AIzaSyDt6eb9buDMCap2GdwF7Y9TcOJaz_B6u8o",
authDomain: "bot-discord-f0d02.firebaseapp.com",
projectId: "bot-discord-f0d02",
storageBucket: "bot-discord-f0d02.appspot.com",
messagingSenderId: "845388166393",
appId: "1:845388166393:web:ed567721531f1259d5de28",
measurementId: "G-87QDVGX3Q2"
}
// Initialize Firebase
firebase.initializeApp(firebaseConfig)
let database = firebase.database()
const customersRef = firebase.database().ref('/users');
const customersRef1 = firebase.database().ref('/notify');
let urls = 'https://cdn-api.co-vin.in/api/v2/admin/location/states'
let options = { json: true };
let optionssta = { json: true };
const prefix = "!";
const prefix1 = "#";
const prefixph = "91";
client.on("ready", () => {
console.log('Ready');
client.guilds.cache.forEach((guild) => {
// Getting one of their channels
let channel = guild.channels.cache.array()[2];
// Sending the channel a message
channel.send("Hey\nType **help** to know the bot");
});
})
//bot ready to start
client.on("message", async msg => {
message = msg.content;
main();
//this one stop the self looping
if (msg.author.bot) {
console.log('Ignoring bot message!');
return;
}
const details = new Discord.MessageEmbed()
.setColor(' 0xFFFFFF')
.setTitle('Type the following to perform the steps')
.setURL('https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae')
.setAuthor('Covin Bot', 'https://images.vexels.com/media/users/3/140503/isolated/lists/24882e71e8111a13f3f1055c1ad53cf3-hand-with-injection.png', 'https://discord.js.org')
.setDescription('Thanks For Choosing ME')
.setThumbnail('https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae')
.addFields(
{ name: '\u200B', value: '\u200B' },
{ name: 'myinfo', value: 'To know your registration details' },
{ name: '\u200B', value: '\u200B' },
{ name: '**vaccine**', value: 'To know avilable centers', inline: true },
{ name: '\u200B', value: '\u200B' },
{ name: ' **register**', value: 'For registration', inline: true },
{ name: '\u200B', value: '\u200B' },
{ name: ' **notify**', value: ' To get notification of the slots', inline: true },
{ name: '\u200B', value: '\u200B' },
{ name: ' **delete_myinfo**', value: 'To delete your info', inline: true },
{ name: '\u200B', value: '\u200B' },
{ name: ' **stop_notify**', value: 'To stop the notification', inline: true },
)
.setImage('https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/photo6147825254626602018.jpg?alt=media&token=38ca1f38-ad75-4ad0-b0fe-5ac4fce18d56')
.setTimestamp()
.setFooter('Get Vaccinated', 'https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae');
if (message.includes('help')) {
msg.channel.send(details);
}
//choose state
if (message.includes('vaccine')) {
msg.reply("HI Choose You Sate");
request(urls, optionssta, (error, res, body) => {
if (error) {
return console.log(error)
};
if (!error && res.statusCode == 200) {
var state = body.states
var arr_len = state.length;
var num_str = '';
for (var i = 0; i < arr_len; i++) {
var state_data = state[i].state_name.toString() + " (" + " Id: " + body.states[i].state_id.toString() + ")";
console.log(state_data);
num_str += state[i].state_name.toString() + " 🆔 == " + "**!" + body.states[i].state_id.toString() + "**"
if (i < (arr_len - 1)) {
num_str += '\n';
}
}
setTimeout(function () {
msg.channel.send({
embed: {
title: "Sate List",
color: 15462131,
description: `${num_str}`,
footer: {
text: "Get Vaccinated",
icon_url: 'https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae',
},
}
});
}, 1 * 1000);
};
});
}
//code for listing districts in the above state
if (msg.content.startsWith(prefix)) {
if (msg.content == "!") {
msg.reply("Please enter valid commands");
}
else {
const useerinput = msg.content.slice(prefix.length).trim().split(' ');
let urld = "https://cdn-api.co-vin.in/api/v2/admin/location/districts/" + useerinput
request(urld, options, (error, res, body) => {
if (error) {
return console.log(error)
};
if (!error && res.statusCode == 200) {
msg.reply("HI Choose You District");
var district = body.districts
var dislength = district.length;
var dist_string = '';
for (var i = 0; i < dislength; i++) {
var dist_data = district[i].district_name.toString() + " (" + " Id: " + body.districts[i].district_id.toString() + ")";
console.log(dist_data);
dist_string += district[i].district_name.toString() + " 🆔 == " + "#" + body.districts[i].district_id.toString()
if (i < (dislength - 1)) {
dist_string += '\n';
}
}
setTimeout(function () {
msg.channel.send({
embed: {
title: "Choose Your District",
color: 15462131,
description: `${dist_string}`,
footer: {
text: "Get Vaccinated",
icon_url: 'https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae',
},
}
});
}, 1 * 1000);
};
});
}
}
//giving the all centers lists
if (msg.content.startsWith(prefix1)) {
if (msg.content == "#") {
msg.reply("Please enter valid commands");
}
else {
var dist_id1 = msg.content.slice(prefix1.length).trim().split(' ');
msg.reply("\n" + "Please Enter Your Preferred Date in this format ** 01-05-2021 **");
const collector = new Discord.MessageCollector(msg.channel, m => m.author.id === msg.author.id, { time: 60000 });
console.log(collector)
collector.on('collect', msg2 => {
var date = msg2.content;
console.log(date)
collector.stop();
let url12 = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByDistrict?district_id=" + dist_id1 + "&date=" + date
console.log(url12)
request(url12, options, (error, res, body) => {
if (error) {
msg.reply("Sorry, there is no Centers Avaliable on " + date)
return console.log(error)
};
if (!error && res.statusCode == 200) {
// here the data of center name
var session = body.sessions
var s_str = '';
var s_len = session.length;
var abc = []
if(s_len < 1){
msg.reply("Sorry, there is no Centers Avaliable on " + date +"\n"+ "Please enter district id and try again! ")
}
else {
for (var i = 0; i < s_len; i++) {
var session_data = session[i].center_id.toString() + " (" + body.sessions[i].name.toString() + ")" + " (" + body.sessions[i].block_name.toString() + ")" + " (" + body.sessions[i].pincode.toString() + ")" + " (" + body.sessions[i].from.toString() + ")" + " (" + body.sessions[i].to.toString() + ")" + " (" + body.sessions[i].lat.toString() + ")" + " (" + body.sessions[i].long.toString() + ")" + " (" + body.sessions[i].slots.toString() + ")";
s_str = " :hospital:" + "\n" + "**Center Id: ** " + session[i].center_id.toString() + "\n" +
"**Center Name: ** " + body.sessions[i].name.toString() + "\n" + "**Block: **" + body.sessions[i].block_name.toString() + " \n" +
"**PIN: **" + body.sessions[i].pincode.toString() + "\n" +
"**Fees: **" + body.sessions[i].fee_type.toString() + " \n" + "**Slot Avaliable For Dose 1: **" + body.sessions[i].available_capacity_dose1.toString() + " \n"
+ "**Slot Avaliable For Dose 2: **" + body.sessions[i].available_capacity_dose2.toString() + " \n" + "**Slot Avaliable- **" + body.sessions[i].available_capacity.toString() + " \n"
+ "**Age: **" + body.sessions[i].min_age_limit.toString() + "+" + " \n" + ":syringe:**Vaccine: **" + body.sessions[i].vaccine.toString() + " \n" +
":stopwatch:**Session Timings**:stopwatch:" + "\n" + body.sessions[i].slots.toString().replace(/,/g, '\n') + "\n" + "\n"
abc.push(s_str)
}
msg.reply("\n" + "** Center Details **");
setTimeout(async () => {
await Promise.all(abc.map(msg1 => (msg.channel.send({
embed: {
Title: "Session Details",
color: 3447003,
description: `${msg1}`,
timestamp: new Date(),
footer: {
text: `Total Parts ${abc.length}`,
icon_url: 'https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae',
},
}
}))))
}, 1 * 1000);
}
}
else {
msg.reply("Sorry, There is no available slots on ")
}
});
collector.stop();
})
}
}
//Asking phone number
if (message.includes('register')) {
msg.channel.send("I'm Concernd About Your privacy, so I have directly send you the details 🔒")
msg.author.send("Enter your Phone number with your contry code (91-India) 📞")
}
//OTP Generations
if (msg.content.startsWith(prefixph)) {
const phone = msg.content.slice(prefixph.length).trim().split(' ');
customersRef.child(msg.author.id).update({
phoneno: phone
});
var data = JSON.stringify({
"mobile": "{{" + phone + "}}",
"secret": "{{U2FsdGVkX1+z/4Nr9nta+2DrVJSv7KS6VoQUSQ1ZXYDx/CJUkWxFYG6P3iM/VW+6jLQ9RDQVzp/RcZ8kbT41xw==}}"
});
var config = {
method: 'post',
url: 'https://cdn-api.co-vin.in/api/v2/auth/generateMobileOTP',
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
'Content-Type': 'application/json'
},
data: data
};
axios(config)
.then(function (response) {
console.log(response.data.txnId);
console.log(msg.author.id)
customersRef.child(msg.author.id).update({
txnID: response.data.txnId,
userId: msg.author.id,
});
msg.author.send("Enter OTP ");
const collector = new Discord.MessageCollector(msg.channel, m => m.author.id === msg.author.id, { time: 120000 });
collector.on('collect', msg1 => {
//OTP Convert to SHA256
const code = crypto.createHash('sha256').update(msg1.content).digest('hex');
console.log(code)
console.log(msg1.content)
//OTP Confirmation
var data = JSON.stringify({
"otp": "{{" + code + "}}",
"txnId": "{{" + response.data.txnId + "}}"
});
var config = {
method: 'post',
url: 'https://cdn-api.co-vin.in/api/v2/auth/validateMobileOtp',
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
'Content-Type': 'application/json'
},
data: data
};
axios(config)
.then(function (response) {
msg.author.send("OTP Verification Successfull 👍")
console.log(JSON.stringify(response.data));
customersRef.child(msg.author.id).update({
token: response.data.token,
});
name();
collector.stop();
})
.catch(function (error) {
console.log(error);
msg.author.send("Sorry, OTP is incorrect 👎")
msg.author.send("You can still store your data for future use \n Enter **'store_info'**")
collector.stop();
});
})
})
.catch(function (error) {
console.log(error);
});
}
//Taking user details
function name() {
msg.author.send("Enter your Full Name")
const collectorname = new Discord.MessageCollector(msg.channel, m => m.author.id === msg.author.id, { time: 100000 });
collectorname.on('collect', msg1 => {
customersRef.child(msg.author.id).update({
name: msg1.content,
});
dname()
collectorname.stop();
})
}
function dname() {
msg.author.send("Enter your District")
const collectordist = new Discord.MessageCollector(msg.channel, m => m.author.id === msg.author.id, { time: 100000 });
collectordist.on('collect', msg2 => {
customersRef.child(msg.author.id).update({
district: msg2.content,
});
address();
collectordist.stop();
})
}
function address() {
msg.author.send("Enter your Address")
const collectoraddress = new Discord.MessageCollector(msg.channel, m => m.author.id === msg.author.id, { time: 1800000 });
collectoraddress.on('collect', msg3 => {
customersRef.child(msg.author.id).update({
address: msg3.content,
});
age();
collectoraddress.stop();
})
}
function age() {
msg.author.send("Enter your age")
const collectorage = new Discord.MessageCollector(msg.channel, m => m.author.id === msg.author.id, { time: 1800000 });
collectorage.on('collect', msg4 => {
customersRef.child(msg.author.id).update({
age: msg4.content,
});
idtype();
collectorage.stop();
})
}
function idtype() {
msg.author.send("Enter your ID Type (adhaar, election id, pan card...")
const collectoridtype = new Discord.MessageCollector(msg.channel, m => m.author.id === msg.author.id, { time: 1800000 });
collectoridtype.on('collect', msg6 => {
customersRef.child(msg.author.id).update({
idtype: msg6.content,
});
idno();
collectoridtype.stop();
})
}
function idno() {
msg.author.send("Enter your ID Number")
const collectoridno = new Discord.MessageCollector(msg.channel, m => m.author.id === msg.author.id, { time: 1800000 });
collectoridno.on('collect', msg5 => {
customersRef.child(msg.author.id).update({
idno: msg5.content,
});
msg.author.send("✅ Done!!" + "\n" + "Enter 'myinfo' to know your details.");
collectoridno.stop();
})
}
//giving users details
if (msg.content == "myinfo") {
customersRef.child(msg.author.id).update({
userId: msg.author.id,
});
msg.channel.send("Checking....⌛")
setTimeout(function () {
database.ref("users/" + msg.author.id).once('value')
.then(function (snapshot) {
var token = snapshot.val().token
var idno = snapshot.val().idno
var idtype = snapshot.val().idtype
var age = snapshot.val().age
var address = snapshot.val().address
var district = snapshot.val().district
var name = snapshot.val().name
var phoneno = snapshot.val().phoneno
if (name === undefined || name == null) {
msg.reply("Sorry You Are Not Registered 😞" + "\n" + "Enter 'register' for registration")
}
//else if (name === undefined || name == null) {
// msg.reply("Hi Your Number Registered, But till your personal data is not added so register again 😞" + "\n" + "Enter 'register' for registration")
// }
else {
msg.channel.send("I'm Concernd About Your privacy so I'm sending it directly to you 🔒")
msg.author.send({
embed: {
title: name,
color: 3447003,
description: "**Disctrict: **" + district + "\n" + "**Address: **" + address + "\n" + "**Age: **" + age + "\n" + "**Personal ID: **" + idtype + "\n" + "**ID Card no.: **" + idno + "\n" + "**Phone no.: **" + phoneno + "\n" + "\n"
+ "Go to the server to use me Again ",
footer: {
text: "Get Vaccinated",
icon_url: 'https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae',
},
}
});
}
})
}, 1 * 1000);
}
//subscribption of notification
if (msg.content == "notify") {
selectstate();
}
function selectstate() {
msg.reply("HI Choose You Sate");
request(urls, optionssta, (error, res, body) => {
if (error) {
return console.log(error)
};
if (!error && res.statusCode == 200) {
var state = body.states
var arr_len = state.length;
var num_str = '';
for (var i = 0; i < arr_len; i++) {
var state_data = state[i].state_name.toString() + " (" + " Id: " + body.states[i].state_id.toString() + ")";
console.log(state_data);
num_str += state[i].state_name.toString() + " 🆔 == " + "**" + body.states[i].state_id.toString() + "**"
if (i < (arr_len - 1)) {
num_str += '\n';
}
}
setTimeout(function () {
msg.channel.send({
embed: {
title: "Sate List",
color: 15462131,
description: `${num_str}`,
footer: {
text: "Get Vaccinated",
icon_url: 'https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae',
},
}
});
}, 1 * 1000);
};
});
const collectorstae = new Discord.MessageCollector(msg.channel, m => m.author.id === msg.author.id, { time: 1800000 });
collectorstae.on('collect', msgs => {
selectdist(msgs.content)
collectorstae.stop();
})
}
function selectdist(id) {
let urld = "https://cdn-api.co-vin.in/api/v2/admin/location/districts/" + id
request(urld, options, (error, res, body) => {
if (error) {
return console.log(error)
};
if (!error && res.statusCode == 200) {
msg.reply("HI Choose You District");
var district = body.districts
var dislength = district.length;
var dist_string = '';
for (var i = 0; i < dislength; i++) {
var dist_data = district[i].district_name.toString() + " (" + " Id: " + body.districts[i].district_id.toString() + ")";
console.log(dist_data);
dist_string += district[i].district_name.toString() + " 🆔 == " + "**" + body.districts[i].district_id.toString() + "**"
if (i < (dislength - 1)) {
dist_string += '\n';
}
}
setTimeout(function () {
msg.channel.send({
embed: {
title: "Choose Your District",
color: 15462131,
description: `${dist_string}`,
footer: {
text: "Get Vaccinated",
icon_url: 'https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae',
},
}
});
}, 1 * 1000);
};
});
const collectordist1 = new Discord.MessageCollector(msg.channel, m => m.author.id === msg.author.id, { time: 1800000 });
collectordist1.on('collect', msgd => {
customersRef1.child(msg.author.id).update({
district: msgd.content,
userid: msg.author.id
});
age1();
collectordist1.stop();
})
}
function age1() {
msg.reply("Enter Your Age")
const collectorage1 = new Discord.MessageCollector(msg.channel, m => m.author.id === msg.author.id, { time: 1800000 });
collectorage1.on('collect', msgg => {
customersRef1.child(msg.author.id).update({
age: msgg.content,
});
msg.reply("**✅ Done!!** You are subscribed to get notification. You will get notification every hour when slots are available \n If you want to unsubscribe notification, then Just Enter '**stop_notify**'")
msg.author.send("✅ Done!! You are Subscribed To Get Notification")
collectorage1.stop();
})
}
//cancel notification
if (msg.content == "stopnotify") {
customersRef1.child(msg.author.id).remove();
msg.reply("❌ You have successfully unsubscribed ")
}
//delete my info
if (msg.content == "delete_myinfo") {
customersRef.child(msg.author.id).remove();
msg.reply("❌ You have successfully deleted your information")
}
//checking every hour ther is any free slots are avilable
function main() {
try {
console.log("vaccine check started")
cron.schedule(' * 1 * * *', async () => {
var db = firebase.database().ref(`notify`);
db.once("value").then(function (snapshot) {
var a = Object.values(snapshot.val());
var b = JSON.stringify(a)
var arr = JSON.parse(b.toString());
const syncWait = ms => {
const end = Date.now() + ms
while (Date.now() < end) continue
}
for (var i = 0; i < arr.length; i++) {
checkAvailability(arr[i].district, arr[i].age, arr[i].userid);
syncWait(5000)
}
})
});
} catch (e) {
console.log('an error occured: ' + JSON.stringify(e, null, 2));
throw e;
}
}
async function checkAvailability(district, age, id) {
let datesArray = await fetchNext7Days();
datesArray.forEach(date => {
getSlotsForDate(date, district, age, id);
})
}
function getSlotsForDate(DATE, district, age, id) {
console.log(DATE, district, age);
let config = {
method: 'get',
url: "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByDistrict?district_id=" + district + "&date=" + DATE,
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'
}
};
axios(config)
.then(function (response) {
let sessions = response.data.sessions;
let validSlots = sessions.filter(response => response.min_age_limit <= age && response.available_capacity > 0)
if (validSlots.length > 0) {
notifyMe(validSlots, DATE, id);
}
})
.catch(function (error) {
// console.log(error+"222");
});
}
async function
notifyMe(validSlots, date, id) {
var daa = JSON.stringify(validSlots, null, '\t');
var sessions = JSON.parse(daa.toString());
var s_str = '';
var s_len = sessions.length;
var abc = []
for (var i = 0; i < s_len; i++) {
s_str = " :hospital:" + "\n" + "**Center Id: ** " + sessions[i].center_id.toString() + "\n" +
"**Center Name: ** " + sessions[i].name.toString() + "\n" + "**Block: **" + sessions[i].block_name.toString() + " \n" +
"**PIN: **" + sessions[i].pincode.toString() + "\n" +
"**Fees: **" + sessions[i].fee_type.toString() + " \n" + "**Slot Avaliable For Dose 1: **" + sessions[i].available_capacity_dose1.toString() + " \n"
+ "**Slot Avaliable For Dose 2: **" + sessions[i].available_capacity_dose2.toString() + " \n" + "**Slot Avaliable- **" + sessions[i].available_capacity.toString() + " \n"
+ "**Age: **" + sessions[i].min_age_limit.toString() + "+" + " \n" + ":syringe:**Vaccine: **" + sessions[i].vaccine.toString() + " \n" +
":stopwatch:**Session Timings**:stopwatch:" + "\n" + sessions[i].slots.toString().replace(/,/g, '\n') + "\n" + "\n"
abc.push(s_str)
}
client.users.fetch(id, false).then((user) => {
user.send({
embed: {
title: "Vaccine Avaliable Slots",
color: 15462131,
description: `${s_str}`,
footer: {
text: "Get Vaccinated",
icon_url: 'https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae',
},
}
});
});
};
async function fetchNext7Days() {
let dates = [];
let today = moment();
for (let i = 0; i < 7; i++) {
let dateString = today.format('DD-MM-YYYY')
dates.push(dateString);
today.add(1, 'day');
}
return dates;
}
if (msg.content == "store_info") {
name();
}
})
client.login(process.env.TOKEN)