catto.js 0.7.0 → 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.
Files changed (2) hide show
  1. package/Bot.js +52 -3
  2. 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
- this.client = new Discord.Client({
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,8 +36,17 @@ 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
  }
49
+ this.currentStatus = void 0;
38
50
  this.buttons = new Map();
39
51
  this.commands = new Map();
40
52
  this.slashCommands = new Map();
@@ -164,6 +176,15 @@ module.exports = class extends EventEmitter {
164
176
  }
165
177
  this.emit("running", { Discord });
166
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
+ });
167
188
  this.client.on("interactionCreate", this.handleInteractionCreate.bind(this));
168
189
  this.client.on("messageCreate", message => {
169
190
  message.author = new User(message.author, this);
@@ -208,6 +229,17 @@ module.exports = class extends EventEmitter {
208
229
  get servers() {
209
230
  var r = Array.from(this.client.guilds.cache.values());
210
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
+ }
238
+ return r;
239
+ }
240
+ get channels() {
241
+ var r = Array.from(this.client.channels.cache.values());
242
+ r.count = r.length;
211
243
  return r;
212
244
  }
213
245
  slashCommand(basic, options, executor) {
@@ -373,4 +405,21 @@ module.exports = class extends EventEmitter {
373
405
  this.emit("interaction", interaction);
374
406
  }
375
407
  }
408
+ setStatus(data) {
409
+ this.currentStatus = data;
410
+ this.client.options.presence = data;
411
+ return this.client.user.setPresence(data);
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
+ }
376
425
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catto.js",
3
- "version": "0.7.0",
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
+ }