catto.js 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Bot.js +41 -3
- package/package.json +12 -3
package/Bot.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
var nacl = require("tweetnacl");
|
|
2
2
|
var events = require("events");
|
|
3
3
|
var Discord = require("discord.js");
|
|
4
|
+
var { ClusterManager, ClusterClient, getInfo, ReClusterManager } = require("discord-hybrid-sharding");
|
|
5
|
+
var path = require("path");
|
|
4
6
|
var User = require("./User");
|
|
5
7
|
var MessageBuilder = require("./MessageBuilder");
|
|
6
8
|
var Base64 = require("./Base64");
|
|
@@ -17,12 +19,13 @@ module.exports = class extends EventEmitter {
|
|
|
17
19
|
"slashListener": !0,
|
|
18
20
|
"buttonListener": !0,
|
|
19
21
|
"publicKey": "",
|
|
20
|
-
"debug": !1
|
|
22
|
+
"debug": !1,
|
|
23
|
+
"sharded": !1
|
|
21
24
|
}, options || {});
|
|
22
25
|
if (client) {
|
|
23
26
|
this.client = client;
|
|
24
27
|
} else {
|
|
25
|
-
|
|
28
|
+
var opts = {
|
|
26
29
|
"intents": new Discord.IntentsBitField(this.options.intents),
|
|
27
30
|
"partials": [Discord.Partials.Channel, Discord.Partials.GuildMember, Discord.Partials.GuildScheduledEvent, Discord.Partials.Message, Discord.Partials.Reaction, Discord.Partials.ThreadMember, Discord.Partials.User],
|
|
28
31
|
"rest": {
|
|
@@ -33,7 +36,15 @@ module.exports = class extends EventEmitter {
|
|
|
33
36
|
"browser": "Discord Android"
|
|
34
37
|
} : {})
|
|
35
38
|
}
|
|
36
|
-
}
|
|
39
|
+
};
|
|
40
|
+
if (this.options.sharded) {
|
|
41
|
+
opts.shards = getInfo().SHARD_LIST;
|
|
42
|
+
opts.shardCount = getInfo().TOTAL_SHARDS;
|
|
43
|
+
}
|
|
44
|
+
this.client = new Discord.Client(opts);
|
|
45
|
+
if (this.options.sharded) {
|
|
46
|
+
this.cluster = new ClusterClient(this.client);
|
|
47
|
+
}
|
|
37
48
|
}
|
|
38
49
|
this.currentStatus = void 0;
|
|
39
50
|
this.buttons = new Map();
|
|
@@ -165,6 +176,15 @@ module.exports = class extends EventEmitter {
|
|
|
165
176
|
}
|
|
166
177
|
this.emit("running", { Discord });
|
|
167
178
|
});
|
|
179
|
+
this.cluster.on("ready", () => {
|
|
180
|
+
if (this.cluster.id == (this.cluster.count - 1)) {
|
|
181
|
+
this.cluster.broadcastEval(client => client.emit("_runningFull"));
|
|
182
|
+
this.emit("runningFullLast", { Discord });
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
this.client.on("_runningFull", () => {
|
|
186
|
+
this.emit("runningFull", { Discord });
|
|
187
|
+
});
|
|
168
188
|
this.client.on("interactionCreate", this.handleInteractionCreate.bind(this));
|
|
169
189
|
this.client.on("messageCreate", message => {
|
|
170
190
|
message.author = new User(message.author, this);
|
|
@@ -209,6 +229,12 @@ module.exports = class extends EventEmitter {
|
|
|
209
229
|
get servers() {
|
|
210
230
|
var r = Array.from(this.client.guilds.cache.values());
|
|
211
231
|
r.count = r.length;
|
|
232
|
+
if (this.options.sharded) {
|
|
233
|
+
return new Promise(async res => {
|
|
234
|
+
r.count = (await this.client.cluster.broadcastEval("this.guilds.cache.size")).reduce((a, b) => a + b, 0);
|
|
235
|
+
res(r);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
212
238
|
return r;
|
|
213
239
|
}
|
|
214
240
|
get channels() {
|
|
@@ -384,4 +410,16 @@ module.exports = class extends EventEmitter {
|
|
|
384
410
|
this.client.options.presence = data;
|
|
385
411
|
return this.client.user.setPresence(data);
|
|
386
412
|
}
|
|
413
|
+
static shard(file, token, type, compression) {
|
|
414
|
+
var manager = new ClusterManager(path.join(__dirname, "..", "..", file), {
|
|
415
|
+
"shardsPerClusters": compression,
|
|
416
|
+
"mode": (["worker", "process"][type - 1] || "worker"),
|
|
417
|
+
token
|
|
418
|
+
});
|
|
419
|
+
manager.extend(new ReClusterManager());
|
|
420
|
+
manager.spawn({
|
|
421
|
+
"timeout": -1
|
|
422
|
+
});
|
|
423
|
+
return manager;
|
|
424
|
+
}
|
|
387
425
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "catto.js",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Universal module for everything.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"body-parser": "^1.20.2",
|
|
46
|
+
"discord-hybrid-sharding": "^2.2.0",
|
|
46
47
|
"discord.js": "^14.15.3",
|
|
47
48
|
"ejs": "^3.1.10",
|
|
48
49
|
"express": "^4.19.2",
|
|
@@ -51,6 +52,14 @@
|
|
|
51
52
|
"node-telegram-bot-api": "^0.66.0",
|
|
52
53
|
"request": "^2.88.2",
|
|
53
54
|
"session-file-store": "^1.5.0",
|
|
54
|
-
"tweetnacl": "^1.0.3"
|
|
55
|
+
"tweetnacl": "^1.0.3",
|
|
56
|
+
"uri-js-replace": "^1.0.0",
|
|
57
|
+
"tough-cookie": "next"
|
|
58
|
+
},
|
|
59
|
+
"overrides": {
|
|
60
|
+
"uri-js": {
|
|
61
|
+
"uri-js-replace": "^1.0.0"
|
|
62
|
+
},
|
|
63
|
+
"tough-cookie": "next"
|
|
55
64
|
}
|
|
56
|
-
}
|
|
65
|
+
}
|