-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcovidscript_updated_1.3.0.js
More file actions
445 lines (400 loc) · 13.8 KB
/
Copy pathcovidscript_updated_1.3.0.js
File metadata and controls
445 lines (400 loc) · 13.8 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
registerPlugin({
name: 'COVID-19 Live Update',
version: '1.1',
description: 'Get latest statistics of COVID-19 (!coronavirus)',
author: 'devdanetra@outlook.com',
requiredModules: ["http"],
vars: [
{
name: "helpMessage1",
type: "string",
title: "Your custom help message (line1).",
placeholder: "[b][COVID-19 Help][/b]",
default: "[b][COVID-19 Help][/b]",
},
{
name: "helpMessage2",
type: "string",
title: "Your custom help message (line2).",
placeholder: "!coronavirus help (shows this)",
default: "!coronavirus help (shows this)",
},
{
name: "helpMessage3",
type: "string",
title: "Your custom help message (line3).",
placeholder: "!coronavirus (Global statistics)",
default: "!coronavirus (Global statistics)",
},
{
name: "helpMessage4",
type: "string",
title: "Your custom help message (line4).",
placeholder: "!coronavirus <countryname> (country statistics)",
default: "!coronavirus <countryname> (country statistics)"
},
{
name: "helpMessage5",
type: "string",
title: "Your custom help message (line5).",
placeholder: "!coronavirus map (links live map)",
default: "!coronavirus map (links live map)",
},
{
name: "globalMessage1",
type: "string",
title: "Your custom global message (line1).",
placeholder: "[b][COVID-19 Global Statistics][/b]",
default: "[b][COVID-19 Global Statistics][/b]",
},
{
name: "countryMessage1",
type: "string",
title: "Your custom country Message (line1)(You should leave an ending space, to include the country name generated by the script).",
placeholder: "",
default: "[b][COVID-19 ",
},
{
name: "countryMessage2",
type: "string",
title: "Your custom country Message (line2).",
placeholder: " Statistics][/b]",
default: " Statistics][/b]",
},
{
name: "totalInfected",
type: "string",
title: "Shows total infected.",
placeholder: "Total Infected : ",
default: "Total Infected : ",
},
{
name: "infectedToday",
type: "string",
title: "Shows infected today.",
placeholder: "Infected Today : ",
default: "Infected Today : "
},
{
name: "totalRecovered",
type: "string",
title: "Shows total Recovered.",
placeholder: "Total Recovered : ",
default: "Total Recovered : ",
},
{
name: "totalDeaths",
type: "string",
title: "Shows total Deaths.",
placeholder: "Total Deaths : ",
default: "Total Deaths : "
},
{
name: "deathsToday",
type: "string",
title: "Shows deaths today.",
placeholder: "deaths Today : ",
default: "Deaths Today : ",
},
{
name: "criticalCases",
type: "string",
title: "Shows critical cases.",
placeholder: "Critical Cases : ",
default: "Critical Cases : ",
},
{
name: "mapMessage",
type: "string",
title: "Links the map.",
placeholder: "[COVID-19 Live Map by WHO][/b]",
default: "[COVID-19 Live Map by WHO][/b]",
},
{
name: "trackGlobalSwitch",
title: 'Enable global tracking?',
type: 'select',
options: ['no', 'yes'],
default: "no",
},
{
name: "trackGlobalType",
title: 'Global Info Type?',
type: 'select',
options: ['Description', 'Channel Name', 'Both'],
default: "Description",
},
{
name: "trackGlobalChannel",
title: 'Select channel to edit for Global Tracking',
type: 'channel',
},
{
name : "trackCountrySwitch",
title: 'Enable country tracking?',
type: 'select',
options: ['no', 'yes'],
default: "no",
},
{
name : "trackCountryType",
title: 'Country Info Type?',
type: 'select',
options: ['Description', 'Channel Name', 'Both'],
default: "Description",
},
{
name: "trackCountryChannel" ,
title: 'Select channel to edit for Country Tracking',
type: 'channel',
},
{
name: "trackCountryString",
title: 'Insert tracked country (in english)',
type: 'string',
default: "italy",
},
{
name : "trackProvinceSwitch",
title: 'Enable country tracking?',
type: 'select',
options: ['no', 'yes'],
default: "no",
},
{
name : "trackProvinceType",
title: 'Country Info Type?',
type: 'select',
options: ['Description', 'Channel Name', 'Both'],
default: "Description",
},
{
name: "trackProvinceChannel" ,
title: 'Select channel to edit for Country Tracking',
type: 'channel',
},
{
name: "trackProvinceID",
title: 'Insert tracked province(get number from https://corona.lmao.ninja/v2/jhucsse)',
type: 'number',
default: "1",
},
{
name: "updateSeconds",
title: 'Insert update time in seconds',
type: 'number',
default: "120",
},
],
}, function(sinusbot, config) {
const engine = require('engine');
const store = require('store');
const backend = require('backend');
const helpers = require('helpers');
const format = require('format');
const http = require('http');
setInterval(updateChannels, config.updateSeconds *1000);
function updateChannels() { //checking to update global and country channel
if(config.trackGlobalSwitch == 1){
engine.log("Updating global Tracking channels.");
updateGlobalChannel();
}
if(config.trackCountrySwitch == 1){
engine.log("Updating country Tracking channels.");
updateCountryChannel();
}
if(config.trackProvinceSwitch == 1){
engine.log("Updating province Tracking channels.");
updateProvinceChannel();
}
return;
}
function updateCountryChannel(){ //updates country channel
var url = "https://corona.lmao.ninja/countries/" + config.trackCountryString;
http.simpleRequest({
'method': 'GET',
'url': url,
'timeout': 6000,
}, function (error, response) {
if (error) {
engine.log("Error: " + error);
return;
}
if (response.statusCode != 200) {
engine.log("HTTP Error: " + response.status);
return;
}
// success!
engine.log("Response: " + response.data);
var result = JSON.parse(response.data);
let channel = backend.getChannelByID(config.trackCountryChannel);
let newDescription = "\n "+ config.countryMessage1 + result.country + config.countryMessage2;
newDescription += "\n\n " + config.totalInfected + result.cases;
newDescription += "\n\n " + config.infectedToday + result.todayCases;
newDescription += "\n\n " + config.totalRecovered + result.recovered;
newDescription += "\n\n " + config.totalDeaths + result.deaths;
newDescription += "\n\n " + config.deathsToday + result.todayDeaths;
newDescription += "\n\n " + config.criticalCases + result.critical;
let newName = "[cspacer] "+ result.country + " | " + result.cases + " | " + result.recovered + " | " + result.deaths;
if(config.trackCountryType==0){
channel.setDescription(newDescription);
}else if (config.trackCountryType==1){
channel.setName(newName);
}else{
channel.setDescription(newDescription);
channel.setName(newName);
}
return;
})};
function updateGlobalChannel(){ //updates global channel
http.simpleRequest({
'method': 'GET',
'url': 'https://corona.lmao.ninja/all',
'timeout': 6000,
}, function (error, response) {
if (error) {
engine.log("Error: " + error);
return;
}
if (response.statusCode != 200) {
engine.log("HTTP Error: " + response.status);
return;
}
// success!
engine.log("Response: " + response.data);
var result = JSON.parse(response.data);
var channel = backend.getChannelByID(config.trackGlobalChannel);
let newDescription = "\n " + config.globalMessage1;
newDescription += "\n\n " + config.totalInfected + result.cases;
newDescription += "\n\n " + config.totalRecovered + result.recovered;
newDescription += "\n\n " + config.totalDeaths + result.deaths;
let newName = "[cspacer] " + " | " + result.cases + " | " + result.recovered + " | " + result.deaths;
if(config.trackGlobalType == 0){
channel.setDescription(newDescription);
}else if (config.trackGlobalType == 1){
channel.setName(newName);
}else{
channel.setDescription(newDescription);
channel.setName(newName);
}
return;
})};
var event = require('event');
event.on('chat', function(ev) { //chat event function
if (ev.client.isSelf())
return;
let message = ev.text.split(" ").filter(i => i.length > 0 && /\s/.test(i) === false);
let command = message[0].toLowerCase();
if(command.startsWith("!coronavirus")){
if(ev.text == "!coronavirus"){
sendResponse(ev.client);
engine.log("Command received");
}else if (ev.text == "!coronavirus help"){
printHelp(ev.client);
engine.log("Command received");
}else if (ev.text == "!coronavirus map"){
printMap(ev.client);
engine.log("Command received");
}else{
sendCountryResponse(ev.client,message[1]);
engine.log("Command received");
return;
}
return;
}});
function updateProvinceChannel(){ //updates country channel
var url = "https://corona.lmao.ninja/v2/jhucsse";
http.simpleRequest({
'method': 'GET',
'url': url,
'timeout': 6000,
}, function (error, response) {
if (error) {
engine.log("Error: " + error);
return;
}
if (response.statusCode != 200) {
engine.log("HTTP Error: " + response.status);
return;
}
// success!
var result = JSON.parse(response.data);
let channel = backend.getChannelByID(config.trackProvinceChannel);
let provinceID = config.trackProvinceID;
let customResult = result[provinceID];
let newDescription = "\n "+ config.countryMessage1 + customResult.province + config.countryMessage2;
newDescription += "\n\n " + config.totalInfected + customResult.stats.confirmed;
newDescription += "\n\n " + config.totalRecovered + customResult.stats.recovered;
newDescription += "\n\n " + config.totalDeaths + customResult.stats.deaths;
let newName = "[cspacer] "+ customResult.province + " | " + customResult.stats.confirmed + " | " + customResult.stats.recovered + " | " + customResult.stats.deaths;
if(config.trackProvinceType==0){
channel.setDescription(newDescription);
}else if (config.trackProvinceType==1){
channel.setName(newName);
}else{
channel.setDescription(newDescription);
channel.setName(newName);
}
return;
})};
function sendResponse(client){ //simple chat response (global)
http.simpleRequest({
'method': 'GET',
'url': 'https://corona.lmao.ninja/all',
'timeout': 6000,
}, function (error, response) {
if (error) {
engine.log("Error: " + error);
return;
}
if (response.statusCode != 200) {
engine.log("HTTP Error: " + response.status);
return;
}
// success!
engine.log("Response: " + response.data);
var result = JSON.parse(response.data);
client.chat("\n " + config.globalMessage1 +
"\n\n " + config.totalInfected + result.cases +
"\n\n " + config.totalRecovered + result.recovered +
"\n\n " + config.totalDeaths + result.deaths);
})};
function sendCountryResponse(client, country){ //simple chat response (country)
var url = "https://corona.lmao.ninja/countries/" + country;
http.simpleRequest({
'method': 'GET',
'url': url,
'timeout': 6000,
}, function (error, response) {
if (error) {
engine.log("Error: " + error);
return;
}
if (response.statusCode != 200) {
engine.log("HTTP Error: " + response.status);
return;
}
// success!
engine.log("Response: " + response.data);
var result = JSON.parse(response.data);
client.chat("\n "+ config.countryMessage1 + result.country + config.countryMessage2 +
"\n\n " + config.totalInfected + result.cases +
"\n\n " + config.infectedToday + result.todayCases +
"\n\n " + config.totalRecovered + result.recovered +
"\n\n " + config.totalDeaths + result.deaths +
"\n\n " + config.deathsToday + result.todayDeaths +
"\n\n " + config.criticalCases + result.critical
);
})};
function printHelp(client){ //displays help
client.chat("\n "+ config.helpMessage1 +
"\n\n " + config.helpMessage2 +
"\n\n " + config.helpMessage3 +
"\n\n " + config.helpMessage4 +
"\n\n " + config.helpMessage5);
};
function printMap(client){ //displays map link
client.chat("\n [b] " + config.mapMessage +
"\n\n [url]https://bit.ly/tscoronavirus[/url]");
};
});