revbot.js 0.0.9 → 0.0.12
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 +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +85 -15
- package/dist/index.mjs +85 -15
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Note: this package is currently in the early stages of development and testing
|
|
4
4
|
|
|
5
|
-
`revbot.js` is a Node.js library for building bots on the Revolt platform. It provides an easy-to-use interface for interacting with Revolt's API, managing events, and handling various bot functionalities.
|
|
5
|
+
`revbot.js` is a Node.js library for building bots on the Revolt platform. It provides an easy-to-use interface for interacting with Revolt's API, managing events, and handling various bot functionalities. NOTE: node 21 is required to run this
|
|
6
6
|
[revolt server](https://rvlt.gg/2NcCgYZ0) [docs](https://jade3375.github.io/revbot.js/)
|
|
7
7
|
|
|
8
8
|
## Installation
|
package/dist/index.d.mts
CHANGED
|
@@ -135,6 +135,7 @@ declare class RestClient {
|
|
|
135
135
|
* @returns The API response.
|
|
136
136
|
*/
|
|
137
137
|
private request;
|
|
138
|
+
private retryRequest;
|
|
138
139
|
/**
|
|
139
140
|
* GET request.
|
|
140
141
|
* @param url The URL for the request.
|
|
@@ -188,6 +189,7 @@ declare class CDNClient {
|
|
|
188
189
|
* @returns The API response.
|
|
189
190
|
*/
|
|
190
191
|
private request;
|
|
192
|
+
private retryRequest;
|
|
191
193
|
/**
|
|
192
194
|
* POST request.
|
|
193
195
|
* @param url The URL for the request.
|
package/dist/index.d.ts
CHANGED
|
@@ -135,6 +135,7 @@ declare class RestClient {
|
|
|
135
135
|
* @returns The API response.
|
|
136
136
|
*/
|
|
137
137
|
private request;
|
|
138
|
+
private retryRequest;
|
|
138
139
|
/**
|
|
139
140
|
* GET request.
|
|
140
141
|
* @param url The URL for the request.
|
|
@@ -188,6 +189,7 @@ declare class CDNClient {
|
|
|
188
189
|
* @returns The API response.
|
|
189
190
|
*/
|
|
190
191
|
private request;
|
|
192
|
+
private retryRequest;
|
|
191
193
|
/**
|
|
192
194
|
* POST request.
|
|
193
195
|
* @param url The URL for the request.
|
package/dist/index.js
CHANGED
|
@@ -3231,8 +3231,11 @@ var ServerMemberManager = class extends BaseManager {
|
|
|
3231
3231
|
// src/client/baseClient.ts
|
|
3232
3232
|
var import_node_events = require("events");
|
|
3233
3233
|
|
|
3234
|
+
// src/rest/restClient.ts
|
|
3235
|
+
var import_axios4 = require("axios");
|
|
3236
|
+
|
|
3234
3237
|
// package.json
|
|
3235
|
-
var version = "0.0.
|
|
3238
|
+
var version = "0.0.12";
|
|
3236
3239
|
|
|
3237
3240
|
// src/rest/restUtils/rateLimitQueue.ts
|
|
3238
3241
|
var import_axios3 = __toESM(require("axios"));
|
|
@@ -3296,13 +3299,7 @@ var RateLimitQueue = class {
|
|
|
3296
3299
|
state.resetAfter = resetAfter;
|
|
3297
3300
|
state.lastPath = path;
|
|
3298
3301
|
}
|
|
3299
|
-
console.log(
|
|
3300
|
-
`Rate limit updated for bucket ${bucket} on path ${path}. Limit: ${limit}, Remaining: ${remaining}, Reset after: ${resetAfter} ms`
|
|
3301
|
-
);
|
|
3302
3302
|
if (remaining <= 0) {
|
|
3303
|
-
console.warn(
|
|
3304
|
-
`Rate limit exceeded for bucket ${bucket} on path ${path}. Remaining: ${remaining}, Reset after: ${new Date(resetAfter).toISOString()}`
|
|
3305
|
-
);
|
|
3306
3303
|
if (state.resetTimeout) clearTimeout(state.resetTimeout);
|
|
3307
3304
|
const delay = resetIn;
|
|
3308
3305
|
state.resetTimeout = setTimeout(() => {
|
|
@@ -3334,8 +3331,9 @@ var RestClient = class {
|
|
|
3334
3331
|
* @param query Query parameters (if applicable).
|
|
3335
3332
|
* @returns The API response.
|
|
3336
3333
|
*/
|
|
3337
|
-
request(method, url, body, query) {
|
|
3334
|
+
request(method, url, body, query, retry) {
|
|
3338
3335
|
return __async(this, null, function* () {
|
|
3336
|
+
var _a;
|
|
3339
3337
|
try {
|
|
3340
3338
|
if (!this.client.token) throw new Error("Token is required");
|
|
3341
3339
|
const authHeader = this.client.bot ? "X-Bot-Token" : "X-Session-Token";
|
|
@@ -3354,8 +3352,43 @@ var RestClient = class {
|
|
|
3354
3352
|
const response = yield this.rateLimitQueue.request(config);
|
|
3355
3353
|
return response.data;
|
|
3356
3354
|
} catch (error) {
|
|
3357
|
-
|
|
3358
|
-
|
|
3355
|
+
if (retry) throw typeof error;
|
|
3356
|
+
if (error instanceof import_axios4.AxiosError) {
|
|
3357
|
+
if (error.status && (error.status === 429 || error.status >= 500)) {
|
|
3358
|
+
return this.retryRequest(0, method, url, body, query);
|
|
3359
|
+
}
|
|
3360
|
+
if (error.status) {
|
|
3361
|
+
throw new Error(
|
|
3362
|
+
`API call failed with status ${error.status}: ${(_a = error.response) == null ? void 0 : _a.statusText}`
|
|
3363
|
+
);
|
|
3364
|
+
}
|
|
3365
|
+
}
|
|
3366
|
+
throw new Error(
|
|
3367
|
+
`API call failed: ${error instanceof Error ? error.message : error}`
|
|
3368
|
+
);
|
|
3369
|
+
}
|
|
3370
|
+
});
|
|
3371
|
+
}
|
|
3372
|
+
retryRequest(attempt = 0, method, url, body, query) {
|
|
3373
|
+
return __async(this, null, function* () {
|
|
3374
|
+
var _a, _b;
|
|
3375
|
+
if (attempt >= ((_b = (_a = this.client.options.rest) == null ? void 0 : _a.retries) != null ? _b : 3)) {
|
|
3376
|
+
throw new Error("Max retries reached");
|
|
3377
|
+
}
|
|
3378
|
+
try {
|
|
3379
|
+
return yield this.request(method, url, body, query, true);
|
|
3380
|
+
} catch (error) {
|
|
3381
|
+
console.warn(`Attempt ${attempt + 1} failed:`, error);
|
|
3382
|
+
yield new Promise(
|
|
3383
|
+
(resolve) => {
|
|
3384
|
+
var _a2, _b2, _c;
|
|
3385
|
+
return setTimeout(
|
|
3386
|
+
resolve,
|
|
3387
|
+
(_c = (_a2 = this.client.options.rest) == null ? void 0 : _a2.timeout) != null ? _c : (_b2 = DEFAULT_CLIENT_OPTIONS.rest) == null ? void 0 : _b2.timeout
|
|
3388
|
+
);
|
|
3389
|
+
}
|
|
3390
|
+
);
|
|
3391
|
+
return this.retryRequest(attempt + 1, method, url, body, query);
|
|
3359
3392
|
}
|
|
3360
3393
|
});
|
|
3361
3394
|
}
|
|
@@ -3420,6 +3453,7 @@ var RestClient = class {
|
|
|
3420
3453
|
};
|
|
3421
3454
|
|
|
3422
3455
|
// src/rest/CDNClient.ts
|
|
3456
|
+
var import_axios5 = require("axios");
|
|
3423
3457
|
var CDNClient = class {
|
|
3424
3458
|
constructor(client3) {
|
|
3425
3459
|
this.client = client3;
|
|
@@ -3433,7 +3467,7 @@ var CDNClient = class {
|
|
|
3433
3467
|
* @param query Query parameters (if applicable).
|
|
3434
3468
|
* @returns The API response.
|
|
3435
3469
|
*/
|
|
3436
|
-
request(method, url, data, query) {
|
|
3470
|
+
request(method, url, data, query, retry) {
|
|
3437
3471
|
return __async(this, null, function* () {
|
|
3438
3472
|
try {
|
|
3439
3473
|
if (!this.client.token) throw new Error("Token is required");
|
|
@@ -3455,8 +3489,44 @@ var CDNClient = class {
|
|
|
3455
3489
|
const response = yield this.rateLimitQueue.request(config);
|
|
3456
3490
|
return response.data;
|
|
3457
3491
|
} catch (error) {
|
|
3458
|
-
|
|
3459
|
-
|
|
3492
|
+
if (retry) throw typeof error;
|
|
3493
|
+
if (error instanceof import_axios5.AxiosError) {
|
|
3494
|
+
if (error.status && (error.status === 429 || error.status >= 500)) {
|
|
3495
|
+
return this.retryRequest(0, method, url, data, query);
|
|
3496
|
+
}
|
|
3497
|
+
if (error.status) {
|
|
3498
|
+
console.error(`API call failed with status ${error.status}:`, error);
|
|
3499
|
+
throw new Error(
|
|
3500
|
+
`API call failed with status ${error.status}: ${error.message}`
|
|
3501
|
+
);
|
|
3502
|
+
}
|
|
3503
|
+
}
|
|
3504
|
+
throw new Error(
|
|
3505
|
+
`API call failed: ${error instanceof Error ? error.message : error}`
|
|
3506
|
+
);
|
|
3507
|
+
}
|
|
3508
|
+
});
|
|
3509
|
+
}
|
|
3510
|
+
retryRequest(attempt = 0, method, url, body, query) {
|
|
3511
|
+
return __async(this, null, function* () {
|
|
3512
|
+
var _a, _b;
|
|
3513
|
+
if (attempt >= ((_b = (_a = this.client.options.rest) == null ? void 0 : _a.retries) != null ? _b : 3)) {
|
|
3514
|
+
throw new Error("Max retries reached");
|
|
3515
|
+
}
|
|
3516
|
+
try {
|
|
3517
|
+
return yield this.request(method, url, body, query, true);
|
|
3518
|
+
} catch (error) {
|
|
3519
|
+
console.warn(`Attempt ${attempt + 1} failed:`, error);
|
|
3520
|
+
yield new Promise(
|
|
3521
|
+
(resolve) => {
|
|
3522
|
+
var _a2, _b2, _c;
|
|
3523
|
+
return setTimeout(
|
|
3524
|
+
resolve,
|
|
3525
|
+
(_c = (_a2 = this.client.options.rest) == null ? void 0 : _a2.timeout) != null ? _c : (_b2 = DEFAULT_CLIENT_OPTIONS.rest) == null ? void 0 : _b2.timeout
|
|
3526
|
+
);
|
|
3527
|
+
}
|
|
3528
|
+
);
|
|
3529
|
+
return this.retryRequest(attempt + 1, method, url, body, query);
|
|
3460
3530
|
}
|
|
3461
3531
|
});
|
|
3462
3532
|
}
|
|
@@ -3489,7 +3559,7 @@ var BaseClient = class extends import_node_events.EventEmitter {
|
|
|
3489
3559
|
__privateAdd(this, _token, null);
|
|
3490
3560
|
/** Whether the client is a bot. */
|
|
3491
3561
|
this.bot = true;
|
|
3492
|
-
this.options = __spreadValues({}, options);
|
|
3562
|
+
this.options = __spreadValues(__spreadValues({}, DEFAULT_CLIENT_OPTIONS), options);
|
|
3493
3563
|
this.bot = (_a = this.options.isBot) != null ? _a : true;
|
|
3494
3564
|
this.api = new RestClient(this);
|
|
3495
3565
|
this.cdn = new CDNClient(this);
|
|
@@ -3725,7 +3795,7 @@ var Message6 = class extends Event {
|
|
|
3725
3795
|
const channel = this.client.channels.cache.get(data.channel);
|
|
3726
3796
|
if (channel == null ? void 0 : channel.isText()) {
|
|
3727
3797
|
const message = channel.messages._add(data);
|
|
3728
|
-
if (data.author !== SYSTEM_USER_ID) {
|
|
3798
|
+
if (data.author !== SYSTEM_USER_ID && !data.webhook) {
|
|
3729
3799
|
yield this.client.users.fetch(data.author, { force: false });
|
|
3730
3800
|
}
|
|
3731
3801
|
this.client.emit("message" /* MESSAGE */, message);
|
package/dist/index.mjs
CHANGED
|
@@ -3157,8 +3157,11 @@ var ServerMemberManager = class extends BaseManager {
|
|
|
3157
3157
|
// src/client/baseClient.ts
|
|
3158
3158
|
import { EventEmitter } from "node:events";
|
|
3159
3159
|
|
|
3160
|
+
// src/rest/restClient.ts
|
|
3161
|
+
import { AxiosError } from "axios";
|
|
3162
|
+
|
|
3160
3163
|
// package.json
|
|
3161
|
-
var version = "0.0.
|
|
3164
|
+
var version = "0.0.12";
|
|
3162
3165
|
|
|
3163
3166
|
// src/rest/restUtils/rateLimitQueue.ts
|
|
3164
3167
|
import axios3 from "axios";
|
|
@@ -3222,13 +3225,7 @@ var RateLimitQueue = class {
|
|
|
3222
3225
|
state.resetAfter = resetAfter;
|
|
3223
3226
|
state.lastPath = path;
|
|
3224
3227
|
}
|
|
3225
|
-
console.log(
|
|
3226
|
-
`Rate limit updated for bucket ${bucket} on path ${path}. Limit: ${limit}, Remaining: ${remaining}, Reset after: ${resetAfter} ms`
|
|
3227
|
-
);
|
|
3228
3228
|
if (remaining <= 0) {
|
|
3229
|
-
console.warn(
|
|
3230
|
-
`Rate limit exceeded for bucket ${bucket} on path ${path}. Remaining: ${remaining}, Reset after: ${new Date(resetAfter).toISOString()}`
|
|
3231
|
-
);
|
|
3232
3229
|
if (state.resetTimeout) clearTimeout(state.resetTimeout);
|
|
3233
3230
|
const delay = resetIn;
|
|
3234
3231
|
state.resetTimeout = setTimeout(() => {
|
|
@@ -3260,8 +3257,9 @@ var RestClient = class {
|
|
|
3260
3257
|
* @param query Query parameters (if applicable).
|
|
3261
3258
|
* @returns The API response.
|
|
3262
3259
|
*/
|
|
3263
|
-
request(method, url, body, query) {
|
|
3260
|
+
request(method, url, body, query, retry) {
|
|
3264
3261
|
return __async(this, null, function* () {
|
|
3262
|
+
var _a;
|
|
3265
3263
|
try {
|
|
3266
3264
|
if (!this.client.token) throw new Error("Token is required");
|
|
3267
3265
|
const authHeader = this.client.bot ? "X-Bot-Token" : "X-Session-Token";
|
|
@@ -3280,8 +3278,43 @@ var RestClient = class {
|
|
|
3280
3278
|
const response = yield this.rateLimitQueue.request(config);
|
|
3281
3279
|
return response.data;
|
|
3282
3280
|
} catch (error) {
|
|
3283
|
-
|
|
3284
|
-
|
|
3281
|
+
if (retry) throw typeof error;
|
|
3282
|
+
if (error instanceof AxiosError) {
|
|
3283
|
+
if (error.status && (error.status === 429 || error.status >= 500)) {
|
|
3284
|
+
return this.retryRequest(0, method, url, body, query);
|
|
3285
|
+
}
|
|
3286
|
+
if (error.status) {
|
|
3287
|
+
throw new Error(
|
|
3288
|
+
`API call failed with status ${error.status}: ${(_a = error.response) == null ? void 0 : _a.statusText}`
|
|
3289
|
+
);
|
|
3290
|
+
}
|
|
3291
|
+
}
|
|
3292
|
+
throw new Error(
|
|
3293
|
+
`API call failed: ${error instanceof Error ? error.message : error}`
|
|
3294
|
+
);
|
|
3295
|
+
}
|
|
3296
|
+
});
|
|
3297
|
+
}
|
|
3298
|
+
retryRequest(attempt = 0, method, url, body, query) {
|
|
3299
|
+
return __async(this, null, function* () {
|
|
3300
|
+
var _a, _b;
|
|
3301
|
+
if (attempt >= ((_b = (_a = this.client.options.rest) == null ? void 0 : _a.retries) != null ? _b : 3)) {
|
|
3302
|
+
throw new Error("Max retries reached");
|
|
3303
|
+
}
|
|
3304
|
+
try {
|
|
3305
|
+
return yield this.request(method, url, body, query, true);
|
|
3306
|
+
} catch (error) {
|
|
3307
|
+
console.warn(`Attempt ${attempt + 1} failed:`, error);
|
|
3308
|
+
yield new Promise(
|
|
3309
|
+
(resolve) => {
|
|
3310
|
+
var _a2, _b2, _c;
|
|
3311
|
+
return setTimeout(
|
|
3312
|
+
resolve,
|
|
3313
|
+
(_c = (_a2 = this.client.options.rest) == null ? void 0 : _a2.timeout) != null ? _c : (_b2 = DEFAULT_CLIENT_OPTIONS.rest) == null ? void 0 : _b2.timeout
|
|
3314
|
+
);
|
|
3315
|
+
}
|
|
3316
|
+
);
|
|
3317
|
+
return this.retryRequest(attempt + 1, method, url, body, query);
|
|
3285
3318
|
}
|
|
3286
3319
|
});
|
|
3287
3320
|
}
|
|
@@ -3346,6 +3379,7 @@ var RestClient = class {
|
|
|
3346
3379
|
};
|
|
3347
3380
|
|
|
3348
3381
|
// src/rest/CDNClient.ts
|
|
3382
|
+
import { AxiosError as AxiosError2 } from "axios";
|
|
3349
3383
|
var CDNClient = class {
|
|
3350
3384
|
constructor(client3) {
|
|
3351
3385
|
this.client = client3;
|
|
@@ -3359,7 +3393,7 @@ var CDNClient = class {
|
|
|
3359
3393
|
* @param query Query parameters (if applicable).
|
|
3360
3394
|
* @returns The API response.
|
|
3361
3395
|
*/
|
|
3362
|
-
request(method, url, data, query) {
|
|
3396
|
+
request(method, url, data, query, retry) {
|
|
3363
3397
|
return __async(this, null, function* () {
|
|
3364
3398
|
try {
|
|
3365
3399
|
if (!this.client.token) throw new Error("Token is required");
|
|
@@ -3381,8 +3415,44 @@ var CDNClient = class {
|
|
|
3381
3415
|
const response = yield this.rateLimitQueue.request(config);
|
|
3382
3416
|
return response.data;
|
|
3383
3417
|
} catch (error) {
|
|
3384
|
-
|
|
3385
|
-
|
|
3418
|
+
if (retry) throw typeof error;
|
|
3419
|
+
if (error instanceof AxiosError2) {
|
|
3420
|
+
if (error.status && (error.status === 429 || error.status >= 500)) {
|
|
3421
|
+
return this.retryRequest(0, method, url, data, query);
|
|
3422
|
+
}
|
|
3423
|
+
if (error.status) {
|
|
3424
|
+
console.error(`API call failed with status ${error.status}:`, error);
|
|
3425
|
+
throw new Error(
|
|
3426
|
+
`API call failed with status ${error.status}: ${error.message}`
|
|
3427
|
+
);
|
|
3428
|
+
}
|
|
3429
|
+
}
|
|
3430
|
+
throw new Error(
|
|
3431
|
+
`API call failed: ${error instanceof Error ? error.message : error}`
|
|
3432
|
+
);
|
|
3433
|
+
}
|
|
3434
|
+
});
|
|
3435
|
+
}
|
|
3436
|
+
retryRequest(attempt = 0, method, url, body, query) {
|
|
3437
|
+
return __async(this, null, function* () {
|
|
3438
|
+
var _a, _b;
|
|
3439
|
+
if (attempt >= ((_b = (_a = this.client.options.rest) == null ? void 0 : _a.retries) != null ? _b : 3)) {
|
|
3440
|
+
throw new Error("Max retries reached");
|
|
3441
|
+
}
|
|
3442
|
+
try {
|
|
3443
|
+
return yield this.request(method, url, body, query, true);
|
|
3444
|
+
} catch (error) {
|
|
3445
|
+
console.warn(`Attempt ${attempt + 1} failed:`, error);
|
|
3446
|
+
yield new Promise(
|
|
3447
|
+
(resolve) => {
|
|
3448
|
+
var _a2, _b2, _c;
|
|
3449
|
+
return setTimeout(
|
|
3450
|
+
resolve,
|
|
3451
|
+
(_c = (_a2 = this.client.options.rest) == null ? void 0 : _a2.timeout) != null ? _c : (_b2 = DEFAULT_CLIENT_OPTIONS.rest) == null ? void 0 : _b2.timeout
|
|
3452
|
+
);
|
|
3453
|
+
}
|
|
3454
|
+
);
|
|
3455
|
+
return this.retryRequest(attempt + 1, method, url, body, query);
|
|
3386
3456
|
}
|
|
3387
3457
|
});
|
|
3388
3458
|
}
|
|
@@ -3415,7 +3485,7 @@ var BaseClient = class extends EventEmitter {
|
|
|
3415
3485
|
__privateAdd(this, _token, null);
|
|
3416
3486
|
/** Whether the client is a bot. */
|
|
3417
3487
|
this.bot = true;
|
|
3418
|
-
this.options = __spreadValues({}, options);
|
|
3488
|
+
this.options = __spreadValues(__spreadValues({}, DEFAULT_CLIENT_OPTIONS), options);
|
|
3419
3489
|
this.bot = (_a = this.options.isBot) != null ? _a : true;
|
|
3420
3490
|
this.api = new RestClient(this);
|
|
3421
3491
|
this.cdn = new CDNClient(this);
|
|
@@ -3651,7 +3721,7 @@ var Message6 = class extends Event {
|
|
|
3651
3721
|
const channel = this.client.channels.cache.get(data.channel);
|
|
3652
3722
|
if (channel == null ? void 0 : channel.isText()) {
|
|
3653
3723
|
const message = channel.messages._add(data);
|
|
3654
|
-
if (data.author !== SYSTEM_USER_ID) {
|
|
3724
|
+
if (data.author !== SYSTEM_USER_ID && !data.webhook) {
|
|
3655
3725
|
yield this.client.users.fetch(data.author, { force: false });
|
|
3656
3726
|
}
|
|
3657
3727
|
this.client.emit("message" /* MESSAGE */, message);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "revbot.js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "A Revolt bot client used to interact with the revolt api for Node.js, written in TypeScript.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=24.0.0"
|
|
13
|
+
},
|
|
11
14
|
"repository": "https://github.com/Jade3375/revbot.js",
|
|
12
15
|
"keywords": [
|
|
13
16
|
"revoltjs",
|