revbot.js 0.1.10 → 0.2.0

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
@@ -449,9 +449,7 @@ var DEFAULT_CLIENT_OPTIONS = {
449
449
  reconnect: true
450
450
  }
451
451
  };
452
- var wsUrl = "wss://ws.revolt.chat?version=1&format=json";
453
- var apiUrl = "https://api.revolt.chat";
454
- var cdnUrl = "https://cdn.revoltusercontent.com";
452
+ var apiUrl = "https://api.stoat.chat";
455
453
  var SYSTEM_USER_ID = "0".repeat(UUID.TIME_LENGTH + UUID.RANDOM_LENGTH);
456
454
 
457
455
  // src/utils/permissions.ts
@@ -736,15 +734,15 @@ var User = class extends Base {
736
734
  });
737
735
  }
738
736
  avatarURL() {
739
- var _a, _b, _c, _d;
737
+ var _a, _b, _c;
740
738
  if (!((_a = this.avatar) == null ? void 0 : _a.id)) return void 0;
741
- 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
+ return `${(_b = this.client.options.rest) == null ? void 0 : _b.instanceCDNURL}/avatars/${(_c = this.avatar) == null ? void 0 : _c.id}`;
742
740
  }
743
741
  displayAvatarURL() {
744
742
  return __async(this, null, function* () {
745
- var _a, _b, _c;
746
- 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`;
747
- return (_c = this.avatarURL()) != null ? _c : defaultAvatar;
743
+ var _a, _b;
744
+ const defaultAvatar = `${(_a = this.client.options.rest) == null ? void 0 : _a.instanceCDNURL}/users/${this.id}/default_avatar`;
745
+ return (_b = this.avatarURL()) != null ? _b : defaultAvatar;
748
746
  });
749
747
  }
750
748
  /**
@@ -3227,10 +3225,10 @@ var ServerMemberManager = class extends BaseManager {
3227
3225
  import { EventEmitter } from "node:events";
3228
3226
 
3229
3227
  // src/rest/restClient.ts
3230
- import { AxiosError } from "axios";
3228
+ import axios4, { AxiosError } from "axios";
3231
3229
 
3232
3230
  // package.json
3233
- var version = "0.1.10";
3231
+ var version = "0.2.0";
3234
3232
 
3235
3233
  // src/rest/restUtils/rateLimitQueue.ts
3236
3234
  import axios3 from "axios";
@@ -3364,6 +3362,26 @@ var RestClient = class {
3364
3362
  }
3365
3363
  });
3366
3364
  }
3365
+ getConfig() {
3366
+ return __async(this, null, function* () {
3367
+ var _a, _b;
3368
+ try {
3369
+ const response = yield axios4.get(
3370
+ `${((_a = this.client.options.rest) == null ? void 0 : _a.instanceURL) ? (_b = this.client.options.rest) == null ? void 0 : _b.instanceURL : apiUrl}/`
3371
+ );
3372
+ const config = response.data;
3373
+ this.client.options.rest = __spreadProps(__spreadValues({}, this.client.options.rest), {
3374
+ instanceCDNURL: config.features.autumn.url
3375
+ });
3376
+ this.client.options.ws = __spreadProps(__spreadValues({}, this.client.options.ws), {
3377
+ instanceURL: config.ws
3378
+ });
3379
+ } catch (error) {
3380
+ console.error("Failed to fetch configuration:", error);
3381
+ process.exit(1);
3382
+ }
3383
+ });
3384
+ }
3367
3385
  retryRequest(attempt = 0, method, url, body, query) {
3368
3386
  return __async(this, null, function* () {
3369
3387
  var _a, _b;
@@ -3464,13 +3482,13 @@ var CDNClient = class {
3464
3482
  */
3465
3483
  request(method, url, data, query, retry) {
3466
3484
  return __async(this, null, function* () {
3467
- var _a, _b, _c, _d;
3485
+ var _a, _b;
3468
3486
  try {
3469
3487
  if (!this.client.token) throw new Error("Token is required");
3470
3488
  const authHeader = this.client.bot ? "X-Bot-Token" : "X-Session-Token";
3471
3489
  const config = __spreadProps(__spreadValues({}, {
3472
3490
  method,
3473
- url: `${((_a = this.client.options.rest) == null ? void 0 : _a.instanceCDNURL) ? (_b = this.client.options.rest) == null ? void 0 : _b.instanceCDNURL : cdnUrl}${url}`,
3491
+ url: `${(_a = this.client.options.rest) == null ? void 0 : _a.instanceCDNURL}${url}`,
3474
3492
  params: query,
3475
3493
  data,
3476
3494
  maxBodyLength: Infinity,
@@ -3480,7 +3498,7 @@ var CDNClient = class {
3480
3498
  "User-Agent": `RevBot.js/${version}`
3481
3499
  }, data.getHeaders())
3482
3500
  }), {
3483
- url: `${((_c = this.client.options.rest) == null ? void 0 : _c.instanceCDNURL) ? (_d = this.client.options.rest) == null ? void 0 : _d.instanceCDNURL : cdnUrl}${url}`
3501
+ url: `${(_b = this.client.options.rest) == null ? void 0 : _b.instanceCDNURL}${url}`
3484
3502
  });
3485
3503
  const response = yield this.rateLimitQueue.request(config);
3486
3504
  return response.data;
@@ -3548,11 +3566,11 @@ var BaseClient = class extends EventEmitter {
3548
3566
  * @param {clientOptions} [options={}] - The options for configuring the client.
3549
3567
  */
3550
3568
  constructor(options = {}) {
3551
- var _a, _b, _c, _d, _e, _f, _g;
3552
- 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)) {
3553
- 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)) {
3569
+ var _a, _b, _c;
3570
+ if ((_a = options.rest) == null ? void 0 : _a.instanceURL) {
3571
+ if (!((_b = options.rest) == null ? void 0 : _b.instanceURL)) {
3554
3572
  console.error(
3555
- 'All instance URLs must be provided (CDN, REST, WS) see docs at "https://jade3375.github.io/revbot.js/interfaces/clientOptions.html"'
3573
+ 'instance URLs must be provided (REST) see docs at "https://jade3375.github.io/revbot.js/interfaces/clientOptions.html"'
3556
3574
  );
3557
3575
  process.exit(0);
3558
3576
  } else {
@@ -3567,7 +3585,7 @@ var BaseClient = class extends EventEmitter {
3567
3585
  /** Whether the client is a bot. */
3568
3586
  this.bot = true;
3569
3587
  this.options = __spreadValues(__spreadValues({}, DEFAULT_CLIENT_OPTIONS), options);
3570
- this.bot = (_g = this.options.isBot) != null ? _g : true;
3588
+ this.bot = (_c = this.options.isBot) != null ? _c : true;
3571
3589
  this.api = new RestClient(this);
3572
3590
  this.cdn = new CDNClient(this);
3573
3591
  }
@@ -4407,7 +4425,7 @@ var WebSocketClient = class {
4407
4425
  * @returns {Promise<this>} A promise that resolves when the connection is established.
4408
4426
  */
4409
4427
  connect() {
4410
- return new Promise((resolve) => {
4428
+ return new Promise((resolve) => __async(this, null, function* () {
4411
4429
  var _a, _b, _c, _d;
4412
4430
  if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN && this.ready) {
4413
4431
  return resolve(this);
@@ -4418,15 +4436,16 @@ var WebSocketClient = class {
4418
4436
  if (typeof this.client.token !== "string") {
4419
4437
  throw new Error("INVALID_TOKEN");
4420
4438
  }
4421
- const ws = this.socket = (_d = this.socket) != null ? _d : new WebSocket(
4422
- `${((_b = this.client.options.ws) == null ? void 0 : _b.instanceURL) ? (_c = this.client.options.ws) == null ? void 0 : _c.instanceURL : wsUrl}`
4423
- );
4439
+ yield this.client.init();
4440
+ if (!((_b = this.client.options.ws) == null ? void 0 : _b.instanceURL))
4441
+ return Promise.reject(new Error("WebSocket instance URL not set."));
4442
+ const ws = this.socket = (_d = this.socket) != null ? _d : new WebSocket((_c = this.client.options.ws) == null ? void 0 : _c.instanceURL);
4424
4443
  ws.onopen = this.onOpen.bind(this);
4425
4444
  ws.onmessage = this.onMessage.bind(this);
4426
4445
  ws.onerror = this.onError.bind(this);
4427
4446
  ws.onclose = this.onClose.bind(this);
4428
4447
  ws.addEventListener("open", () => resolve(this));
4429
- });
4448
+ }));
4430
4449
  }
4431
4450
  /**
4432
4451
  * Destroys the WebSocket connection and clears its state.
@@ -4472,6 +4491,15 @@ var client2 = class extends BaseClient {
4472
4491
  /** The timestamp when the client became ready, or `null` if not ready. */
4473
4492
  this.readyAt = null;
4474
4493
  }
4494
+ /**
4495
+ * Initializes the client.
4496
+ * @private
4497
+ */
4498
+ init() {
4499
+ return __async(this, null, function* () {
4500
+ yield this.api.getConfig();
4501
+ });
4502
+ }
4475
4503
  /**
4476
4504
  * Gets the timestamp when the client became ready.
4477
4505
  *
@@ -4592,8 +4620,6 @@ export {
4592
4620
  VoiceChannel,
4593
4621
  WSEvents,
4594
4622
  apiUrl,
4595
- cdnUrl,
4596
- client2 as client,
4597
- wsUrl
4623
+ client2 as client
4598
4624
  };
4599
4625
  //# sourceMappingURL=index.mjs.map