forked from bwpikaard/HyperCast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (36 loc) · 1.25 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
require.extensions['.txt'] = function (module, filename) { module.exports = require("fs").readFileSync(filename, 'utf8'); };
const { Collection } = require("discord.js");
const build = require("./build");
console.log(build);
const config = require(`./configs/${build}`);
const SHARD_COUNT = config.shards;
const CLIENT_TOKEN = config.token;
const Shard = require("./structures/Shard");
class ShardingMaster extends Collection {
constructor() {
super();
this.stats = [];
for (let s = 0; s < SHARD_COUNT; s++) {
setTimeout(() => this.set(s, new Shard(this, s, SHARD_COUNT, CLIENT_TOKEN, build)), (9000 * s));
}
}
broadcast(type, data) {
this.forEach(shard => {
shard.send({
type,
data
});
});
}
updateStats(shard, data) {
Object.keys(data).map(key => this.get(shard).stats[key] = data[key]);
const newData = {};
this.forEach(shard => {
Object.keys(shard.stats).forEach(key => {
newData[key] ? newData[key] += shard.stats[key] : newData[key] = shard.stats[key];
});
});
this.broadcast("stats", newData);
}
}
new ShardingMaster();