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.mjs CHANGED
@@ -104,14 +104,14 @@ var _BaseManager = class _BaseManager {
104
104
  }
105
105
  /** Adjust the maximum size for this manager at runtime. */
106
106
  setMaxSize(size) {
107
- if (!Number.isFinite(size) || size < 0)
107
+ if (!Number.isFinite(size) || size < -1)
108
108
  throw new RangeError("maxSize must be a non-negative finite number");
109
109
  this.maxSize = size;
110
110
  this.enforceMaxSize();
111
111
  }
112
112
  /** Force eviction until cache size is within the limit. */
113
113
  enforceMaxSize() {
114
- if (this.cache.size === -1) return;
114
+ if (this.maxSize === -1) return;
115
115
  if (this.maxSize === 0) {
116
116
  this.cache.clear();
117
117
  return;
@@ -142,7 +142,7 @@ var _BaseManager = class _BaseManager {
142
142
  }
143
143
  };
144
144
  /** Shared default max size for all managers (can be changed globally). */
145
- _BaseManager.defaultMaxSize = 1e3;
145
+ _BaseManager.defaultMaxSize = -1;
146
146
  var BaseManager = _BaseManager;
147
147
 
148
148
  // src/utils/bitField.ts
@@ -733,15 +733,15 @@ var User = class extends Base {
733
733
  });
734
734
  }
735
735
  avatarURL() {
736
- var _a, _b;
736
+ var _a, _b, _c, _d;
737
737
  if (!((_a = this.avatar) == null ? void 0 : _a.id)) return void 0;
738
- return `${cdnUrl}/avatars/${(_b = this.avatar) == null ? void 0 : _b.id}`;
738
+ 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}`;
739
739
  }
740
740
  displayAvatarURL() {
741
741
  return __async(this, null, function* () {
742
- var _a;
743
- const defaultAvatar = `${cdnUrl}/users/${this.id}/default_avatar`;
744
- return (_a = this.avatarURL()) != null ? _a : defaultAvatar;
742
+ var _a, _b, _c;
743
+ 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`;
744
+ return (_c = this.avatarURL()) != null ? _c : defaultAvatar;
745
745
  });
746
746
  }
747
747
  /**
@@ -2689,7 +2689,7 @@ import { Readable as Readable2 } from "stream";
2689
2689
  import FormData2 from "form-data";
2690
2690
  import axios2 from "axios";
2691
2691
  var MessageManager = class extends BaseManager {
2692
- constructor(channel, maxSize = 2) {
2692
+ constructor(channel, maxSize = 1e3) {
2693
2693
  super(channel.client, maxSize);
2694
2694
  this.channel = channel;
2695
2695
  this.holds = MessageStruct;
@@ -3199,7 +3199,7 @@ import { EventEmitter } from "node:events";
3199
3199
  import { AxiosError } from "axios";
3200
3200
 
3201
3201
  // package.json
3202
- var version = "0.1.5";
3202
+ var version = "0.1.7";
3203
3203
 
3204
3204
  // src/rest/restUtils/rateLimitQueue.ts
3205
3205
  import axios3 from "axios";
@@ -3297,13 +3297,13 @@ var RestClient = class {
3297
3297
  */
3298
3298
  request(method, url, body, query, retry) {
3299
3299
  return __async(this, null, function* () {
3300
- var _a;
3300
+ var _a, _b, _c;
3301
3301
  try {
3302
3302
  if (!this.client.token) throw new Error("Token is required");
3303
3303
  const authHeader = this.client.bot ? "X-Bot-Token" : "X-Session-Token";
3304
3304
  const config = __spreadProps(__spreadValues({}, {
3305
3305
  method,
3306
- url: `${apiUrl}${url}`,
3306
+ url: `${((_a = this.client.options.rest) == null ? void 0 : _a.instanceURL) ? (_b = this.client.options.rest) == null ? void 0 : _b.instanceURL : apiUrl}${url}`,
3307
3307
  params: query,
3308
3308
  data: body == null ? void 0 : body.body,
3309
3309
  headers: {
@@ -3323,7 +3323,7 @@ var RestClient = class {
3323
3323
  }
3324
3324
  if (error.status) {
3325
3325
  throw new Error(
3326
- `API call failed with status ${error.status}: ${(_a = error.response) == null ? void 0 : _a.statusText}`
3326
+ `API call failed with status ${error.status}: ${(_c = error.response) == null ? void 0 : _c.statusText}`
3327
3327
  );
3328
3328
  }
3329
3329
  }
@@ -3433,12 +3433,13 @@ var CDNClient = class {
3433
3433
  */
3434
3434
  request(method, url, data, query, retry) {
3435
3435
  return __async(this, null, function* () {
3436
+ var _a, _b, _c, _d;
3436
3437
  try {
3437
3438
  if (!this.client.token) throw new Error("Token is required");
3438
3439
  const authHeader = this.client.bot ? "X-Bot-Token" : "X-Session-Token";
3439
3440
  const config = __spreadProps(__spreadValues({}, {
3440
3441
  method,
3441
- url: `${cdnUrl}${url}`,
3442
+ url: `${((_a = this.client.options.rest) == null ? void 0 : _a.instanceCDNURL) ? (_b = this.client.options.rest) == null ? void 0 : _b.instanceCDNURL : cdnUrl}${url}`,
3442
3443
  params: query,
3443
3444
  data,
3444
3445
  maxBodyLength: Infinity,
@@ -3448,7 +3449,7 @@ var CDNClient = class {
3448
3449
  "User-Agent": `RevBot.js/${version}`
3449
3450
  }, data.getHeaders())
3450
3451
  }), {
3451
- url: `${cdnUrl}${url}`
3452
+ url: `${((_c = this.client.options.rest) == null ? void 0 : _c.instanceCDNURL) ? (_d = this.client.options.rest) == null ? void 0 : _d.instanceCDNURL : cdnUrl}${url}`
3452
3453
  });
3453
3454
  const response = yield this.rateLimitQueue.request(config);
3454
3455
  return response.data;
@@ -3517,14 +3518,26 @@ var BaseClient = class extends EventEmitter {
3517
3518
  * @param {clientOptions} [options={}] - The options for configuring the client.
3518
3519
  */
3519
3520
  constructor(options = {}) {
3520
- var _a;
3521
+ var _a, _b, _c, _d, _e, _f, _g;
3522
+ 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)) {
3523
+ 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)) {
3524
+ console.error(
3525
+ 'All instance URLs must be provided (CDN, REST, WS) see docs at "https://jade3375.github.io/revbot.js/interfaces/clientOptions.html"'
3526
+ );
3527
+ process.exit(0);
3528
+ } else {
3529
+ console.warn(
3530
+ "You are connecting to a custom instance of Revolt. compatibility with RevBot.js is not guaranteed."
3531
+ );
3532
+ }
3533
+ }
3521
3534
  super();
3522
3535
  /** The authentication token for the client. */
3523
3536
  __privateAdd(this, _token, null);
3524
3537
  /** Whether the client is a bot. */
3525
3538
  this.bot = true;
3526
3539
  this.options = __spreadValues(__spreadValues({}, DEFAULT_CLIENT_OPTIONS), options);
3527
- this.bot = (_a = this.options.isBot) != null ? _a : true;
3540
+ this.bot = (_g = this.options.isBot) != null ? _g : true;
3528
3541
  this.api = new RestClient(this);
3529
3542
  this.cdn = new CDNClient(this);
3530
3543
  }
@@ -4362,7 +4375,7 @@ var WebSocketClient = class {
4362
4375
  */
4363
4376
  connect() {
4364
4377
  return new Promise((resolve) => {
4365
- var _a, _b;
4378
+ var _a, _b, _c, _d;
4366
4379
  if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN && this.ready) {
4367
4380
  return resolve(this);
4368
4381
  }
@@ -4372,7 +4385,9 @@ var WebSocketClient = class {
4372
4385
  if (typeof this.client.token !== "string") {
4373
4386
  throw new Error("INVALID_TOKEN");
4374
4387
  }
4375
- const ws = this.socket = (_b = this.socket) != null ? _b : new WebSocket(`${wsUrl}`);
4388
+ const ws = this.socket = (_d = this.socket) != null ? _d : new WebSocket(
4389
+ `${((_b = this.client.options.ws) == null ? void 0 : _b.instanceURL) ? (_c = this.client.options.ws) == null ? void 0 : _c.instanceURL : wsUrl}`
4390
+ );
4376
4391
  ws.onopen = this.onOpen.bind(this);
4377
4392
  ws.onmessage = this.onMessage.bind(this);
4378
4393
  ws.onerror = this.onError.bind(this);