@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.cjs +33 -15
- 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 +33 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -2
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,35 @@ 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
|
|
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, {
|
|
1424
1428
|
method: method.toUpperCase(),
|
|
1425
1429
|
headers: {
|
|
1426
1430
|
"X-Bot-Token": this.token,
|
|
1427
1431
|
"Content-Type": "application/json"
|
|
1428
1432
|
},
|
|
1429
|
-
...body ? { body: JSON.stringify(body) } : {}
|
|
1430
|
-
};
|
|
1431
|
-
const
|
|
1432
|
-
const
|
|
1433
|
-
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");
|
|
1434
1437
|
if (remainingHeader !== void 0 && resetAfterHeader !== void 0) {
|
|
1435
1438
|
bucket.remaining = Number(remainingHeader);
|
|
1436
1439
|
bucket.resetAt = Date.now() + Number(resetAfterHeader);
|
|
1437
1440
|
}
|
|
1438
|
-
const textBody = await response.
|
|
1441
|
+
const textBody = await response.text();
|
|
1439
1442
|
let data;
|
|
1440
1443
|
try {
|
|
1441
1444
|
data = JSON.parse(textBody);
|
|
1442
1445
|
} catch {
|
|
1443
1446
|
data = textBody;
|
|
1444
1447
|
}
|
|
1445
|
-
if (response.
|
|
1448
|
+
if (response.status === 429) {
|
|
1446
1449
|
const retryMs = typeof data === "object" && data?.retry_after ? data.retry_after : Number(resetAfterHeader) || 5e3;
|
|
1447
1450
|
this.client.emit("debug", `Hit 429 on [${method}:${endpoint}]. Retrying in ${retryMs}ms.`);
|
|
1448
1451
|
bucket.remaining = 0;
|
|
@@ -1450,8 +1453,8 @@ var RESTManager = class {
|
|
|
1450
1453
|
await sleep(retryMs);
|
|
1451
1454
|
return this.execute(method, endpoint, body, bucket);
|
|
1452
1455
|
}
|
|
1453
|
-
if (response.
|
|
1454
|
-
throw new StoatAPIError(response.
|
|
1456
|
+
if (response.status >= 400) {
|
|
1457
|
+
throw new StoatAPIError(response.status, data, method, endpoint);
|
|
1455
1458
|
}
|
|
1456
1459
|
return data;
|
|
1457
1460
|
}
|
|
@@ -1646,8 +1649,8 @@ var MessageManager = class extends BaseManager {
|
|
|
1646
1649
|
async send(contentOrOptions) {
|
|
1647
1650
|
const opts = typeof contentOrOptions === "string" ? { content: contentOrOptions } : contentOrOptions;
|
|
1648
1651
|
const payload = {};
|
|
1649
|
-
if (opts.
|
|
1650
|
-
payload.
|
|
1652
|
+
if (opts.content) {
|
|
1653
|
+
payload.content = opts.content;
|
|
1651
1654
|
}
|
|
1652
1655
|
if (opts.attachments && opts.attachments.length > 0) {
|
|
1653
1656
|
const resolved = await Promise.all(
|
|
@@ -1658,6 +1661,21 @@ var MessageManager = class extends BaseManager {
|
|
|
1658
1661
|
payload.attachments = validAttachments;
|
|
1659
1662
|
}
|
|
1660
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
|
+
}
|
|
1661
1679
|
const data = await this.client.rest.post(`/channels/${this.channel.id}/messages`, payload);
|
|
1662
1680
|
return new Message(this.client, data);
|
|
1663
1681
|
}
|