forked from HackingTV/DefectorBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (26 loc) · 868 Bytes
/
index.js
File metadata and controls
34 lines (26 loc) · 868 Bytes
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
require('dotenv').config()
const bot = require('./bot')
const server = require('./server')
const CronJob = require('cron').CronJob;
const api = require('./api')
const logger = require('./logger')
const updateDatabase = async () => {
let followers = await api.getUsersFromFollowers()
let users = followers.map(user => ({
id: user.id,
username: user.display_name
}))
let result = users.map(user => api.saveUser(user))
return true
}
const init = async () => (
await Promise.all([api.subscribeToFollowerHook(), updateDatabase()])
)
const cronJobFunc = async () => {
logger.info('cronjob is running')
let defectors = await api.getDefectors
defectors.map(defector => api.saveDefector(defector))
await init()
}
const job = new CronJob('00 00 23 * * *', cronJobFunc, () => logger.error('cron job failed'), true, 'America/Toronto')
// init()