@stoatx/client 0.6.1 → 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
@@ -1067,10 +1067,21 @@ var GatewayManager = class {
1067
1067
  }
1068
1068
  case "UserUpdate": {
1069
1069
  const existing = this.client.users.cache.get(payload.id);
1070
+ const isClientUser = this.client.user?.id === payload.id;
1071
+ let oldUser;
1072
+ let newUser;
1070
1073
  if (existing) {
1071
- const oldUser = existing._clone();
1074
+ oldUser = existing._clone();
1072
1075
  existing._patch(payload.data, payload.clear);
1073
- this.client.emit("userUpdate", oldUser, existing);
1076
+ newUser = existing;
1077
+ }
1078
+ if (isClientUser) {
1079
+ oldUser = this.client.user?._clone();
1080
+ this.client.user?._patch(payload.data, payload.clear);
1081
+ newUser = this.client.user;
1082
+ }
1083
+ if (oldUser && newUser) {
1084
+ this.client.emit("userUpdate", oldUser, newUser);
1074
1085
  }
1075
1086
  break;
1076
1087
  }
@@ -1120,9 +1131,6 @@ var GatewayManager = class {
1120
1131
  }
1121
1132
  };
1122
1133
 
1123
- // src/rest/RESTManager.ts
1124
- import { request } from "undici";
1125
-
1126
1134
  // src/utils/schema.ts
1127
1135
  var queryParams = {
1128
1136
  "/": { get: [] },
@@ -1336,29 +1344,35 @@ var RESTManager = class {
1336
1344
  this.client.emit("debug", `Bucket [${method}:${endpoint}] exhausted. Waiting ${waitTime}ms proactively...`);
1337
1345
  await sleep(waitTime);
1338
1346
  }
1339
- 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, {
1340
1355
  method: method.toUpperCase(),
1341
1356
  headers: {
1342
1357
  "X-Bot-Token": this.token,
1343
1358
  "Content-Type": "application/json"
1344
1359
  },
1345
- ...body ? { body: JSON.stringify(body) } : {}
1346
- };
1347
- const response = await request(url, options);
1348
- const remainingHeader = response.headers["x-ratelimit-remaining"];
1349
- 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");
1350
1364
  if (remainingHeader !== void 0 && resetAfterHeader !== void 0) {
1351
1365
  bucket.remaining = Number(remainingHeader);
1352
1366
  bucket.resetAt = Date.now() + Number(resetAfterHeader);
1353
1367
  }
1354
- const textBody = await response.body.text();
1368
+ const textBody = await response.text();
1355
1369
  let data;
1356
1370
  try {
1357
1371
  data = JSON.parse(textBody);
1358
1372
  } catch {
1359
1373
  data = textBody;
1360
1374
  }
1361
- if (response.statusCode === 429) {
1375
+ if (response.status === 429) {
1362
1376
  const retryMs = typeof data === "object" && data?.retry_after ? data.retry_after : Number(resetAfterHeader) || 5e3;
1363
1377
  this.client.emit("debug", `Hit 429 on [${method}:${endpoint}]. Retrying in ${retryMs}ms.`);
1364
1378
  bucket.remaining = 0;
@@ -1366,8 +1380,8 @@ var RESTManager = class {
1366
1380
  await sleep(retryMs);
1367
1381
  return this.execute(method, endpoint, body, bucket);
1368
1382
  }
1369
- if (response.statusCode >= 400) {
1370
- throw new StoatAPIError(response.statusCode, data, method, endpoint);
1383
+ if (response.status >= 400) {
1384
+ throw new StoatAPIError(response.status, data, method, endpoint);
1371
1385
  }
1372
1386
  return data;
1373
1387
  }
@@ -1562,8 +1576,8 @@ var MessageManager = class extends BaseManager {
1562
1576
  async send(contentOrOptions) {
1563
1577
  const opts = typeof contentOrOptions === "string" ? { content: contentOrOptions } : contentOrOptions;
1564
1578
  const payload = {};
1565
- if (opts.embeds && opts.embeds.length) {
1566
- payload.embeds = opts.embeds.map((embed) => typeof embed.toJSON === "function" ? embed.toJSON() : embed);
1579
+ if (opts.content) {
1580
+ payload.content = opts.content;
1567
1581
  }
1568
1582
  if (opts.attachments && opts.attachments.length > 0) {
1569
1583
  const resolved = await Promise.all(
@@ -1574,6 +1588,21 @@ var MessageManager = class extends BaseManager {
1574
1588
  payload.attachments = validAttachments;
1575
1589
  }
1576
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
+ }
1577
1606
  const data = await this.client.rest.post(`/channels/${this.channel.id}/messages`, payload);
1578
1607
  return new Message(this.client, data);
1579
1608
  }