revbot.js 0.1.5 → 0.1.7
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/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +34 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -274,9 +274,13 @@ interface clientOptions {
|
|
|
274
274
|
/** Configuration for REST API requests. */
|
|
275
275
|
rest?: {
|
|
276
276
|
/** The timeout for REST requests in milliseconds. */
|
|
277
|
-
timeout
|
|
277
|
+
timeout?: number;
|
|
278
278
|
/** The number of retries for failed REST requests. */
|
|
279
|
-
retries
|
|
279
|
+
retries?: number;
|
|
280
|
+
/** URL for revolt API instance without trailing slash */
|
|
281
|
+
instanceURL?: string;
|
|
282
|
+
/** URL for revolt CDN instance without trailing slash */
|
|
283
|
+
instanceCDNURL?: string;
|
|
280
284
|
};
|
|
281
285
|
MessageCache?: {
|
|
282
286
|
/** The maximum size of the cache. */
|
|
@@ -288,6 +292,8 @@ interface clientOptions {
|
|
|
288
292
|
heartbeatInterval?: number;
|
|
289
293
|
/** Whether to automatically reconnect on disconnection. */
|
|
290
294
|
reconnect?: boolean;
|
|
295
|
+
/** URL for revolt WebSocket instance without trailing slash */
|
|
296
|
+
instanceURL?: string;
|
|
291
297
|
};
|
|
292
298
|
}
|
|
293
299
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -274,9 +274,13 @@ interface clientOptions {
|
|
|
274
274
|
/** Configuration for REST API requests. */
|
|
275
275
|
rest?: {
|
|
276
276
|
/** The timeout for REST requests in milliseconds. */
|
|
277
|
-
timeout
|
|
277
|
+
timeout?: number;
|
|
278
278
|
/** The number of retries for failed REST requests. */
|
|
279
|
-
retries
|
|
279
|
+
retries?: number;
|
|
280
|
+
/** URL for revolt API instance without trailing slash */
|
|
281
|
+
instanceURL?: string;
|
|
282
|
+
/** URL for revolt CDN instance without trailing slash */
|
|
283
|
+
instanceCDNURL?: string;
|
|
280
284
|
};
|
|
281
285
|
MessageCache?: {
|
|
282
286
|
/** The maximum size of the cache. */
|
|
@@ -288,6 +292,8 @@ interface clientOptions {
|
|
|
288
292
|
heartbeatInterval?: number;
|
|
289
293
|
/** Whether to automatically reconnect on disconnection. */
|
|
290
294
|
reconnect?: boolean;
|
|
295
|
+
/** URL for revolt WebSocket instance without trailing slash */
|
|
296
|
+
instanceURL?: string;
|
|
291
297
|
};
|
|
292
298
|
}
|
|
293
299
|
/**
|
package/dist/index.js
CHANGED
|
@@ -182,14 +182,14 @@ var _BaseManager = class _BaseManager {
|
|
|
182
182
|
}
|
|
183
183
|
/** Adjust the maximum size for this manager at runtime. */
|
|
184
184
|
setMaxSize(size) {
|
|
185
|
-
if (!Number.isFinite(size) || size <
|
|
185
|
+
if (!Number.isFinite(size) || size < -1)
|
|
186
186
|
throw new RangeError("maxSize must be a non-negative finite number");
|
|
187
187
|
this.maxSize = size;
|
|
188
188
|
this.enforceMaxSize();
|
|
189
189
|
}
|
|
190
190
|
/** Force eviction until cache size is within the limit. */
|
|
191
191
|
enforceMaxSize() {
|
|
192
|
-
if (this.
|
|
192
|
+
if (this.maxSize === -1) return;
|
|
193
193
|
if (this.maxSize === 0) {
|
|
194
194
|
this.cache.clear();
|
|
195
195
|
return;
|
|
@@ -220,7 +220,7 @@ var _BaseManager = class _BaseManager {
|
|
|
220
220
|
}
|
|
221
221
|
};
|
|
222
222
|
/** Shared default max size for all managers (can be changed globally). */
|
|
223
|
-
_BaseManager.defaultMaxSize =
|
|
223
|
+
_BaseManager.defaultMaxSize = -1;
|
|
224
224
|
var BaseManager = _BaseManager;
|
|
225
225
|
|
|
226
226
|
// src/utils/bitField.ts
|
|
@@ -811,15 +811,15 @@ var User = class extends Base {
|
|
|
811
811
|
});
|
|
812
812
|
}
|
|
813
813
|
avatarURL() {
|
|
814
|
-
var _a, _b;
|
|
814
|
+
var _a, _b, _c, _d;
|
|
815
815
|
if (!((_a = this.avatar) == null ? void 0 : _a.id)) return void 0;
|
|
816
|
-
return `${cdnUrl}/avatars/${(
|
|
816
|
+
return `${((_b = this.client.options.rest) == null ? void 0 : _b.instanceCDNURL) ? (_c = this.client.options.rest) == null ? void 0 : _c.instanceCDNURL : cdnUrl}/avatars/${(_d = this.avatar) == null ? void 0 : _d.id}`;
|
|
817
817
|
}
|
|
818
818
|
displayAvatarURL() {
|
|
819
819
|
return __async(this, null, function* () {
|
|
820
|
-
var _a;
|
|
821
|
-
const defaultAvatar = `${cdnUrl}/users/${this.id}/default_avatar`;
|
|
822
|
-
return (
|
|
820
|
+
var _a, _b, _c;
|
|
821
|
+
const defaultAvatar = `${((_a = this.client.options.rest) == null ? void 0 : _a.instanceCDNURL) ? (_b = this.client.options.rest) == null ? void 0 : _b.instanceCDNURL : cdnUrl}/users/${this.id}/default_avatar`;
|
|
822
|
+
return (_c = this.avatarURL()) != null ? _c : defaultAvatar;
|
|
823
823
|
});
|
|
824
824
|
}
|
|
825
825
|
/**
|
|
@@ -2767,7 +2767,7 @@ var import_stream2 = require("stream");
|
|
|
2767
2767
|
var import_form_data2 = __toESM(require("form-data"));
|
|
2768
2768
|
var import_axios2 = __toESM(require("axios"));
|
|
2769
2769
|
var MessageManager = class extends BaseManager {
|
|
2770
|
-
constructor(channel, maxSize =
|
|
2770
|
+
constructor(channel, maxSize = 1e3) {
|
|
2771
2771
|
super(channel.client, maxSize);
|
|
2772
2772
|
this.channel = channel;
|
|
2773
2773
|
this.holds = MessageStruct;
|
|
@@ -3277,7 +3277,7 @@ var import_node_events = require("events");
|
|
|
3277
3277
|
var import_axios4 = require("axios");
|
|
3278
3278
|
|
|
3279
3279
|
// package.json
|
|
3280
|
-
var version = "0.1.
|
|
3280
|
+
var version = "0.1.7";
|
|
3281
3281
|
|
|
3282
3282
|
// src/rest/restUtils/rateLimitQueue.ts
|
|
3283
3283
|
var import_axios3 = __toESM(require("axios"));
|
|
@@ -3375,13 +3375,13 @@ var RestClient = class {
|
|
|
3375
3375
|
*/
|
|
3376
3376
|
request(method, url, body, query, retry) {
|
|
3377
3377
|
return __async(this, null, function* () {
|
|
3378
|
-
var _a;
|
|
3378
|
+
var _a, _b, _c;
|
|
3379
3379
|
try {
|
|
3380
3380
|
if (!this.client.token) throw new Error("Token is required");
|
|
3381
3381
|
const authHeader = this.client.bot ? "X-Bot-Token" : "X-Session-Token";
|
|
3382
3382
|
const config = __spreadProps(__spreadValues({}, {
|
|
3383
3383
|
method,
|
|
3384
|
-
url: `${apiUrl}${url}`,
|
|
3384
|
+
url: `${((_a = this.client.options.rest) == null ? void 0 : _a.instanceURL) ? (_b = this.client.options.rest) == null ? void 0 : _b.instanceURL : apiUrl}${url}`,
|
|
3385
3385
|
params: query,
|
|
3386
3386
|
data: body == null ? void 0 : body.body,
|
|
3387
3387
|
headers: {
|
|
@@ -3401,7 +3401,7 @@ var RestClient = class {
|
|
|
3401
3401
|
}
|
|
3402
3402
|
if (error.status) {
|
|
3403
3403
|
throw new Error(
|
|
3404
|
-
`API call failed with status ${error.status}: ${(
|
|
3404
|
+
`API call failed with status ${error.status}: ${(_c = error.response) == null ? void 0 : _c.statusText}`
|
|
3405
3405
|
);
|
|
3406
3406
|
}
|
|
3407
3407
|
}
|
|
@@ -3511,12 +3511,13 @@ var CDNClient = class {
|
|
|
3511
3511
|
*/
|
|
3512
3512
|
request(method, url, data, query, retry) {
|
|
3513
3513
|
return __async(this, null, function* () {
|
|
3514
|
+
var _a, _b, _c, _d;
|
|
3514
3515
|
try {
|
|
3515
3516
|
if (!this.client.token) throw new Error("Token is required");
|
|
3516
3517
|
const authHeader = this.client.bot ? "X-Bot-Token" : "X-Session-Token";
|
|
3517
3518
|
const config = __spreadProps(__spreadValues({}, {
|
|
3518
3519
|
method,
|
|
3519
|
-
url: `${cdnUrl}${url}`,
|
|
3520
|
+
url: `${((_a = this.client.options.rest) == null ? void 0 : _a.instanceCDNURL) ? (_b = this.client.options.rest) == null ? void 0 : _b.instanceCDNURL : cdnUrl}${url}`,
|
|
3520
3521
|
params: query,
|
|
3521
3522
|
data,
|
|
3522
3523
|
maxBodyLength: Infinity,
|
|
@@ -3526,7 +3527,7 @@ var CDNClient = class {
|
|
|
3526
3527
|
"User-Agent": `RevBot.js/${version}`
|
|
3527
3528
|
}, data.getHeaders())
|
|
3528
3529
|
}), {
|
|
3529
|
-
url: `${cdnUrl}${url}`
|
|
3530
|
+
url: `${((_c = this.client.options.rest) == null ? void 0 : _c.instanceCDNURL) ? (_d = this.client.options.rest) == null ? void 0 : _d.instanceCDNURL : cdnUrl}${url}`
|
|
3530
3531
|
});
|
|
3531
3532
|
const response = yield this.rateLimitQueue.request(config);
|
|
3532
3533
|
return response.data;
|
|
@@ -3595,14 +3596,26 @@ var BaseClient = class extends import_node_events.EventEmitter {
|
|
|
3595
3596
|
* @param {clientOptions} [options={}] - The options for configuring the client.
|
|
3596
3597
|
*/
|
|
3597
3598
|
constructor(options = {}) {
|
|
3598
|
-
var _a;
|
|
3599
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3600
|
+
if (((_a = options.rest) == null ? void 0 : _a.instanceCDNURL) || ((_b = options.rest) == null ? void 0 : _b.instanceURL) || ((_c = options.ws) == null ? void 0 : _c.instanceURL)) {
|
|
3601
|
+
if (!((_d = options.rest) == null ? void 0 : _d.instanceCDNURL) || !((_e = options.rest) == null ? void 0 : _e.instanceURL) || !((_f = options.ws) == null ? void 0 : _f.instanceURL)) {
|
|
3602
|
+
console.error(
|
|
3603
|
+
'All instance URLs must be provided (CDN, REST, WS) see docs at "https://jade3375.github.io/revbot.js/interfaces/clientOptions.html"'
|
|
3604
|
+
);
|
|
3605
|
+
process.exit(0);
|
|
3606
|
+
} else {
|
|
3607
|
+
console.warn(
|
|
3608
|
+
"You are connecting to a custom instance of Revolt. compatibility with RevBot.js is not guaranteed."
|
|
3609
|
+
);
|
|
3610
|
+
}
|
|
3611
|
+
}
|
|
3599
3612
|
super();
|
|
3600
3613
|
/** The authentication token for the client. */
|
|
3601
3614
|
__privateAdd(this, _token, null);
|
|
3602
3615
|
/** Whether the client is a bot. */
|
|
3603
3616
|
this.bot = true;
|
|
3604
3617
|
this.options = __spreadValues(__spreadValues({}, DEFAULT_CLIENT_OPTIONS), options);
|
|
3605
|
-
this.bot = (
|
|
3618
|
+
this.bot = (_g = this.options.isBot) != null ? _g : true;
|
|
3606
3619
|
this.api = new RestClient(this);
|
|
3607
3620
|
this.cdn = new CDNClient(this);
|
|
3608
3621
|
}
|
|
@@ -4440,7 +4453,7 @@ var WebSocketClient = class {
|
|
|
4440
4453
|
*/
|
|
4441
4454
|
connect() {
|
|
4442
4455
|
return new Promise((resolve) => {
|
|
4443
|
-
var _a, _b;
|
|
4456
|
+
var _a, _b, _c, _d;
|
|
4444
4457
|
if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN && this.ready) {
|
|
4445
4458
|
return resolve(this);
|
|
4446
4459
|
}
|
|
@@ -4450,7 +4463,9 @@ var WebSocketClient = class {
|
|
|
4450
4463
|
if (typeof this.client.token !== "string") {
|
|
4451
4464
|
throw new Error("INVALID_TOKEN");
|
|
4452
4465
|
}
|
|
4453
|
-
const ws = this.socket = (
|
|
4466
|
+
const ws = this.socket = (_d = this.socket) != null ? _d : new WebSocket(
|
|
4467
|
+
`${((_b = this.client.options.ws) == null ? void 0 : _b.instanceURL) ? (_c = this.client.options.ws) == null ? void 0 : _c.instanceURL : wsUrl}`
|
|
4468
|
+
);
|
|
4454
4469
|
ws.onopen = this.onOpen.bind(this);
|
|
4455
4470
|
ws.onmessage = this.onMessage.bind(this);
|
|
4456
4471
|
ws.onerror = this.onError.bind(this);
|