This repository has been archived by the owner on Jul 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
67 lines (61 loc) · 1.88 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict';
const config = require('./config');
const { Master: Sharder } = require('eris-sharder');
const axios = require('axios');
const log = require('./util/modules/log');
const r = process.argv.includes('--no-db') ? false : require('rethinkdbdash')({
servers: [
{ host: config.database.host, port: config.database.port }
],
silent: true,
log: (message) => {
log.info(message);
}
});
const master = new Sharder(config.token, '/main.js', {
stats: true,
name: 'Yuuri',
clientOptions: {
disableEvents: {
TYPING_START: true
},
messageLimit: 25,
defaultImageSize: 2048,
},
guildsPerShards: 1750,
debug: true,
shards: 1,
clusters: 1
});
master.on('stats', res => {
if (r) {
r.db('data').table('stats')
.insert({ id: 1, stats: res }, { conflict: 'update' })
.run();
}
master.broadcast(1, { type: 'statsUpdate', data: res });
});
if (require('cluster').isMaster) {
if (r) {
setInterval(async() => {
const { stats: { guilds } } = await r.db('data').table('stats')
.get(1)
.run();
for (const botList in config.botLists) {
if (botList.token) {
axios({
method: 'post',
url: botList.url,
data: { server_count: guilds },
headers: { 'Authorization': botList.token, 'Content-Type': 'application/json' },
timeout: 15000
}).then(() => {
log.info(`Successfully posted guild stats to ${botList}`);
}).catch(err => {
log.error(`Failed to post guild stats to ${botList}: ${err}`);
});
}
}
}, 3600000);
}
}