forked from Keiaxx/covid-cases-discordbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcovidsourcerunner.js
49 lines (32 loc) · 1.06 KB
/
covidsourcerunner.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
const CovidSources = require('./covidsource').CovidSources
const sources = new CovidSources()
const sourceRefreshSeconds = 60
let latestCachedData = []
async function loadSourceData(){
const latestData = await sources.loadAll()
latestCachedData = latestData
}
const Discord = require('discord.js');
const client = new Discord.Client();
const config = require('./config')
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === config.prefix + "cases") {
latestCachedData.forEach(location => {
msg.reply('There are '+location.total+' cases in '+location.name+' as of '+location.lastUpdated);
})
console.log(latestCachedData)
}
});
client.login(config.bot_token);
// 1 minute event loop for covidsource refresh
setTimeout(function doSomething() {
console.log('Refreshing COVID source data')
loadSourceData()
setTimeout(doSomething, sourceRefreshSeconds * 1000)
}, sourceRefreshSeconds * 1000);
// Initial load
loadSourceData()
module.exports = {latestCachedData}