-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
1328 lines (1233 loc) · 47.9 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
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
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
require("dotenv").config(); //initialize dotenv
const axios = require("axios"); //add this line at the top
const Discord = require("discord.js"); //import discord.js
const { parse } = require("path/posix");
const { CLIENT_RENEG_WINDOW } = require("tls");
let googleNewsAPI = require("google-news-json");
const client = new Discord.Client({
intents: [Discord.Intents.FLAGS.GUILD_MESSAGES, Discord.Intents.FLAGS.GUILDS],
});
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity("!covidhelp", { type: "LISTENING" });
});
function date_format(date) {
const d = new Date(date);
const ye = new Intl.DateTimeFormat("el", { year: "numeric" }).format(d);
const mo = new Intl.DateTimeFormat("el", { month: "short" }).format(d);
const da = new Intl.DateTimeFormat("el", { day: "2-digit" }).format(d);
date = `${da}-${mo}-${ye}`;
return date;
}
url_cases = "https://covid-19-greece.herokuapp.com/all"; // Done
url_deaths = "https://covid-19-greece.herokuapp.com/deaths"; // Done
url_vaccinations = "https://covid-19-greece.herokuapp.com/total-vaccinations"; // Done
url_risklevels = "https://covid-19-greece.herokuapp.com/risk-levels"; // Done
url_entatiki = "https://covid-19-greece.herokuapp.com/intensive-care"; // Done
url_tests = "https://covid-19-greece.herokuapp.com/total-tests"; // Done
url_male = "https://covid-19-greece.herokuapp.com/male-cases-history";
url_female = "https://covid-19-greece.herokuapp.com/female-cases-history";
url_age = "https://covid-19-greece.herokuapp.com/age-distribution"; // Done
const cases = async () => {
try {
const result = await axios.get(url_cases);
let the_cases = result.data.cases;
let length_of_cases = the_cases.length;
let today = length_of_cases - 1;
let todays_cases = the_cases[today];
let confirmed = todays_cases["confirmed"];
let last_update = todays_cases["date"];
last_update = date_format(last_update);
let the_result = {};
the_result.last_update = last_update;
the_result.confirmed = confirmed;
return JSON.stringify(the_result);
} catch (err) {
console.log(err);
}
};
const max_deaths = async () => {
try {
const result = await axios.get(url_deaths);
let the_cases = result.data.cases;
let length_of_cases = the_cases.length;
let today = length_of_cases - 1;
let todays_cases = the_cases[today];
let last_update = todays_cases["date"];
last_update = date_format(last_update);
let i = 0;
let date_array = [];
let num_array = [];
for (i = 0; i < length_of_cases; i++) {
let death_date = the_cases[i]["date"];
let death_num = the_cases[i]["deaths"];
date_array.push(death_date);
num_array.push(death_num);
}
let j = 0;
let day_deaths = [];
for (j = 0; j < num_array.length; j++) {
the_last_number = num_array[j];
the_previous_number = num_array[j - 1];
let the_new_number = the_last_number - the_previous_number;
day_deaths.push(the_new_number);
}
day_deaths = day_deaths.filter(function (value) {
return !Number.isNaN(value);
});
let max = Math.max(...day_deaths);
let index = day_deaths.indexOf(max);
let date_max = date_array[index + 1];
date_max = date_format(date_max);
let the_result = {};
the_result.last_update = last_update;
the_result.max = max;
the_result.max_date = date_max;
return JSON.stringify(the_result);
} catch (err) {
console.log(err);
}
};
const vaccs_call = async () => {
try {
const result = await axios.get(url_vaccinations);
let the_vaccinations = result.data;
let total = the_vaccinations["total-vaccinations"];
let total_vaccinations = total.totalvaccinations;
let last_update = total.updated;
last_update = date_format(last_update);
let the_result = {};
the_result.last_update = last_update;
the_result.vaccinations = total_vaccinations;
return JSON.stringify(the_result);
} catch (err) {
console.log(err);
}
};
const deaths_call = async () => {
try {
const result = await axios.get(url_deaths);
let the_cases = result.data.cases;
let length_of_cases = the_cases.length;
let today = length_of_cases - 1;
let todays_cases = the_cases[today];
let deaths = todays_cases["deaths"];
let last_update = todays_cases["date"];
last_update = date_format(last_update);
let the_result = {};
the_result.last_update = last_update;
the_result.deaths = deaths;
return JSON.stringify(the_result);
} catch (err) {
console.log(err);
}
};
const ic_call = async () => {
try {
const result = await axios.get(url_entatiki);
let the_cases = result.data.cases;
let length_of_cases = the_cases.length;
let today = length_of_cases - 1;
let todays_cases = the_cases[today];
let ic = todays_cases["intensive_care"];
let last_update = todays_cases["date"];
last_update = date_format(last_update);
let the_result = {};
the_result.last_update = last_update;
the_result.ic = ic;
return JSON.stringify(the_result);
} catch (err) {
console.log(err);
}
};
const tests_call = async () => {
try {
const result = await axios.get(url_tests);
let the_cases = result.data.total_tests;
let length_of_cases = the_cases.length;
let today = length_of_cases - 1;
let todays_cases = the_cases[today];
let last_update = todays_cases["date"];
let rapids = todays_cases["rapid-tests"];
let the_tests = todays_cases["tests"];
let total_tests = rapids + the_tests;
last_update = date_format(last_update);
let the_result = {};
the_result.last_update = last_update;
the_result.rapids = rapids;
the_result.the_tests = the_tests;
the_result.total_tests = total_tests;
return JSON.stringify(the_result);
} catch (err) {
console.log(err);
}
};
const age_call = async () => {
try {
const result = await axios.get(url_age);
let the_cases = result.data.age_distribution;
let last_update = the_cases.updated;
last_update = date_format(last_update);
let average = the_cases.age_average;
let average_death = the_cases.average_death_age;
let total_age_groups = the_cases.total_age_groups;
let the_result = {};
the_result.last_update = last_update;
the_result.average = average;
the_result.average_death = average_death;
the_result.total_age_groups = total_age_groups;
return JSON.stringify(the_result);
} catch (err) {
console.log(err);
}
};
const levels = async () => {
try {
const result = await axios.get(url_risklevels);
let the_cases = result.data.risk_levels;
let last_update = the_cases.last_updated;
last_update = date_format(last_update);
let regions = the_cases.region;
let attica = regions.Attica;
let centralgreece = regions.Central_Greece;
let centralmac = regions.Central_Macedonia;
let crete = regions.Crete;
let eastern = regions.Eastern_Macedonia_and_Thrace;
let epirus = regions.Epirus;
let aegean = regions.North_Aegean;
let peloponissos = regions.Peloponnese;
let s_aegean = regions.South_Aegean;
let thessaly = regions.Thessaly;
let western_greece = regions.Western_Greece;
let western_macedonia = regions.Western_Macedonia;
let the_result = {};
the_result.last_update = last_update;
the_result.attica = attica;
the_result.centralgreece = centralgreece;
the_result.centralmac = centralmac;
the_result.crete = crete;
the_result.eastern = eastern;
the_result.epirus = epirus;
the_result.aegean = aegean;
the_result.peloponissos = peloponissos;
the_result.s_aegean = s_aegean;
the_result.thessaly = thessaly;
the_result.western_greece = western_greece;
the_result.western_macedonia = western_macedonia;
return JSON.stringify(the_result);
} catch (err) {
console.log(err);
}
};
function risk_level_switch(risk_level) {
switch (risk_level) {
case "A":
risk_level = "Επίπεδο 1";
break;
case "B":
risk_level = "Επίπεδο 2";
break;
case "C":
risk_level = "Επίπεδο 3";
break;
case "D":
risk_level = "Επίπεδο 4";
break;
}
return risk_level;
}
client.on("message", async (msg) => {
switch (msg.content) {
case "!covidhelp":
const help_embed = new Discord.MessageEmbed()
.setColor("#2f3136")
.setTitle("CovidGR-Bot Commands")
.addFields(
{ name: "Bot Commands", value: "!covidhelp" },
{
name: "Έλεγχος εγκυρότητας πιστοποιητικού εμβολιασμού",
value: "!validate",
},
{ name: "Ραντεβού εμβολιασμού", value: "!emvolio" },
{ name: "3 τελευταία νέα για τον ιό στην Ελλάδα", value: "!news" },
{ name: "Περισσότερα για μένα", value: "!about" },
{ name: "Κρούσματα", value: "!cases" },
{ name: "Θανάτοι", value: "!deaths" },
{ name: "Διασωληνομένοι", value: "!ic" },
{ name: "Εμβολιασμοί", value: "!vaccs" },
{ name: "Tests", value: "!tests" },
{ name: "Ηλικιακά δεδομένα", value: "!age" },
{ name: "Μέγιστος αριθμός θανάτων ανά ημέρα", value: "!maxdeaths" },
{
name: "Δείκτης θετικότητας ελέγχων ανά περιφέρεια",
value: "!risklevels",
}
)
.setFooter("Για οποιαδήποτε απορια στείλε στον gioiliop7#9306");
msg.channel.send({ embeds: [help_embed] });
break;
case "!validate":
msg.channel.send(
"Δώσε την ημερομηνία που ολοκλήρωσες τον εμβολιασμό σου στη μορφή 'ΗΗ-ΜΜ-ΕΕΕΕ' ή στη μορφή 'ΗΗ/ΜΜ/ΕΕΕΕ'"
);
const collector = new Discord.MessageCollector(
msg.channel,
(m) => m.author.id === msg.author.id || m.author.id === guest.id,
{
time: 1000,
max: 1,
maxMatches: 100,
}
);
collector.on("collect", (m) => {
var today = new Date();
var myDate = m.content;
if (myDate.includes(".")) {
m.channel.send(
"Δεν έδωσες έγκυρη μορφή ημερομηνίας,παρακαλώ ξαναπροσπάθησε με το command !validate"
);
collector.stop();
return;
}
if (myDate.includes("/")) {
myDate = myDate.split("/");
} else {
myDate = myDate.split("-");
}
day_given = myDate[0];
month_given = myDate[1];
year_given = myDate[2];
day_parsed = parseInt(day_given);
month_parsed = parseInt(month_given);
year_parsed = parseInt(year_given);
if (
(day_given > 31 && m.author.id === m.author.id) ||
(month_given > 12 && m.author.id === m.author.id)
) {
m.channel.send(
"Δεν έδωσες έγκυρη ημερομηνία,παρακαλώ ξαναπροσπάθησε με το command !validate"
);
collector.stop();
return;
}
if (
(year_given < 2020 && m.author.id === m.author.id) ||
(year_given == 2020 &&
month_given < 12 &&
m.author.id === m.author.id)
) {
m.channel.send(
"Δεν είχαν ξεκινήσει οι εμβολιασμοί την δωθέσα ημερομηνία,παρακαλώ ξαναπροσπάθησε με το command !validate"
);
collector.stop();
return;
}
var newDate = new Date(myDate[2], myDate[1] - 1, myDate[0]);
var newDate = newDate.getTime(); // Give that from user
var today_date = new Date();
var dd = String(today_date.getDate()).padStart(2, "0");
var mm = String(today_date.getMonth() + 1).padStart(2, "0");
var yyyy = today_date.getFullYear();
today_date = dd + "-" + mm + "-" + yyyy;
today_date = today_date.split("-");
today_date = new Date(today_date[2], today_date[1] - 1, today_date[0]);
today_date = today_date.getTime();
if (today_date < newDate) {
m.channel.send(
"Έδωσες μεταγενέστερη ημερομηνία,παρακαλώ ξαναπροσπάθησε με το command !validate"
);
collector.stop();
return;
}
fourteen_days = today.setDate(today.getDate() - 14);
if (newDate <= fourteen_days && m.author.id === m.author.id) {
m.channel.send("Έχεις έγκυρο πιστοποιητικό");
m.react("✅");
collector.stop();
} else if (newDate > fourteen_days) {
m.channel.send("Δεν έχεις έγκυρο πιστοποιητικό");
m.react("❌");
collector.stop();
}
});
break;
case "!emvolio":
msg.reply(
"Δες περισσότερες πληροφορίες για το εμβόλιο στο https://emvolio.gov.gr/"
);
break;
case "!certficate":
msg.reply(
"Βγάλε το Ευρωπαϊκό ψηφιακό COVID-19 πιστοποιητικό στο https://www.gov.gr/ipiresies/ugeia-kai-pronoia/koronoios-covid-19/greencertificate"
);
break;
case "!about":
msg.reply(
"Created with 😊 by gioiliop7. Βρές το source code του bot στο https://github.com/gioiliop7/CovidGR-DiscordBot"
);
break;
case "!cases":
const todays_cases = await cases();
const resultjson = await JSON.parse(todays_cases);
let update_in = resultjson.last_update;
let cases_num = resultjson.confirmed;
const embed = new Discord.MessageEmbed()
.setColor("#faed93")
.setTitle("Συνολικά κρούσματα: " + cases_num)
.setAuthor(
"Επίσημα δεδομένα κυβέρνησης covid",
"https://upload.wikimedia.org/wikipedia/commons/8/82/SARS-CoV-2_without_background.png",
"https://covid19.gov.gr/"
)
.setFooter("Τελευταία ενημέρωση δεδομένων - " + update_in);
msg.channel.send({ embeds: [embed] });
break;
case "!deaths":
const todays_deaths = await deaths_call();
const deathsresultjson = await JSON.parse(todays_deaths);
let deaths_update_in = deathsresultjson.last_update;
let deaths_num = deathsresultjson.deaths;
const deaths_embed = new Discord.MessageEmbed()
.setColor("#ce3423")
.setTitle("Συνολικοί θανάτοι: " + deaths_num)
.setAuthor(
"Επίσημα δεδομένα κυβέρνησης covid",
"https://upload.wikimedia.org/wikipedia/commons/8/82/SARS-CoV-2_without_background.png",
"https://covid19.gov.gr/"
)
.setFooter("Τελευταία ενημέρωση δεδομένων - " + deaths_update_in);
msg.channel.send({ embeds: [deaths_embed] });
break;
case "!maxdeaths":
const max_deaths_result = await max_deaths();
const maxdeathsresultjson = await JSON.parse(max_deaths_result);
let maxdeaths_update_in = maxdeathsresultjson.last_update;
let maxdeaths_num = maxdeathsresultjson.max;
let maxdeaths_date = maxdeathsresultjson.max_date;
const max_deaths_embed = new Discord.MessageEmbed()
.setColor("#712735")
.setTitle("Μέγιστος αριθμός θανάτων ανά ημέρα: " + maxdeaths_num)
.addFields({ name: "Ημερομηνία", value: `${maxdeaths_date}` })
.setAuthor(
"Επίσημα δεδομένα κυβέρνησης covid",
"https://upload.wikimedia.org/wikipedia/commons/8/82/SARS-CoV-2_without_background.png",
"https://covid19.gov.gr/"
)
.setFooter("Τελευταία ενημέρωση δεδομένων - " + maxdeaths_update_in);
msg.channel.send({ embeds: [max_deaths_embed] });
break;
case "!ic":
const todays_ic = await ic_call();
const icresultjson = await JSON.parse(todays_ic);
let ic_update_in = icresultjson.last_update;
let ic_num = icresultjson.ic;
const ic_embed = new Discord.MessageEmbed()
.setColor("#ffc522")
.setTitle("Διασωληνομένοι: " + ic_num)
.setAuthor(
"Επίσημα δεδομένα κυβέρνησης covid",
"https://upload.wikimedia.org/wikipedia/commons/8/82/SARS-CoV-2_without_background.png",
"https://covid19.gov.gr/"
)
.setFooter("Τελευταία ενημέρωση δεδομένων - " + ic_update_in);
msg.channel.send({ embeds: [ic_embed] });
break;
case "!vaccs":
const todays_vaccs = await vaccs_call();
const vaccsresultjson = await JSON.parse(todays_vaccs);
let vaccs_update_in = vaccsresultjson.last_update;
let vaccs_num = vaccsresultjson.vaccinations;
const vaccs_embed = new Discord.MessageEmbed()
.setColor("#84c77a")
.setTitle("Συνολικοί εμβολιασμοί: " + vaccs_num)
.setAuthor(
"Επίσημα δεδομένα κυβέρνησης covid",
"https://upload.wikimedia.org/wikipedia/commons/8/82/SARS-CoV-2_without_background.png",
"https://covid19.gov.gr/"
)
.setFooter("Τελευταία ενημέρωση δεδομένων - " + vaccs_update_in);
msg.channel.send({ embeds: [vaccs_embed] });
break;
case "!tests":
const todays_tests = await tests_call();
const testsresultjson = await JSON.parse(todays_tests);
let tests_update_in = testsresultjson.last_update;
let rapids_num = testsresultjson.rapids;
let moriaka = testsresultjson.the_tests;
let total_tests = testsresultjson.total_tests;
const tests_embed = new Discord.MessageEmbed()
.setColor("#00aeef")
.setTitle("Συνολικά tests: " + total_tests)
.addFields(
{ name: "Μοριακά:", value: "" + moriaka, inline: true },
{ name: "Rapid:", value: "" + rapids_num, inline: true }
)
.setAuthor(
"Επίσημα δεδομένα κυβέρνησης covid",
"https://upload.wikimedia.org/wikipedia/commons/8/82/SARS-CoV-2_without_background.png",
"https://covid19.gov.gr/"
)
.setFooter("Τελευταία ενημέρωση δεδομένων - " + tests_update_in);
msg.channel.send({ embeds: [tests_embed] });
break;
case "!age":
const todays_age_ds = await age_call();
const ageresultjson = await JSON.parse(todays_age_ds);
let age_update_in = ageresultjson.last_update;
let age_average = ageresultjson.average;
let age_average_death = ageresultjson.average_death;
let age_groups = ageresultjson.total_age_groups;
let age_groups_cases = age_groups.cases;
let age_groups_critical = age_groups.critical;
let age_groups_deaths = age_groups.deaths;
let cases0 = age_groups_cases["0-17"];
let critical0 = age_groups_critical["0-17"];
let deaths0 = age_groups_deaths["0-17"];
let cases18 = age_groups_cases["18-39"];
let critical18 = age_groups_critical["18-39"];
let deaths18 = age_groups_deaths["18-39"];
let cases40 = age_groups_cases["40-64"];
let critical40 = age_groups_critical["40-64"];
let deaths40 = age_groups_deaths["40-64"];
let cases65 = age_groups_cases["65+"];
let critical65 = age_groups_critical["65+"];
let deaths65 = age_groups_deaths["65+"];
const total_age_embed = new Discord.MessageEmbed()
.setColor("#cacaca")
.setTitle("Ηλικιακά δεδομένα")
.addFields(
{ name: "Mέσος όρος ηλικίας", value: "" + age_average, inline: true },
{
name: "Μέσος όρος ηλικίας θανάτου",
value: "" + age_average_death,
inline: true,
}
)
.setAuthor(
"Επίσημα δεδομένα κυβέρνησης covid",
"https://upload.wikimedia.org/wikipedia/commons/8/82/SARS-CoV-2_without_background.png",
"https://covid19.gov.gr/"
)
.setFooter("Τελευταία ενημέρωση δεδομένων - " + age_update_in);
const zero_embed = new Discord.MessageEmbed()
.setColor("#06306a")
.setTitle("Ηλικιακά δεδομένα 0-17")
.addFields(
{ name: "Κρούσματα", value: "" + cases0, inline: true },
{
name: "Σε κρίσιμη κατάσταση",
value: "" + critical0,
inline: true,
},
{
name: "Θάνατοι",
value: "" + deaths0,
inline: true,
}
)
.setAuthor(
"Επίσημα δεδομένα κυβέρνησης covid",
"https://upload.wikimedia.org/wikipedia/commons/8/82/SARS-CoV-2_without_background.png",
"https://covid19.gov.gr/"
)
.setFooter("Τελευταία ενημέρωση δεδομένων - " + age_update_in);
const eighteen_embed = new Discord.MessageEmbed()
.setColor("#9c2424")
.setTitle("Ηλικιακά δεδομένα 18-39")
.addFields(
{ name: "Κρούσματα", value: "" + cases18, inline: true },
{
name: "Σε κρίσιμη κατάσταση",
value: "" + critical18,
inline: true,
},
{
name: "Θάνατοι",
value: "" + deaths18,
inline: true,
}
)
.setAuthor(
"Επίσημα δεδομένα κυβέρνησης covid",
"https://upload.wikimedia.org/wikipedia/commons/8/82/SARS-CoV-2_without_background.png",
"https://covid19.gov.gr/"
)
.setFooter("Τελευταία ενημέρωση δεδομένων - " + age_update_in);
const fourty_embed = new Discord.MessageEmbed()
.setColor("#edd5ca")
.setTitle("Ηλικιακά δεδομένα 40-64")
.addFields(
{ name: "Κρούσματα", value: "" + cases40, inline: true },
{
name: "Σε κρίσιμη κατάσταση",
value: "" + critical40,
inline: true,
},
{
name: "Θάνατοι",
value: "" + deaths40,
inline: true,
}
)
.setAuthor(
"Επίσημα δεδομένα κυβέρνησης covid",
"https://upload.wikimedia.org/wikipedia/commons/8/82/SARS-CoV-2_without_background.png",
"https://covid19.gov.gr/"
)
.setFooter("Τελευταία ενημέρωση δεδομένων - " + age_update_in);
const sixtyfive_embed = new Discord.MessageEmbed()
.setColor("#8e8e8f")
.setTitle("Ηλικιακά δεδομένα 65+")
.addFields(
{ name: "Κρούσματα", value: "" + cases65, inline: true },
{
name: "Σε κρίσιμη κατάσταση",
value: "" + critical65,
inline: true,
},
{
name: "Θάνατοι",
value: "" + deaths65,
inline: true,
}
)
.setAuthor(
"Επίσημα δεδομένα κυβέρνησης covid",
"https://upload.wikimedia.org/wikipedia/commons/8/82/SARS-CoV-2_without_background.png",
"https://covid19.gov.gr/"
)
.setFooter("Τελευταία ενημέρωση δεδομένων - " + age_update_in);
msg.channel.send({
embeds: [
total_age_embed,
zero_embed,
eighteen_embed,
fourty_embed,
sixtyfive_embed,
],
});
break;
case "!news":
let news = await googleNewsAPI.getNews(
googleNewsAPI.SEARCH,
"κορονοιοσ ελλαδα",
"el-GR"
);
let items = news.items;
length = items.length;
i = 0;
for (i = 0; i < 3; i++) {
let last_item = items[i];
// let random_item = items[Math.floor(Math.random()*items.length)];
let last_item_title = last_item.title;
let last_item_link = last_item.link;
let last_item_date = last_item.pubDate;
last_item_date = date_format(last_item_date);
let publisher = last_item.source.text;
const newsEmbed = new Discord.MessageEmbed()
.setColor("#379c6f")
.setTitle("" + last_item_title)
.setURL("" + last_item_link)
.setFooter("Δημοσιέυθηκε - " + publisher + " - " + last_item_date);
msg.channel.send({
embeds: [newsEmbed],
});
}
break;
case "!risklevels":
const todays_risks = await levels();
const risksresultjson = await JSON.parse(todays_risks);
let risks_update_in = risksresultjson.last_update;
let attica_data = risksresultjson.attica;
let centralgreece_data = risksresultjson.centralgreece;
let centralmac_data = risksresultjson.centralmac;
let crete_data = risksresultjson.crete;
let eastern_data = risksresultjson.eastern;
let epirus_data = risksresultjson.epirus;
let aegean_data = risksresultjson.aegean;
let pelo_data = risksresultjson.peloponissos;
let s_aegean_data = risksresultjson.s_aegean;
let thessaly_data = risksresultjson.thessaly;
let western_greece_data = risksresultjson.western_greece;
let western_macedonia_data = risksresultjson.western_macedonia;
let centralmac_items = [];
centralmac_data.forEach((element) => {
let ru_cm = element["regional_unit"];
let risk_level_cm = element["risk_level"];
switch (ru_cm) {
case "Chalkidiki":
ru_cm = "Χαλκιδική";
break;
case "Imathia":
ru_cm = "Ιμαθία";
break;
case "Kilkis":
ru_cm = "Κιλκίς";
break;
case "Pella":
ru_cm = "Πέλλα";
break;
case "Pieria":
ru_cm = "Πιερία";
break;
case "Serres":
ru_cm = "Σέρρες";
break;
case "Thessaloniki":
ru_cm = "Θεσσαλονίκη";
break;
}
risk_level_cm = risk_level_switch(risk_level_cm);
centralmac_items.push({ ru_cm, risk_level_cm });
});
let centralgreece_items = [];
centralgreece_data.forEach((element) => {
let ru_cg = element["regional_unit"];
let risk_level_cg = element["risk_level"];
switch (ru_cg) {
case "Boeotia":
ru_cg = "Βοιωτία";
break;
case "Euboea":
ru_cg = "Εύβοια";
break;
case "Evrytania":
ru_cg = "Ευρτανία";
break;
case "Phocis":
ru_cg = "Φωκίδα";
break;
case "Phthiotis":
ru_cg = "Φθιώτιδα";
break;
}
risk_level_cg = risk_level_switch(risk_level_cg);
centralgreece_items.push({ ru_cg, risk_level_cg });
});
let attica_items = [];
attica_data.forEach((element) => {
let ru_attica = element["regional_unit"];
let risk_level_attica = element["risk_level"];
switch (ru_attica) {
case "Central_Athens":
ru_attica = "Κεντρική Αθήνα";
break;
case "East_Attica":
ru_attica = "Ανατολική αττική";
break;
case "Islands":
ru_attica = "Νησιά Αττικής";
break;
case "North_Athens":
ru_attica = "Βόρεια Αθήνα";
break;
case "Piraeus":
ru_attica = "Πειραιάς";
break;
case "South_Athens":
ru_attica = "Νότια Αθήνα";
break;
case "West_Athens":
ru_attica = "Δυτική Αθήνα";
break;
case "West_Attica":
ru_attica = "Δυτική Αττική";
break;
}
risk_level_attica = risk_level_switch(risk_level_attica);
attica_items.push({ ru_attica, risk_level_attica });
});
let crete_items = [];
crete_data.forEach((element) => {
let ru_crete = element["regional_unit"];
let risk_level_crete = element["risk_level"];
switch (ru_crete) {
case "Chania":
ru_crete = "Χανιά";
break;
case "Rethymno":
ru_crete = "Ρέθυμνο";
break;
case "Heraklion":
ru_crete = "Ηράκλειο";
break;
case "Lasithi":
ru_crete = "Λασίθι";
break;
}
risk_level_crete = risk_level_switch(risk_level_crete);
crete_items.push({ ru_crete, risk_level_crete });
});
let eastern_items = [];
eastern_data.forEach((element) => {
let ru_eastern = element["regional_unit"];
let risk_level_eastern = element["risk_level"];
switch (ru_eastern) {
case "Drama":
ru_eastern = "Δράμα";
break;
case "Evros":
ru_eastern = "Έβρος";
break;
case "Kavala":
ru_eastern = "Καβάλα";
break;
case "Rhodope":
ru_eastern = "Ροδόπη";
break;
case "Thasos":
ru_eastern = "Θάσος";
break;
case "Xanthi":
ru_eastern = "Ξάνθη";
break;
}
risk_level_eastern = risk_level_switch(risk_level_eastern);
eastern_items.push({ ru_eastern, risk_level_eastern });
});
let epirus_items = [];
epirus_data.forEach((element) => {
let ru_epirus = element["regional_unit"];
let risk_level_epirus = element["risk_level"];
switch (ru_epirus) {
case "Arta":
ru_epirus = "Άρτα";
break;
case "Ioannina":
ru_epirus = "Ιωάννινα";
break;
case "Preveza":
ru_epirus = "Πρέβεζα";
break;
case "Thesprotia":
ru_epirus = "Θεσπρωτία";
break;
}
risk_level_epirus = risk_level_switch(risk_level_epirus);
epirus_items.push({ ru_epirus, risk_level_epirus });
});
let aegean_items = [];
aegean_data.forEach((element) => {
let ru_aegean = element["regional_unit"];
let risk_level_aegean = element["risk_level"];
switch (ru_aegean) {
case "Chios":
ru_aegean = "Χίος";
break;
case "Ikaria":
ru_aegean = "Ικαρία";
break;
case "Lemnos":
ru_aegean = "Λήμνος";
break;
case "Lesbos":
ru_aegean = "Λέσβος";
break;
case "Samos":
ru_aegean = "Σάμος";
break;
}
risk_level_aegean = risk_level_switch(risk_level_aegean);
aegean_items.push({ ru_aegean, risk_level_aegean });
});
let pelo_items = [];
pelo_data.forEach((element) => {
let ru_pelo = element["regional_unit"];
let risk_level_pelo = element["risk_level"];
switch (ru_pelo) {
case "Arcadia":
ru_pelo = "Αρκαδία";
break;
case "Argolis":
ru_pelo = "Αργολίδα";
break;
case "Corinthia":
ru_pelo = "Κορινθία";
break;
case "Laconia":
ru_pelo = "Λακωνία";
break;
case "Messenia":
ru_pelo = "Μεσσηνία";
break;
}
risk_level_pelo = risk_level_switch(risk_level_pelo);
pelo_items.push({ ru_pelo, risk_level_pelo });
});
let s_aegean_items = [];
s_aegean_data.forEach((element) => {
let ru_s_aegean = element["regional_unit"];
let risk_level_s_aegean = element["risk_level"];
switch (ru_s_aegean) {
case "Andros":
ru_s_aegean = "Άνδρος";
break;
case "Kalymnos":
ru_s_aegean = "Κάλυμνος";
break;
case "Karpathos":
ru_s_aegean = "Κάρπαθος";
break;
case "Kea-Kythnos":
ru_s_aegean = "Κέα - Κύθνος";
break;
case "Kos":
ru_s_aegean = "Κως";
break;
case "Milos":
ru_s_aegean = "Μήλος";
break;
case "Mykonos":
ru_s_aegean = "Μύκονος";
break;
case "Naxos":
ru_s_aegean = "Νάξος";
break;
case "Paros":
ru_s_aegean = "Πάρος";
break;
case "Rhodes":
ru_s_aegean = "Ρόδος";
break;
case "Syros":
ru_s_aegean = "Σύρος";
break;
case "Thira":
ru_s_aegean = "Θήρα";
break;
case "Tinos":
ru_s_aegean = "Τήνος";
break;
}
risk_level_s_aegean = risk_level_switch(risk_level_s_aegean);
s_aegean_items.push({ ru_s_aegean, risk_level_s_aegean });
});
let thessaly_items = [];
thessaly_data.forEach((element) => {
let ru_thessaly = element["regional_unit"];
let risk_level_thessaly = element["risk_level"];
switch (ru_thessaly) {
case "Karditsa":
ru_thessaly = "Καρδίτσα";
break;
case "Larissa":
ru_thessaly = "Λάρισα";
break;
case "Magnesia":
ru_thessaly = "Μαγνησία";
break;
case "Sporades":
ru_thessaly = "Σποράδες";
break;
case "Trikala":
ru_thessaly = "Τρίκαλα";
break;
}
risk_level_thessaly = risk_level_switch(risk_level_thessaly);
thessaly_items.push({ ru_thessaly, risk_level_thessaly });
});
let western_greece_items = [];
western_greece_data.forEach((element) => {
let ru_western_greece = element["regional_unit"];
let risk_level_western_greece = element["risk_level"];
switch (ru_western_greece) {
case "Aetolia-Acarnania":
ru_western_greece = "Αιτωλοακαρνανία";
break;
case "Achaea":
ru_western_greece = "Αχαΐα";
break;
case "Elis":
ru_western_greece = "Ηλεία";
break;
}
risk_level_western_greece = risk_level_switch(
risk_level_western_greece
);
western_greece_items.push({
ru_western_greece,
risk_level_western_greece,
});
});
let western_macedonia_items = [];
western_macedonia_data.forEach((element) => {
let ru_western_macedonia = element["regional_unit"];
let risk_level_western_macedonia = element["risk_level"];
switch (ru_western_macedonia) {
case "Florina":
ru_western_macedonia = "Φλώρινα";
break;
case "Grevena":
ru_western_macedonia = "Γρεβενά";