revbot.js 0.2.4 → 0.2.6
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.mts +814 -361
- package/dist/index.d.ts +814 -361
- package/dist/index.js +584 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +585 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -392,6 +392,9 @@ var Events = /* @__PURE__ */ ((Events2) => {
|
|
|
392
392
|
Events2["TYPING_START"] = "typingStart";
|
|
393
393
|
Events2["TYPING_STOP"] = "typingStop";
|
|
394
394
|
Events2["USER_UPDATE"] = "userUpdate";
|
|
395
|
+
Events2["WEBHOOKS_CREATE"] = "webhookCreate";
|
|
396
|
+
Events2["WEBHOOKS_DELETE"] = "webhookDelete";
|
|
397
|
+
Events2["WEBHOOKS_UPDATE"] = "webhookUpdate";
|
|
395
398
|
return Events2;
|
|
396
399
|
})(Events || {});
|
|
397
400
|
var WSEvents = /* @__PURE__ */ ((WSEvents2) => {
|
|
@@ -425,6 +428,9 @@ var WSEvents = /* @__PURE__ */ ((WSEvents2) => {
|
|
|
425
428
|
WSEvents2["SERVER_UPDATE"] = "ServerUpdate";
|
|
426
429
|
WSEvents2["USER_RELATIONSHIP"] = "UserRelationship";
|
|
427
430
|
WSEvents2["USER_UPDATE"] = "UserUpdate";
|
|
431
|
+
WSEvents2["WEBHOOKS_CREATE"] = "WebhooksCreate";
|
|
432
|
+
WSEvents2["WEBHOOKS_DELETE"] = "WebhooksDelete";
|
|
433
|
+
WSEvents2["WEBHOOKS_UPDATE"] = "WebhooksUpdate";
|
|
428
434
|
return WSEvents2;
|
|
429
435
|
})(WSEvents || {});
|
|
430
436
|
var ChannelTypes = /* @__PURE__ */ ((ChannelTypes2) => {
|
|
@@ -1396,6 +1402,237 @@ var Channel = class extends Base {
|
|
|
1396
1402
|
fetch(force = true) {
|
|
1397
1403
|
return this.client.channels.fetch(this, { force });
|
|
1398
1404
|
}
|
|
1405
|
+
edit(data) {
|
|
1406
|
+
return __async(this, null, function* () {
|
|
1407
|
+
const id = this.id;
|
|
1408
|
+
if (!id) {
|
|
1409
|
+
throw new TypeError("INVALID_ID");
|
|
1410
|
+
}
|
|
1411
|
+
const response = yield this.client.api.patch(`/channels/${id}`, {
|
|
1412
|
+
body: data
|
|
1413
|
+
});
|
|
1414
|
+
return response;
|
|
1415
|
+
});
|
|
1416
|
+
}
|
|
1417
|
+
// Implementation
|
|
1418
|
+
setRolePermissions(roleId, allowOrOptions, deny) {
|
|
1419
|
+
return __async(this, null, function* () {
|
|
1420
|
+
const id = this.id;
|
|
1421
|
+
if (!id) {
|
|
1422
|
+
throw new TypeError("INVALID_ID");
|
|
1423
|
+
}
|
|
1424
|
+
let allow;
|
|
1425
|
+
let denyPermissions;
|
|
1426
|
+
if (Array.isArray(allowOrOptions)) {
|
|
1427
|
+
allow = allowOrOptions;
|
|
1428
|
+
denyPermissions = deny;
|
|
1429
|
+
} else if (allowOrOptions && typeof allowOrOptions === "object") {
|
|
1430
|
+
allow = allowOrOptions.allow;
|
|
1431
|
+
denyPermissions = allowOrOptions.deny;
|
|
1432
|
+
if (allow === void 0 && denyPermissions === void 0) {
|
|
1433
|
+
throw new TypeError(
|
|
1434
|
+
"At least one of 'allow' or 'deny' must be provided in options"
|
|
1435
|
+
);
|
|
1436
|
+
}
|
|
1437
|
+
} else {
|
|
1438
|
+
throw new TypeError("Invalid arguments provided");
|
|
1439
|
+
}
|
|
1440
|
+
const requestBody = {
|
|
1441
|
+
allow: 0,
|
|
1442
|
+
deny: 0
|
|
1443
|
+
};
|
|
1444
|
+
if (allow !== void 0) {
|
|
1445
|
+
requestBody.allow = new FullPermissions(allow).bitfield;
|
|
1446
|
+
}
|
|
1447
|
+
if (denyPermissions !== void 0) {
|
|
1448
|
+
requestBody.deny = new FullPermissions(denyPermissions).bitfield;
|
|
1449
|
+
}
|
|
1450
|
+
yield this.client.api.put(`/channels/${id}/permissions/${roleId}`, {
|
|
1451
|
+
body: { permissions: requestBody }
|
|
1452
|
+
});
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
// Implementation
|
|
1456
|
+
setDefaultPermissions(allowOrOptionsOrPermissions) {
|
|
1457
|
+
return __async(this, null, function* () {
|
|
1458
|
+
const id = this.id;
|
|
1459
|
+
if (!id) {
|
|
1460
|
+
throw new TypeError("INVALID_ID");
|
|
1461
|
+
}
|
|
1462
|
+
let allow;
|
|
1463
|
+
let deny;
|
|
1464
|
+
if (Array.isArray(allowOrOptionsOrPermissions)) {
|
|
1465
|
+
allow = allowOrOptionsOrPermissions;
|
|
1466
|
+
} else if (allowOrOptionsOrPermissions && typeof allowOrOptionsOrPermissions === "object") {
|
|
1467
|
+
if ("a" in allowOrOptionsOrPermissions || "d" in allowOrOptionsOrPermissions) {
|
|
1468
|
+
const legacyPerms = allowOrOptionsOrPermissions;
|
|
1469
|
+
allow = legacyPerms.a;
|
|
1470
|
+
deny = legacyPerms.d;
|
|
1471
|
+
} else {
|
|
1472
|
+
const options = allowOrOptionsOrPermissions;
|
|
1473
|
+
allow = options.allow;
|
|
1474
|
+
deny = options.deny;
|
|
1475
|
+
if (allow === void 0 && deny === void 0) {
|
|
1476
|
+
throw new TypeError(
|
|
1477
|
+
"At least one of 'allow' or 'deny' must be provided in options"
|
|
1478
|
+
);
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
} else {
|
|
1482
|
+
throw new TypeError("Invalid arguments provided");
|
|
1483
|
+
}
|
|
1484
|
+
const requestBody = {};
|
|
1485
|
+
if (allow !== void 0) {
|
|
1486
|
+
requestBody.allow = new FullPermissions(allow).bitfield;
|
|
1487
|
+
}
|
|
1488
|
+
if (deny !== void 0) {
|
|
1489
|
+
requestBody.deny = new FullPermissions(deny).bitfield;
|
|
1490
|
+
}
|
|
1491
|
+
if (requestBody.allow === void 0) {
|
|
1492
|
+
requestBody.allow = 0;
|
|
1493
|
+
}
|
|
1494
|
+
if (requestBody.deny === void 0) {
|
|
1495
|
+
requestBody.deny = 0;
|
|
1496
|
+
}
|
|
1497
|
+
yield this.client.api.put(`/channels/${id}/permissions/default`, {
|
|
1498
|
+
body: { permissions: requestBody }
|
|
1499
|
+
});
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
/**
|
|
1503
|
+
* Creates a new webhook in this channel.
|
|
1504
|
+
*
|
|
1505
|
+
* @param name - The name of the webhook
|
|
1506
|
+
* @param avatar - Optional avatar for the webhook. Can be a URL string, Readable stream, or File object
|
|
1507
|
+
* @returns Promise resolving to the created webhook response
|
|
1508
|
+
*
|
|
1509
|
+
* @example
|
|
1510
|
+
* ```typescript
|
|
1511
|
+
* const webhook = await channel.createWebhook("My Webhook", "https://example.com/avatar.png");
|
|
1512
|
+
* ```
|
|
1513
|
+
*/
|
|
1514
|
+
createWebhook(name, avatar) {
|
|
1515
|
+
return __async(this, null, function* () {
|
|
1516
|
+
return this.client.webhooks.create(this.id, name, avatar);
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
/**
|
|
1520
|
+
* Retrieves all webhooks for this channel.
|
|
1521
|
+
*
|
|
1522
|
+
* @returns Promise resolving to an array of webhook responses
|
|
1523
|
+
*
|
|
1524
|
+
* @example
|
|
1525
|
+
* ```typescript
|
|
1526
|
+
* const webhooks = await channel.getWebhooks();
|
|
1527
|
+
* console.log(`Found ${webhooks.length} webhooks`);
|
|
1528
|
+
* ```
|
|
1529
|
+
*/
|
|
1530
|
+
getWebhooks() {
|
|
1531
|
+
return __async(this, null, function* () {
|
|
1532
|
+
return this.client.webhooks.getAll(this.id);
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
/**
|
|
1536
|
+
* Retrieves a specific webhook by ID and token.
|
|
1537
|
+
*
|
|
1538
|
+
* @param webhookId - The ID of the webhook to retrieve
|
|
1539
|
+
* @param token - The token of the webhook
|
|
1540
|
+
* @returns Promise resolving to the webhook response
|
|
1541
|
+
*
|
|
1542
|
+
* @example
|
|
1543
|
+
* ```typescript
|
|
1544
|
+
* const webhook = await channel.getWebhook("webhookId", "webhookToken");
|
|
1545
|
+
* console.log(`Webhook name: ${webhook.name}`);
|
|
1546
|
+
* ```
|
|
1547
|
+
*/
|
|
1548
|
+
getWebhook(webhookId, token) {
|
|
1549
|
+
return __async(this, null, function* () {
|
|
1550
|
+
return this.client.webhooks.get(webhookId, token);
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
/**
|
|
1554
|
+
* Sends a message through a webhook in this channel.
|
|
1555
|
+
*
|
|
1556
|
+
* @param webhookId - The ID of the webhook to send the message through
|
|
1557
|
+
* @param token - The token of the webhook
|
|
1558
|
+
* @param content - The message content. Can be a string or MessageOptions object with attachments and embeds
|
|
1559
|
+
* @returns Promise resolving to the sent message
|
|
1560
|
+
*
|
|
1561
|
+
* @example
|
|
1562
|
+
* ```typescript
|
|
1563
|
+
* // Send a simple text message
|
|
1564
|
+
* await channel.sendWebhookMessage("webhookId", "token", "Hello, world!");
|
|
1565
|
+
*
|
|
1566
|
+
* // Send a message with embeds and attachments
|
|
1567
|
+
* await channel.sendWebhookMessage("webhookId", "token", {
|
|
1568
|
+
* content: "Check out this image!",
|
|
1569
|
+
* attachments: ["https://example.com/image.png"],
|
|
1570
|
+
* embeds: [myEmbed]
|
|
1571
|
+
* });
|
|
1572
|
+
* ```
|
|
1573
|
+
*/
|
|
1574
|
+
sendWebhookMessage(webhookId, token, content) {
|
|
1575
|
+
return __async(this, null, function* () {
|
|
1576
|
+
return this.client.webhooks.send(webhookId, token, content);
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
/**
|
|
1580
|
+
* Deletes a webhook.
|
|
1581
|
+
*
|
|
1582
|
+
* @param webhookId - The ID of the webhook to delete
|
|
1583
|
+
* @param token - The token of the webhook
|
|
1584
|
+
* @returns Promise that resolves when the webhook is deleted
|
|
1585
|
+
*
|
|
1586
|
+
* @example
|
|
1587
|
+
* ```typescript
|
|
1588
|
+
* await channel.deleteWebhook("webhookId", "webhookToken");
|
|
1589
|
+
* console.log("Webhook deleted successfully");
|
|
1590
|
+
* ```
|
|
1591
|
+
*/
|
|
1592
|
+
deleteWebhook(webhookId, token) {
|
|
1593
|
+
return __async(this, null, function* () {
|
|
1594
|
+
return this.client.webhooks.delete(webhookId, token);
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1598
|
+
* Edits a webhook's properties.
|
|
1599
|
+
*
|
|
1600
|
+
* @param webhookId - The ID of the webhook to edit
|
|
1601
|
+
* @param token - The token of the webhook
|
|
1602
|
+
* @param options - The options to edit on the webhook
|
|
1603
|
+
* @returns Promise resolving to the updated webhook response
|
|
1604
|
+
*
|
|
1605
|
+
* @example
|
|
1606
|
+
* ```typescript
|
|
1607
|
+
* const updatedWebhook = await channel.editWebhook("webhookId", "token", {
|
|
1608
|
+
* name: "New Webhook Name",
|
|
1609
|
+
* avatar: "https://example.com/new-avatar.png"
|
|
1610
|
+
* });
|
|
1611
|
+
* ```
|
|
1612
|
+
*/
|
|
1613
|
+
editWebhook(webhookId, token, options) {
|
|
1614
|
+
return __async(this, null, function* () {
|
|
1615
|
+
return this.client.webhooks.edit(webhookId, token, options);
|
|
1616
|
+
});
|
|
1617
|
+
}
|
|
1618
|
+
/**
|
|
1619
|
+
* Retrieves partial information about a webhook using only its ID.
|
|
1620
|
+
* This method provides limited webhook information without requiring a token.
|
|
1621
|
+
*
|
|
1622
|
+
* @param webhookId - The ID of the webhook to retrieve partial information for
|
|
1623
|
+
* @returns Promise resolving to the webhook response with partial information
|
|
1624
|
+
*
|
|
1625
|
+
* @example
|
|
1626
|
+
* ```typescript
|
|
1627
|
+
* const partialWebhook = await channel.getPartialWebhook("webhookId");
|
|
1628
|
+
* console.log(`Webhook name: ${partialWebhook.name}`);
|
|
1629
|
+
* ```
|
|
1630
|
+
*/
|
|
1631
|
+
getPartialWebhook(webhookId) {
|
|
1632
|
+
return __async(this, null, function* () {
|
|
1633
|
+
return this.client.webhooks.getPartial(webhookId);
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1399
1636
|
};
|
|
1400
1637
|
|
|
1401
1638
|
// src/struct/dmChannel.ts
|
|
@@ -1794,7 +2031,7 @@ var Mentions = class {
|
|
|
1794
2031
|
import { Readable } from "stream";
|
|
1795
2032
|
import axios from "axios";
|
|
1796
2033
|
import FormData from "form-data";
|
|
1797
|
-
import { File } from "node:buffer";
|
|
2034
|
+
import { File as File2 } from "node:buffer";
|
|
1798
2035
|
var _url, _title, _description, _icon_url, _color, _media;
|
|
1799
2036
|
var MessageEmbed = class {
|
|
1800
2037
|
constructor() {
|
|
@@ -1894,7 +2131,7 @@ var MessageEmbed = class {
|
|
|
1894
2131
|
if (att instanceof Readable) {
|
|
1895
2132
|
data.append("file", att);
|
|
1896
2133
|
}
|
|
1897
|
-
if (att instanceof
|
|
2134
|
+
if (att instanceof File2) {
|
|
1898
2135
|
const buffer = Buffer.from(yield att.arrayBuffer());
|
|
1899
2136
|
data.append("file", buffer, { filename: att.name });
|
|
1900
2137
|
}
|
|
@@ -2778,7 +3015,7 @@ var UserManager = class extends BaseManager {
|
|
|
2778
3015
|
};
|
|
2779
3016
|
|
|
2780
3017
|
// src/managers/messageManager.ts
|
|
2781
|
-
import { File as
|
|
3018
|
+
import { File as File3 } from "node:buffer";
|
|
2782
3019
|
import { Readable as Readable2 } from "stream";
|
|
2783
3020
|
import FormData2 from "form-data";
|
|
2784
3021
|
import axios2 from "axios";
|
|
@@ -2817,7 +3054,7 @@ var MessageManager = class extends BaseManager {
|
|
|
2817
3054
|
if (att instanceof Readable2) {
|
|
2818
3055
|
data.append("file", att);
|
|
2819
3056
|
}
|
|
2820
|
-
if (att instanceof
|
|
3057
|
+
if (att instanceof File3) {
|
|
2821
3058
|
const buffer = Buffer.from(yield att.arrayBuffer());
|
|
2822
3059
|
data.append("file", buffer, { filename: att.name });
|
|
2823
3060
|
}
|
|
@@ -2951,9 +3188,14 @@ var MessageManager = class extends BaseManager {
|
|
|
2951
3188
|
}
|
|
2952
3189
|
if (typeof query === "number") query = { limit: query };
|
|
2953
3190
|
else if (typeof query === "undefined") query = { limit: 100 };
|
|
3191
|
+
const queryObj = Object.fromEntries(
|
|
3192
|
+
Object.entries(query).filter(
|
|
3193
|
+
([, v]) => v !== void 0
|
|
3194
|
+
)
|
|
3195
|
+
);
|
|
2954
3196
|
const messages = yield this.client.api.get(
|
|
2955
3197
|
`/channels/${this.channel.id}/messages`,
|
|
2956
|
-
|
|
3198
|
+
queryObj
|
|
2957
3199
|
);
|
|
2958
3200
|
return messages.reduce((coll, cur) => {
|
|
2959
3201
|
const msg = this._add(cur);
|
|
@@ -3293,17 +3535,283 @@ var ServerMemberManager = class extends BaseManager {
|
|
|
3293
3535
|
}
|
|
3294
3536
|
};
|
|
3295
3537
|
|
|
3538
|
+
// src/managers/webhookManager.ts
|
|
3539
|
+
import { Readable as Readable3 } from "stream";
|
|
3540
|
+
import axios3 from "axios";
|
|
3541
|
+
import FormData3 from "form-data";
|
|
3542
|
+
var WebhookManager = class {
|
|
3543
|
+
/**
|
|
3544
|
+
* Creates a new WebhookManager instance.
|
|
3545
|
+
*
|
|
3546
|
+
* @param client - The client instance this manager belongs to
|
|
3547
|
+
*/
|
|
3548
|
+
constructor(client3) {
|
|
3549
|
+
this.client = client3;
|
|
3550
|
+
}
|
|
3551
|
+
/**
|
|
3552
|
+
* Creates a new webhook in the specified channel.
|
|
3553
|
+
*
|
|
3554
|
+
* @param channelId - The ID of the channel where the webhook will be created
|
|
3555
|
+
* @param name - The name of the webhook
|
|
3556
|
+
* @param avatar - Optional avatar for the webhook. Can be a URL string, Readable stream, or File object
|
|
3557
|
+
* @returns Promise resolving to the created webhook response
|
|
3558
|
+
*
|
|
3559
|
+
* @example
|
|
3560
|
+
* ```typescript
|
|
3561
|
+
* const webhook = await client.webhooks.create("channelId", "My Webhook", "https://example.com/avatar.png");
|
|
3562
|
+
* ```
|
|
3563
|
+
*/
|
|
3564
|
+
create(channelId, name, avatar) {
|
|
3565
|
+
return __async(this, null, function* () {
|
|
3566
|
+
const data = new FormData3();
|
|
3567
|
+
let avatarID = void 0;
|
|
3568
|
+
if (typeof avatar === "string") {
|
|
3569
|
+
const readableStream = yield axios3.get(avatar, {
|
|
3570
|
+
responseType: "stream"
|
|
3571
|
+
});
|
|
3572
|
+
data.append("file", readableStream.data, {
|
|
3573
|
+
filename: avatar.split("/").pop()
|
|
3574
|
+
});
|
|
3575
|
+
}
|
|
3576
|
+
if (avatar instanceof Readable3) {
|
|
3577
|
+
data.append("file", avatar, { filename: "avatar.png" });
|
|
3578
|
+
}
|
|
3579
|
+
if (avatar instanceof File) {
|
|
3580
|
+
const buffer = Buffer.from(yield avatar.arrayBuffer());
|
|
3581
|
+
data.append("file", buffer, { filename: avatar.name });
|
|
3582
|
+
}
|
|
3583
|
+
if (avatar) {
|
|
3584
|
+
yield this.client.cdn.post("/avatars", data).then((attachment) => {
|
|
3585
|
+
const { id } = attachment;
|
|
3586
|
+
avatarID = id;
|
|
3587
|
+
});
|
|
3588
|
+
}
|
|
3589
|
+
const response = yield this.client.api.post(
|
|
3590
|
+
`/channels/${channelId}/webhooks`,
|
|
3591
|
+
{
|
|
3592
|
+
body: {
|
|
3593
|
+
name,
|
|
3594
|
+
avatar: avatarID
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
);
|
|
3598
|
+
return response;
|
|
3599
|
+
});
|
|
3600
|
+
}
|
|
3601
|
+
/**
|
|
3602
|
+
* Retrieves all webhooks for the specified channel.
|
|
3603
|
+
*
|
|
3604
|
+
* @param channelId - The ID of the channel to get webhooks from
|
|
3605
|
+
* @returns Promise resolving to an array of webhook responses
|
|
3606
|
+
*
|
|
3607
|
+
* @example
|
|
3608
|
+
* ```typescript
|
|
3609
|
+
* const webhooks = await client.webhooks.getAll("channelId");
|
|
3610
|
+
* console.log(`Found ${webhooks.length} webhooks`);
|
|
3611
|
+
* ```
|
|
3612
|
+
*/
|
|
3613
|
+
getAll(channelId) {
|
|
3614
|
+
return __async(this, null, function* () {
|
|
3615
|
+
const response = yield this.client.api.get(
|
|
3616
|
+
`/channels/${channelId}/webhooks`
|
|
3617
|
+
);
|
|
3618
|
+
return response;
|
|
3619
|
+
});
|
|
3620
|
+
}
|
|
3621
|
+
/**
|
|
3622
|
+
* Retrieves a specific webhook by ID and token.
|
|
3623
|
+
*
|
|
3624
|
+
* @param webhookId - The ID of the webhook to retrieve
|
|
3625
|
+
* @param token - The token of the webhook
|
|
3626
|
+
* @returns Promise resolving to the webhook response
|
|
3627
|
+
*
|
|
3628
|
+
* @example
|
|
3629
|
+
* ```typescript
|
|
3630
|
+
* const webhook = await client.webhooks.get("webhookId", "webhookToken");
|
|
3631
|
+
* console.log(`Webhook name: ${webhook.name}`);
|
|
3632
|
+
* ```
|
|
3633
|
+
*/
|
|
3634
|
+
get(webhookId, token) {
|
|
3635
|
+
return __async(this, null, function* () {
|
|
3636
|
+
const response = yield this.client.api.get(
|
|
3637
|
+
`/webhooks/${webhookId}/${token}`
|
|
3638
|
+
);
|
|
3639
|
+
return response;
|
|
3640
|
+
});
|
|
3641
|
+
}
|
|
3642
|
+
/**
|
|
3643
|
+
* Sends a message through a webhook.
|
|
3644
|
+
*
|
|
3645
|
+
* @param webhookId - The ID of the webhook to send the message through
|
|
3646
|
+
* @param token - The token of the webhook
|
|
3647
|
+
* @param content - The message content. Can be a string or MessageOptions object with attachments and embeds
|
|
3648
|
+
* @returns Promise resolving to the sent message
|
|
3649
|
+
*
|
|
3650
|
+
* @example
|
|
3651
|
+
* ```typescript
|
|
3652
|
+
* // Send a simple text message
|
|
3653
|
+
* await client.webhooks.send("webhookId", "token", "Hello, world!");
|
|
3654
|
+
*
|
|
3655
|
+
* // Send a message with embeds and attachments
|
|
3656
|
+
* await client.webhooks.send("webhookId", "token", {
|
|
3657
|
+
* content: "Check out this image!",
|
|
3658
|
+
* attachments: ["https://example.com/image.png"],
|
|
3659
|
+
* embeds: [myEmbed]
|
|
3660
|
+
* });
|
|
3661
|
+
* ```
|
|
3662
|
+
*/
|
|
3663
|
+
send(webhookId, token, content) {
|
|
3664
|
+
return __async(this, null, function* () {
|
|
3665
|
+
if (typeof content === "string") content = { content };
|
|
3666
|
+
let attachments = [];
|
|
3667
|
+
let embeds = [];
|
|
3668
|
+
if (Array.isArray(content.attachments)) {
|
|
3669
|
+
const promises = content.attachments.map((att) => __async(this, null, function* () {
|
|
3670
|
+
const data = new FormData3();
|
|
3671
|
+
if (typeof att === "string") {
|
|
3672
|
+
const readableStream = yield axios3.get(att, {
|
|
3673
|
+
responseType: "stream"
|
|
3674
|
+
});
|
|
3675
|
+
data.append("file", readableStream.data, {
|
|
3676
|
+
filename: att.split("/").pop()
|
|
3677
|
+
});
|
|
3678
|
+
}
|
|
3679
|
+
if (att instanceof Readable3) {
|
|
3680
|
+
data.append("file", att);
|
|
3681
|
+
}
|
|
3682
|
+
if (att instanceof File) {
|
|
3683
|
+
const buffer = Buffer.from(yield att.arrayBuffer());
|
|
3684
|
+
data.append("file", buffer, { filename: att.name });
|
|
3685
|
+
}
|
|
3686
|
+
yield this.client.cdn.post("/attachments", data).then((attachment) => {
|
|
3687
|
+
const { id } = attachment;
|
|
3688
|
+
attachments.push(id);
|
|
3689
|
+
});
|
|
3690
|
+
}));
|
|
3691
|
+
yield Promise.all(promises);
|
|
3692
|
+
}
|
|
3693
|
+
if (Array.isArray(content.embeds)) {
|
|
3694
|
+
const promises = content.embeds.map((embed) => __async(this, null, function* () {
|
|
3695
|
+
const json = yield embed.toJSONWithMedia(this.client);
|
|
3696
|
+
embeds.push(json);
|
|
3697
|
+
}));
|
|
3698
|
+
yield Promise.all(promises);
|
|
3699
|
+
}
|
|
3700
|
+
const resp = yield this.client.api.post(
|
|
3701
|
+
`/webhooks/${webhookId}/${token}`,
|
|
3702
|
+
{
|
|
3703
|
+
body: __spreadProps(__spreadValues({}, content), { attachments, embeds, nonce: UUID.generate() })
|
|
3704
|
+
}
|
|
3705
|
+
);
|
|
3706
|
+
return resp;
|
|
3707
|
+
});
|
|
3708
|
+
}
|
|
3709
|
+
/**
|
|
3710
|
+
* Deletes a webhook.
|
|
3711
|
+
*
|
|
3712
|
+
* @param webhookId - The ID of the webhook to delete
|
|
3713
|
+
* @param token - The token of the webhook
|
|
3714
|
+
* @returns Promise that resolves when the webhook is deleted
|
|
3715
|
+
*
|
|
3716
|
+
* @example
|
|
3717
|
+
* ```typescript
|
|
3718
|
+
* await client.webhooks.delete("webhookId", "webhookToken");
|
|
3719
|
+
* console.log("Webhook deleted successfully");
|
|
3720
|
+
* ```
|
|
3721
|
+
*/
|
|
3722
|
+
delete(webhookId, token) {
|
|
3723
|
+
return __async(this, null, function* () {
|
|
3724
|
+
yield this.client.api.delete(`/webhooks/${webhookId}/${token}`);
|
|
3725
|
+
});
|
|
3726
|
+
}
|
|
3727
|
+
/**
|
|
3728
|
+
* Edits a webhook's properties.
|
|
3729
|
+
*
|
|
3730
|
+
* @param webhookId - The ID of the webhook to edit
|
|
3731
|
+
* @param token - The token of the webhook
|
|
3732
|
+
* @param options - The options to edit on the webhook
|
|
3733
|
+
* @returns Promise resolving to the updated webhook response
|
|
3734
|
+
*
|
|
3735
|
+
* @example
|
|
3736
|
+
* ```typescript
|
|
3737
|
+
* const updatedWebhook = await client.webhooks.edit("webhookId", "token", {
|
|
3738
|
+
* name: "New Webhook Name",
|
|
3739
|
+
* avatar: "https://example.com/new-avatar.png"
|
|
3740
|
+
* });
|
|
3741
|
+
* ```
|
|
3742
|
+
*/
|
|
3743
|
+
edit(webhookId, token, options) {
|
|
3744
|
+
return __async(this, null, function* () {
|
|
3745
|
+
var _a;
|
|
3746
|
+
const data = new FormData3();
|
|
3747
|
+
let avatarID = void 0;
|
|
3748
|
+
if (typeof options.avatar === "string") {
|
|
3749
|
+
const readableStream = yield axios3.get(options.avatar, {
|
|
3750
|
+
responseType: "stream"
|
|
3751
|
+
});
|
|
3752
|
+
data.append("file", readableStream.data, {
|
|
3753
|
+
filename: options.avatar.split("/").pop()
|
|
3754
|
+
});
|
|
3755
|
+
}
|
|
3756
|
+
if (options.avatar instanceof Readable3) {
|
|
3757
|
+
data.append("file", options.avatar, { filename: "avatar.png" });
|
|
3758
|
+
}
|
|
3759
|
+
if (options.avatar instanceof File) {
|
|
3760
|
+
const buffer = Buffer.from(yield options.avatar.arrayBuffer());
|
|
3761
|
+
data.append("file", buffer, { filename: options.avatar.name });
|
|
3762
|
+
}
|
|
3763
|
+
if (options.avatar) {
|
|
3764
|
+
yield this.client.cdn.post("/avatars", data).then((attachment) => {
|
|
3765
|
+
const { id } = attachment;
|
|
3766
|
+
avatarID = id;
|
|
3767
|
+
});
|
|
3768
|
+
}
|
|
3769
|
+
const response = yield this.client.api.patch(
|
|
3770
|
+
`/webhooks/${webhookId}/${token}`,
|
|
3771
|
+
{
|
|
3772
|
+
body: __spreadProps(__spreadValues({}, options), {
|
|
3773
|
+
avatar: avatarID,
|
|
3774
|
+
remove: (_a = options.remove) != null ? _a : []
|
|
3775
|
+
})
|
|
3776
|
+
}
|
|
3777
|
+
);
|
|
3778
|
+
return response;
|
|
3779
|
+
});
|
|
3780
|
+
}
|
|
3781
|
+
/**
|
|
3782
|
+
* Retrieves partial information about a webhook using only its ID.
|
|
3783
|
+
* This method provides limited webhook information without requiring a token.
|
|
3784
|
+
*
|
|
3785
|
+
* @param webhookId - The ID of the webhook to retrieve partial information for
|
|
3786
|
+
* @returns Promise resolving to the webhook response with partial information
|
|
3787
|
+
*
|
|
3788
|
+
* @example
|
|
3789
|
+
* ```typescript
|
|
3790
|
+
* const partialWebhook = await client.webhooks.getPartial("webhookId");
|
|
3791
|
+
* console.log(`Webhook name: ${partialWebhook.name}`);
|
|
3792
|
+
* ```
|
|
3793
|
+
*/
|
|
3794
|
+
getPartial(webhookId) {
|
|
3795
|
+
return __async(this, null, function* () {
|
|
3796
|
+
const response = yield this.client.api.get(
|
|
3797
|
+
`/webhooks/${webhookId}`
|
|
3798
|
+
);
|
|
3799
|
+
return response;
|
|
3800
|
+
});
|
|
3801
|
+
}
|
|
3802
|
+
};
|
|
3803
|
+
|
|
3296
3804
|
// src/client/baseClient.ts
|
|
3297
3805
|
import { EventEmitter } from "node:events";
|
|
3298
3806
|
|
|
3299
3807
|
// src/rest/restClient.ts
|
|
3300
|
-
import
|
|
3808
|
+
import axios5, { AxiosError } from "axios";
|
|
3301
3809
|
|
|
3302
3810
|
// package.json
|
|
3303
|
-
var version = "0.2.
|
|
3811
|
+
var version = "0.2.6";
|
|
3304
3812
|
|
|
3305
3813
|
// src/rest/restUtils/rateLimitQueue.ts
|
|
3306
|
-
import
|
|
3814
|
+
import axios4 from "axios";
|
|
3307
3815
|
var RateLimitQueue = class {
|
|
3308
3816
|
constructor() {
|
|
3309
3817
|
this.bucketMap = /* @__PURE__ */ new Map();
|
|
@@ -3332,7 +3840,7 @@ var RateLimitQueue = class {
|
|
|
3332
3840
|
}
|
|
3333
3841
|
_doRequest(config, path) {
|
|
3334
3842
|
return __async(this, null, function* () {
|
|
3335
|
-
const response = yield
|
|
3843
|
+
const response = yield axios4(config);
|
|
3336
3844
|
this._updateRateLimit(path, response);
|
|
3337
3845
|
return response;
|
|
3338
3846
|
});
|
|
@@ -3398,7 +3906,7 @@ var RestClient = class {
|
|
|
3398
3906
|
*/
|
|
3399
3907
|
request(method, url, body, query, retry) {
|
|
3400
3908
|
return __async(this, null, function* () {
|
|
3401
|
-
var _a, _b, _c, _d, _e;
|
|
3909
|
+
var _a, _b, _c, _d, _e, _f;
|
|
3402
3910
|
try {
|
|
3403
3911
|
if (!this.client.token) throw new Error("Token is required");
|
|
3404
3912
|
const authHeader = this.client.bot ? "X-Bot-Token" : "X-Session-Token";
|
|
@@ -3423,8 +3931,15 @@ var RestClient = class {
|
|
|
3423
3931
|
return this.retryRequest(0, method, url, body, query);
|
|
3424
3932
|
}
|
|
3425
3933
|
if (error.status) {
|
|
3934
|
+
if (process.env.NODE_ENV === "test") {
|
|
3935
|
+
console.error("Error details:", error);
|
|
3936
|
+
console.error("Error response data:", (_e = error.response) == null ? void 0 : _e.data);
|
|
3937
|
+
console.error("Error request config:", error.config);
|
|
3938
|
+
console.error("Error message:", error.message);
|
|
3939
|
+
console.error("Error URL:", url);
|
|
3940
|
+
}
|
|
3426
3941
|
throw new Error(
|
|
3427
|
-
`API call failed with status ${error.status}: ${(
|
|
3942
|
+
`API call failed with status ${error.status}: ${(_f = error.response) == null ? void 0 : _f.statusText}`
|
|
3428
3943
|
);
|
|
3429
3944
|
}
|
|
3430
3945
|
}
|
|
@@ -3438,7 +3953,7 @@ var RestClient = class {
|
|
|
3438
3953
|
return __async(this, null, function* () {
|
|
3439
3954
|
var _a, _b;
|
|
3440
3955
|
try {
|
|
3441
|
-
const response = yield
|
|
3956
|
+
const response = yield axios5.get(
|
|
3442
3957
|
`${((_a = this.client.options.rest) == null ? void 0 : _a.instanceURL) ? (_b = this.client.options.rest) == null ? void 0 : _b.instanceURL : apiUrl}/`
|
|
3443
3958
|
);
|
|
3444
3959
|
const config = response.data;
|
|
@@ -4188,6 +4703,58 @@ var MessageUnreact = class extends Event {
|
|
|
4188
4703
|
}
|
|
4189
4704
|
};
|
|
4190
4705
|
|
|
4706
|
+
// src/client/events/webhookCreate.ts
|
|
4707
|
+
var WebhookCreate = class extends Event {
|
|
4708
|
+
/**
|
|
4709
|
+
* Handles the webhook create event.
|
|
4710
|
+
* @param {id: string, channel_id: string, server_id: string, name: string} data - The data for the event, containing the webhook ID, channel ID, server ID, and name.
|
|
4711
|
+
* @returns {void}
|
|
4712
|
+
*/
|
|
4713
|
+
handle(data) {
|
|
4714
|
+
const webhookData = {
|
|
4715
|
+
webhookId: data.id,
|
|
4716
|
+
channelId: data.channel_id,
|
|
4717
|
+
name: data.name,
|
|
4718
|
+
creatorId: data.creator_id,
|
|
4719
|
+
token: data.token
|
|
4720
|
+
};
|
|
4721
|
+
this.client.emit("webhookCreate" /* WEBHOOKS_CREATE */, webhookData);
|
|
4722
|
+
}
|
|
4723
|
+
};
|
|
4724
|
+
|
|
4725
|
+
// src/client/events/webhookDelete.ts
|
|
4726
|
+
var WebhookDelete = class extends Event {
|
|
4727
|
+
/**
|
|
4728
|
+
* Handles the webhook delete event.
|
|
4729
|
+
* @param {id: string, channel_id: string, server_id: string} data - The data for the event, containing the webhook ID, channel ID, and server ID.
|
|
4730
|
+
* @returns {void}
|
|
4731
|
+
*/
|
|
4732
|
+
handle(data) {
|
|
4733
|
+
const webhookData = {
|
|
4734
|
+
webhookId: data.id
|
|
4735
|
+
};
|
|
4736
|
+
this.client.emit("webhookDelete" /* WEBHOOKS_DELETE */, webhookData);
|
|
4737
|
+
}
|
|
4738
|
+
};
|
|
4739
|
+
|
|
4740
|
+
// src/client/events/webhookUpdate.ts
|
|
4741
|
+
var WebhookUpdate = class extends Event {
|
|
4742
|
+
/**
|
|
4743
|
+
* Handles the webhook update event.
|
|
4744
|
+
* @param {id: string, data: { name: string; avatar?: { _id: string; tag: string; filename: string; metadata: any; content_type: string; size: number; }; remove: string[]; }} data- The data for the event, containing the webhook ID and updated webhook data.
|
|
4745
|
+
* @returns {void}
|
|
4746
|
+
*/
|
|
4747
|
+
handle(data) {
|
|
4748
|
+
const webhookData = {
|
|
4749
|
+
webhookId: data.id,
|
|
4750
|
+
name: data.data.name,
|
|
4751
|
+
avatar: data.data.avatar,
|
|
4752
|
+
remove: data.data.remove
|
|
4753
|
+
};
|
|
4754
|
+
this.client.emit("webhookUpdate" /* WEBHOOKS_UPDATE */, webhookData);
|
|
4755
|
+
}
|
|
4756
|
+
};
|
|
4757
|
+
|
|
4191
4758
|
// src/client/events/index.ts
|
|
4192
4759
|
var EventMap = {
|
|
4193
4760
|
bulkMessageDelete: BulkMessageDelete,
|
|
@@ -4211,7 +4778,10 @@ var EventMap = {
|
|
|
4211
4778
|
serverUpdate: ServerUpdate,
|
|
4212
4779
|
userUpdate: UserUpdate,
|
|
4213
4780
|
messageReact: MessageReact,
|
|
4214
|
-
messageUnreact: MessageUnreact
|
|
4781
|
+
messageUnreact: MessageUnreact,
|
|
4782
|
+
webhookCreate: WebhookCreate,
|
|
4783
|
+
webhookDelete: WebhookDelete,
|
|
4784
|
+
webhookUpdate: WebhookUpdate
|
|
4215
4785
|
};
|
|
4216
4786
|
|
|
4217
4787
|
// src/client/events/eventManager.ts
|
|
@@ -4603,6 +5173,8 @@ var client2 = class extends BaseClient {
|
|
|
4603
5173
|
this.users = new UserManager(this);
|
|
4604
5174
|
/** Manages the events in the client. */
|
|
4605
5175
|
this.events = new EventManager(this);
|
|
5176
|
+
/** Manages the webhooks in the client. */
|
|
5177
|
+
this.webhooks = new WebhookManager(this);
|
|
4606
5178
|
/** The authenticated user, or `null` if not logged in. */
|
|
4607
5179
|
this.user = null;
|
|
4608
5180
|
/** The timestamp when the client became ready, or `null` if not ready. */
|