-
Notifications
You must be signed in to change notification settings - Fork 1
/
slack-notification.js
48 lines (41 loc) · 1.25 KB
/
slack-notification.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
45
46
47
48
const async = require('async')
const Slack = require('node-slack');
const config = require('./config.json')
const moment = require('moment')
const bluebird = require('bluebird')
const redis = require("redis")
bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);
const client = redis.createClient(config.redis_port)
notify = (stats) => {
async.parallel([() => {
const slack = new Slack(config.slack_hook_url);
slack.send({
text: stats,
channel: '#game-stats',
username: 'Crazy Particles Statistics',
icon_emoji: ":ghost:"
});
}])
}
const schedule = require('node-schedule')
schedule.scheduleJob('0 16 * * *', () => {
client.keysAsync('user:*').then(data => {
let all = client.multi()
for (let i = 0; i < data.length; i++) {
all.hgetall(data[i])
}
all.execAsync().then(res => {
let not_played = 0
for (let i = 0; i < res.length; i++) {
if(res[i]['played_count']==='0') ++not_played;
}
let last_user = 'Last user ' + res.length + ' registered ' + moment(res[res.length-1]['registered'].replace(' (CEST)',''), 'ddd MMM DD YYYY HH:mm:ss').fromNow()
let msg = [
'Users never played: ' + not_played,
last_user,
].join("\n");
notify(msg)
})
})
})