-
Notifications
You must be signed in to change notification settings - Fork 4
/
bot.js
34 lines (30 loc) · 1.02 KB
/
bot.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
const {job} = require('cron');
const {get} = require('./request');
const {vs} = require('./format');
const {todayUpcoming, todaySummary} = require('./announcers');
const Match = require('./match');
const active = {};
const update = async () => {
console.log('Update start');
const matches = await get('/matches/today');
matches
.filter(matchData => matchData.status !== 'future')
.forEach(matchData => {
let current;
if (matchData.status !== 'completed') {
console.log(`Match ongoing: ${vs(matchData)}`);
active[matchData.datetime] = active[matchData.datetime] || new Match();
current = active[matchData.datetime];
} else if (active[matchData.datetime]) {
console.log(`Match complete! ${vs(matchData)}`);
current = active[matchData.datetime];
delete active[matchData.datetime];
}
if (current) {
current.update(matchData);
}
});
};
job('*/30 * * * * *', update, null, true, 'UTC');
job('0 0 7 * * *', todayUpcoming, null, true, 'UTC');
job('0 0 20 * * *', todaySummary, null, true, 'UTC');