forked from Zepsey/discord-covid-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (30 loc) · 1017 Bytes
/
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
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
const axios = require('axios');
const countries = require("./countries.json");
const url = 'https://api.covid19api.com/total/country/';
const WAKE_COMMAND = '!cases';
client.on('message', async (msg) => {
const content = msg.content.split(/[ ,]+/);
if(content[0] === WAKE_COMMAND){
if(content.length > 2){
msg.reply("Too many arguments...")
}
else if(content.length === 1){
msg.reply("Not enough arguments")
}
else if(!countries[content[1]]){
msg.reply("Wrong country format")
}
else{
const slug = content[1]
const payload = await axios.get(`${url}${slug}`)
const covidData = payload.data.pop();
msg.reply(`Confirmed: ${covidData.Confirmed}, Deaths: ${covidData.Deaths}, Recovered: ${covidData.Recovered}, Active: ${covidData.Active} `)
}
}
});
client.login('token');