@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.cjs +46 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +46 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -2
package/dist/index.cjs
CHANGED
|
@@ -1140,10 +1140,21 @@ var GatewayManager = class {
|
|
|
1140
1140
|
}
|
|
1141
1141
|
case "UserUpdate": {
|
|
1142
1142
|
const existing = this.client.users.cache.get(payload.id);
|
|
1143
|
+
const isClientUser = this.client.user?.id === payload.id;
|
|
1144
|
+
let oldUser;
|
|
1145
|
+
let newUser;
|
|
1143
1146
|
if (existing) {
|
|
1144
|
-
|
|
1147
|
+
oldUser = existing._clone();
|
|
1145
1148
|
existing._patch(payload.data, payload.clear);
|
|
1146
|
-
|
|
1149
|
+
newUser = existing;
|
|
1150
|
+
}
|
|
1151
|
+
if (isClientUser) {
|
|
1152
|
+
oldUser = this.client.user?._clone();
|
|
1153
|
+
this.client.user?._patch(payload.data, payload.clear);
|
|
1154
|
+
newUser = this.client.user;
|
|
1155
|
+
}
|
|
1156
|
+
if (oldUser && newUser) {
|
|
1157
|
+
this.client.emit("userUpdate", oldUser, newUser);
|
|
1147
1158
|
}
|
|
1148
1159
|
break;
|
|
1149
1160
|
}
|
|
@@ -1193,9 +1204,6 @@ var GatewayManager = class {
|
|
|
1193
1204
|
}
|
|
1194
1205
|
};
|
|
1195
1206
|
|
|
1196
|
-
// src/rest/RESTManager.ts
|
|
1197
|
-
var import_undici = require("undici");
|
|
1198
|
-
|
|
1199
1207
|
// src/utils/schema.ts
|
|
1200
1208
|
var queryParams = {
|
|
1201
1209
|
"/": { get: [] },
|
|
@@ -1409,29 +1417,35 @@ var RESTManager = class {
|
|
|
1409
1417
|
this.client.emit("debug", `Bucket [${method}:${endpoint}] exhausted. Waiting ${waitTime}ms proactively...`);
|
|
1410
1418
|
await sleep(waitTime);
|
|
1411
1419
|
}
|
|
1412
|
-
const
|
|
1420
|
+
const headers = {
|
|
1421
|
+
"X-Bot-Token": this.token
|
|
1422
|
+
};
|
|
1423
|
+
if (body) {
|
|
1424
|
+
headers["Content-Type"] = "application/json";
|
|
1425
|
+
}
|
|
1426
|
+
console.log("FETCH", method.toUpperCase(), url, JSON.stringify(body));
|
|
1427
|
+
const response = await fetch(url, {
|
|
1413
1428
|
method: method.toUpperCase(),
|
|
1414
1429
|
headers: {
|
|
1415
1430
|
"X-Bot-Token": this.token,
|
|
1416
1431
|
"Content-Type": "application/json"
|
|
1417
1432
|
},
|
|
1418
|
-
...body ? { body: JSON.stringify(body) } : {}
|
|
1419
|
-
};
|
|
1420
|
-
const
|
|
1421
|
-
const
|
|
1422
|
-
const resetAfterHeader = response.headers["x-ratelimit-reset-after"];
|
|
1433
|
+
...body !== void 0 ? { body: JSON.stringify(body) } : {}
|
|
1434
|
+
});
|
|
1435
|
+
const remainingHeader = response.headers.get("x-ratelimit-remaining");
|
|
1436
|
+
const resetAfterHeader = response.headers.get("x-ratelimit-reset-after");
|
|
1423
1437
|
if (remainingHeader !== void 0 && resetAfterHeader !== void 0) {
|
|
1424
1438
|
bucket.remaining = Number(remainingHeader);
|
|
1425
1439
|
bucket.resetAt = Date.now() + Number(resetAfterHeader);
|
|
1426
1440
|
}
|
|
1427
|
-
const textBody = await response.
|
|
1441
|
+
const textBody = await response.text();
|
|
1428
1442
|
let data;
|
|
1429
1443
|
try {
|
|
1430
1444
|
data = JSON.parse(textBody);
|
|
1431
1445
|
} catch {
|
|
1432
1446
|
data = textBody;
|
|
1433
1447
|
}
|
|
1434
|
-
if (response.
|
|
1448
|
+
if (response.status === 429) {
|
|
1435
1449
|
const retryMs = typeof data === "object" && data?.retry_after ? data.retry_after : Number(resetAfterHeader) || 5e3;
|
|
1436
1450
|
this.client.emit("debug", `Hit 429 on [${method}:${endpoint}]. Retrying in ${retryMs}ms.`);
|
|
1437
1451
|
bucket.remaining = 0;
|
|
@@ -1439,8 +1453,8 @@ var RESTManager = class {
|
|
|
1439
1453
|
await sleep(retryMs);
|
|
1440
1454
|
return this.execute(method, endpoint, body, bucket);
|
|
1441
1455
|
}
|
|
1442
|
-
if (response.
|
|
1443
|
-
throw new StoatAPIError(response.
|
|
1456
|
+
if (response.status >= 400) {
|
|
1457
|
+
throw new StoatAPIError(response.status, data, method, endpoint);
|
|
1444
1458
|
}
|
|
1445
1459
|
return data;
|
|
1446
1460
|
}
|
|
@@ -1635,8 +1649,8 @@ var MessageManager = class extends BaseManager {
|
|
|
1635
1649
|
async send(contentOrOptions) {
|
|
1636
1650
|
const opts = typeof contentOrOptions === "string" ? { content: contentOrOptions } : contentOrOptions;
|
|
1637
1651
|
const payload = {};
|
|
1638
|
-
if (opts.
|
|
1639
|
-
payload.
|
|
1652
|
+
if (opts.content) {
|
|
1653
|
+
payload.content = opts.content;
|
|
1640
1654
|
}
|
|
1641
1655
|
if (opts.attachments && opts.attachments.length > 0) {
|
|
1642
1656
|
const resolved = await Promise.all(
|
|
@@ -1647,6 +1661,21 @@ var MessageManager = class extends BaseManager {
|
|
|
1647
1661
|
payload.attachments = validAttachments;
|
|
1648
1662
|
}
|
|
1649
1663
|
}
|
|
1664
|
+
if (opts.replies) {
|
|
1665
|
+
payload.replies = opts.replies;
|
|
1666
|
+
}
|
|
1667
|
+
if (opts.embeds && opts.embeds.length) {
|
|
1668
|
+
payload.embeds = opts.embeds.map((embed) => typeof embed.toJSON === "function" ? embed.toJSON() : embed);
|
|
1669
|
+
}
|
|
1670
|
+
if (opts.masquerade) {
|
|
1671
|
+
payload.masquerade = opts.masquerade;
|
|
1672
|
+
}
|
|
1673
|
+
if (opts.interactions) {
|
|
1674
|
+
payload.interactions = opts.interactions;
|
|
1675
|
+
}
|
|
1676
|
+
if (opts.flags) {
|
|
1677
|
+
payload.flags = opts.flags;
|
|
1678
|
+
}
|
|
1650
1679
|
const data = await this.client.rest.post(`/channels/${this.channel.id}/messages`, payload);
|
|
1651
1680
|
return new Message(this.client, data);
|
|
1652
1681
|
}
|