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.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
  /**
@@ -2023,6 +2021,8 @@ var ServerChannel = class extends Channel {
2023
2021
  this.description = null;
2024
2022
  /** The icon of the channel, or `null` if none is set. */
2025
2023
  this.icon = null;
2024
+ /** Manages the messages in this Server channel. */
2025
+ this.messages = new MessageManager(this);
2026
2026
  /** The permission overwrites for the channel. */
2027
2027
  this.overwrites = /* @__PURE__ */ new Map();
2028
2028
  /** Whether the channel is marked as NSFW (Not Safe For Work). */
@@ -2093,6 +2093,20 @@ var ServerChannel = class extends Channel {
2093
2093
  get server() {
2094
2094
  return this.client.servers.cache.get(this.serverId);
2095
2095
  }
2096
+ /**
2097
+ * Sends a message to this Server channel.
2098
+ *
2099
+ * @param {MessageOptions | string} options - The message content or options for the message.
2100
+ * @returns {Promise<Message>} A promise that resolves with the sent message.
2101
+ *
2102
+ * @example
2103
+ * ```typescript
2104
+ * await serverChannel.send("Hello, world!");
2105
+ * ```
2106
+ */
2107
+ send(options) {
2108
+ return this.messages.send(options);
2109
+ }
2096
2110
  /**
2097
2111
  * Retrieves the category this channel belongs to, if any.
2098
2112
  *
@@ -3211,10 +3225,10 @@ var ServerMemberManager = class extends BaseManager {
3211
3225
  import { EventEmitter } from "node:events";
3212
3226
 
3213
3227
  // src/rest/restClient.ts
3214
- import { AxiosError } from "axios";
3228
+ import axios4, { AxiosError } from "axios";
3215
3229
 
3216
3230
  // package.json
3217
- var version = "0.1.8";
3231
+ var version = "0.2.0";
3218
3232
 
3219
3233
  // src/rest/restUtils/rateLimitQueue.ts
3220
3234
  import axios3 from "axios";
@@ -3348,6 +3362,26 @@ var RestClient = class {
3348
3362
  }
3349
3363
  });
3350
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
+ }
3351
3385
  retryRequest(attempt = 0, method, url, body, query) {
3352
3386
  return __async(this, null, function* () {
3353
3387
  var _a, _b;
@@ -3448,13 +3482,13 @@ var CDNClient = class {
3448
3482
  */
3449
3483
  request(method, url, data, query, retry) {
3450
3484
  return __async(this, null, function* () {
3451
- var _a, _b, _c, _d;
3485
+ var _a, _b;
3452
3486
  try {
3453
3487
  if (!this.client.token) throw new Error("Token is required");
3454
3488
  const authHeader = this.client.bot ? "X-Bot-Token" : "X-Session-Token";
3455
3489
  const config = __spreadProps(__spreadValues({}, {
3456
3490
  method,
3457
- 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}`,
3458
3492
  params: query,
3459
3493
  data,
3460
3494
  maxBodyLength: Infinity,
@@ -3464,7 +3498,7 @@ var CDNClient = class {
3464
3498
  "User-Agent": `RevBot.js/${version}`
3465
3499
  }, data.getHeaders())
3466
3500
  }), {
3467
- 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}`
3468
3502
  });
3469
3503
  const response = yield this.rateLimitQueue.request(config);
3470
3504
  return response.data;
@@ -3532,11 +3566,11 @@ var BaseClient = class extends EventEmitter {
3532
3566
  * @param {clientOptions} [options={}] - The options for configuring the client.
3533
3567
  */
3534
3568
  constructor(options = {}) {
3535
- var _a, _b, _c, _d, _e, _f, _g;
3536
- 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)) {
3537
- 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)) {
3538
3572
  console.error(
3539
- '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"'
3540
3574
  );
3541
3575
  process.exit(0);
3542
3576
  } else {
@@ -3551,7 +3585,7 @@ var BaseClient = class extends EventEmitter {
3551
3585
  /** Whether the client is a bot. */
3552
3586
  this.bot = true;
3553
3587
  this.options = __spreadValues(__spreadValues({}, DEFAULT_CLIENT_OPTIONS), options);
3554
- this.bot = (_g = this.options.isBot) != null ? _g : true;
3588
+ this.bot = (_c = this.options.isBot) != null ? _c : true;
3555
3589
  this.api = new RestClient(this);
3556
3590
  this.cdn = new CDNClient(this);
3557
3591
  }
@@ -4350,21 +4384,21 @@ var WebSocketClient = class {
4350
4384
  this.client.users._add(user);
4351
4385
  }
4352
4386
  }
4353
- for (const server of packet.servers) {
4354
- const s = this.client.servers._add(server);
4355
- if (this.client.options.fetchMembers) {
4356
- promises.push(s.members.fetch());
4357
- }
4358
- }
4359
- for (const channel of packet.channels) {
4360
- this.client.channels._add(channel);
4361
- }
4362
4387
  for (const member of packet.members) {
4363
4388
  (_a = this.client.servers.cache.get(member._id.server)) == null ? void 0 : _a.members._add(member);
4364
4389
  }
4365
4390
  for (const emoji of packet.emojis) {
4366
4391
  (_b = this.client.servers.cache.get(emoji.parent.id)) == null ? void 0 : _b.emojis.set(emoji._id, __spreadProps(__spreadValues({}, emoji), { _id: emoji._id }));
4367
4392
  }
4393
+ for (const channel of packet.channels) {
4394
+ this.client.channels._add(channel);
4395
+ }
4396
+ for (const server of packet.servers) {
4397
+ const s = this.client.servers._add(server);
4398
+ if (this.client.options.fetchMembers) {
4399
+ promises.push(s.members.fetch());
4400
+ }
4401
+ }
4368
4402
  this.setHeartbeatTimer(
4369
4403
  (_d = (_c = this.client.options.ws) == null ? void 0 : _c.heartbeatInterval) != null ? _d : 3e4
4370
4404
  );
@@ -4391,7 +4425,7 @@ var WebSocketClient = class {
4391
4425
  * @returns {Promise<this>} A promise that resolves when the connection is established.
4392
4426
  */
4393
4427
  connect() {
4394
- return new Promise((resolve) => {
4428
+ return new Promise((resolve) => __async(this, null, function* () {
4395
4429
  var _a, _b, _c, _d;
4396
4430
  if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN && this.ready) {
4397
4431
  return resolve(this);
@@ -4402,15 +4436,16 @@ var WebSocketClient = class {
4402
4436
  if (typeof this.client.token !== "string") {
4403
4437
  throw new Error("INVALID_TOKEN");
4404
4438
  }
4405
- const ws = this.socket = (_d = this.socket) != null ? _d : new WebSocket(
4406
- `${((_b = this.client.options.ws) == null ? void 0 : _b.instanceURL) ? (_c = this.client.options.ws) == null ? void 0 : _c.instanceURL : wsUrl}`
4407
- );
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);
4408
4443
  ws.onopen = this.onOpen.bind(this);
4409
4444
  ws.onmessage = this.onMessage.bind(this);
4410
4445
  ws.onerror = this.onError.bind(this);
4411
4446
  ws.onclose = this.onClose.bind(this);
4412
4447
  ws.addEventListener("open", () => resolve(this));
4413
- });
4448
+ }));
4414
4449
  }
4415
4450
  /**
4416
4451
  * Destroys the WebSocket connection and clears its state.
@@ -4456,6 +4491,15 @@ var client2 = class extends BaseClient {
4456
4491
  /** The timestamp when the client became ready, or `null` if not ready. */
4457
4492
  this.readyAt = null;
4458
4493
  }
4494
+ /**
4495
+ * Initializes the client.
4496
+ * @private
4497
+ */
4498
+ init() {
4499
+ return __async(this, null, function* () {
4500
+ yield this.api.getConfig();
4501
+ });
4502
+ }
4459
4503
  /**
4460
4504
  * Gets the timestamp when the client became ready.
4461
4505
  *
@@ -4576,8 +4620,6 @@ export {
4576
4620
  VoiceChannel,
4577
4621
  WSEvents,
4578
4622
  apiUrl,
4579
- cdnUrl,
4580
- client2 as client,
4581
- wsUrl
4623
+ client2 as client
4582
4624
  };
4583
4625
  //# sourceMappingURL=index.mjs.map