catto.js 1.4.3 → 1.4.5
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/.github/workflows/publish.yml +7 -18
- package/Bot.js +74 -2
- package/package.json +8 -8
- package/utils.js +32 -15
|
@@ -1,32 +1,21 @@
|
|
|
1
|
-
name: Publish
|
|
1
|
+
name: Publish to NPM
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
release:
|
|
5
5
|
types: [created]
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
steps:
|
|
11
|
-
- uses: actions/checkout@v3
|
|
12
|
-
- uses: actions/setup-node@v3
|
|
13
|
-
with:
|
|
14
|
-
node-version: 20
|
|
15
|
-
- run: npm i --package-lock-only
|
|
16
|
-
- run: npm ci
|
|
17
|
-
- run: npm test
|
|
7
|
+
permissions:
|
|
8
|
+
id-token: write
|
|
9
|
+
contents: read
|
|
18
10
|
|
|
11
|
+
jobs:
|
|
19
12
|
publish-npm:
|
|
20
|
-
needs: build
|
|
21
13
|
runs-on: ubuntu-latest
|
|
22
14
|
steps:
|
|
23
15
|
- uses: actions/checkout@v3
|
|
24
16
|
- uses: actions/setup-node@v3
|
|
25
17
|
with:
|
|
26
|
-
node-version:
|
|
18
|
+
node-version: 24
|
|
27
19
|
registry-url: https://registry.npmjs.org/
|
|
28
|
-
- run: npm i
|
|
29
|
-
- run: npm ci
|
|
20
|
+
- run: npm i
|
|
30
21
|
- run: npm publish
|
|
31
|
-
env:
|
|
32
|
-
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
package/Bot.js
CHANGED
|
@@ -3,6 +3,7 @@ var events = require("events");
|
|
|
3
3
|
var Discord = require("discord.js");
|
|
4
4
|
var djsws = require("@discordjs/ws");
|
|
5
5
|
var { ClusterManager, ClusterClient, getInfo, ReClusterManager } = require("discord-hybrid-sharding");
|
|
6
|
+
var fs = require("fs");
|
|
6
7
|
var path = require("path");
|
|
7
8
|
var User = require("./User");
|
|
8
9
|
var MessageBuilder = require("./MessageBuilder");
|
|
@@ -23,7 +24,10 @@ module.exports = class extends EventEmitter {
|
|
|
23
24
|
"debug": !1,
|
|
24
25
|
"mobile": !1,
|
|
25
26
|
"sharded": !1,
|
|
26
|
-
"partials": !1
|
|
27
|
+
"partials": !1,
|
|
28
|
+
"messageDeleteExecutor": !1,
|
|
29
|
+
"auditIndexation": !1,
|
|
30
|
+
"auditFile": null
|
|
27
31
|
}, options || {});
|
|
28
32
|
if (client) {
|
|
29
33
|
this.client = client;
|
|
@@ -241,6 +245,26 @@ module.exports = class extends EventEmitter {
|
|
|
241
245
|
});
|
|
242
246
|
});
|
|
243
247
|
}
|
|
248
|
+
if (this.options.auditIndexation) {
|
|
249
|
+
this.auditDatabase = {};
|
|
250
|
+
for (var server of this.servers) {
|
|
251
|
+
if (!server.members.me.permissions.has(Discord.PermissionsBitField.Flags.VIEW_AUDIT_LOG)) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
var fetchedLogs = (await server.fetchAuditLogs({
|
|
256
|
+
"limit": 100,
|
|
257
|
+
"type": 72
|
|
258
|
+
})).entries.filter(log => log.targetType == "Message");
|
|
259
|
+
for (var log of fetchedLogs.values()) {
|
|
260
|
+
this.auditDatabase[log.id] = log.extra.count;
|
|
261
|
+
}
|
|
262
|
+
} catch {}
|
|
263
|
+
}
|
|
264
|
+
if (this.options.auditFile) {
|
|
265
|
+
fs.writeFileSync(this.options.auditFile.replace("%", this.cluster ? this.cluster.id.toString() : "0"), JSON.stringify(this.auditDatabase, null, 2));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
244
268
|
this.emit("running", { Discord });
|
|
245
269
|
if (this.cluster && this.cluster.id == (this.cluster.count - 1)) {
|
|
246
270
|
this.cluster.broadcastEval(client => client.emit("_runningFull"));
|
|
@@ -272,13 +296,48 @@ module.exports = class extends EventEmitter {
|
|
|
272
296
|
}
|
|
273
297
|
this.emit("message", message);
|
|
274
298
|
});
|
|
275
|
-
this.client.on("messageDelete", message => {
|
|
299
|
+
this.client.on("messageDelete", async message => {
|
|
276
300
|
if (message.author && !(message.author instanceof User)) {
|
|
277
301
|
message.author = new User(message.author, this);
|
|
278
302
|
}
|
|
279
303
|
if (message.member && message.member.user && !(message.member.user instanceof User)) {
|
|
280
304
|
message.member.user = new User(message.member.user, this);
|
|
281
305
|
}
|
|
306
|
+
if (!this.options.messageDeleteExecutor) {
|
|
307
|
+
return this.emit("messageDeleted", message);
|
|
308
|
+
}
|
|
309
|
+
if (!message.guild.members.me.permissions.has(Discord.PermissionsBitField.Flags.VIEW_AUDIT_LOG)) {
|
|
310
|
+
return this.emit("messageDeleted", message);
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
var fetchedLogs = (await message.guild.fetchAuditLogs({
|
|
314
|
+
"limit": 100,
|
|
315
|
+
"type": 72
|
|
316
|
+
})).entries.filter(log => log.targetType == "Message");
|
|
317
|
+
} catch {
|
|
318
|
+
return this.emit("messageDeleted", message);
|
|
319
|
+
}
|
|
320
|
+
var found = !1;
|
|
321
|
+
for (var log of fetchedLogs.values()) {
|
|
322
|
+
if (log.targetId != message.author.id || log.extra.channel.id != message.channel.id) {
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
if (this.auditDatabase[log.id] !== log.extra.count) {
|
|
326
|
+
if (!found) {
|
|
327
|
+
found = true;
|
|
328
|
+
message.deletedBy = new User(log.executor, this);
|
|
329
|
+
message.deletedById = log.executorId;
|
|
330
|
+
}
|
|
331
|
+
this.auditDatabase[log.id] = log.extra.count;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (this.options.auditFile) {
|
|
335
|
+
fs.writeFileSync(this.options.auditFile.replace("%", this.cluster ? this.cluster.id.toString() : "0"), JSON.stringify(this.auditDatabase, null, 2));
|
|
336
|
+
}
|
|
337
|
+
if (!found) {
|
|
338
|
+
message.deletedBy = message.author;
|
|
339
|
+
message.deletedById = message.author.id;
|
|
340
|
+
}
|
|
282
341
|
this.emit("messageDeleted", message);
|
|
283
342
|
});
|
|
284
343
|
this.client.on("guildCreate", guild => {
|
|
@@ -287,6 +346,13 @@ module.exports = class extends EventEmitter {
|
|
|
287
346
|
this.client.on("guildDelete", guild => {
|
|
288
347
|
this.emit("botDelete", guild);
|
|
289
348
|
});
|
|
349
|
+
this.auditDatabase = {};
|
|
350
|
+
if (this.options.auditFile) {
|
|
351
|
+
if (!fs.existsSync(this.options.auditFile.replace("%", this.cluster ? this.cluster.id.toString() : "0"))) {
|
|
352
|
+
fs.writeFileSync(this.options.auditFile.replace("%", this.cluster ? this.cluster.id.toString() : "0"), "{}");
|
|
353
|
+
}
|
|
354
|
+
this.auditDatabase = JSON.parse(fs.readFileSync(this.options.auditFile.replace("%", this.cluster ? this.cluster.id.toString() : "0")).toString("utf-8"));
|
|
355
|
+
}
|
|
290
356
|
}
|
|
291
357
|
get cluster() {
|
|
292
358
|
return this.client.cluster;
|
|
@@ -305,6 +371,12 @@ module.exports = class extends EventEmitter {
|
|
|
305
371
|
get channels() {
|
|
306
372
|
var r = Array.from(this.client.channels.cache.values());
|
|
307
373
|
r.count = r.length;
|
|
374
|
+
if (this.options.sharded) {
|
|
375
|
+
return new Promise(async res => {
|
|
376
|
+
r.count = (await this.cluster.broadcastEval("this.channels.cache.size")).reduce((a, b) => a + b, 0);
|
|
377
|
+
res(r);
|
|
378
|
+
});
|
|
379
|
+
}
|
|
308
380
|
return r;
|
|
309
381
|
}
|
|
310
382
|
slashCommand(basic, options, executor) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "catto.js",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"description": "Universal module for everything.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -40,20 +40,20 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/BoryaGames/catto.js#readme",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"body-parser": "^1.20.
|
|
44
|
-
"discord-hybrid-sharding": "^3.0.
|
|
45
|
-
"discord.js": "^14.
|
|
43
|
+
"body-parser": "^1.20.4",
|
|
44
|
+
"discord-hybrid-sharding": "^3.0.1",
|
|
45
|
+
"discord.js": "^14.25.1",
|
|
46
46
|
"ejs": "^3.1.10",
|
|
47
|
-
"express": "^4.
|
|
48
|
-
"express-session": "^1.18.
|
|
47
|
+
"express": "^4.22.1",
|
|
48
|
+
"express-session": "^1.18.2",
|
|
49
49
|
"express-ws": "^5.0.2",
|
|
50
50
|
"node-fetch": "^3.3.2",
|
|
51
|
-
"oci-common": "^2.
|
|
51
|
+
"oci-common": "^2.122.2",
|
|
52
52
|
"session-file-store": "^1.5.0",
|
|
53
53
|
"telegraf": "^4.16.3",
|
|
54
54
|
"tweetnacl": "^1.0.3"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"jest": "^30.0
|
|
57
|
+
"jest": "^30.2.0"
|
|
58
58
|
}
|
|
59
59
|
}
|
package/utils.js
CHANGED
|
@@ -1,18 +1,35 @@
|
|
|
1
|
-
Array.prototype
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
Object.defineProperty(Array.prototype, "remove", {
|
|
2
|
+
"value": function(index) {
|
|
3
|
+
return this.splice(index, 1)[0];
|
|
4
|
+
},
|
|
5
|
+
"enumerable": false
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(Array.prototype, "has", {
|
|
8
|
+
"value": function(data) {
|
|
9
|
+
return this.includes(data);
|
|
10
|
+
},
|
|
11
|
+
"enumerable": false
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(Array.prototype, "random", {
|
|
14
|
+
"value": function() {
|
|
15
|
+
return this[Math.floor(Math.random() *this.length)];
|
|
16
|
+
},
|
|
17
|
+
"enumerable": false
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
Object.defineProperty(String.prototype, "replaceAsync", {
|
|
21
|
+
"value": async function(regex, asyncFn) {
|
|
22
|
+
var promises = [];
|
|
23
|
+
this.replace(regex, (full, ...args) => {
|
|
24
|
+
promises.push(asyncFn(full, ...args));
|
|
25
|
+
return full;
|
|
26
|
+
});
|
|
27
|
+
var data = await Promise.all(promises);
|
|
28
|
+
return this.replace(regex, () => data.shift());
|
|
29
|
+
},
|
|
30
|
+
"enumerable": false
|
|
31
|
+
});
|
|
32
|
+
|
|
16
33
|
var utils = {};
|
|
17
34
|
utils.waitFor = (obj, prop) => {
|
|
18
35
|
return new Promise(r => {
|