@stoatx/client 0.6.2 → 0.6.3

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.cts CHANGED
@@ -1933,7 +1933,10 @@ interface MessageOptions {
1933
1933
  content?: string;
1934
1934
  embeds?: (TextEmbedData | EmbedBuilder)[];
1935
1935
  attachments?: string[] | AttachmentBuilder[];
1936
- interactions?: any[];
1936
+ interactions?: {
1937
+ reactions?: string[] | null;
1938
+ restrict_reactions?: boolean;
1939
+ };
1937
1940
  flags?: number;
1938
1941
  masquerade?: Masquerade;
1939
1942
  replies?: ReplyIntent[];
package/dist/index.d.ts CHANGED
@@ -1933,7 +1933,10 @@ interface MessageOptions {
1933
1933
  content?: string;
1934
1934
  embeds?: (TextEmbedData | EmbedBuilder)[];
1935
1935
  attachments?: string[] | AttachmentBuilder[];
1936
- interactions?: any[];
1936
+ interactions?: {
1937
+ reactions?: string[] | null;
1938
+ restrict_reactions?: boolean;
1939
+ };
1937
1940
  flags?: number;
1938
1941
  masquerade?: Masquerade;
1939
1942
  replies?: ReplyIntent[];
package/dist/index.js CHANGED
@@ -1131,9 +1131,6 @@ var GatewayManager = class {
1131
1131
  }
1132
1132
  };
1133
1133
 
1134
- // src/rest/RESTManager.ts
1135
- import { request } from "undici";
1136
-
1137
1134
  // src/utils/schema.ts
1138
1135
  var queryParams = {
1139
1136
  "/": { get: [] },
@@ -1347,29 +1344,35 @@ var RESTManager = class {
1347
1344
  this.client.emit("debug", `Bucket [${method}:${endpoint}] exhausted. Waiting ${waitTime}ms proactively...`);
1348
1345
  await sleep(waitTime);
1349
1346
  }
1350
- const options = {
1347
+ const headers = {
1348
+ "X-Bot-Token": this.token
1349
+ };
1350
+ if (body) {
1351
+ headers["Content-Type"] = "application/json";
1352
+ }
1353
+ console.log("FETCH", method.toUpperCase(), url, JSON.stringify(body));
1354
+ const response = await fetch(url, {
1351
1355
  method: method.toUpperCase(),
1352
1356
  headers: {
1353
1357
  "X-Bot-Token": this.token,
1354
1358
  "Content-Type": "application/json"
1355
1359
  },
1356
- ...body ? { body: JSON.stringify(body) } : {}
1357
- };
1358
- const response = await request(url, options);
1359
- const remainingHeader = response.headers["x-ratelimit-remaining"];
1360
- const resetAfterHeader = response.headers["x-ratelimit-reset-after"];
1360
+ ...body !== void 0 ? { body: JSON.stringify(body) } : {}
1361
+ });
1362
+ const remainingHeader = response.headers.get("x-ratelimit-remaining");
1363
+ const resetAfterHeader = response.headers.get("x-ratelimit-reset-after");
1361
1364
  if (remainingHeader !== void 0 && resetAfterHeader !== void 0) {
1362
1365
  bucket.remaining = Number(remainingHeader);
1363
1366
  bucket.resetAt = Date.now() + Number(resetAfterHeader);
1364
1367
  }
1365
- const textBody = await response.body.text();
1368
+ const textBody = await response.text();
1366
1369
  let data;
1367
1370
  try {
1368
1371
  data = JSON.parse(textBody);
1369
1372
  } catch {
1370
1373
  data = textBody;
1371
1374
  }
1372
- if (response.statusCode === 429) {
1375
+ if (response.status === 429) {
1373
1376
  const retryMs = typeof data === "object" && data?.retry_after ? data.retry_after : Number(resetAfterHeader) || 5e3;
1374
1377
  this.client.emit("debug", `Hit 429 on [${method}:${endpoint}]. Retrying in ${retryMs}ms.`);
1375
1378
  bucket.remaining = 0;
@@ -1377,8 +1380,8 @@ var RESTManager = class {
1377
1380
  await sleep(retryMs);
1378
1381
  return this.execute(method, endpoint, body, bucket);
1379
1382
  }
1380
- if (response.statusCode >= 400) {
1381
- throw new StoatAPIError(response.statusCode, data, method, endpoint);
1383
+ if (response.status >= 400) {
1384
+ throw new StoatAPIError(response.status, data, method, endpoint);
1382
1385
  }
1383
1386
  return data;
1384
1387
  }
@@ -1573,8 +1576,8 @@ var MessageManager = class extends BaseManager {
1573
1576
  async send(contentOrOptions) {
1574
1577
  const opts = typeof contentOrOptions === "string" ? { content: contentOrOptions } : contentOrOptions;
1575
1578
  const payload = {};
1576
- if (opts.embeds && opts.embeds.length) {
1577
- payload.embeds = opts.embeds.map((embed) => typeof embed.toJSON === "function" ? embed.toJSON() : embed);
1579
+ if (opts.content) {
1580
+ payload.content = opts.content;
1578
1581
  }
1579
1582
  if (opts.attachments && opts.attachments.length > 0) {
1580
1583
  const resolved = await Promise.all(
@@ -1585,6 +1588,21 @@ var MessageManager = class extends BaseManager {
1585
1588
  payload.attachments = validAttachments;
1586
1589
  }
1587
1590
  }
1591
+ if (opts.replies) {
1592
+ payload.replies = opts.replies;
1593
+ }
1594
+ if (opts.embeds && opts.embeds.length) {
1595
+ payload.embeds = opts.embeds.map((embed) => typeof embed.toJSON === "function" ? embed.toJSON() : embed);
1596
+ }
1597
+ if (opts.masquerade) {
1598
+ payload.masquerade = opts.masquerade;
1599
+ }
1600
+ if (opts.interactions) {
1601
+ payload.interactions = opts.interactions;
1602
+ }
1603
+ if (opts.flags) {
1604
+ payload.flags = opts.flags;
1605
+ }
1588
1606
  const data = await this.client.rest.post(`/channels/${this.channel.id}/messages`, payload);
1589
1607
  return new Message(this.client, data);
1590
1608
  }