forked from ParadoxalCorp/felix-production
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
100 lines (94 loc) · 3.51 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const config = require('./config');
const { Master: Sharder } = require('eris-sharder');
const axios = require('axios').default;
const log = require('./utils/log');
const r = process.argv.includes('--no-db') ? false : require('rethinkdbdash')({
servers: [
{ host: config.database.host, port: config.database.port }
],
silent: true
});
process.on('beforeExit', () => {
setTimeout(() => {
process.exit();
}, 10000);
});
process.on('SIGINT', () => {
setTimeout(() => {
process.exit();
}, 10000);
});
const master = new Sharder(config.token, '/main.js', {
stats: true,
name: 'Felix',
clientOptions: {
disableEvents: {
TYPING_START: true
},
messageLimit: 0,
defaultImageSize: 1024,
},
guildsPerShards: config.process.guildsPerShards,
debug: config.process.debug,
shards: config.process.shards,
clusters: config.process.clusters
});
master.on('stats', res => {
if (r) {
r.db(config.database.database).table('stats')
.insert({ id: 1, stats: res }, { conflict: 'update' })
.run();
}
master.broadcast(1, { type: 'statsUpdate', data: res });
});
if (require('cluster').isMaster) {
if (r) {
const postGuilds = async() => {
const { stats } = await r.db(config.database.database).table('stats')
.get(1);
for (const botList in config.botLists) {
if (config.botLists[botList].token && !config.botLists[botList].disabled) {
axios({
method: 'POST',
url: `http://${config.proxy.host}:${config.proxy.port}/`,
data: {
data: {
server_count: stats.guilds
},
url: config.botLists[botList].url,
headers: { 'Authorization': config.botLists[botList].token, 'Content-Type': 'application/json' },
method: 'POST'
},
headers: { 'Authorization': config.proxy.auth, '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}`);
});
}
}
if (config.botLists.dbl) {
axios.post(`http://${config.proxy.host}:${config.proxy.port}/`, {
data: {
guilds: stats.guilds,
users: stats.users,
'voice_connections': stats.voice
},
url: config.botLists.dbl.url,
headers: { 'Authorization': `Bot ${config.botLists.dbl.token}`, 'Content-Type': 'application/json' },
method: 'POST'
}, {
headers: { 'Authorization': config.proxy.auth, 'Content-Type': 'application/json' },
timeout: 15000
}).then(() => {
log.info(`Successfully posted stats to DBL`);
}).catch(err => {
log.error(`Failed to post stats to DBL: ${err}`);
});
}
};
setTimeout(postGuilds, 180000);
setInterval(postGuilds, 3600000);
}
}