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.d.mts CHANGED
@@ -138,6 +138,7 @@ declare class RestClient {
138
138
  * @returns The API response.
139
139
  */
140
140
  private request;
141
+ getConfig(): Promise<void>;
141
142
  private retryRequest;
142
143
  /**
143
144
  * GET request.
@@ -439,12 +440,8 @@ declare enum ChannelTypes {
439
440
  * The default options for configuring the client.
440
441
  */
441
442
  declare const DEFAULT_CLIENT_OPTIONS: clientOptions;
442
- /** The WebSocket URL for connecting to the Revolt API. */
443
- declare const wsUrl = "wss://ws.revolt.chat?version=1&format=json";
444
- /** The base API URL for interacting with the Revolt API. */
445
- declare const apiUrl = "https://api.revolt.chat";
446
- /** The base URL for the Revolt CDN, used for serving static assets. */
447
- declare const cdnUrl = "https://cdn.revoltusercontent.com";
443
+ /** The base API URL for interacting with the Stoat API. */
444
+ declare const apiUrl = "https://api.stoat.chat";
448
445
  /** The system user ID used for identifying system messages. */
449
446
  declare const SYSTEM_USER_ID: string;
450
447
 
@@ -2298,6 +2295,11 @@ declare class client extends BaseClient {
2298
2295
  user: ClientUser | null;
2299
2296
  /** The timestamp when the client became ready, or `null` if not ready. */
2300
2297
  readyAt: Date | null;
2298
+ /**
2299
+ * Initializes the client.
2300
+ * @private
2301
+ */
2302
+ init(): Promise<void>;
2301
2303
  /**
2302
2304
  * Gets the timestamp when the client became ready.
2303
2305
  *
@@ -2700,4 +2702,4 @@ declare class ServerMemberManager extends BaseManager<ServerMember, Member> {
2700
2702
  resolveId(member: ServerMemberResolvable): string | null;
2701
2703
  }
2702
2704
 
2703
- export { Attachment, type BadgeString, Badges, type BadgesResolvable, Base, BaseManager, BitField, type BitFieldResolvable, Category, Channel, ChannelManager, ChannelPermissions, type ChannelPermissionsResolvable, type ChannelPermissionsString, type ChannelResolvable, ChannelTypes, type CreateChannelOptions, DEFAULT_CLIENT_OPTIONS, DEFAULT_PERMISSION_DM, DMChannel, type EditServerMemberOptions, type EditServerOptions, type Embed, type EmbedImage, type EmbedSpecial, type EmbedVideo, Emoji, Events, FullPermissions, GroupChannel, Invite, Mentions, type MessageEditOptions, MessageEmbed, MessageManager, type MessageOptions, type MessageQueryOptions, type MessageReply, type MessageResolvable, type MessageSearchOptions, MessageStruct, NotesChannel, type Overwrite, type PartialObject, Presence, Role, RoleManager, type RoleResolvable, SYSTEM_USER_ID, Server, ServerChannel, ServerChannelManager, type ServerChannelResolvable, ServerManager, ServerMember, ServerMemberManager, type ServerMemberResolvable, ServerPermissions, type ServerPermissionsResolvable, type ServerPermissionsString, type ServerResolvable, Status, TextChannel, UUID, User, UserManager, UserPermissions, type UserPermissionsResolvable, type UserPermissionsString, type UserResolvable, VoiceChannel, WSEvents, apiUrl, cdnUrl, client, wsUrl };
2705
+ export { Attachment, type BadgeString, Badges, type BadgesResolvable, Base, BaseManager, BitField, type BitFieldResolvable, Category, Channel, ChannelManager, ChannelPermissions, type ChannelPermissionsResolvable, type ChannelPermissionsString, type ChannelResolvable, ChannelTypes, type CreateChannelOptions, DEFAULT_CLIENT_OPTIONS, DEFAULT_PERMISSION_DM, DMChannel, type EditServerMemberOptions, type EditServerOptions, type Embed, type EmbedImage, type EmbedSpecial, type EmbedVideo, Emoji, Events, FullPermissions, GroupChannel, Invite, Mentions, type MessageEditOptions, MessageEmbed, MessageManager, type MessageOptions, type MessageQueryOptions, type MessageReply, type MessageResolvable, type MessageSearchOptions, MessageStruct, NotesChannel, type Overwrite, type PartialObject, Presence, Role, RoleManager, type RoleResolvable, SYSTEM_USER_ID, Server, ServerChannel, ServerChannelManager, type ServerChannelResolvable, ServerManager, ServerMember, ServerMemberManager, type ServerMemberResolvable, ServerPermissions, type ServerPermissionsResolvable, type ServerPermissionsString, type ServerResolvable, Status, TextChannel, UUID, User, UserManager, UserPermissions, type UserPermissionsResolvable, type UserPermissionsString, type UserResolvable, VoiceChannel, WSEvents, apiUrl, client };
package/dist/index.d.ts CHANGED
@@ -138,6 +138,7 @@ declare class RestClient {
138
138
  * @returns The API response.
139
139
  */
140
140
  private request;
141
+ getConfig(): Promise<void>;
141
142
  private retryRequest;
142
143
  /**
143
144
  * GET request.
@@ -439,12 +440,8 @@ declare enum ChannelTypes {
439
440
  * The default options for configuring the client.
440
441
  */
441
442
  declare const DEFAULT_CLIENT_OPTIONS: clientOptions;
442
- /** The WebSocket URL for connecting to the Revolt API. */
443
- declare const wsUrl = "wss://ws.revolt.chat?version=1&format=json";
444
- /** The base API URL for interacting with the Revolt API. */
445
- declare const apiUrl = "https://api.revolt.chat";
446
- /** The base URL for the Revolt CDN, used for serving static assets. */
447
- declare const cdnUrl = "https://cdn.revoltusercontent.com";
443
+ /** The base API URL for interacting with the Stoat API. */
444
+ declare const apiUrl = "https://api.stoat.chat";
448
445
  /** The system user ID used for identifying system messages. */
449
446
  declare const SYSTEM_USER_ID: string;
450
447
 
@@ -2298,6 +2295,11 @@ declare class client extends BaseClient {
2298
2295
  user: ClientUser | null;
2299
2296
  /** The timestamp when the client became ready, or `null` if not ready. */
2300
2297
  readyAt: Date | null;
2298
+ /**
2299
+ * Initializes the client.
2300
+ * @private
2301
+ */
2302
+ init(): Promise<void>;
2301
2303
  /**
2302
2304
  * Gets the timestamp when the client became ready.
2303
2305
  *
@@ -2700,4 +2702,4 @@ declare class ServerMemberManager extends BaseManager<ServerMember, Member> {
2700
2702
  resolveId(member: ServerMemberResolvable): string | null;
2701
2703
  }
2702
2704
 
2703
- export { Attachment, type BadgeString, Badges, type BadgesResolvable, Base, BaseManager, BitField, type BitFieldResolvable, Category, Channel, ChannelManager, ChannelPermissions, type ChannelPermissionsResolvable, type ChannelPermissionsString, type ChannelResolvable, ChannelTypes, type CreateChannelOptions, DEFAULT_CLIENT_OPTIONS, DEFAULT_PERMISSION_DM, DMChannel, type EditServerMemberOptions, type EditServerOptions, type Embed, type EmbedImage, type EmbedSpecial, type EmbedVideo, Emoji, Events, FullPermissions, GroupChannel, Invite, Mentions, type MessageEditOptions, MessageEmbed, MessageManager, type MessageOptions, type MessageQueryOptions, type MessageReply, type MessageResolvable, type MessageSearchOptions, MessageStruct, NotesChannel, type Overwrite, type PartialObject, Presence, Role, RoleManager, type RoleResolvable, SYSTEM_USER_ID, Server, ServerChannel, ServerChannelManager, type ServerChannelResolvable, ServerManager, ServerMember, ServerMemberManager, type ServerMemberResolvable, ServerPermissions, type ServerPermissionsResolvable, type ServerPermissionsString, type ServerResolvable, Status, TextChannel, UUID, User, UserManager, UserPermissions, type UserPermissionsResolvable, type UserPermissionsString, type UserResolvable, VoiceChannel, WSEvents, apiUrl, cdnUrl, client, wsUrl };
2705
+ export { Attachment, type BadgeString, Badges, type BadgesResolvable, Base, BaseManager, BitField, type BitFieldResolvable, Category, Channel, ChannelManager, ChannelPermissions, type ChannelPermissionsResolvable, type ChannelPermissionsString, type ChannelResolvable, ChannelTypes, type CreateChannelOptions, DEFAULT_CLIENT_OPTIONS, DEFAULT_PERMISSION_DM, DMChannel, type EditServerMemberOptions, type EditServerOptions, type Embed, type EmbedImage, type EmbedSpecial, type EmbedVideo, Emoji, Events, FullPermissions, GroupChannel, Invite, Mentions, type MessageEditOptions, MessageEmbed, MessageManager, type MessageOptions, type MessageQueryOptions, type MessageReply, type MessageResolvable, type MessageSearchOptions, MessageStruct, NotesChannel, type Overwrite, type PartialObject, Presence, Role, RoleManager, type RoleResolvable, SYSTEM_USER_ID, Server, ServerChannel, ServerChannelManager, type ServerChannelResolvable, ServerManager, ServerMember, ServerMemberManager, type ServerMemberResolvable, ServerPermissions, type ServerPermissionsResolvable, type ServerPermissionsString, type ServerResolvable, Status, TextChannel, UUID, User, UserManager, UserPermissions, type UserPermissionsResolvable, type UserPermissionsString, type UserResolvable, VoiceChannel, WSEvents, apiUrl, client };
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
  /**
@@ -3305,10 +3301,10 @@ var ServerMemberManager = class extends BaseManager {
3305
3301
  var import_node_events = require("events");
3306
3302
 
3307
3303
  // src/rest/restClient.ts
3308
- var import_axios4 = require("axios");
3304
+ var import_axios4 = __toESM(require("axios"));
3309
3305
 
3310
3306
  // package.json
3311
- var version = "0.1.10";
3307
+ var version = "0.2.0";
3312
3308
 
3313
3309
  // src/rest/restUtils/rateLimitQueue.ts
3314
3310
  var import_axios3 = __toESM(require("axios"));
@@ -3442,6 +3438,26 @@ var RestClient = class {
3442
3438
  }
3443
3439
  });
3444
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
+ }
3445
3461
  retryRequest(attempt = 0, method, url, body, query) {
3446
3462
  return __async(this, null, function* () {
3447
3463
  var _a, _b;
@@ -3542,13 +3558,13 @@ var CDNClient = class {
3542
3558
  */
3543
3559
  request(method, url, data, query, retry) {
3544
3560
  return __async(this, null, function* () {
3545
- var _a, _b, _c, _d;
3561
+ var _a, _b;
3546
3562
  try {
3547
3563
  if (!this.client.token) throw new Error("Token is required");
3548
3564
  const authHeader = this.client.bot ? "X-Bot-Token" : "X-Session-Token";
3549
3565
  const config = __spreadProps(__spreadValues({}, {
3550
3566
  method,
3551
- 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}`,
3552
3568
  params: query,
3553
3569
  data,
3554
3570
  maxBodyLength: Infinity,
@@ -3558,7 +3574,7 @@ var CDNClient = class {
3558
3574
  "User-Agent": `RevBot.js/${version}`
3559
3575
  }, data.getHeaders())
3560
3576
  }), {
3561
- 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}`
3562
3578
  });
3563
3579
  const response = yield this.rateLimitQueue.request(config);
3564
3580
  return response.data;
@@ -3626,11 +3642,11 @@ var BaseClient = class extends import_node_events.EventEmitter {
3626
3642
  * @param {clientOptions} [options={}] - The options for configuring the client.
3627
3643
  */
3628
3644
  constructor(options = {}) {
3629
- var _a, _b, _c, _d, _e, _f, _g;
3630
- 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)) {
3631
- 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)) {
3632
3648
  console.error(
3633
- '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"'
3634
3650
  );
3635
3651
  process.exit(0);
3636
3652
  } else {
@@ -3645,7 +3661,7 @@ var BaseClient = class extends import_node_events.EventEmitter {
3645
3661
  /** Whether the client is a bot. */
3646
3662
  this.bot = true;
3647
3663
  this.options = __spreadValues(__spreadValues({}, DEFAULT_CLIENT_OPTIONS), options);
3648
- this.bot = (_g = this.options.isBot) != null ? _g : true;
3664
+ this.bot = (_c = this.options.isBot) != null ? _c : true;
3649
3665
  this.api = new RestClient(this);
3650
3666
  this.cdn = new CDNClient(this);
3651
3667
  }
@@ -4485,7 +4501,7 @@ var WebSocketClient = class {
4485
4501
  * @returns {Promise<this>} A promise that resolves when the connection is established.
4486
4502
  */
4487
4503
  connect() {
4488
- return new Promise((resolve) => {
4504
+ return new Promise((resolve) => __async(this, null, function* () {
4489
4505
  var _a, _b, _c, _d;
4490
4506
  if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN && this.ready) {
4491
4507
  return resolve(this);
@@ -4496,15 +4512,16 @@ var WebSocketClient = class {
4496
4512
  if (typeof this.client.token !== "string") {
4497
4513
  throw new Error("INVALID_TOKEN");
4498
4514
  }
4499
- const ws = this.socket = (_d = this.socket) != null ? _d : new WebSocket(
4500
- `${((_b = this.client.options.ws) == null ? void 0 : _b.instanceURL) ? (_c = this.client.options.ws) == null ? void 0 : _c.instanceURL : wsUrl}`
4501
- );
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);
4502
4519
  ws.onopen = this.onOpen.bind(this);
4503
4520
  ws.onmessage = this.onMessage.bind(this);
4504
4521
  ws.onerror = this.onError.bind(this);
4505
4522
  ws.onclose = this.onClose.bind(this);
4506
4523
  ws.addEventListener("open", () => resolve(this));
4507
- });
4524
+ }));
4508
4525
  }
4509
4526
  /**
4510
4527
  * Destroys the WebSocket connection and clears its state.
@@ -4550,6 +4567,15 @@ var client2 = class extends BaseClient {
4550
4567
  /** The timestamp when the client became ready, or `null` if not ready. */
4551
4568
  this.readyAt = null;
4552
4569
  }
4570
+ /**
4571
+ * Initializes the client.
4572
+ * @private
4573
+ */
4574
+ init() {
4575
+ return __async(this, null, function* () {
4576
+ yield this.api.getConfig();
4577
+ });
4578
+ }
4553
4579
  /**
4554
4580
  * Gets the timestamp when the client became ready.
4555
4581
  *
@@ -4671,8 +4697,6 @@ var client2 = class extends BaseClient {
4671
4697
  VoiceChannel,
4672
4698
  WSEvents,
4673
4699
  apiUrl,
4674
- cdnUrl,
4675
- client,
4676
- wsUrl
4700
+ client
4677
4701
  });
4678
4702
  //# sourceMappingURL=index.js.map