revbot.js 0.2.1 → 0.2.3
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/README.md +1 -1
- package/dist/index.d.mts +39 -4
- package/dist/index.d.ts +39 -4
- package/dist/index.js +112 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +112 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -864,11 +864,14 @@ var MessageStruct = class extends Base {
|
|
|
864
864
|
/**
|
|
865
865
|
* Retrieves the author of the message.
|
|
866
866
|
*
|
|
867
|
-
* @returns {User | null} The user who authored the message, or `null` if not found.
|
|
867
|
+
* @returns {User | ServerMember | null} The user who authored the message, or `null` if not found.
|
|
868
868
|
*/
|
|
869
869
|
get author() {
|
|
870
|
-
var _a;
|
|
871
|
-
|
|
870
|
+
var _a, _b, _c, _d;
|
|
871
|
+
if (this.inServer()) {
|
|
872
|
+
return (_c = (_b = (_a = this.server) == null ? void 0 : _a.members.cache.get(this.authorId)) != null ? _b : this.client.users.cache.get(this.authorId)) != null ? _c : null;
|
|
873
|
+
}
|
|
874
|
+
return (_d = this.client.users.cache.get(this.authorId)) != null ? _d : null;
|
|
872
875
|
}
|
|
873
876
|
/**
|
|
874
877
|
* Retrieves the channel where the message was sent.
|
|
@@ -2276,6 +2279,58 @@ var ServerMember3 = class extends Base {
|
|
|
2276
2279
|
leave() {
|
|
2277
2280
|
return this.client.servers.delete(this.serverId);
|
|
2278
2281
|
}
|
|
2282
|
+
/**
|
|
2283
|
+
* Gets the effective permissions for this server member based on their roles.
|
|
2284
|
+
*
|
|
2285
|
+
* The permissions are calculated by:
|
|
2286
|
+
* 1. Starting with a base FullPermissions with no permissions
|
|
2287
|
+
* 2. For each role the member has, applying the role's allow permissions
|
|
2288
|
+
* 3. For each role the member has, removing the role's deny permissions
|
|
2289
|
+
*
|
|
2290
|
+
* @returns {FullPermissions} The effective permissions for this member
|
|
2291
|
+
*
|
|
2292
|
+
* @example
|
|
2293
|
+
* ```typescript
|
|
2294
|
+
* const permissions = member.getPermissions();
|
|
2295
|
+
* console.log(permissions.has('MANAGE_MESSAGES')); // true or false
|
|
2296
|
+
* ```
|
|
2297
|
+
*/
|
|
2298
|
+
permissions() {
|
|
2299
|
+
var _a, _b;
|
|
2300
|
+
let permissions = new FullPermissions();
|
|
2301
|
+
for (const role of this.roles) {
|
|
2302
|
+
if ((_a = role.overwrite) == null ? void 0 : _a.allow) {
|
|
2303
|
+
permissions = permissions.add(role.overwrite.allow);
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
for (const role of this.roles) {
|
|
2307
|
+
if ((_b = role.overwrite) == null ? void 0 : _b.deny) {
|
|
2308
|
+
permissions = permissions.remove(role.overwrite.deny);
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2311
|
+
return permissions;
|
|
2312
|
+
}
|
|
2313
|
+
/**
|
|
2314
|
+
* Checks if this server member has a specific permission.
|
|
2315
|
+
*
|
|
2316
|
+
* @param {string | number | FullPermissions} permission - The permission to check for
|
|
2317
|
+
* @returns {boolean} Whether the member has the permission
|
|
2318
|
+
*
|
|
2319
|
+
* @example
|
|
2320
|
+
* ```typescript
|
|
2321
|
+
* if (member.hasPermission('MANAGE_MESSAGES')) {
|
|
2322
|
+
* // Member can manage messages
|
|
2323
|
+
* }
|
|
2324
|
+
* ```
|
|
2325
|
+
*
|
|
2326
|
+
* note this works on the same basis as stoats permissions checking
|
|
2327
|
+
*/
|
|
2328
|
+
hasPermission(permission) {
|
|
2329
|
+
var _a;
|
|
2330
|
+
if (((_a = this.client.servers.cache.get(this.serverId)) == null ? void 0 : _a.ownerId) === this.id)
|
|
2331
|
+
return true;
|
|
2332
|
+
return this.permissions().has(permission);
|
|
2333
|
+
}
|
|
2279
2334
|
// async displayAvatarURL(options?: { size: number }): Promise<string> {
|
|
2280
2335
|
// return await this.user.displayAvatarURL(options);
|
|
2281
2336
|
// }
|
|
@@ -2691,7 +2746,8 @@ var UserManager = class extends BaseManager {
|
|
|
2691
2746
|
});
|
|
2692
2747
|
}
|
|
2693
2748
|
resolve(resolvable) {
|
|
2694
|
-
if (resolvable instanceof MessageStruct)
|
|
2749
|
+
if (resolvable instanceof MessageStruct)
|
|
2750
|
+
return resolvable.author;
|
|
2695
2751
|
return super.resolve(resolvable);
|
|
2696
2752
|
}
|
|
2697
2753
|
/**
|
|
@@ -3228,7 +3284,7 @@ import { EventEmitter } from "node:events";
|
|
|
3228
3284
|
import axios4, { AxiosError } from "axios";
|
|
3229
3285
|
|
|
3230
3286
|
// package.json
|
|
3231
|
-
var version = "0.2.
|
|
3287
|
+
var version = "0.2.3";
|
|
3232
3288
|
|
|
3233
3289
|
// src/rest/restUtils/rateLimitQueue.ts
|
|
3234
3290
|
import axios3 from "axios";
|
|
@@ -3994,13 +4050,33 @@ var ServerRoleUpdate = class extends Event {
|
|
|
3994
4050
|
* @returns {void}
|
|
3995
4051
|
*/
|
|
3996
4052
|
handle(data) {
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4053
|
+
return __async(this, null, function* () {
|
|
4054
|
+
const server = this.client.servers.cache.get(data.id);
|
|
4055
|
+
if (!server) return;
|
|
4056
|
+
let role = server.roles.cache.get(data.role_id);
|
|
4057
|
+
const oldRole = role == null ? void 0 : role._update(data.data, data.clear);
|
|
4058
|
+
if (!oldRole && !role) {
|
|
4059
|
+
yield Promise.all(
|
|
4060
|
+
Object.values(data.data).map((raw) => __async(this, null, function* () {
|
|
4061
|
+
if (raw && typeof raw === "object") {
|
|
4062
|
+
server.roles._add(__spreadProps(__spreadValues({
|
|
4063
|
+
name: "",
|
|
4064
|
+
permissions: {
|
|
4065
|
+
a: 0,
|
|
4066
|
+
d: 0
|
|
4067
|
+
}
|
|
4068
|
+
}, raw), {
|
|
4069
|
+
id: data.role_id
|
|
4070
|
+
}));
|
|
4071
|
+
}
|
|
4072
|
+
}))
|
|
4073
|
+
);
|
|
4074
|
+
role = server.roles.cache.get(data.role_id);
|
|
4075
|
+
}
|
|
4076
|
+
if (role && oldRole && !role.equals(oldRole)) {
|
|
4077
|
+
this.client.emit("roleUpdate" /* ROLE_UPDATE */, oldRole, role);
|
|
4078
|
+
}
|
|
4079
|
+
});
|
|
4004
4080
|
}
|
|
4005
4081
|
};
|
|
4006
4082
|
|
|
@@ -4230,6 +4306,8 @@ var WebSocketClient = class {
|
|
|
4230
4306
|
this.reconnecting = null;
|
|
4231
4307
|
/** Whether the WebSocket client is ready. */
|
|
4232
4308
|
this.ready = false;
|
|
4309
|
+
/** The number of reconnection attempts made. */
|
|
4310
|
+
this.retryCount = 0;
|
|
4233
4311
|
}
|
|
4234
4312
|
/**
|
|
4235
4313
|
* Logs a debug message.
|
|
@@ -4369,6 +4447,8 @@ var WebSocketClient = class {
|
|
|
4369
4447
|
break;
|
|
4370
4448
|
case "Authenticated" /* AUTHENTICATED */:
|
|
4371
4449
|
this.connected = true;
|
|
4450
|
+
this.retryCount = 0;
|
|
4451
|
+
this.debug(`Successfully authenticated.`);
|
|
4372
4452
|
break;
|
|
4373
4453
|
case "Pong" /* PONG */:
|
|
4374
4454
|
this.debug(`Received a heartbeat.`);
|
|
@@ -4428,6 +4508,15 @@ var WebSocketClient = class {
|
|
|
4428
4508
|
* @returns {Promise<this>} A promise that resolves when the connection is established.
|
|
4429
4509
|
*/
|
|
4430
4510
|
connect() {
|
|
4511
|
+
this.retryCount = this.retryCount + 1;
|
|
4512
|
+
if (this.retryCount > 10) {
|
|
4513
|
+
this.debug("Max retry attempts reached");
|
|
4514
|
+
return Promise.reject(
|
|
4515
|
+
new Error(
|
|
4516
|
+
"Max retry attempts reached on WS connection, try again later."
|
|
4517
|
+
)
|
|
4518
|
+
);
|
|
4519
|
+
}
|
|
4431
4520
|
return new Promise((resolve) => __async(this, null, function* () {
|
|
4432
4521
|
var _a, _b, _c, _d;
|
|
4433
4522
|
if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN && this.ready) {
|
|
@@ -4455,7 +4544,7 @@ var WebSocketClient = class {
|
|
|
4455
4544
|
*
|
|
4456
4545
|
* @returns {Promise<void>} A promise that resolves when the connection is destroyed.
|
|
4457
4546
|
*/
|
|
4458
|
-
destroy() {
|
|
4547
|
+
destroy(isUserInitiated) {
|
|
4459
4548
|
return new Promise((resolve) => {
|
|
4460
4549
|
var _a;
|
|
4461
4550
|
this.setHeartbeatTimer(-1);
|
|
@@ -4464,11 +4553,20 @@ var WebSocketClient = class {
|
|
|
4464
4553
|
if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN) {
|
|
4465
4554
|
this.socket.addEventListener("close", () => {
|
|
4466
4555
|
this.socket = null;
|
|
4556
|
+
if (!isUserInitiated) {
|
|
4557
|
+
setTimeout(() => this.connect(), 1e3);
|
|
4558
|
+
}
|
|
4467
4559
|
resolve();
|
|
4468
4560
|
});
|
|
4469
4561
|
this.socket.close();
|
|
4562
|
+
if (!isUserInitiated) {
|
|
4563
|
+
setTimeout(() => this.connect(), 1e3);
|
|
4564
|
+
}
|
|
4470
4565
|
} else {
|
|
4471
4566
|
this.socket = null;
|
|
4567
|
+
if (!isUserInitiated) {
|
|
4568
|
+
setTimeout(() => this.connect(), 1e3);
|
|
4569
|
+
}
|
|
4472
4570
|
resolve();
|
|
4473
4571
|
}
|
|
4474
4572
|
});
|
|
@@ -4560,7 +4658,7 @@ var client2 = class extends BaseClient {
|
|
|
4560
4658
|
this.token = null;
|
|
4561
4659
|
this.user = null;
|
|
4562
4660
|
this.readyAt = null;
|
|
4563
|
-
yield this.ws.destroy();
|
|
4661
|
+
yield this.ws.destroy(true);
|
|
4564
4662
|
});
|
|
4565
4663
|
}
|
|
4566
4664
|
/**
|