revbot.js 0.1.9 → 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.js CHANGED
@@ -151,9 +151,7 @@ __export(index_exports, {
151
151
  VoiceChannel: () => VoiceChannel,
152
152
  WSEvents: () => WSEvents,
153
153
  apiUrl: () => apiUrl,
154
- cdnUrl: () => cdnUrl,
155
- client: () => client2,
156
- wsUrl: () => wsUrl
154
+ client: () => client2
157
155
  });
158
156
  module.exports = __toCommonJS(index_exports);
159
157
 
@@ -527,9 +525,7 @@ var DEFAULT_CLIENT_OPTIONS = {
527
525
  reconnect: true
528
526
  }
529
527
  };
530
- var wsUrl = "wss://ws.revolt.chat?version=1&format=json";
531
- var apiUrl = "https://api.revolt.chat";
532
- var cdnUrl = "https://cdn.revoltusercontent.com";
528
+ var apiUrl = "https://api.stoat.chat";
533
529
  var SYSTEM_USER_ID = "0".repeat(UUID.TIME_LENGTH + UUID.RANDOM_LENGTH);
534
530
 
535
531
  // src/utils/permissions.ts
@@ -814,15 +810,15 @@ var User = class extends Base {
814
810
  });
815
811
  }
816
812
  avatarURL() {
817
- var _a, _b, _c, _d;
813
+ var _a, _b, _c;
818
814
  if (!((_a = this.avatar) == null ? void 0 : _a.id)) return void 0;
819
- 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}`;
815
+ return `${(_b = this.client.options.rest) == null ? void 0 : _b.instanceCDNURL}/avatars/${(_c = this.avatar) == null ? void 0 : _c.id}`;
820
816
  }
821
817
  displayAvatarURL() {
822
818
  return __async(this, null, function* () {
823
- var _a, _b, _c;
824
- 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`;
825
- return (_c = this.avatarURL()) != null ? _c : defaultAvatar;
819
+ var _a, _b;
820
+ const defaultAvatar = `${(_a = this.client.options.rest) == null ? void 0 : _a.instanceCDNURL}/users/${this.id}/default_avatar`;
821
+ return (_b = this.avatarURL()) != null ? _b : defaultAvatar;
826
822
  });
827
823
  }
828
824
  /**
@@ -2101,6 +2097,8 @@ var ServerChannel = class extends Channel {
2101
2097
  this.description = null;
2102
2098
  /** The icon of the channel, or `null` if none is set. */
2103
2099
  this.icon = null;
2100
+ /** Manages the messages in this Server channel. */
2101
+ this.messages = new MessageManager(this);
2104
2102
  /** The permission overwrites for the channel. */
2105
2103
  this.overwrites = /* @__PURE__ */ new Map();
2106
2104
  /** Whether the channel is marked as NSFW (Not Safe For Work). */
@@ -2171,6 +2169,20 @@ var ServerChannel = class extends Channel {
2171
2169
  get server() {
2172
2170
  return this.client.servers.cache.get(this.serverId);
2173
2171
  }
2172
+ /**
2173
+ * Sends a message to this Server channel.
2174
+ *
2175
+ * @param {MessageOptions | string} options - The message content or options for the message.
2176
+ * @returns {Promise<Message>} A promise that resolves with the sent message.
2177
+ *
2178
+ * @example
2179
+ * ```typescript
2180
+ * await serverChannel.send("Hello, world!");
2181
+ * ```
2182
+ */
2183
+ send(options) {
2184
+ return this.messages.send(options);
2185
+ }
2174
2186
  /**
2175
2187
  * Retrieves the category this channel belongs to, if any.
2176
2188
  *
@@ -3289,10 +3301,10 @@ var ServerMemberManager = class extends BaseManager {
3289
3301
  var import_node_events = require("events");
3290
3302
 
3291
3303
  // src/rest/restClient.ts
3292
- var import_axios4 = require("axios");
3304
+ var import_axios4 = __toESM(require("axios"));
3293
3305
 
3294
3306
  // package.json
3295
- var version = "0.1.8";
3307
+ var version = "0.2.0";
3296
3308
 
3297
3309
  // src/rest/restUtils/rateLimitQueue.ts
3298
3310
  var import_axios3 = __toESM(require("axios"));
@@ -3426,6 +3438,26 @@ var RestClient = class {
3426
3438
  }
3427
3439
  });
3428
3440
  }
3441
+ getConfig() {
3442
+ return __async(this, null, function* () {
3443
+ var _a, _b;
3444
+ try {
3445
+ const response = yield import_axios4.default.get(
3446
+ `${((_a = this.client.options.rest) == null ? void 0 : _a.instanceURL) ? (_b = this.client.options.rest) == null ? void 0 : _b.instanceURL : apiUrl}/`
3447
+ );
3448
+ const config = response.data;
3449
+ this.client.options.rest = __spreadProps(__spreadValues({}, this.client.options.rest), {
3450
+ instanceCDNURL: config.features.autumn.url
3451
+ });
3452
+ this.client.options.ws = __spreadProps(__spreadValues({}, this.client.options.ws), {
3453
+ instanceURL: config.ws
3454
+ });
3455
+ } catch (error) {
3456
+ console.error("Failed to fetch configuration:", error);
3457
+ process.exit(1);
3458
+ }
3459
+ });
3460
+ }
3429
3461
  retryRequest(attempt = 0, method, url, body, query) {
3430
3462
  return __async(this, null, function* () {
3431
3463
  var _a, _b;
@@ -3526,13 +3558,13 @@ var CDNClient = class {
3526
3558
  */
3527
3559
  request(method, url, data, query, retry) {
3528
3560
  return __async(this, null, function* () {
3529
- var _a, _b, _c, _d;
3561
+ var _a, _b;
3530
3562
  try {
3531
3563
  if (!this.client.token) throw new Error("Token is required");
3532
3564
  const authHeader = this.client.bot ? "X-Bot-Token" : "X-Session-Token";
3533
3565
  const config = __spreadProps(__spreadValues({}, {
3534
3566
  method,
3535
- url: `${((_a = this.client.options.rest) == null ? void 0 : _a.instanceCDNURL) ? (_b = this.client.options.rest) == null ? void 0 : _b.instanceCDNURL : cdnUrl}${url}`,
3567
+ url: `${(_a = this.client.options.rest) == null ? void 0 : _a.instanceCDNURL}${url}`,
3536
3568
  params: query,
3537
3569
  data,
3538
3570
  maxBodyLength: Infinity,
@@ -3542,7 +3574,7 @@ var CDNClient = class {
3542
3574
  "User-Agent": `RevBot.js/${version}`
3543
3575
  }, data.getHeaders())
3544
3576
  }), {
3545
- url: `${((_c = this.client.options.rest) == null ? void 0 : _c.instanceCDNURL) ? (_d = this.client.options.rest) == null ? void 0 : _d.instanceCDNURL : cdnUrl}${url}`
3577
+ url: `${(_b = this.client.options.rest) == null ? void 0 : _b.instanceCDNURL}${url}`
3546
3578
  });
3547
3579
  const response = yield this.rateLimitQueue.request(config);
3548
3580
  return response.data;
@@ -3610,11 +3642,11 @@ var BaseClient = class extends import_node_events.EventEmitter {
3610
3642
  * @param {clientOptions} [options={}] - The options for configuring the client.
3611
3643
  */
3612
3644
  constructor(options = {}) {
3613
- var _a, _b, _c, _d, _e, _f, _g;
3614
- 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)) {
3615
- 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)) {
3645
+ var _a, _b, _c;
3646
+ if ((_a = options.rest) == null ? void 0 : _a.instanceURL) {
3647
+ if (!((_b = options.rest) == null ? void 0 : _b.instanceURL)) {
3616
3648
  console.error(
3617
- 'All instance URLs must be provided (CDN, REST, WS) see docs at "https://jade3375.github.io/revbot.js/interfaces/clientOptions.html"'
3649
+ 'instance URLs must be provided (REST) see docs at "https://jade3375.github.io/revbot.js/interfaces/clientOptions.html"'
3618
3650
  );
3619
3651
  process.exit(0);
3620
3652
  } else {
@@ -3629,7 +3661,7 @@ var BaseClient = class extends import_node_events.EventEmitter {
3629
3661
  /** Whether the client is a bot. */
3630
3662
  this.bot = true;
3631
3663
  this.options = __spreadValues(__spreadValues({}, DEFAULT_CLIENT_OPTIONS), options);
3632
- this.bot = (_g = this.options.isBot) != null ? _g : true;
3664
+ this.bot = (_c = this.options.isBot) != null ? _c : true;
3633
3665
  this.api = new RestClient(this);
3634
3666
  this.cdn = new CDNClient(this);
3635
3667
  }
@@ -4428,21 +4460,21 @@ var WebSocketClient = class {
4428
4460
  this.client.users._add(user);
4429
4461
  }
4430
4462
  }
4431
- for (const server of packet.servers) {
4432
- const s = this.client.servers._add(server);
4433
- if (this.client.options.fetchMembers) {
4434
- promises.push(s.members.fetch());
4435
- }
4436
- }
4437
- for (const channel of packet.channels) {
4438
- this.client.channels._add(channel);
4439
- }
4440
4463
  for (const member of packet.members) {
4441
4464
  (_a = this.client.servers.cache.get(member._id.server)) == null ? void 0 : _a.members._add(member);
4442
4465
  }
4443
4466
  for (const emoji of packet.emojis) {
4444
4467
  (_b = this.client.servers.cache.get(emoji.parent.id)) == null ? void 0 : _b.emojis.set(emoji._id, __spreadProps(__spreadValues({}, emoji), { _id: emoji._id }));
4445
4468
  }
4469
+ for (const channel of packet.channels) {
4470
+ this.client.channels._add(channel);
4471
+ }
4472
+ for (const server of packet.servers) {
4473
+ const s = this.client.servers._add(server);
4474
+ if (this.client.options.fetchMembers) {
4475
+ promises.push(s.members.fetch());
4476
+ }
4477
+ }
4446
4478
  this.setHeartbeatTimer(
4447
4479
  (_d = (_c = this.client.options.ws) == null ? void 0 : _c.heartbeatInterval) != null ? _d : 3e4
4448
4480
  );
@@ -4469,7 +4501,7 @@ var WebSocketClient = class {
4469
4501
  * @returns {Promise<this>} A promise that resolves when the connection is established.
4470
4502
  */
4471
4503
  connect() {
4472
- return new Promise((resolve) => {
4504
+ return new Promise((resolve) => __async(this, null, function* () {
4473
4505
  var _a, _b, _c, _d;
4474
4506
  if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN && this.ready) {
4475
4507
  return resolve(this);
@@ -4480,15 +4512,16 @@ var WebSocketClient = class {
4480
4512
  if (typeof this.client.token !== "string") {
4481
4513
  throw new Error("INVALID_TOKEN");
4482
4514
  }
4483
- const ws = this.socket = (_d = this.socket) != null ? _d : new WebSocket(
4484
- `${((_b = this.client.options.ws) == null ? void 0 : _b.instanceURL) ? (_c = this.client.options.ws) == null ? void 0 : _c.instanceURL : wsUrl}`
4485
- );
4515
+ yield this.client.init();
4516
+ if (!((_b = this.client.options.ws) == null ? void 0 : _b.instanceURL))
4517
+ return Promise.reject(new Error("WebSocket instance URL not set."));
4518
+ const ws = this.socket = (_d = this.socket) != null ? _d : new WebSocket((_c = this.client.options.ws) == null ? void 0 : _c.instanceURL);
4486
4519
  ws.onopen = this.onOpen.bind(this);
4487
4520
  ws.onmessage = this.onMessage.bind(this);
4488
4521
  ws.onerror = this.onError.bind(this);
4489
4522
  ws.onclose = this.onClose.bind(this);
4490
4523
  ws.addEventListener("open", () => resolve(this));
4491
- });
4524
+ }));
4492
4525
  }
4493
4526
  /**
4494
4527
  * Destroys the WebSocket connection and clears its state.
@@ -4534,6 +4567,15 @@ var client2 = class extends BaseClient {
4534
4567
  /** The timestamp when the client became ready, or `null` if not ready. */
4535
4568
  this.readyAt = null;
4536
4569
  }
4570
+ /**
4571
+ * Initializes the client.
4572
+ * @private
4573
+ */
4574
+ init() {
4575
+ return __async(this, null, function* () {
4576
+ yield this.api.getConfig();
4577
+ });
4578
+ }
4537
4579
  /**
4538
4580
  * Gets the timestamp when the client became ready.
4539
4581
  *
@@ -4655,8 +4697,6 @@ var client2 = class extends BaseClient {
4655
4697
  VoiceChannel,
4656
4698
  WSEvents,
4657
4699
  apiUrl,
4658
- cdnUrl,
4659
- client,
4660
- wsUrl
4700
+ client
4661
4701
  });
4662
4702
  //# sourceMappingURL=index.js.map