@stoatx/client 0.6.2 → 0.6.4

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.cjs CHANGED
@@ -1204,9 +1204,6 @@ var GatewayManager = class {
1204
1204
  }
1205
1205
  };
1206
1206
 
1207
- // src/rest/RESTManager.ts
1208
- var import_undici = require("undici");
1209
-
1210
1207
  // src/utils/schema.ts
1211
1208
  var queryParams = {
1212
1209
  "/": { get: [] },
@@ -1420,29 +1417,28 @@ var RESTManager = class {
1420
1417
  this.client.emit("debug", `Bucket [${method}:${endpoint}] exhausted. Waiting ${waitTime}ms proactively...`);
1421
1418
  await sleep(waitTime);
1422
1419
  }
1423
- const options = {
1420
+ const response = await fetch(url, {
1424
1421
  method: method.toUpperCase(),
1425
1422
  headers: {
1426
1423
  "X-Bot-Token": this.token,
1427
1424
  "Content-Type": "application/json"
1428
1425
  },
1429
- ...body ? { body: JSON.stringify(body) } : {}
1430
- };
1431
- const response = await (0, import_undici.request)(url, options);
1432
- const remainingHeader = response.headers["x-ratelimit-remaining"];
1433
- const resetAfterHeader = response.headers["x-ratelimit-reset-after"];
1426
+ ...body !== void 0 ? { body: JSON.stringify(body) } : {}
1427
+ });
1428
+ const remainingHeader = response.headers.get("x-ratelimit-remaining");
1429
+ const resetAfterHeader = response.headers.get("x-ratelimit-reset-after");
1434
1430
  if (remainingHeader !== void 0 && resetAfterHeader !== void 0) {
1435
1431
  bucket.remaining = Number(remainingHeader);
1436
1432
  bucket.resetAt = Date.now() + Number(resetAfterHeader);
1437
1433
  }
1438
- const textBody = await response.body.text();
1434
+ const textBody = await response.text();
1439
1435
  let data;
1440
1436
  try {
1441
1437
  data = JSON.parse(textBody);
1442
1438
  } catch {
1443
1439
  data = textBody;
1444
1440
  }
1445
- if (response.statusCode === 429) {
1441
+ if (response.status === 429) {
1446
1442
  const retryMs = typeof data === "object" && data?.retry_after ? data.retry_after : Number(resetAfterHeader) || 5e3;
1447
1443
  this.client.emit("debug", `Hit 429 on [${method}:${endpoint}]. Retrying in ${retryMs}ms.`);
1448
1444
  bucket.remaining = 0;
@@ -1450,8 +1446,8 @@ var RESTManager = class {
1450
1446
  await sleep(retryMs);
1451
1447
  return this.execute(method, endpoint, body, bucket);
1452
1448
  }
1453
- if (response.statusCode >= 400) {
1454
- throw new StoatAPIError(response.statusCode, data, method, endpoint);
1449
+ if (response.status >= 400) {
1450
+ throw new StoatAPIError(response.status, data, method, endpoint);
1455
1451
  }
1456
1452
  return data;
1457
1453
  }
@@ -1646,8 +1642,8 @@ var MessageManager = class extends BaseManager {
1646
1642
  async send(contentOrOptions) {
1647
1643
  const opts = typeof contentOrOptions === "string" ? { content: contentOrOptions } : contentOrOptions;
1648
1644
  const payload = {};
1649
- if (opts.embeds && opts.embeds.length) {
1650
- payload.embeds = opts.embeds.map((embed) => typeof embed.toJSON === "function" ? embed.toJSON() : embed);
1645
+ if (opts.content) {
1646
+ payload.content = opts.content;
1651
1647
  }
1652
1648
  if (opts.attachments && opts.attachments.length > 0) {
1653
1649
  const resolved = await Promise.all(
@@ -1658,6 +1654,21 @@ var MessageManager = class extends BaseManager {
1658
1654
  payload.attachments = validAttachments;
1659
1655
  }
1660
1656
  }
1657
+ if (opts.replies) {
1658
+ payload.replies = opts.replies;
1659
+ }
1660
+ if (opts.embeds && opts.embeds.length) {
1661
+ payload.embeds = opts.embeds.map((embed) => typeof embed.toJSON === "function" ? embed.toJSON() : embed);
1662
+ }
1663
+ if (opts.masquerade) {
1664
+ payload.masquerade = opts.masquerade;
1665
+ }
1666
+ if (opts.interactions) {
1667
+ payload.interactions = opts.interactions;
1668
+ }
1669
+ if (opts.flags) {
1670
+ payload.flags = opts.flags;
1671
+ }
1661
1672
  const data = await this.client.rest.post(`/channels/${this.channel.id}/messages`, payload);
1662
1673
  return new Message(this.client, data);
1663
1674
  }