revbot.js 0.0.13 → 0.0.15-build-test
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/chunk-35BYGFDX.js +25 -0
- package/dist/chunk-35BYGFDX.js.map +1 -0
- package/dist/chunk-3ANNOYXY.js +30 -0
- package/dist/chunk-3ANNOYXY.js.map +1 -0
- package/dist/chunk-3GLQHMWL.js +39 -0
- package/dist/chunk-3GLQHMWL.js.map +1 -0
- package/dist/chunk-43CUB3NP.js +30 -0
- package/dist/chunk-43CUB3NP.js.map +1 -0
- package/dist/chunk-55PAATU6.js +101 -0
- package/dist/chunk-55PAATU6.js.map +1 -0
- package/dist/chunk-5RK7FEID.js +47 -0
- package/dist/chunk-5RK7FEID.js.map +1 -0
- package/dist/chunk-6V6HPZ33.js +27 -0
- package/dist/chunk-6V6HPZ33.js.map +1 -0
- package/dist/chunk-6WJXGICC.js +25 -0
- package/dist/chunk-6WJXGICC.js.map +1 -0
- package/dist/chunk-7PA5MDKS.js +157 -0
- package/dist/chunk-7PA5MDKS.js.map +1 -0
- package/dist/chunk-7XUN3OQT.js +1 -0
- package/dist/chunk-7XUN3OQT.js.map +1 -0
- package/dist/chunk-AOKM5TCP.js +37 -0
- package/dist/chunk-AOKM5TCP.js.map +1 -0
- package/dist/chunk-BQS6ZLNY.js +80 -0
- package/dist/chunk-BQS6ZLNY.js.map +1 -0
- package/dist/chunk-CQ4AJZQD.js +51 -0
- package/dist/chunk-CQ4AJZQD.js.map +1 -0
- package/dist/chunk-DSM44DGO.js +156 -0
- package/dist/chunk-DSM44DGO.js.map +1 -0
- package/dist/chunk-E2P4PIDH.js +35 -0
- package/dist/chunk-E2P4PIDH.js.map +1 -0
- package/dist/chunk-EOZ7QHOH.js +151 -0
- package/dist/chunk-EOZ7QHOH.js.map +1 -0
- package/dist/chunk-FKNQEJE7.js +20 -0
- package/dist/chunk-FKNQEJE7.js.map +1 -0
- package/dist/chunk-G7DLVJKH.js +34 -0
- package/dist/chunk-G7DLVJKH.js.map +1 -0
- package/dist/chunk-GCIV7PRI.js +30 -0
- package/dist/chunk-GCIV7PRI.js.map +1 -0
- package/dist/chunk-GNQQG7EP.js +88 -0
- package/dist/chunk-GNQQG7EP.js.map +1 -0
- package/dist/chunk-H4SZEZP2.js +38 -0
- package/dist/chunk-H4SZEZP2.js.map +1 -0
- package/dist/chunk-HETUKFLM.js +7 -0
- package/dist/chunk-HETUKFLM.js.map +1 -0
- package/dist/chunk-HKLTWZSB.js +112 -0
- package/dist/chunk-HKLTWZSB.js.map +1 -0
- package/dist/chunk-ICANLKGX.js +97 -0
- package/dist/chunk-ICANLKGX.js.map +1 -0
- package/dist/chunk-J2RF7D67.js +105 -0
- package/dist/chunk-J2RF7D67.js.map +1 -0
- package/dist/chunk-K4VAG5ZU.js +16 -0
- package/dist/chunk-K4VAG5ZU.js.map +1 -0
- package/dist/chunk-LAL23AQK.js +105 -0
- package/dist/chunk-LAL23AQK.js.map +1 -0
- package/dist/chunk-LQUZ7Q7D.js +29 -0
- package/dist/chunk-LQUZ7Q7D.js.map +1 -0
- package/dist/chunk-LUDTY3LL.js +103 -0
- package/dist/chunk-LUDTY3LL.js.map +1 -0
- package/dist/chunk-LY7OFI25.js +26 -0
- package/dist/chunk-LY7OFI25.js.map +1 -0
- package/dist/chunk-MLKHJGSQ.js +68 -0
- package/dist/chunk-MLKHJGSQ.js.map +1 -0
- package/dist/chunk-MSJCRRXO.js +32 -0
- package/dist/chunk-MSJCRRXO.js.map +1 -0
- package/dist/chunk-O2IN5OZI.js +27 -0
- package/dist/chunk-O2IN5OZI.js.map +1 -0
- package/dist/chunk-OETI5C5L.js +30 -0
- package/dist/chunk-OETI5C5L.js.map +1 -0
- package/dist/chunk-OK227BBS.js +38 -0
- package/dist/chunk-OK227BBS.js.map +1 -0
- package/dist/chunk-R2PF552K.js +67 -0
- package/dist/chunk-R2PF552K.js.map +1 -0
- package/dist/chunk-RMACMP4R.js +26 -0
- package/dist/chunk-RMACMP4R.js.map +1 -0
- package/dist/chunk-SYXHGCHU.js +26 -0
- package/dist/chunk-SYXHGCHU.js.map +1 -0
- package/dist/chunk-VELIOWTX.js +25 -0
- package/dist/chunk-VELIOWTX.js.map +1 -0
- package/dist/chunk-VU3XNPDE.js +37 -0
- package/dist/chunk-VU3XNPDE.js.map +1 -0
- package/dist/chunk-W4XDXSOK.js +32 -0
- package/dist/chunk-W4XDXSOK.js.map +1 -0
- package/dist/chunk-WMWOEYVA.js +26 -0
- package/dist/chunk-WMWOEYVA.js.map +1 -0
- package/dist/chunk-X7VEORVS.js +43 -0
- package/dist/chunk-X7VEORVS.js.map +1 -0
- package/dist/chunk-XMS4UTPG.js +49 -0
- package/dist/chunk-XMS4UTPG.js.map +1 -0
- package/dist/chunk-XQEYCTYC.js +2601 -0
- package/dist/chunk-XQEYCTYC.js.map +1 -0
- package/dist/chunk-YLSAAPO4.js +79 -0
- package/dist/chunk-YLSAAPO4.js.map +1 -0
- package/dist/chunk-YXX4DJB3.js +27 -0
- package/dist/chunk-YXX4DJB3.js.map +1 -0
- package/dist/client/baseClient.cjs +799 -0
- package/dist/client/baseClient.cjs.map +1 -0
- package/dist/client/baseClient.d.cts +10 -0
- package/dist/client/baseClient.d.ts +10 -0
- package/dist/client/baseClient.js +18 -0
- package/dist/client/baseClient.js.map +1 -0
- package/dist/client/client.cjs +4286 -0
- package/dist/client/client.cjs.map +1 -0
- package/dist/client/client.d.cts +10 -0
- package/dist/client/client.d.ts +10 -0
- package/dist/client/client.js +53 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/events/bulkMessageDelete.cjs +104 -0
- package/dist/client/events/bulkMessageDelete.cjs.map +1 -0
- package/dist/client/events/bulkMessageDelete.d.cts +28 -0
- package/dist/client/events/bulkMessageDelete.d.ts +28 -0
- package/dist/client/events/bulkMessageDelete.js +11 -0
- package/dist/client/events/bulkMessageDelete.js.map +1 -0
- package/dist/client/events/channelCreate.cjs +136 -0
- package/dist/client/events/channelCreate.cjs.map +1 -0
- package/dist/client/events/channelCreate.d.cts +27 -0
- package/dist/client/events/channelCreate.d.ts +27 -0
- package/dist/client/events/channelCreate.js +11 -0
- package/dist/client/events/channelCreate.js.map +1 -0
- package/dist/client/events/channelDelete.cjs +113 -0
- package/dist/client/events/channelDelete.cjs.map +1 -0
- package/dist/client/events/channelDelete.d.cts +29 -0
- package/dist/client/events/channelDelete.d.ts +29 -0
- package/dist/client/events/channelDelete.js +11 -0
- package/dist/client/events/channelDelete.js.map +1 -0
- package/dist/client/events/channelGroupJoin.cjs +133 -0
- package/dist/client/events/channelGroupJoin.cjs.map +1 -0
- package/dist/client/events/channelGroupJoin.d.cts +30 -0
- package/dist/client/events/channelGroupJoin.d.ts +30 -0
- package/dist/client/events/channelGroupJoin.js +11 -0
- package/dist/client/events/channelGroupJoin.js.map +1 -0
- package/dist/client/events/channelGroupLeave.cjs +133 -0
- package/dist/client/events/channelGroupLeave.cjs.map +1 -0
- package/dist/client/events/channelGroupLeave.d.cts +30 -0
- package/dist/client/events/channelGroupLeave.d.ts +30 -0
- package/dist/client/events/channelGroupLeave.js +11 -0
- package/dist/client/events/channelGroupLeave.js.map +1 -0
- package/dist/client/events/channelStarttyping.cjs +110 -0
- package/dist/client/events/channelStarttyping.cjs.map +1 -0
- package/dist/client/events/channelStarttyping.d.cts +30 -0
- package/dist/client/events/channelStarttyping.d.ts +30 -0
- package/dist/client/events/channelStarttyping.js +11 -0
- package/dist/client/events/channelStarttyping.js.map +1 -0
- package/dist/client/events/channelStopTyping.cjs +110 -0
- package/dist/client/events/channelStopTyping.cjs.map +1 -0
- package/dist/client/events/channelStopTyping.d.cts +30 -0
- package/dist/client/events/channelStopTyping.d.ts +30 -0
- package/dist/client/events/channelStopTyping.js +11 -0
- package/dist/client/events/channelStopTyping.js.map +1 -0
- package/dist/client/events/channelUpdate.cjs +109 -0
- package/dist/client/events/channelUpdate.cjs.map +1 -0
- package/dist/client/events/channelUpdate.d.cts +31 -0
- package/dist/client/events/channelUpdate.d.ts +31 -0
- package/dist/client/events/channelUpdate.js +11 -0
- package/dist/client/events/channelUpdate.js.map +1 -0
- package/dist/client/events/event.cjs +124 -0
- package/dist/client/events/event.cjs.map +1 -0
- package/dist/client/events/event.d.cts +11 -0
- package/dist/client/events/event.d.ts +11 -0
- package/dist/client/events/event.js +13 -0
- package/dist/client/events/event.js.map +1 -0
- package/dist/client/events/eventManager.cjs +657 -0
- package/dist/client/events/eventManager.cjs.map +1 -0
- package/dist/client/events/eventManager.d.cts +10 -0
- package/dist/client/events/eventManager.d.ts +10 -0
- package/dist/client/events/eventManager.js +34 -0
- package/dist/client/events/eventManager.js.map +1 -0
- package/dist/client/events/index.cjs +629 -0
- package/dist/client/events/index.cjs.map +1 -0
- package/dist/client/events/index.d.cts +32 -0
- package/dist/client/events/index.d.ts +32 -0
- package/dist/client/events/index.js +96 -0
- package/dist/client/events/index.js.map +1 -0
- package/dist/client/events/message.cjs +136 -0
- package/dist/client/events/message.cjs.map +1 -0
- package/dist/client/events/message.d.cts +27 -0
- package/dist/client/events/message.d.ts +27 -0
- package/dist/client/events/message.js +11 -0
- package/dist/client/events/message.js.map +1 -0
- package/dist/client/events/messageDelete.cjs +114 -0
- package/dist/client/events/messageDelete.cjs.map +1 -0
- package/dist/client/events/messageDelete.d.cts +30 -0
- package/dist/client/events/messageDelete.d.ts +30 -0
- package/dist/client/events/messageDelete.js +11 -0
- package/dist/client/events/messageDelete.js.map +1 -0
- package/dist/client/events/messageReact.cjs +138 -0
- package/dist/client/events/messageReact.cjs.map +1 -0
- package/dist/client/events/messageReact.d.cts +40 -0
- package/dist/client/events/messageReact.d.ts +40 -0
- package/dist/client/events/messageReact.js +11 -0
- package/dist/client/events/messageReact.js.map +1 -0
- package/dist/client/events/messageUnreact.cjs +144 -0
- package/dist/client/events/messageUnreact.cjs.map +1 -0
- package/dist/client/events/messageUnreact.d.cts +28 -0
- package/dist/client/events/messageUnreact.d.ts +28 -0
- package/dist/client/events/messageUnreact.js +11 -0
- package/dist/client/events/messageUnreact.js.map +1 -0
- package/dist/client/events/messageUpdate.cjs +111 -0
- package/dist/client/events/messageUpdate.cjs.map +1 -0
- package/dist/client/events/messageUpdate.d.cts +31 -0
- package/dist/client/events/messageUpdate.d.ts +31 -0
- package/dist/client/events/messageUpdate.js +11 -0
- package/dist/client/events/messageUpdate.js.map +1 -0
- package/dist/client/events/serverCreate.cjs +131 -0
- package/dist/client/events/serverCreate.cjs.map +1 -0
- package/dist/client/events/serverCreate.d.cts +27 -0
- package/dist/client/events/serverCreate.d.ts +27 -0
- package/dist/client/events/serverCreate.js +11 -0
- package/dist/client/events/serverCreate.js.map +1 -0
- package/dist/client/events/serverDelete.cjs +110 -0
- package/dist/client/events/serverDelete.cjs.map +1 -0
- package/dist/client/events/serverDelete.d.cts +27 -0
- package/dist/client/events/serverDelete.d.ts +27 -0
- package/dist/client/events/serverDelete.js +11 -0
- package/dist/client/events/serverDelete.js.map +1 -0
- package/dist/client/events/serverMemberJoin.cjs +135 -0
- package/dist/client/events/serverMemberJoin.cjs.map +1 -0
- package/dist/client/events/serverMemberJoin.d.cts +30 -0
- package/dist/client/events/serverMemberJoin.d.ts +30 -0
- package/dist/client/events/serverMemberJoin.js +11 -0
- package/dist/client/events/serverMemberJoin.js.map +1 -0
- package/dist/client/events/serverMemberLeave.cjs +114 -0
- package/dist/client/events/serverMemberLeave.cjs.map +1 -0
- package/dist/client/events/serverMemberLeave.d.cts +30 -0
- package/dist/client/events/serverMemberLeave.d.ts +30 -0
- package/dist/client/events/serverMemberLeave.js +11 -0
- package/dist/client/events/serverMemberLeave.js.map +1 -0
- package/dist/client/events/serverMemberUpdate.cjs +135 -0
- package/dist/client/events/serverMemberUpdate.cjs.map +1 -0
- package/dist/client/events/serverMemberUpdate.d.cts +33 -0
- package/dist/client/events/serverMemberUpdate.d.ts +33 -0
- package/dist/client/events/serverMemberUpdate.js +11 -0
- package/dist/client/events/serverMemberUpdate.js.map +1 -0
- package/dist/client/events/serverRoleDelete.cjs +114 -0
- package/dist/client/events/serverRoleDelete.cjs.map +1 -0
- package/dist/client/events/serverRoleDelete.d.cts +30 -0
- package/dist/client/events/serverRoleDelete.d.ts +30 -0
- package/dist/client/events/serverRoleDelete.js +11 -0
- package/dist/client/events/serverRoleDelete.js.map +1 -0
- package/dist/client/events/serverRoleUpdate.cjs +111 -0
- package/dist/client/events/serverRoleUpdate.cjs.map +1 -0
- package/dist/client/events/serverRoleUpdate.d.cts +34 -0
- package/dist/client/events/serverRoleUpdate.d.ts +34 -0
- package/dist/client/events/serverRoleUpdate.js +11 -0
- package/dist/client/events/serverRoleUpdate.js.map +1 -0
- package/dist/client/events/serverupdate.cjs +109 -0
- package/dist/client/events/serverupdate.cjs.map +1 -0
- package/dist/client/events/serverupdate.d.cts +31 -0
- package/dist/client/events/serverupdate.d.ts +31 -0
- package/dist/client/events/serverupdate.js +11 -0
- package/dist/client/events/serverupdate.js.map +1 -0
- package/dist/client/events/userUpdate.cjs +109 -0
- package/dist/client/events/userUpdate.cjs.map +1 -0
- package/dist/client/events/userUpdate.d.cts +31 -0
- package/dist/client/events/userUpdate.d.ts +31 -0
- package/dist/client/events/userUpdate.js +11 -0
- package/dist/client/events/userUpdate.js.map +1 -0
- package/dist/client/webSocket.cjs +1018 -0
- package/dist/client/webSocket.cjs.map +1 -0
- package/dist/client/webSocket.d.cts +10 -0
- package/dist/client/webSocket.d.ts +10 -0
- package/dist/client/webSocket.js +53 -0
- package/dist/client/webSocket.js.map +1 -0
- package/dist/{index.d.mts → index-D44PqKGb.d.ts} +4 -242
- package/dist/index-XkxTx7UU.d.cts +2386 -0
- package/dist/{index.mjs → index.cjs} +112 -36
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -2624
- package/dist/index.js +111 -4535
- package/dist/index.js.map +1 -0
- package/dist/managers/baseManager.cjs +63 -0
- package/dist/managers/baseManager.cjs.map +1 -0
- package/dist/managers/baseManager.d.cts +10 -0
- package/dist/managers/baseManager.d.ts +10 -0
- package/dist/managers/baseManager.js +8 -0
- package/dist/managers/baseManager.js.map +1 -0
- package/dist/managers/channelManager.cjs +1978 -0
- package/dist/managers/channelManager.cjs.map +1 -0
- package/dist/managers/channelManager.d.cts +10 -0
- package/dist/managers/channelManager.d.ts +10 -0
- package/dist/managers/channelManager.js +53 -0
- package/dist/managers/channelManager.js.map +1 -0
- package/dist/managers/index.cjs +2992 -0
- package/dist/managers/index.cjs.map +1 -0
- package/dist/managers/index.d.cts +10 -0
- package/dist/managers/index.d.ts +10 -0
- package/dist/managers/index.js +68 -0
- package/dist/managers/index.js.map +1 -0
- package/dist/managers/messageManager.cjs +1153 -0
- package/dist/managers/messageManager.cjs.map +1 -0
- package/dist/managers/messageManager.d.cts +10 -0
- package/dist/managers/messageManager.d.ts +10 -0
- package/dist/managers/messageManager.js +53 -0
- package/dist/managers/messageManager.js.map +1 -0
- package/dist/managers/roleManager.cjs +700 -0
- package/dist/managers/roleManager.cjs.map +1 -0
- package/dist/managers/roleManager.d.cts +10 -0
- package/dist/managers/roleManager.d.ts +10 -0
- package/dist/managers/roleManager.js +53 -0
- package/dist/managers/roleManager.js.map +1 -0
- package/dist/managers/serverChannelManager.cjs +1622 -0
- package/dist/managers/serverChannelManager.cjs.map +1 -0
- package/dist/managers/serverChannelManager.d.cts +10 -0
- package/dist/managers/serverChannelManager.d.ts +10 -0
- package/dist/managers/serverChannelManager.js +53 -0
- package/dist/managers/serverChannelManager.js.map +1 -0
- package/dist/managers/serverManager.cjs +2508 -0
- package/dist/managers/serverManager.cjs.map +1 -0
- package/dist/managers/serverManager.d.cts +10 -0
- package/dist/managers/serverManager.d.ts +10 -0
- package/dist/managers/serverManager.js +53 -0
- package/dist/managers/serverManager.js.map +1 -0
- package/dist/managers/serverMemberManager.cjs +1037 -0
- package/dist/managers/serverMemberManager.cjs.map +1 -0
- package/dist/managers/serverMemberManager.d.cts +10 -0
- package/dist/managers/serverMemberManager.d.ts +10 -0
- package/dist/managers/serverMemberManager.js +53 -0
- package/dist/managers/serverMemberManager.js.map +1 -0
- package/dist/managers/userManager.cjs +1103 -0
- package/dist/managers/userManager.cjs.map +1 -0
- package/dist/managers/userManager.d.cts +10 -0
- package/dist/managers/userManager.d.ts +10 -0
- package/dist/managers/userManager.js +53 -0
- package/dist/managers/userManager.js.map +1 -0
- package/dist/rest/CDNClient.cjs +608 -0
- package/dist/rest/CDNClient.cjs.map +1 -0
- package/dist/rest/CDNClient.d.cts +10 -0
- package/dist/rest/CDNClient.d.ts +10 -0
- package/dist/rest/CDNClient.js +16 -0
- package/dist/rest/CDNClient.js.map +1 -0
- package/dist/rest/restClient.cjs +652 -0
- package/dist/rest/restClient.cjs.map +1 -0
- package/dist/rest/restClient.d.cts +10 -0
- package/dist/rest/restClient.d.ts +10 -0
- package/dist/rest/restClient.js +16 -0
- package/dist/rest/restClient.js.map +1 -0
- package/dist/rest/restUtils/rateLimitQueue.cjs +138 -0
- package/dist/rest/restUtils/rateLimitQueue.cjs.map +1 -0
- package/dist/rest/restUtils/rateLimitQueue.d.cts +13 -0
- package/dist/rest/restUtils/rateLimitQueue.d.ts +13 -0
- package/dist/rest/restUtils/rateLimitQueue.js +8 -0
- package/dist/rest/restUtils/rateLimitQueue.js.map +1 -0
- package/dist/struct/attachment.cjs +263 -0
- package/dist/struct/attachment.cjs.map +1 -0
- package/dist/struct/attachment.d.cts +10 -0
- package/dist/struct/attachment.d.ts +10 -0
- package/dist/struct/attachment.js +10 -0
- package/dist/struct/attachment.js.map +1 -0
- package/dist/struct/base.cjs +234 -0
- package/dist/struct/base.cjs.map +1 -0
- package/dist/struct/base.d.cts +10 -0
- package/dist/struct/base.d.ts +10 -0
- package/dist/struct/base.js +9 -0
- package/dist/struct/base.js.map +1 -0
- package/dist/struct/category.cjs +532 -0
- package/dist/struct/category.cjs.map +1 -0
- package/dist/struct/category.d.cts +10 -0
- package/dist/struct/category.d.ts +10 -0
- package/dist/struct/category.js +53 -0
- package/dist/struct/category.js.map +1 -0
- package/dist/struct/channel.cjs +539 -0
- package/dist/struct/channel.cjs.map +1 -0
- package/dist/struct/channel.d.cts +10 -0
- package/dist/struct/channel.d.ts +10 -0
- package/dist/struct/channel.js +15 -0
- package/dist/struct/channel.js.map +1 -0
- package/dist/struct/clientUser.cjs +741 -0
- package/dist/struct/clientUser.cjs.map +1 -0
- package/dist/struct/clientUser.d.cts +10 -0
- package/dist/struct/clientUser.d.ts +10 -0
- package/dist/struct/clientUser.js +53 -0
- package/dist/struct/clientUser.js.map +1 -0
- package/dist/struct/dmChannel.cjs +1320 -0
- package/dist/struct/dmChannel.cjs.map +1 -0
- package/dist/struct/dmChannel.d.cts +10 -0
- package/dist/struct/dmChannel.d.ts +10 -0
- package/dist/struct/dmChannel.js +53 -0
- package/dist/struct/dmChannel.js.map +1 -0
- package/dist/struct/emoji.cjs +273 -0
- package/dist/struct/emoji.cjs.map +1 -0
- package/dist/struct/emoji.d.cts +10 -0
- package/dist/struct/emoji.d.ts +10 -0
- package/dist/struct/emoji.js +10 -0
- package/dist/struct/emoji.js.map +1 -0
- package/dist/struct/groupChannel.cjs +1519 -0
- package/dist/struct/groupChannel.cjs.map +1 -0
- package/dist/struct/groupChannel.d.cts +10 -0
- package/dist/struct/groupChannel.d.ts +10 -0
- package/dist/struct/groupChannel.js +53 -0
- package/dist/struct/groupChannel.js.map +1 -0
- package/dist/struct/index.cjs +2970 -0
- package/dist/struct/index.cjs.map +1 -0
- package/dist/struct/index.d.cts +10 -0
- package/dist/struct/index.d.ts +10 -0
- package/dist/struct/index.js +101 -0
- package/dist/struct/index.js.map +1 -0
- package/dist/struct/interfaces/baseChannel.cjs +19 -0
- package/dist/struct/interfaces/baseChannel.cjs.map +1 -0
- package/dist/struct/interfaces/baseChannel.d.cts +10 -0
- package/dist/struct/interfaces/baseChannel.d.ts +10 -0
- package/dist/struct/interfaces/baseChannel.js +1 -0
- package/dist/struct/interfaces/baseChannel.js.map +1 -0
- package/dist/struct/invite.cjs +293 -0
- package/dist/struct/invite.cjs.map +1 -0
- package/dist/struct/invite.d.cts +10 -0
- package/dist/struct/invite.d.ts +10 -0
- package/dist/struct/invite.js +10 -0
- package/dist/struct/invite.js.map +1 -0
- package/dist/struct/mentions.cjs +104 -0
- package/dist/struct/mentions.cjs.map +1 -0
- package/dist/struct/mentions.d.cts +10 -0
- package/dist/struct/mentions.d.ts +10 -0
- package/dist/struct/mentions.js +8 -0
- package/dist/struct/mentions.js.map +1 -0
- package/dist/struct/message.cjs +817 -0
- package/dist/struct/message.cjs.map +1 -0
- package/dist/struct/message.d.cts +10 -0
- package/dist/struct/message.d.ts +10 -0
- package/dist/struct/message.js +53 -0
- package/dist/struct/message.js.map +1 -0
- package/dist/struct/messageEmbed.cjs +205 -0
- package/dist/struct/messageEmbed.cjs.map +1 -0
- package/dist/struct/messageEmbed.d.cts +10 -0
- package/dist/struct/messageEmbed.d.ts +10 -0
- package/dist/struct/messageEmbed.js +8 -0
- package/dist/struct/messageEmbed.js.map +1 -0
- package/dist/struct/notesChannel.cjs +1327 -0
- package/dist/struct/notesChannel.cjs.map +1 -0
- package/dist/struct/notesChannel.d.cts +10 -0
- package/dist/struct/notesChannel.d.ts +10 -0
- package/dist/struct/notesChannel.js +53 -0
- package/dist/struct/notesChannel.js.map +1 -0
- package/dist/struct/presence.cjs +254 -0
- package/dist/struct/presence.cjs.map +1 -0
- package/dist/struct/presence.d.cts +10 -0
- package/dist/struct/presence.d.ts +10 -0
- package/dist/struct/presence.js +12 -0
- package/dist/struct/presence.js.map +1 -0
- package/dist/struct/role.cjs +572 -0
- package/dist/struct/role.cjs.map +1 -0
- package/dist/struct/role.d.cts +10 -0
- package/dist/struct/role.d.ts +10 -0
- package/dist/struct/role.js +53 -0
- package/dist/struct/role.js.map +1 -0
- package/dist/struct/server.cjs +2454 -0
- package/dist/struct/server.cjs.map +1 -0
- package/dist/struct/server.d.cts +10 -0
- package/dist/struct/server.d.ts +10 -0
- package/dist/struct/server.js +53 -0
- package/dist/struct/server.js.map +1 -0
- package/dist/struct/serverChannel.cjs +776 -0
- package/dist/struct/serverChannel.cjs.map +1 -0
- package/dist/struct/serverChannel.d.cts +10 -0
- package/dist/struct/serverChannel.d.ts +10 -0
- package/dist/struct/serverChannel.js +53 -0
- package/dist/struct/serverChannel.js.map +1 -0
- package/dist/struct/serverMember.cjs +711 -0
- package/dist/struct/serverMember.cjs.map +1 -0
- package/dist/struct/serverMember.d.cts +10 -0
- package/dist/struct/serverMember.d.ts +10 -0
- package/dist/struct/serverMember.js +53 -0
- package/dist/struct/serverMember.js.map +1 -0
- package/dist/struct/textChannel.cjs +1502 -0
- package/dist/struct/textChannel.cjs.map +1 -0
- package/dist/struct/textChannel.d.cts +10 -0
- package/dist/struct/textChannel.d.ts +10 -0
- package/dist/struct/textChannel.js +53 -0
- package/dist/struct/textChannel.js.map +1 -0
- package/dist/struct/user.cjs +690 -0
- package/dist/struct/user.cjs.map +1 -0
- package/dist/struct/user.d.cts +10 -0
- package/dist/struct/user.d.ts +10 -0
- package/dist/struct/user.js +53 -0
- package/dist/struct/user.js.map +1 -0
- package/dist/struct/voiceChannels.cjs +820 -0
- package/dist/struct/voiceChannels.cjs.map +1 -0
- package/dist/struct/voiceChannels.d.cts +10 -0
- package/dist/struct/voiceChannels.d.ts +10 -0
- package/dist/struct/voiceChannels.js +53 -0
- package/dist/struct/voiceChannels.js.map +1 -0
- package/dist/utils/UUID.cjs +75 -0
- package/dist/utils/UUID.cjs.map +1 -0
- package/dist/utils/UUID.d.cts +14 -0
- package/dist/utils/UUID.d.ts +14 -0
- package/dist/utils/UUID.js +8 -0
- package/dist/utils/UUID.js.map +1 -0
- package/dist/utils/badges.cjs +181 -0
- package/dist/utils/badges.cjs.map +1 -0
- package/dist/utils/badges.d.cts +25 -0
- package/dist/utils/badges.d.ts +25 -0
- package/dist/utils/badges.js +9 -0
- package/dist/utils/badges.js.map +1 -0
- package/dist/utils/bitField.cjs +161 -0
- package/dist/utils/bitField.cjs.map +1 -0
- package/dist/utils/bitField.d.cts +51 -0
- package/dist/utils/bitField.d.ts +51 -0
- package/dist/utils/bitField.js +8 -0
- package/dist/utils/bitField.js.map +1 -0
- package/dist/utils/constants.cjs +179 -0
- package/dist/utils/constants.cjs.map +1 -0
- package/dist/utils/constants.d.cts +10 -0
- package/dist/utils/constants.d.ts +10 -0
- package/dist/utils/constants.js +23 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/index.cjs +489 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +11 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.js +47 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/permissions.cjs +314 -0
- package/dist/utils/permissions.cjs.map +1 -0
- package/dist/utils/permissions.d.cts +110 -0
- package/dist/utils/permissions.d.ts +110 -0
- package/dist/utils/permissions.js +17 -0
- package/dist/utils/permissions.js.map +1 -0
- package/dist/utils/types.cjs +19 -0
- package/dist/utils/types.cjs.map +1 -0
- package/dist/utils/types.d.cts +60 -0
- package/dist/utils/types.d.ts +60 -0
- package/dist/utils/types.js +1 -0
- package/dist/utils/types.js.map +1 -0
- package/package.json +16 -5
|
@@ -0,0 +1,4286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
13
|
+
var __typeError = (msg) => {
|
|
14
|
+
throw TypeError(msg);
|
|
15
|
+
};
|
|
16
|
+
var __pow = Math.pow;
|
|
17
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
18
|
+
var __spreadValues = (a, b) => {
|
|
19
|
+
for (var prop in b || (b = {}))
|
|
20
|
+
if (__hasOwnProp.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
if (__getOwnPropSymbols)
|
|
23
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
24
|
+
if (__propIsEnum.call(b, prop))
|
|
25
|
+
__defNormalProp(a, prop, b[prop]);
|
|
26
|
+
}
|
|
27
|
+
return a;
|
|
28
|
+
};
|
|
29
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
30
|
+
var __export = (target, all) => {
|
|
31
|
+
for (var name in all)
|
|
32
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
33
|
+
};
|
|
34
|
+
var __copyProps = (to, from, except, desc) => {
|
|
35
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
36
|
+
for (let key of __getOwnPropNames(from))
|
|
37
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
38
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
39
|
+
}
|
|
40
|
+
return to;
|
|
41
|
+
};
|
|
42
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
43
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
44
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
45
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
46
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
47
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
48
|
+
mod
|
|
49
|
+
));
|
|
50
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
51
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
52
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
53
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
54
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
55
|
+
var __async = (__this, __arguments, generator) => {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
var fulfilled = (value) => {
|
|
58
|
+
try {
|
|
59
|
+
step(generator.next(value));
|
|
60
|
+
} catch (e) {
|
|
61
|
+
reject(e);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var rejected = (value) => {
|
|
65
|
+
try {
|
|
66
|
+
step(generator.throw(value));
|
|
67
|
+
} catch (e) {
|
|
68
|
+
reject(e);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
72
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
var __await = function(promise, isYieldStar) {
|
|
76
|
+
this[0] = promise;
|
|
77
|
+
this[1] = isYieldStar;
|
|
78
|
+
};
|
|
79
|
+
var __yieldStar = (value) => {
|
|
80
|
+
var obj = value[__knownSymbol("asyncIterator")], isAwait = false, method, it = {};
|
|
81
|
+
if (obj == null) {
|
|
82
|
+
obj = value[__knownSymbol("iterator")]();
|
|
83
|
+
method = (k) => it[k] = (x) => obj[k](x);
|
|
84
|
+
} else {
|
|
85
|
+
obj = obj.call(value);
|
|
86
|
+
method = (k) => it[k] = (v) => {
|
|
87
|
+
if (isAwait) {
|
|
88
|
+
isAwait = false;
|
|
89
|
+
if (k === "throw") throw v;
|
|
90
|
+
return v;
|
|
91
|
+
}
|
|
92
|
+
isAwait = true;
|
|
93
|
+
return {
|
|
94
|
+
done: false,
|
|
95
|
+
value: new __await(new Promise((resolve) => {
|
|
96
|
+
var x = obj[k](v);
|
|
97
|
+
if (!(x instanceof Object)) __typeError("Object expected");
|
|
98
|
+
resolve(x);
|
|
99
|
+
}), 1)
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => {
|
|
104
|
+
throw x;
|
|
105
|
+
}, "return" in obj && method("return"), it;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// src/client/client.ts
|
|
109
|
+
var client_exports = {};
|
|
110
|
+
__export(client_exports, {
|
|
111
|
+
client: () => client
|
|
112
|
+
});
|
|
113
|
+
module.exports = __toCommonJS(client_exports);
|
|
114
|
+
|
|
115
|
+
// src/managers/baseManager.ts
|
|
116
|
+
var BaseManager = class {
|
|
117
|
+
constructor(client3) {
|
|
118
|
+
this.client = client3;
|
|
119
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
120
|
+
}
|
|
121
|
+
_add(raw) {
|
|
122
|
+
if (!this.holds) throw new Error("Holds is not defined");
|
|
123
|
+
const obj = new this.holds(this.client, raw);
|
|
124
|
+
this.cache.set(obj.id, obj);
|
|
125
|
+
return obj;
|
|
126
|
+
}
|
|
127
|
+
_remove(id) {
|
|
128
|
+
this.cache.delete(id);
|
|
129
|
+
}
|
|
130
|
+
resolve(resolvable) {
|
|
131
|
+
var _a;
|
|
132
|
+
const id = this.resolveId(resolvable);
|
|
133
|
+
if (id) return (_a = this.cache.get(id)) != null ? _a : null;
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
resolveId(resolvable) {
|
|
137
|
+
var _a;
|
|
138
|
+
if (resolvable == null) return null;
|
|
139
|
+
if (typeof resolvable === "string") return resolvable;
|
|
140
|
+
if (this.holds && resolvable instanceof this.holds) return resolvable.id;
|
|
141
|
+
const raw = resolvable;
|
|
142
|
+
if (typeof raw === "object" && "_id" in raw) (_a = raw._id) != null ? _a : null;
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
valueOf() {
|
|
146
|
+
return this.cache;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// src/utils/bitField.ts
|
|
151
|
+
var DEFAULT_BIT = 0;
|
|
152
|
+
var _BitField = class _BitField {
|
|
153
|
+
constructor(bits = DEFAULT_BIT) {
|
|
154
|
+
this.bitfield = DEFAULT_BIT;
|
|
155
|
+
this.bitfield = this.self.resolve(bits);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Resolves a bitfield or an array of bitfields into a single number.
|
|
159
|
+
* @param bit The bitfield or array of bitfields to resolve.
|
|
160
|
+
* @returns The resolved bitfield as a number.
|
|
161
|
+
*/
|
|
162
|
+
static resolve(bit) {
|
|
163
|
+
if (bit instanceof _BitField) return bit.bitfield;
|
|
164
|
+
if (typeof bit === "number" && bit >= DEFAULT_BIT) return bit;
|
|
165
|
+
if (Array.isArray(bit)) {
|
|
166
|
+
return bit.map((p) => this.resolve(p)).reduce((prev, p) => prev | p, DEFAULT_BIT);
|
|
167
|
+
}
|
|
168
|
+
if (typeof this.FLAGS[bit] !== "undefined") return this.FLAGS[bit];
|
|
169
|
+
throw new Error("BITFIELD_INVALID");
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Returns the class that this instance belongs to.
|
|
173
|
+
* @returns The class of the bitfield.
|
|
174
|
+
*/
|
|
175
|
+
get self() {
|
|
176
|
+
return this.constructor;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Checks if any of the bits in the bitfield are set.
|
|
180
|
+
* @param bit The bitfield or array of bitfields to check.
|
|
181
|
+
* @returns True if any bits are set, false otherwise.
|
|
182
|
+
*/
|
|
183
|
+
any(bit) {
|
|
184
|
+
bit = this.self.resolve(bit);
|
|
185
|
+
return (this.bitfield & bit) !== DEFAULT_BIT;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* checks if a specific permission is set.
|
|
189
|
+
*/
|
|
190
|
+
has(bit) {
|
|
191
|
+
bit = this.self.resolve(bit);
|
|
192
|
+
return (this.bitfield & bit) === bit;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Returns an array of all the Permissions that are set in the bitfield.
|
|
196
|
+
* @returns An array of flag names.
|
|
197
|
+
*/
|
|
198
|
+
toArray() {
|
|
199
|
+
return Object.keys(this.self.FLAGS).filter((bit) => this.has(bit));
|
|
200
|
+
}
|
|
201
|
+
add(...bits) {
|
|
202
|
+
let total = 0;
|
|
203
|
+
for (const bit of bits) {
|
|
204
|
+
total |= this.self.resolve(bit);
|
|
205
|
+
}
|
|
206
|
+
if (Object.isFrozen(this)) {
|
|
207
|
+
return new this.self(this.bitfield | total);
|
|
208
|
+
}
|
|
209
|
+
this.bitfield |= total;
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
remove(...bits) {
|
|
213
|
+
let total = 0;
|
|
214
|
+
for (const bit of bits) {
|
|
215
|
+
total |= this.self.resolve(bit);
|
|
216
|
+
}
|
|
217
|
+
if (Object.isFrozen(this)) {
|
|
218
|
+
return new this.self(this.bitfield & ~total);
|
|
219
|
+
}
|
|
220
|
+
this.bitfield &= ~total;
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
freeze() {
|
|
224
|
+
return Object.freeze(this);
|
|
225
|
+
}
|
|
226
|
+
valueOf() {
|
|
227
|
+
return this.bitfield;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
*
|
|
231
|
+
* @returns A record of all flags and their boolean values indicating whether they are set.
|
|
232
|
+
*/
|
|
233
|
+
serialize() {
|
|
234
|
+
const serialized = {};
|
|
235
|
+
for (const [flag, bit] of Object.entries(this.self.FLAGS)) {
|
|
236
|
+
serialized[flag] = this.has(bit);
|
|
237
|
+
}
|
|
238
|
+
return serialized;
|
|
239
|
+
}
|
|
240
|
+
*[Symbol.iterator]() {
|
|
241
|
+
yield* __yieldStar(this.toArray());
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
_BitField.FLAGS = {};
|
|
245
|
+
var BitField = _BitField;
|
|
246
|
+
|
|
247
|
+
// src/struct/base.ts
|
|
248
|
+
var Base = class _Base {
|
|
249
|
+
/**
|
|
250
|
+
* Creates a new Base instance.
|
|
251
|
+
*
|
|
252
|
+
* @param {client} client - The client instance.
|
|
253
|
+
*/
|
|
254
|
+
constructor(client3) {
|
|
255
|
+
this.client = client3;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Compares this object with another to determine if they are equal.
|
|
259
|
+
*
|
|
260
|
+
* @param {this | null} [obj] - The object to compare with.
|
|
261
|
+
* @returns {boolean} `true` if the objects are equal, otherwise `false`.
|
|
262
|
+
*/
|
|
263
|
+
equals(obj) {
|
|
264
|
+
if (!obj) return false;
|
|
265
|
+
for (const key in obj) {
|
|
266
|
+
const a = obj[key], b = this[key];
|
|
267
|
+
if (a instanceof _Base && !a.equals(b)) return false;
|
|
268
|
+
if (a instanceof BitField && a.bitfield !== b.bitfield)
|
|
269
|
+
return false;
|
|
270
|
+
if (typeof a === "object" && a !== null) continue;
|
|
271
|
+
if (a !== b) return false;
|
|
272
|
+
}
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Updates the object with new data and returns a clone of the object.
|
|
277
|
+
*
|
|
278
|
+
* @param {PartialObject} data - The data to update the object with.
|
|
279
|
+
* @param {string[]} [clear] - Fields to clear in the object.
|
|
280
|
+
* @returns {this} A clone of the updated object.
|
|
281
|
+
*/
|
|
282
|
+
_update(data, clear) {
|
|
283
|
+
const clone = this._clone();
|
|
284
|
+
this._patch(data, clear);
|
|
285
|
+
return clone;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Patches the object with new data.
|
|
289
|
+
*
|
|
290
|
+
* @param {PartialObject} data - The data to patch the object with.
|
|
291
|
+
* @param {string[]} [_clear] - Fields to clear in the object.
|
|
292
|
+
* @returns {this} The updated object.
|
|
293
|
+
* @protected
|
|
294
|
+
*/
|
|
295
|
+
_patch(data, _clear) {
|
|
296
|
+
if ("id" in data) this.id = data.id;
|
|
297
|
+
if ("_id" in data) {
|
|
298
|
+
if (typeof data._id === "string") this.id = data._id;
|
|
299
|
+
if (typeof data._id === "object") this.id = data._id.user;
|
|
300
|
+
}
|
|
301
|
+
return this;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Creates a deep clone of the object.
|
|
305
|
+
*
|
|
306
|
+
* @returns {this} A clone of the object.
|
|
307
|
+
*/
|
|
308
|
+
_clone() {
|
|
309
|
+
const clone = Object.assign(Object.create(this), this);
|
|
310
|
+
for (const key in clone) {
|
|
311
|
+
const prop = clone[key];
|
|
312
|
+
if (prop instanceof _Base) clone[key] = prop._clone();
|
|
313
|
+
}
|
|
314
|
+
return clone;
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
// src/utils/UUID.ts
|
|
319
|
+
var import_crypto = require("crypto");
|
|
320
|
+
var _UUID = class _UUID extends null {
|
|
321
|
+
static get PROG() {
|
|
322
|
+
return (0, import_crypto.randomBytes)(1).readUInt8() / 255;
|
|
323
|
+
}
|
|
324
|
+
static time(now = Date.now()) {
|
|
325
|
+
let mod, result = "";
|
|
326
|
+
for (let i = this.TIME_LENGTH; i > 0; i--) {
|
|
327
|
+
mod = now % this.ENCODING_LENGTH;
|
|
328
|
+
result = this.ENCODING.charAt(mod) + result;
|
|
329
|
+
now = (now - mod) / this.ENCODING_LENGTH;
|
|
330
|
+
}
|
|
331
|
+
return result;
|
|
332
|
+
}
|
|
333
|
+
static hash() {
|
|
334
|
+
let result = "";
|
|
335
|
+
for (let i = this.RANDOM_LENGTH; i > 0; i--) {
|
|
336
|
+
let random = Math.floor(this.PROG * this.ENCODING_LENGTH);
|
|
337
|
+
if (random === this.ENCODING_LENGTH) {
|
|
338
|
+
random = this.ENCODING_LENGTH - 1;
|
|
339
|
+
}
|
|
340
|
+
result = this.ENCODING.charAt(random) + result;
|
|
341
|
+
}
|
|
342
|
+
return result;
|
|
343
|
+
}
|
|
344
|
+
static generate(timestamp = Date.now()) {
|
|
345
|
+
return this.time(timestamp) + this.hash();
|
|
346
|
+
}
|
|
347
|
+
static timestampOf(id) {
|
|
348
|
+
const timestamp = id.slice(0, this.TIME_LENGTH).split("").reverse().reduce((carry, char, index) => {
|
|
349
|
+
const encodingIndex = this.ENCODING.indexOf(char);
|
|
350
|
+
if (encodingIndex === -1) {
|
|
351
|
+
throw new Error("invalid character found: " + char);
|
|
352
|
+
}
|
|
353
|
+
return carry += encodingIndex * Math.pow(this.ENCODING_LENGTH, index);
|
|
354
|
+
}, 0);
|
|
355
|
+
return new Date(timestamp);
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
_UUID.ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
359
|
+
_UUID.ENCODING_LENGTH = _UUID.ENCODING.length;
|
|
360
|
+
_UUID.RANDOM_LENGTH = 16;
|
|
361
|
+
_UUID.TIME_LENGTH = 10;
|
|
362
|
+
_UUID.TIME_MAX = Math.pow(2, 48) - 1;
|
|
363
|
+
var UUID = _UUID;
|
|
364
|
+
|
|
365
|
+
// src/utils/constants.ts
|
|
366
|
+
var DEFAULT_CLIENT_OPTIONS = {
|
|
367
|
+
fetchMembers: true,
|
|
368
|
+
rest: {
|
|
369
|
+
timeout: 15e3,
|
|
370
|
+
retries: 3
|
|
371
|
+
},
|
|
372
|
+
ws: {
|
|
373
|
+
heartbeatInterval: 3e4,
|
|
374
|
+
reconnect: true
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
var wsUrl = "wss://ws.revolt.chat?version=1&format=json";
|
|
378
|
+
var apiUrl = "https://api.revolt.chat";
|
|
379
|
+
var cdnUrl = "https://cdn.revoltusercontent.com";
|
|
380
|
+
var SYSTEM_USER_ID = "0".repeat(UUID.TIME_LENGTH + UUID.RANDOM_LENGTH);
|
|
381
|
+
|
|
382
|
+
// src/utils/permissions.ts
|
|
383
|
+
var ChannelPermissions = class extends BitField {
|
|
384
|
+
constructor(bits) {
|
|
385
|
+
super(bits);
|
|
386
|
+
}
|
|
387
|
+
static resolve(bit) {
|
|
388
|
+
return super.resolve(bit);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
ChannelPermissions.FLAGS = {
|
|
392
|
+
VIEW_CHANNEL: __pow(1, 0),
|
|
393
|
+
SEND_MESSAGE: __pow(1, 22),
|
|
394
|
+
MANAGE_MESSAGE: __pow(1, 2),
|
|
395
|
+
MANAGE_CHANNEL: __pow(1, 3),
|
|
396
|
+
VOICE_CALL: __pow(1, 4),
|
|
397
|
+
INVITE_OTHERS: __pow(1, 5),
|
|
398
|
+
EMBED_LINKS: __pow(1, 6),
|
|
399
|
+
UPLOAD_FILES: __pow(1, 7)
|
|
400
|
+
};
|
|
401
|
+
var UserPermissions = class extends BitField {
|
|
402
|
+
constructor(bits) {
|
|
403
|
+
super(bits);
|
|
404
|
+
}
|
|
405
|
+
static resolve(bit) {
|
|
406
|
+
return super.resolve(bit);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
UserPermissions.FLAGS = {
|
|
410
|
+
ACCESS: __pow(1, 0),
|
|
411
|
+
VIEW_PROFILE: __pow(1, 1),
|
|
412
|
+
SEND_MESSAGES: __pow(1, 2),
|
|
413
|
+
INVITE: __pow(1, 3)
|
|
414
|
+
};
|
|
415
|
+
var ServerPermissions = class extends BitField {
|
|
416
|
+
constructor(bits) {
|
|
417
|
+
super(bits);
|
|
418
|
+
}
|
|
419
|
+
static resolve(bit) {
|
|
420
|
+
return super.resolve(bit);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
ServerPermissions.FLAGS = {
|
|
424
|
+
VIEW_SERVER: __pow(1, 0),
|
|
425
|
+
MANAGE_ROLES: __pow(1, 1),
|
|
426
|
+
MANAGE_CHANNELS: __pow(1, 2),
|
|
427
|
+
MANAGE_SERVER: __pow(1, 3),
|
|
428
|
+
KICK_MEMBERS: __pow(1, 4),
|
|
429
|
+
BAN_MEMBERS: __pow(1, 5),
|
|
430
|
+
CHANGE_NICKNAME: __pow(1, 12),
|
|
431
|
+
MANAGE_NICKNAMES: __pow(1, 13),
|
|
432
|
+
CHANGE_AVATAR: __pow(1, 14),
|
|
433
|
+
REMOVE_AVATARS: __pow(1, 15)
|
|
434
|
+
};
|
|
435
|
+
var FullPermissions = class extends BitField {
|
|
436
|
+
constructor(bits) {
|
|
437
|
+
super(bits);
|
|
438
|
+
}
|
|
439
|
+
static resolve(bit) {
|
|
440
|
+
return super.resolve(bit);
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
FullPermissions.FLAGS = {
|
|
444
|
+
// * Generic permissions
|
|
445
|
+
/// Manage the channel or channels on the server
|
|
446
|
+
ManageChannel: __pow(2, 0),
|
|
447
|
+
/// Manage the server
|
|
448
|
+
ManageServer: __pow(2, 1),
|
|
449
|
+
/// Manage permissions on servers or channels
|
|
450
|
+
ManagePermissions: __pow(2, 2),
|
|
451
|
+
/// Manage roles on server
|
|
452
|
+
ManageRole: __pow(2, 3),
|
|
453
|
+
/// Manage server customisation (includes emoji)
|
|
454
|
+
ManageCustomisation: __pow(2, 4),
|
|
455
|
+
// * Member permissions
|
|
456
|
+
/// Kick other members below their ranking
|
|
457
|
+
KickMembers: __pow(2, 6),
|
|
458
|
+
/// Ban other members below their ranking
|
|
459
|
+
BanMembers: __pow(2, 7),
|
|
460
|
+
/// Timeout other members below their ranking
|
|
461
|
+
TimeoutMembers: __pow(2, 8),
|
|
462
|
+
/// Assign roles to members below their ranking
|
|
463
|
+
AssignRoles: __pow(2, 9),
|
|
464
|
+
/// Change own nickname
|
|
465
|
+
ChangeNickname: __pow(2, 10),
|
|
466
|
+
/// Change or remove other's nicknames below their ranking
|
|
467
|
+
ManageNicknames: __pow(2, 11),
|
|
468
|
+
/// Change own avatar
|
|
469
|
+
ChangeAvatar: __pow(2, 12),
|
|
470
|
+
/// Remove other's avatars below their ranking
|
|
471
|
+
RemoveAvatars: __pow(2, 13),
|
|
472
|
+
// * Channel permissions
|
|
473
|
+
/// View a channel
|
|
474
|
+
ViewChannel: __pow(2, 20),
|
|
475
|
+
/// Read a channel's past message history
|
|
476
|
+
ReadMessageHistory: __pow(2, 21),
|
|
477
|
+
/// Send a message in a channel
|
|
478
|
+
SendMessage: __pow(2, 22),
|
|
479
|
+
/// Delete messages in a channel
|
|
480
|
+
ManageMessages: __pow(2, 23),
|
|
481
|
+
/// Manage webhook entries on a channel
|
|
482
|
+
ManageWebhooks: __pow(2, 24),
|
|
483
|
+
/// Create invites to this channel
|
|
484
|
+
InviteOthers: __pow(2, 25),
|
|
485
|
+
/// Send embedded content in this channel
|
|
486
|
+
SendEmbeds: __pow(2, 26),
|
|
487
|
+
/// Send attachments and media in this channel
|
|
488
|
+
UploadFiles: __pow(2, 27),
|
|
489
|
+
/// Masquerade messages using custom nickname and avatar
|
|
490
|
+
Masquerade: __pow(2, 28),
|
|
491
|
+
/// React to messages with emoji
|
|
492
|
+
React: __pow(2, 29),
|
|
493
|
+
// * Voice permissions
|
|
494
|
+
/// Connect to a voice channel
|
|
495
|
+
Connect: __pow(2, 30),
|
|
496
|
+
/// Speak in a voice call
|
|
497
|
+
Speak: __pow(2, 31),
|
|
498
|
+
/// Share video in a voice call
|
|
499
|
+
Video: __pow(2, 32),
|
|
500
|
+
/// Mute other members with lower ranking in a voice call
|
|
501
|
+
MuteMembers: __pow(2, 33),
|
|
502
|
+
/// Deafen other members with lower ranking in a voice call
|
|
503
|
+
DeafenMembers: __pow(2, 34),
|
|
504
|
+
/// Move members between voice channels
|
|
505
|
+
MoveMembers: __pow(2, 35),
|
|
506
|
+
// * Mention permissions
|
|
507
|
+
/// Mention @everyone or @online
|
|
508
|
+
MentionEveryone: __pow(2, 37),
|
|
509
|
+
/// Mention a role
|
|
510
|
+
MentionRoles: __pow(2, 38),
|
|
511
|
+
// * Grant all permissions
|
|
512
|
+
/// Safely grant all permissions
|
|
513
|
+
GrantAll: 4503599627370495
|
|
514
|
+
};
|
|
515
|
+
var DEFAULT_PERMISSION_DM = new ChannelPermissions([
|
|
516
|
+
"VIEW_CHANNEL",
|
|
517
|
+
"VIEW_CHANNEL",
|
|
518
|
+
"MANAGE_CHANNEL",
|
|
519
|
+
"VOICE_CALL",
|
|
520
|
+
"EMBED_LINKS",
|
|
521
|
+
"UPLOAD_FILES"
|
|
522
|
+
]).freeze();
|
|
523
|
+
|
|
524
|
+
// src/utils/badges.ts
|
|
525
|
+
var Badges = class extends BitField {
|
|
526
|
+
constructor(bits) {
|
|
527
|
+
super(bits);
|
|
528
|
+
}
|
|
529
|
+
static resolve(bit) {
|
|
530
|
+
return super.resolve(bit);
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
Badges.FLAGS = {
|
|
534
|
+
DEVELOPER: 1 << 0,
|
|
535
|
+
TRANSLATOR: 1 << 1,
|
|
536
|
+
SUPPORTER: 1 << 2,
|
|
537
|
+
RESPONSIBLE_DISCLOSURE: 1 << 3,
|
|
538
|
+
REVOLT_TEAM: 1 << 4,
|
|
539
|
+
EARLY_ADOPTER: 1 << 8
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
// src/struct/user.ts
|
|
543
|
+
var User = class extends Base {
|
|
544
|
+
/**
|
|
545
|
+
* Creates a new User instance.
|
|
546
|
+
*
|
|
547
|
+
* @param {client} client - The client instance.
|
|
548
|
+
* @param {APIUser} data - The raw data for the user from the API.
|
|
549
|
+
*/
|
|
550
|
+
constructor(client3, data) {
|
|
551
|
+
super(client3);
|
|
552
|
+
/** The avatar of the user, or `null` if none is set. */
|
|
553
|
+
this.avatar = null;
|
|
554
|
+
/** The presence status of the user. */
|
|
555
|
+
this.presence = new Presence(this.client);
|
|
556
|
+
/** Whether the user is a bot. */
|
|
557
|
+
this.bot = false;
|
|
558
|
+
this._patch(data);
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Updates the user instance with new data from the API.
|
|
562
|
+
*
|
|
563
|
+
* @param {APIUser} data - The raw data for the user from the API.
|
|
564
|
+
* @param {FieldsUser[]} [clear=[]] - Fields to clear in the user.
|
|
565
|
+
* @returns {this} The updated user instance.
|
|
566
|
+
* @protected
|
|
567
|
+
*/
|
|
568
|
+
_patch(data, clear = []) {
|
|
569
|
+
var _a, _b;
|
|
570
|
+
super._patch(data);
|
|
571
|
+
if (data.username) {
|
|
572
|
+
this.username = data.username;
|
|
573
|
+
}
|
|
574
|
+
if (data.bot) {
|
|
575
|
+
this.bot = true;
|
|
576
|
+
}
|
|
577
|
+
if (typeof data.badges === "number") {
|
|
578
|
+
this.badges = new Badges(data.badges).freeze();
|
|
579
|
+
}
|
|
580
|
+
if (data.avatar) {
|
|
581
|
+
this.avatar = new Attachment(this.client, data.avatar);
|
|
582
|
+
}
|
|
583
|
+
if (data.status) {
|
|
584
|
+
this.presence.status = data.status.presence ? (_a = Status[data.status.presence]) != null ? _a : "OFFLINE" /* Invisible */ : "OFFLINE" /* Invisible */;
|
|
585
|
+
this.presence.text = (_b = data.status.text) != null ? _b : null;
|
|
586
|
+
}
|
|
587
|
+
for (const field of clear) {
|
|
588
|
+
if (field === "Avatar") this.avatar = null;
|
|
589
|
+
if (field === "StatusText") this.presence.text = null;
|
|
590
|
+
if (field === "StatusPresence") this.presence.status = "OFFLINE" /* Invisible */;
|
|
591
|
+
}
|
|
592
|
+
return this;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Gets the creation date of the user.
|
|
596
|
+
*
|
|
597
|
+
* @returns {Date} The date when the user was created.
|
|
598
|
+
*/
|
|
599
|
+
get createdAt() {
|
|
600
|
+
return UUID.timestampOf(this.id);
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Gets the creation timestamp of the user in milliseconds.
|
|
604
|
+
*
|
|
605
|
+
* @returns {number} The timestamp of when the user was created.
|
|
606
|
+
*/
|
|
607
|
+
get createdTimestamp() {
|
|
608
|
+
return this.createdAt.getTime();
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Blocks the user.
|
|
612
|
+
*
|
|
613
|
+
* @returns {Promise<void>} A promise that resolves when the user is blocked.
|
|
614
|
+
*
|
|
615
|
+
* @example
|
|
616
|
+
* ```typescript
|
|
617
|
+
* await user.block();
|
|
618
|
+
* ```
|
|
619
|
+
*/
|
|
620
|
+
block() {
|
|
621
|
+
return __async(this, null, function* () {
|
|
622
|
+
yield this.client.api.put(`/users/${this.id}/block`);
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Unblocks the user.
|
|
627
|
+
*
|
|
628
|
+
* @returns {Promise<void>} A promise that resolves when the user is unblocked.
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* ```typescript
|
|
632
|
+
* await user.unblock();
|
|
633
|
+
* ```
|
|
634
|
+
*/
|
|
635
|
+
unblock() {
|
|
636
|
+
return __async(this, null, function* () {
|
|
637
|
+
yield this.client.api.delete(`/users/${this.id}/block`);
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Creates a direct message (DM) channel with the user.
|
|
642
|
+
*
|
|
643
|
+
* @returns {Promise<DMChannel>} A promise that resolves with the created DM channel.
|
|
644
|
+
*
|
|
645
|
+
* @example
|
|
646
|
+
* ```typescript
|
|
647
|
+
* const dmChannel = await user.createDM();
|
|
648
|
+
* ```
|
|
649
|
+
*/
|
|
650
|
+
createDM() {
|
|
651
|
+
return __async(this, null, function* () {
|
|
652
|
+
const data = yield this.client.api.get(`/users/${this.id}/dm`);
|
|
653
|
+
return this.client.channels._add(data);
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
avatarURL() {
|
|
657
|
+
var _a, _b;
|
|
658
|
+
if (!((_a = this.avatar) == null ? void 0 : _a.id)) return void 0;
|
|
659
|
+
return `${cdnUrl}/avatars/${(_b = this.avatar) == null ? void 0 : _b.id}`;
|
|
660
|
+
}
|
|
661
|
+
displayAvatarURL() {
|
|
662
|
+
return __async(this, null, function* () {
|
|
663
|
+
var _a;
|
|
664
|
+
const defaultAvatar = `${cdnUrl}/users/${this.id}/default_avatar`;
|
|
665
|
+
return (_a = this.avatarURL()) != null ? _a : defaultAvatar;
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Fetches the latest data for the user from the API.
|
|
670
|
+
*
|
|
671
|
+
* @param {boolean} [force=false] - Whether to force a fetch even if the user is cached.
|
|
672
|
+
* @returns {Promise<User>} A promise that resolves with the updated user instance.
|
|
673
|
+
*/
|
|
674
|
+
fetch(force = false) {
|
|
675
|
+
return this.client.users.fetch(this, { force });
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Converts the user to a string representation.
|
|
679
|
+
*
|
|
680
|
+
* @returns {string} A string representation of the user in the format `<@userId>`.
|
|
681
|
+
*/
|
|
682
|
+
toString() {
|
|
683
|
+
return `<@${this.id}>`;
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
// src/struct/message.ts
|
|
688
|
+
var Message = class extends Base {
|
|
689
|
+
/**
|
|
690
|
+
* Creates a new Message instance.
|
|
691
|
+
*
|
|
692
|
+
* @param {client} client - The client instance.
|
|
693
|
+
* @param {APIMessage} data - The raw data for the message from the API.
|
|
694
|
+
*/
|
|
695
|
+
constructor(client3, data) {
|
|
696
|
+
super(client3);
|
|
697
|
+
/** The type of the message (e.g., TEXT, SYSTEM). */
|
|
698
|
+
this.type = "TEXT";
|
|
699
|
+
/** The content of the message. */
|
|
700
|
+
this.content = "";
|
|
701
|
+
/** The ID of the channel where the message was sent. */
|
|
702
|
+
this.channelId = "";
|
|
703
|
+
/** The ID of the user who authored the message. */
|
|
704
|
+
this.authorId = "";
|
|
705
|
+
/** An array of embeds included in the message. */
|
|
706
|
+
this.embeds = [];
|
|
707
|
+
/** An array of file attachments included in the message. */
|
|
708
|
+
this.attachments = [];
|
|
709
|
+
/** Mentions included in the message. */
|
|
710
|
+
this.mentions = new Mentions(this, []);
|
|
711
|
+
/** The timestamp of when the message was last edited, or `null` if not edited. */
|
|
712
|
+
this.editedTimestamp = null;
|
|
713
|
+
/** the reactions and count on a message */
|
|
714
|
+
this.reactions = /* @__PURE__ */ new Map();
|
|
715
|
+
this._patch(data);
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Updates the message instance with new data from the API.
|
|
719
|
+
*
|
|
720
|
+
* @param {APIMessage} data - The raw data for the message from the API.
|
|
721
|
+
* @returns {this} The updated message instance.
|
|
722
|
+
* @protected
|
|
723
|
+
*/
|
|
724
|
+
_patch(data) {
|
|
725
|
+
super._patch(data);
|
|
726
|
+
if (Array.isArray(data.embeds)) {
|
|
727
|
+
this.embeds = data.embeds;
|
|
728
|
+
}
|
|
729
|
+
if (Array.isArray(data.attachments)) {
|
|
730
|
+
this.attachments = data.attachments;
|
|
731
|
+
}
|
|
732
|
+
if (Array.isArray(data.mentions)) {
|
|
733
|
+
this.mentions = new Mentions(this, data.mentions);
|
|
734
|
+
}
|
|
735
|
+
if (data.author) {
|
|
736
|
+
this.authorId = data.author;
|
|
737
|
+
}
|
|
738
|
+
if (data.channel) {
|
|
739
|
+
this.channelId = data.channel;
|
|
740
|
+
}
|
|
741
|
+
if (typeof data.content === "string") {
|
|
742
|
+
this.content = data.content;
|
|
743
|
+
}
|
|
744
|
+
if (data.system) {
|
|
745
|
+
this.type = data.system.type.toUpperCase();
|
|
746
|
+
}
|
|
747
|
+
if (data.edited) {
|
|
748
|
+
this.editedTimestamp = Date.parse(data.edited);
|
|
749
|
+
}
|
|
750
|
+
return this;
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Gets the creation date of the message.
|
|
754
|
+
*
|
|
755
|
+
* @returns {Date} The date when the message was created.
|
|
756
|
+
*/
|
|
757
|
+
get createdAt() {
|
|
758
|
+
return UUID.timestampOf(this.id);
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Gets the creation timestamp of the message in milliseconds.
|
|
762
|
+
*
|
|
763
|
+
* @returns {number} The timestamp of when the message was created.
|
|
764
|
+
*/
|
|
765
|
+
get createdTimestamp() {
|
|
766
|
+
return this.createdAt.getTime();
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Gets the date when the message was last edited.
|
|
770
|
+
*
|
|
771
|
+
* @returns {Date | null} The date of the last edit, or `null` if not edited.
|
|
772
|
+
*/
|
|
773
|
+
get editedAt() {
|
|
774
|
+
return this.editedTimestamp ? new Date(this.editedTimestamp) : null;
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Checks if the message is a system message.
|
|
778
|
+
*
|
|
779
|
+
* @returns {boolean} `true` if the message is a system message, otherwise `false`.
|
|
780
|
+
*/
|
|
781
|
+
get system() {
|
|
782
|
+
return this.type !== "TEXT";
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Retrieves the author of the message.
|
|
786
|
+
*
|
|
787
|
+
* @returns {User | null} The user who authored the message, or `null` if not found.
|
|
788
|
+
*/
|
|
789
|
+
get author() {
|
|
790
|
+
var _a;
|
|
791
|
+
return (_a = this.client.users.cache.get(this.authorId)) != null ? _a : null;
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Retrieves the channel where the message was sent.
|
|
795
|
+
*
|
|
796
|
+
* @returns {TextChannel | DMChannel | GroupChannel} The channel instance.
|
|
797
|
+
*/
|
|
798
|
+
get channel() {
|
|
799
|
+
return this.client.channels.cache.get(this.channelId);
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Retrieves the server ID associated with the message, if any.
|
|
803
|
+
*
|
|
804
|
+
* @returns {string | null} The server ID, or `null` if the message is not in a server.
|
|
805
|
+
*/
|
|
806
|
+
get serverId() {
|
|
807
|
+
const channel = this.channel;
|
|
808
|
+
return channel.inServer() ? channel.serverId : null;
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Retrieves the server associated with the message, if any.
|
|
812
|
+
*
|
|
813
|
+
* @returns {Server | null} The server instance, or `null` if not found.
|
|
814
|
+
*/
|
|
815
|
+
get server() {
|
|
816
|
+
var _a;
|
|
817
|
+
return (_a = this.client.servers.cache.get(this.serverId)) != null ? _a : null;
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* Retrieves the server member who authored the message, if any.
|
|
821
|
+
*
|
|
822
|
+
* @returns {ServerMember | null} The server member instance, or `null` if not found.
|
|
823
|
+
*/
|
|
824
|
+
get member() {
|
|
825
|
+
var _a, _b;
|
|
826
|
+
return (_b = (_a = this.server) == null ? void 0 : _a.members.cache.get(this.authorId)) != null ? _b : null;
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Gets the URL of the message.
|
|
830
|
+
*
|
|
831
|
+
* @returns {string} The URL of the message.
|
|
832
|
+
*/
|
|
833
|
+
get url() {
|
|
834
|
+
return `https://app.revolt.chat/${this.serverId ? `server/${this.serverId}` : ""}/channel/${this.channelId}/${this.id}`;
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Acknowledges the message.
|
|
838
|
+
*
|
|
839
|
+
* @returns {Promise<void>} A promise that resolves when the message is acknowledged.
|
|
840
|
+
*/
|
|
841
|
+
ack() {
|
|
842
|
+
return this.channel.messages.ack(this);
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Deletes the message.
|
|
846
|
+
*
|
|
847
|
+
* @returns {Promise<void>} A promise that resolves when the message is deleted.
|
|
848
|
+
*/
|
|
849
|
+
delete() {
|
|
850
|
+
return this.channel.messages.delete(this);
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Replies to the message.
|
|
854
|
+
*
|
|
855
|
+
* @param {string} content - The content of the reply.
|
|
856
|
+
* @param {boolean} [mention=true] - Whether to mention the original message author.
|
|
857
|
+
* @returns {Promise<Message>} A promise that resolves with the sent reply message.
|
|
858
|
+
*/
|
|
859
|
+
reply(content, mention = true) {
|
|
860
|
+
return this.channel.messages.send(__spreadProps(__spreadValues({}, typeof content === "object" ? content : { content }), {
|
|
861
|
+
replies: [{ id: this.id, mention }]
|
|
862
|
+
}));
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Edits the message.
|
|
866
|
+
*
|
|
867
|
+
* @param {MessageEditOptions | string} options - The new content or edit options.
|
|
868
|
+
* @returns {Promise<void>} A promise that resolves when the message is edited.
|
|
869
|
+
*/
|
|
870
|
+
edit(options) {
|
|
871
|
+
return this.channel.messages.edit(this, options);
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* Fetches the latest data for the message.
|
|
875
|
+
*
|
|
876
|
+
* @returns {Promise<Message>} A promise that resolves with the updated message instance.
|
|
877
|
+
*/
|
|
878
|
+
fetch() {
|
|
879
|
+
return this.channel.messages.fetch(this.id);
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Adds a reaction to the message.
|
|
883
|
+
*
|
|
884
|
+
* @param {string} emoji - The emoji to react with.
|
|
885
|
+
* @returns {Promise<void>} A promise that resolves when the reaction is added.
|
|
886
|
+
*/
|
|
887
|
+
addReaction(emoji) {
|
|
888
|
+
return this.channel.messages.addReaction(this, emoji);
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Removes a reaction from the message.
|
|
892
|
+
*
|
|
893
|
+
* @param {string} emoji - The emoji to remove the reaction for.
|
|
894
|
+
* @param {object} [options] - Options for removing the reaction.
|
|
895
|
+
* @param {string} [options.user_id] - The user ID to remove the reaction for. If not provided, removes the reaction for the current user.
|
|
896
|
+
* @param {boolean} [options.remove_all=false] - Whether to remove all of the specified reaction for the message.
|
|
897
|
+
* @returns {Promise<void>} A promise that resolves when the reaction is removed.
|
|
898
|
+
*/
|
|
899
|
+
removeReaction(emoji, options) {
|
|
900
|
+
var _a, _b;
|
|
901
|
+
return this.channel.messages.removeReaction(
|
|
902
|
+
this,
|
|
903
|
+
emoji,
|
|
904
|
+
(_a = options == null ? void 0 : options.user_id) != null ? _a : void 0,
|
|
905
|
+
(_b = options == null ? void 0 : options.remove_all) != null ? _b : false
|
|
906
|
+
);
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* Removes all reactions from the message.
|
|
910
|
+
*
|
|
911
|
+
* @returns {Promise<void>} A promise that resolves when all reactions are removed.
|
|
912
|
+
*/
|
|
913
|
+
removeAllReactions() {
|
|
914
|
+
return this.channel.messages.removeAllReactions(this);
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Checks if the message is in a server.
|
|
918
|
+
*
|
|
919
|
+
* @returns {boolean} `true` if the message is in a server, otherwise `false`.
|
|
920
|
+
*/
|
|
921
|
+
inServer() {
|
|
922
|
+
return this.channel.inServer();
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Converts the message to a string representation.
|
|
926
|
+
*
|
|
927
|
+
* @returns {string} The content of the message.
|
|
928
|
+
*/
|
|
929
|
+
toString() {
|
|
930
|
+
return this.content;
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
|
|
934
|
+
// src/struct/attachment.ts
|
|
935
|
+
var Attachment = class extends Base {
|
|
936
|
+
/**
|
|
937
|
+
* Creates a new Attachment instance.
|
|
938
|
+
*
|
|
939
|
+
* @param {client} client - The client instance.
|
|
940
|
+
* @param {File} data - The raw data for the attachment from the API.
|
|
941
|
+
*/
|
|
942
|
+
constructor(client3, data) {
|
|
943
|
+
super(client3);
|
|
944
|
+
this._patch(data);
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Updates the attachment instance with new data from the API.
|
|
948
|
+
*
|
|
949
|
+
* @param {File} data - The raw data for the attachment from the API.
|
|
950
|
+
* @returns {this} The updated attachment instance.
|
|
951
|
+
* @protected
|
|
952
|
+
*/
|
|
953
|
+
_patch(data) {
|
|
954
|
+
super._patch(data);
|
|
955
|
+
if (data.filename) this.filename = data.filename;
|
|
956
|
+
if (data.content_type) this.type = data.content_type;
|
|
957
|
+
if (typeof data.size === "number") this.size = data.size;
|
|
958
|
+
if (data.metadata) this.metadata = data.metadata;
|
|
959
|
+
return this;
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
|
|
963
|
+
// src/struct/presence.ts
|
|
964
|
+
var Status = /* @__PURE__ */ ((Status3) => {
|
|
965
|
+
Status3["Online"] = "ONLINE";
|
|
966
|
+
Status3["Idle"] = "IDLE";
|
|
967
|
+
Status3["Busy"] = "DND";
|
|
968
|
+
Status3["Invisible"] = "OFFLINE";
|
|
969
|
+
return Status3;
|
|
970
|
+
})(Status || {});
|
|
971
|
+
var Presence = class extends Base {
|
|
972
|
+
constructor() {
|
|
973
|
+
super(...arguments);
|
|
974
|
+
/** The custom status text of the user, or `null` if none is set. */
|
|
975
|
+
this.text = null;
|
|
976
|
+
/** The current status of the user (e.g., Online, Idle, Busy, Invisible). */
|
|
977
|
+
this.status = "OFFLINE" /* Invisible */;
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
// src/struct/server.ts
|
|
982
|
+
var Server2 = class extends Base {
|
|
983
|
+
/**
|
|
984
|
+
* Creates a new Server instance.
|
|
985
|
+
*
|
|
986
|
+
* @param {client} client - The client instance.
|
|
987
|
+
* @param {APIServer} data - The raw data for the server from the API.
|
|
988
|
+
*/
|
|
989
|
+
constructor(client3, data) {
|
|
990
|
+
super(client3);
|
|
991
|
+
/** The description of the server, or `null` if none is set. */
|
|
992
|
+
this.description = null;
|
|
993
|
+
/** Manages the members of the server. */
|
|
994
|
+
this.members = new ServerMemberManager(this);
|
|
995
|
+
/** Manages the channels of the server. */
|
|
996
|
+
this.channels = new ServerChannelManager(this);
|
|
997
|
+
/** Manages the roles of the server. */
|
|
998
|
+
this.roles = new RoleManager(this);
|
|
999
|
+
/** The icon of the server, or `null` if none is set. */
|
|
1000
|
+
this.icon = null;
|
|
1001
|
+
/** The banner of the server, or `null` if none is set. */
|
|
1002
|
+
this.banner = null;
|
|
1003
|
+
/** Whether analytics are enabled for the server. */
|
|
1004
|
+
this.analytics = false;
|
|
1005
|
+
/** Whether the server is discoverable. */
|
|
1006
|
+
this.discoverable = false;
|
|
1007
|
+
/** Whether the server is marked as NSFW (Not Safe For Work). */
|
|
1008
|
+
this.nsfw = false;
|
|
1009
|
+
/** The categories in the server. */
|
|
1010
|
+
this.categories = /* @__PURE__ */ new Map();
|
|
1011
|
+
/** the emojies associated with the server */
|
|
1012
|
+
this.emojis = /* @__PURE__ */ new Map();
|
|
1013
|
+
this._patch(data);
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Updates the server instance with new data from the API.
|
|
1017
|
+
*
|
|
1018
|
+
* @param {APIServer} data - The raw data for the server from the API.
|
|
1019
|
+
* @param {FieldsServer[]} [clear=[]] - Fields to clear in the server.
|
|
1020
|
+
* @returns {this} The updated server instance.
|
|
1021
|
+
* @protected
|
|
1022
|
+
*/
|
|
1023
|
+
_patch(data, clear = []) {
|
|
1024
|
+
var _a;
|
|
1025
|
+
super._patch(data);
|
|
1026
|
+
if (Array.isArray(data.categories)) {
|
|
1027
|
+
this.categories.clear();
|
|
1028
|
+
for (const cat of data.categories) {
|
|
1029
|
+
const category = new Category(this, cat);
|
|
1030
|
+
this.categories.set(category.id, category);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
if (data.icon) {
|
|
1034
|
+
this.icon = new Attachment(this.client, data.icon);
|
|
1035
|
+
}
|
|
1036
|
+
if (data.banner) {
|
|
1037
|
+
this.banner = new Attachment(this.client, data.banner);
|
|
1038
|
+
}
|
|
1039
|
+
if (data.owner) {
|
|
1040
|
+
this.ownerId = data.owner;
|
|
1041
|
+
}
|
|
1042
|
+
if (data.name) {
|
|
1043
|
+
this.name = data.name;
|
|
1044
|
+
}
|
|
1045
|
+
if ("description" in data) {
|
|
1046
|
+
this.description = (_a = data.description) != null ? _a : null;
|
|
1047
|
+
}
|
|
1048
|
+
if (Array.isArray(data.channels)) {
|
|
1049
|
+
for (const id of data.channels) {
|
|
1050
|
+
const channel = this.client.channels.cache.get(id);
|
|
1051
|
+
if (channel == null ? void 0 : channel.inServer()) this.channels.cache.set(channel.id, channel);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
if (typeof data.roles === "object") {
|
|
1055
|
+
for (const [id, raw] of Object.entries(data.roles)) {
|
|
1056
|
+
this.roles._add(Object.assign(raw, { id }));
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
if (typeof data.default_permissions === "number") {
|
|
1060
|
+
this.permissions = new FullPermissions(data.default_permissions).freeze();
|
|
1061
|
+
}
|
|
1062
|
+
if (typeof data.analytics === "boolean") this.analytics = data.analytics;
|
|
1063
|
+
if (typeof data.discoverable === "boolean") {
|
|
1064
|
+
this.discoverable = data.discoverable;
|
|
1065
|
+
}
|
|
1066
|
+
if (typeof data.nsfw === "boolean") this.nsfw = data.nsfw;
|
|
1067
|
+
for (const field of clear) {
|
|
1068
|
+
if (field === "Icon") this.icon = null;
|
|
1069
|
+
if (field === "Description") this.description = null;
|
|
1070
|
+
if (field === "Banner") this.banner = null;
|
|
1071
|
+
}
|
|
1072
|
+
return this;
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Retrieves the current user's member instance in the server.
|
|
1076
|
+
*
|
|
1077
|
+
* @returns {ServerMember | null} The current user's member instance, or `null` if not found.
|
|
1078
|
+
*/
|
|
1079
|
+
get me() {
|
|
1080
|
+
var _a, _b;
|
|
1081
|
+
return (_b = this.members.cache.get((_a = this.client.user) == null ? void 0 : _a.id)) != null ? _b : null;
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Gets the creation date of the server.
|
|
1085
|
+
*
|
|
1086
|
+
* @returns {Date} The date when the server was created.
|
|
1087
|
+
*/
|
|
1088
|
+
get createdAt() {
|
|
1089
|
+
return UUID.timestampOf(this.id);
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Gets the creation timestamp of the server in milliseconds.
|
|
1093
|
+
*
|
|
1094
|
+
* @returns {number} The timestamp of when the server was created.
|
|
1095
|
+
*/
|
|
1096
|
+
get createdTimestamp() {
|
|
1097
|
+
return this.createdAt.getTime();
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Retrieves the owner of the server.
|
|
1101
|
+
*
|
|
1102
|
+
* @returns {User | null} The owner of the server, or `null` if not found.
|
|
1103
|
+
*/
|
|
1104
|
+
get owner() {
|
|
1105
|
+
var _a;
|
|
1106
|
+
return (_a = this.client.users.cache.get(this.ownerId)) != null ? _a : null;
|
|
1107
|
+
}
|
|
1108
|
+
// iconURL(options?: { size: number }): string | null {
|
|
1109
|
+
// return this.icon
|
|
1110
|
+
// ? this.client.api.cdn.icon(this.icon.id, options?.size)
|
|
1111
|
+
// : null;
|
|
1112
|
+
// }
|
|
1113
|
+
// bannerURL(options?: { size: number }): string | null {
|
|
1114
|
+
// return this.banner
|
|
1115
|
+
// ? this.client.api.cdn.banner(this.banner.id, options?.size)
|
|
1116
|
+
// : null;
|
|
1117
|
+
// }
|
|
1118
|
+
/**
|
|
1119
|
+
* Converts the server to a string representation.
|
|
1120
|
+
*
|
|
1121
|
+
* @returns {string} The name of the server.
|
|
1122
|
+
*/
|
|
1123
|
+
toString() {
|
|
1124
|
+
return this.name;
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
// src/struct/role.ts
|
|
1129
|
+
var Role = class extends Base {
|
|
1130
|
+
/**
|
|
1131
|
+
* Creates a new Role instance.
|
|
1132
|
+
*
|
|
1133
|
+
* @param {Server} server - The server this role belongs to.
|
|
1134
|
+
* @param {APIRole & { id: string }} data - The raw data for the role from the API.
|
|
1135
|
+
*/
|
|
1136
|
+
constructor(server, data) {
|
|
1137
|
+
super(server.client);
|
|
1138
|
+
this.server = server;
|
|
1139
|
+
/** The color of the role, or `null` if no color is set. */
|
|
1140
|
+
this.color = null;
|
|
1141
|
+
/** Whether the role is displayed separately in the member list. */
|
|
1142
|
+
this.hoist = false;
|
|
1143
|
+
this._patch(data);
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* Updates the role instance with new data from the API.
|
|
1147
|
+
*
|
|
1148
|
+
* @param {APIRole & { _id?: string }} data - The raw data for the role from the API.
|
|
1149
|
+
* @param {FieldsRole[]} [clear=[]] - Fields to clear in the role.
|
|
1150
|
+
* @returns {this} The updated role instance.
|
|
1151
|
+
* @protected
|
|
1152
|
+
*/
|
|
1153
|
+
_patch(data, clear = []) {
|
|
1154
|
+
var _a;
|
|
1155
|
+
super._patch(data);
|
|
1156
|
+
if (data.name) this.name = data.name;
|
|
1157
|
+
if (typeof data.hoist === "boolean") this.hoist = data.hoist;
|
|
1158
|
+
if (typeof data.rank === "number") this.rank = data.rank;
|
|
1159
|
+
if ("colour" in data) this.color = (_a = data.colour) != null ? _a : null;
|
|
1160
|
+
if (data.permissions) {
|
|
1161
|
+
const { a, d } = data.permissions;
|
|
1162
|
+
this.overwrite = {
|
|
1163
|
+
allow: new FullPermissions(a),
|
|
1164
|
+
deny: new FullPermissions(d)
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
for (const field of clear) {
|
|
1168
|
+
if (field === "Colour") this.color = null;
|
|
1169
|
+
}
|
|
1170
|
+
return this;
|
|
1171
|
+
}
|
|
1172
|
+
/**
|
|
1173
|
+
* Gets the date when the role was created.
|
|
1174
|
+
*
|
|
1175
|
+
* @returns {Date} The creation date of the role.
|
|
1176
|
+
*/
|
|
1177
|
+
get createdAt() {
|
|
1178
|
+
return UUID.timestampOf(this.id);
|
|
1179
|
+
}
|
|
1180
|
+
/**
|
|
1181
|
+
* Gets the timestamp of when the role was created.
|
|
1182
|
+
*
|
|
1183
|
+
* @returns {number} The creation timestamp of the role in milliseconds.
|
|
1184
|
+
*/
|
|
1185
|
+
get createdTimestamp() {
|
|
1186
|
+
return this.createdAt.getTime();
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Gets the permissions overwrite for the role.
|
|
1190
|
+
*
|
|
1191
|
+
* @returns {Overwrite} The permissions overwrite for the role.
|
|
1192
|
+
*/
|
|
1193
|
+
get permissions() {
|
|
1194
|
+
return this.overwrite;
|
|
1195
|
+
}
|
|
1196
|
+
/**
|
|
1197
|
+
* Deletes the role from the server.
|
|
1198
|
+
*
|
|
1199
|
+
* @returns {Promise<void>} A promise that resolves when the role is deleted.
|
|
1200
|
+
*
|
|
1201
|
+
* @example
|
|
1202
|
+
* ```typescript
|
|
1203
|
+
* await role.delete();
|
|
1204
|
+
* console.log("Role deleted successfully.");
|
|
1205
|
+
* ```
|
|
1206
|
+
*/
|
|
1207
|
+
delete() {
|
|
1208
|
+
return this.server.roles.delete(this);
|
|
1209
|
+
}
|
|
1210
|
+
edit(data) {
|
|
1211
|
+
return this.server.roles.edit(this, data);
|
|
1212
|
+
}
|
|
1213
|
+
/**
|
|
1214
|
+
* Converts the role to a string representation.
|
|
1215
|
+
*
|
|
1216
|
+
* @returns {string} A string representation of the role in the format `<@&roleId>`.
|
|
1217
|
+
*/
|
|
1218
|
+
toString() {
|
|
1219
|
+
return `<@&${this.id}>`;
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1222
|
+
|
|
1223
|
+
// src/struct/channel.ts
|
|
1224
|
+
var Channel = class extends Base {
|
|
1225
|
+
constructor() {
|
|
1226
|
+
super(...arguments);
|
|
1227
|
+
this.type = "UNKNOWN";
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Gets the timestamp (in milliseconds) when the channel was created.
|
|
1231
|
+
*
|
|
1232
|
+
* @returns {number} The timestamp of the channel's creation.
|
|
1233
|
+
*/
|
|
1234
|
+
get createdTimestamp() {
|
|
1235
|
+
return this.createdAt.getTime();
|
|
1236
|
+
}
|
|
1237
|
+
/**
|
|
1238
|
+
* Gets the date and time when the channel was created.
|
|
1239
|
+
*
|
|
1240
|
+
* @returns {Date} The creation date of the channel.
|
|
1241
|
+
*/
|
|
1242
|
+
get createdAt() {
|
|
1243
|
+
return UUID.timestampOf(this.id);
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Deletes the current channel instance from the client's channel collection.
|
|
1247
|
+
*
|
|
1248
|
+
* This method interacts with the client's channel management system to remove
|
|
1249
|
+
* the channel. Once deleted, the channel will no longer be accessible through
|
|
1250
|
+
* the client.
|
|
1251
|
+
*
|
|
1252
|
+
* @returns {Promise<void>} A promise that resolves when the channel has been successfully deleted.
|
|
1253
|
+
*
|
|
1254
|
+
* @example
|
|
1255
|
+
* ```typescript
|
|
1256
|
+
* const channel = client.channels.get('1234567890');
|
|
1257
|
+
* if (channel) {
|
|
1258
|
+
* await channel.delete();
|
|
1259
|
+
* console.log('Channel deleted successfully.');
|
|
1260
|
+
* }
|
|
1261
|
+
* ```
|
|
1262
|
+
*/
|
|
1263
|
+
delete() {
|
|
1264
|
+
return this.client.channels.delete(this);
|
|
1265
|
+
}
|
|
1266
|
+
/**
|
|
1267
|
+
* Checks if the channel is a text-based channel.
|
|
1268
|
+
*
|
|
1269
|
+
* @returns {boolean} True if the channel is a text-based channel, otherwise false.
|
|
1270
|
+
*/
|
|
1271
|
+
isText() {
|
|
1272
|
+
return "messages" in this;
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* Checks if the channel is a voice channel.
|
|
1276
|
+
*
|
|
1277
|
+
* @returns {boolean} True if the channel is a voice channel, otherwise false.
|
|
1278
|
+
*/
|
|
1279
|
+
isVoice() {
|
|
1280
|
+
return this.type === "VOICE" /* VOICE */;
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Checks if the channel is a group channel.
|
|
1284
|
+
*
|
|
1285
|
+
* @returns {boolean} True if the channel is a group channel, otherwise false.
|
|
1286
|
+
*/
|
|
1287
|
+
isGroup() {
|
|
1288
|
+
return this.type === "GROUP" /* GROUP */;
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Checks if the channel is part of a server.
|
|
1292
|
+
*
|
|
1293
|
+
* @returns {boolean} True if the channel is a server channel, otherwise false.
|
|
1294
|
+
*/
|
|
1295
|
+
inServer() {
|
|
1296
|
+
return "serverId" in this;
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* Converts the channel to a string representation.
|
|
1300
|
+
*
|
|
1301
|
+
* @returns {string} A string representation of the channel in the format `<#channelId>`.
|
|
1302
|
+
*/
|
|
1303
|
+
toString() {
|
|
1304
|
+
return `<#${this.id}>`;
|
|
1305
|
+
}
|
|
1306
|
+
/**
|
|
1307
|
+
* Fetches the latest data for the channel from the client's channel collection.
|
|
1308
|
+
*
|
|
1309
|
+
* @param {boolean} [force=true] - Whether to force a fetch even if the channel is cached.
|
|
1310
|
+
* @returns {Promise<Channel>} A promise that resolves with the updated channel instance.
|
|
1311
|
+
*/
|
|
1312
|
+
fetch(force = true) {
|
|
1313
|
+
return this.client.channels.fetch(this, { force });
|
|
1314
|
+
}
|
|
1315
|
+
};
|
|
1316
|
+
|
|
1317
|
+
// src/struct/dmChannel.ts
|
|
1318
|
+
var DMChannel3 = class extends Channel {
|
|
1319
|
+
/**
|
|
1320
|
+
* Creates a new DMChannel instance.
|
|
1321
|
+
*
|
|
1322
|
+
* @param {client} client - The client instance.
|
|
1323
|
+
* @param {APIDirectChannel} data - The raw data for the DM channel from the API.
|
|
1324
|
+
*/
|
|
1325
|
+
constructor(client3, data) {
|
|
1326
|
+
super(client3);
|
|
1327
|
+
/** The type of the channel, which is always `DM` for direct message channels. */
|
|
1328
|
+
this.type = "DM" /* DM */;
|
|
1329
|
+
/** The default permissions for the DM channel. */
|
|
1330
|
+
this.permissions = DEFAULT_PERMISSION_DM;
|
|
1331
|
+
/** Manages the messages in this DM channel. */
|
|
1332
|
+
this.messages = new MessageManager(this);
|
|
1333
|
+
/** The ID of the last message sent in this DM channel, if any. */
|
|
1334
|
+
this.lastMessageId = null;
|
|
1335
|
+
this._patch(data);
|
|
1336
|
+
}
|
|
1337
|
+
/**
|
|
1338
|
+
* Updates the DM channel instance with new data from the API.
|
|
1339
|
+
*
|
|
1340
|
+
* @param {APIDirectChannel} data - The raw data for the DM channel from the API.
|
|
1341
|
+
* @returns {this} The updated DM channel instance.
|
|
1342
|
+
* @protected
|
|
1343
|
+
*/
|
|
1344
|
+
_patch(data) {
|
|
1345
|
+
super._patch(data);
|
|
1346
|
+
if (typeof data.active === "boolean") this.active = data.active;
|
|
1347
|
+
if (data.last_message_id) this.lastMessageId = data.last_message_id;
|
|
1348
|
+
return this;
|
|
1349
|
+
}
|
|
1350
|
+
/**
|
|
1351
|
+
* Retrieves the last message sent in this DM channel.
|
|
1352
|
+
*
|
|
1353
|
+
* @returns {Message | null} The last message, or `null` if no message exists.
|
|
1354
|
+
*/
|
|
1355
|
+
get lastMessage() {
|
|
1356
|
+
var _a;
|
|
1357
|
+
if (!this.lastMessageId) return null;
|
|
1358
|
+
return (_a = this.messages.cache.get(this.lastMessageId)) != null ? _a : null;
|
|
1359
|
+
}
|
|
1360
|
+
/**
|
|
1361
|
+
* Deletes multiple messages from this DM channel.
|
|
1362
|
+
*
|
|
1363
|
+
* @param {MessageResolvable[] | Map<string, Message> | number} messages - The messages to delete. This can be an array of message resolvables, a map of messages, or a number indicating how many recent messages to delete.
|
|
1364
|
+
* @returns {Promise<void>} A promise that resolves when the messages have been successfully deleted.
|
|
1365
|
+
*
|
|
1366
|
+
* @example
|
|
1367
|
+
* ```typescript
|
|
1368
|
+
* await dmChannel.bulkDelete(10); // Deletes the last 10 messages.
|
|
1369
|
+
* ```
|
|
1370
|
+
*/
|
|
1371
|
+
bulkDelete(messages) {
|
|
1372
|
+
return this.messages.bulkDelete(messages);
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Sends a message to this DM channel.
|
|
1376
|
+
*
|
|
1377
|
+
* @param {MessageOptions | string} options - The message content or options for the message.
|
|
1378
|
+
* @returns {Promise<Message>} A promise that resolves with the sent message.
|
|
1379
|
+
*
|
|
1380
|
+
* @example
|
|
1381
|
+
* ```typescript
|
|
1382
|
+
* await dmChannel.send("Hello, world!");
|
|
1383
|
+
* ```
|
|
1384
|
+
*/
|
|
1385
|
+
send(options) {
|
|
1386
|
+
return this.messages.send(options);
|
|
1387
|
+
}
|
|
1388
|
+
};
|
|
1389
|
+
|
|
1390
|
+
// src/struct/groupChannel.ts
|
|
1391
|
+
var GroupChannel2 = class extends Channel {
|
|
1392
|
+
/**
|
|
1393
|
+
* Creates a new GroupChannel instance.
|
|
1394
|
+
*
|
|
1395
|
+
* @param {client} client - The client instance.
|
|
1396
|
+
* @param {APIGroupChannel} data - The raw data for the group channel from the API.
|
|
1397
|
+
*/
|
|
1398
|
+
constructor(client3, data) {
|
|
1399
|
+
super(client3);
|
|
1400
|
+
/** The type of the channel, which is always `GROUP` for group channels. */
|
|
1401
|
+
this.type = "GROUP" /* GROUP */;
|
|
1402
|
+
/** The description of the group channel, if any. */
|
|
1403
|
+
this.description = null;
|
|
1404
|
+
/** The icon of the group channel, if any. */
|
|
1405
|
+
this.icon = null;
|
|
1406
|
+
/** Manages the messages in this group channel. */
|
|
1407
|
+
this.messages = new MessageManager(this);
|
|
1408
|
+
/** The ID of the last message sent in this group channel, if any. */
|
|
1409
|
+
this.lastMessageId = null;
|
|
1410
|
+
/** A map of user IDs to their corresponding `User` instances in the group channel. */
|
|
1411
|
+
this.users = /* @__PURE__ */ new Map();
|
|
1412
|
+
/** Whether the group channel is marked as NSFW (Not Safe For Work). */
|
|
1413
|
+
this.nsfw = false;
|
|
1414
|
+
this._patch(data);
|
|
1415
|
+
}
|
|
1416
|
+
/**
|
|
1417
|
+
* Updates the group channel instance with new data from the API.
|
|
1418
|
+
*
|
|
1419
|
+
* @param {APIGroupChannel} data - The raw data for the group channel from the API.
|
|
1420
|
+
* @returns {this} The updated group channel instance.
|
|
1421
|
+
* @protected
|
|
1422
|
+
*/
|
|
1423
|
+
_patch(data) {
|
|
1424
|
+
var _a;
|
|
1425
|
+
super._patch(data);
|
|
1426
|
+
if ("description" in data) {
|
|
1427
|
+
this.description = (_a = data.description) != null ? _a : null;
|
|
1428
|
+
}
|
|
1429
|
+
if (Array.isArray(data.recipients)) {
|
|
1430
|
+
this.users.clear();
|
|
1431
|
+
for (const userId of data.recipients) {
|
|
1432
|
+
const user = this.client.users.cache.get(userId);
|
|
1433
|
+
if (user) this.users.set(user.id, user);
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
if (typeof data.permissions === "number") {
|
|
1437
|
+
this.permissions = new ChannelPermissions(data.permissions).freeze();
|
|
1438
|
+
}
|
|
1439
|
+
if (data.owner) {
|
|
1440
|
+
this.ownerId = data.owner;
|
|
1441
|
+
}
|
|
1442
|
+
if (data.icon) {
|
|
1443
|
+
this.icon = new Attachment(this.client, data.icon);
|
|
1444
|
+
}
|
|
1445
|
+
if (data.name) {
|
|
1446
|
+
this.name = data.name;
|
|
1447
|
+
}
|
|
1448
|
+
if (data.last_message_id) this.lastMessageId = data.last_message_id;
|
|
1449
|
+
if (typeof data.nsfw === "boolean") this.nsfw = data.nsfw;
|
|
1450
|
+
return this;
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* Retrieves the last message sent in this group channel.
|
|
1454
|
+
*
|
|
1455
|
+
* @returns {Message | null} The last message, or `null` if no message exists.
|
|
1456
|
+
*/
|
|
1457
|
+
get lastMessage() {
|
|
1458
|
+
var _a;
|
|
1459
|
+
if (!this.lastMessageId) return null;
|
|
1460
|
+
return (_a = this.messages.cache.get(this.lastMessageId)) != null ? _a : null;
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
* Retrieves the owner of the group channel.
|
|
1464
|
+
*
|
|
1465
|
+
* @returns {User | null} The owner of the group channel, or `null` if not found.
|
|
1466
|
+
*/
|
|
1467
|
+
get owner() {
|
|
1468
|
+
var _a;
|
|
1469
|
+
return (_a = this.client.users.cache.get(this.ownerId)) != null ? _a : null;
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Deletes multiple messages from this group channel.
|
|
1473
|
+
*
|
|
1474
|
+
* @param {MessageResolvable[] | Map<string, Message> | number} messages - The messages to delete. This can be an array of message resolvables, a map of messages, or a number indicating how many recent messages to delete.
|
|
1475
|
+
* @returns {Promise<void>} A promise that resolves when the messages have been successfully deleted.
|
|
1476
|
+
*
|
|
1477
|
+
* @example
|
|
1478
|
+
* ```typescript
|
|
1479
|
+
* await groupChannel.bulkDelete(10); // Deletes the last 10 messages.
|
|
1480
|
+
* ```
|
|
1481
|
+
*/
|
|
1482
|
+
bulkDelete(messages) {
|
|
1483
|
+
return this.messages.bulkDelete(messages);
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Creates an invite for the group channel.
|
|
1487
|
+
*
|
|
1488
|
+
* @returns {Promise<Invite>} A promise that resolves with the created invite.
|
|
1489
|
+
*
|
|
1490
|
+
* @example
|
|
1491
|
+
* ```typescript
|
|
1492
|
+
* const invite = await groupChannel.createInvite();
|
|
1493
|
+
* console.log(`Invite created: ${invite}`);
|
|
1494
|
+
* ```
|
|
1495
|
+
*/
|
|
1496
|
+
createInvite() {
|
|
1497
|
+
return __async(this, null, function* () {
|
|
1498
|
+
const data = yield this.client.api.post(`/channels/${this.id}/invites`, {});
|
|
1499
|
+
return new Invite(
|
|
1500
|
+
this.client,
|
|
1501
|
+
data
|
|
1502
|
+
);
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
/**
|
|
1506
|
+
* Adds a user to the group channel.
|
|
1507
|
+
*
|
|
1508
|
+
* @param {UserResolvable} user - The user to add to the group channel.
|
|
1509
|
+
* @returns {Promise<void>} A promise that resolves when the user has been successfully added.
|
|
1510
|
+
*
|
|
1511
|
+
* @example
|
|
1512
|
+
* ```typescript
|
|
1513
|
+
* await groupChannel.add(user);
|
|
1514
|
+
* ```
|
|
1515
|
+
*/
|
|
1516
|
+
add(user) {
|
|
1517
|
+
return __async(this, null, function* () {
|
|
1518
|
+
const id = this.client.users.resolveId(user);
|
|
1519
|
+
if (!id) throw new TypeError("INVALID_TYPE");
|
|
1520
|
+
yield this.client.api.put(`/channels/${this.id}/recipients/${id}`);
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Removes a user from the group channel.
|
|
1525
|
+
*
|
|
1526
|
+
* @param {UserResolvable} user - The user to remove from the group channel.
|
|
1527
|
+
* @returns {Promise<void>} A promise that resolves when the user has been successfully removed.
|
|
1528
|
+
*
|
|
1529
|
+
* @example
|
|
1530
|
+
* ```typescript
|
|
1531
|
+
* await groupChannel.remove(user);
|
|
1532
|
+
* ```
|
|
1533
|
+
*/
|
|
1534
|
+
remove(user) {
|
|
1535
|
+
return __async(this, null, function* () {
|
|
1536
|
+
const id = this.client.users.resolveId(user);
|
|
1537
|
+
if (!id) throw new TypeError("INVALID_TYPE");
|
|
1538
|
+
yield this.client.api.delete(`/channels/${this.id}/recipients/${id}`);
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
/**
|
|
1542
|
+
* Leaves the group channel.
|
|
1543
|
+
*
|
|
1544
|
+
* @returns {Promise<void>} A promise that resolves when the group channel has been successfully left.
|
|
1545
|
+
*
|
|
1546
|
+
* @example
|
|
1547
|
+
* ```typescript
|
|
1548
|
+
* await groupChannel.leave();
|
|
1549
|
+
* ```
|
|
1550
|
+
*/
|
|
1551
|
+
leave() {
|
|
1552
|
+
return super.delete();
|
|
1553
|
+
}
|
|
1554
|
+
/**
|
|
1555
|
+
* Sends a message to this group channel.
|
|
1556
|
+
*
|
|
1557
|
+
* @param {MessageOptions | string} options - The message content or options for the message.
|
|
1558
|
+
* @returns {Promise<Message>} A promise that resolves with the sent message.
|
|
1559
|
+
*
|
|
1560
|
+
* @example
|
|
1561
|
+
* ```typescript
|
|
1562
|
+
* await groupChannel.send("Hello, group!");
|
|
1563
|
+
* ```
|
|
1564
|
+
*/
|
|
1565
|
+
send(options) {
|
|
1566
|
+
return this.messages.send(options);
|
|
1567
|
+
}
|
|
1568
|
+
// iconURL(options?: { size: number }): string | null {
|
|
1569
|
+
// if (!this.icon) return null;
|
|
1570
|
+
// return this.client.api.cdn.icon(this.icon.id, options?.size);
|
|
1571
|
+
// }
|
|
1572
|
+
};
|
|
1573
|
+
|
|
1574
|
+
// src/struct/invite.ts
|
|
1575
|
+
var Invite = class extends Base {
|
|
1576
|
+
/**
|
|
1577
|
+
* Creates a new Invite instance.
|
|
1578
|
+
*
|
|
1579
|
+
* @param {client} client - The client instance.
|
|
1580
|
+
* @param {APIInvite} data - The raw data for the invite from the API.
|
|
1581
|
+
*/
|
|
1582
|
+
constructor(client3, data) {
|
|
1583
|
+
super(client3);
|
|
1584
|
+
/** The ID of the server associated with the invite, if any. */
|
|
1585
|
+
this.serverId = null;
|
|
1586
|
+
this._patch(data);
|
|
1587
|
+
}
|
|
1588
|
+
/**
|
|
1589
|
+
* Updates the invite instance with new data from the API.
|
|
1590
|
+
*
|
|
1591
|
+
* @param {APIInvite} data - The raw data for the invite from the API.
|
|
1592
|
+
* @returns {this} The updated invite instance.
|
|
1593
|
+
* @protected
|
|
1594
|
+
*/
|
|
1595
|
+
_patch(data) {
|
|
1596
|
+
super._patch(data);
|
|
1597
|
+
if (data.channel) this.channelId = data.channel;
|
|
1598
|
+
if (data.creator) this.inviterId = data.channel;
|
|
1599
|
+
return this;
|
|
1600
|
+
}
|
|
1601
|
+
/**
|
|
1602
|
+
* Retrieves the server associated with the invite.
|
|
1603
|
+
*
|
|
1604
|
+
* @returns {Server | null} The server associated with the invite, or `null` if not found.
|
|
1605
|
+
*/
|
|
1606
|
+
get server() {
|
|
1607
|
+
var _a;
|
|
1608
|
+
return (_a = this.client.servers.cache.get(this.serverId)) != null ? _a : null;
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1611
|
+
* Retrieves the channel associated with the invite.
|
|
1612
|
+
*
|
|
1613
|
+
* @returns {Channel | null} The channel associated with the invite, or `null` if not found.
|
|
1614
|
+
*/
|
|
1615
|
+
get channel() {
|
|
1616
|
+
var _a;
|
|
1617
|
+
return (_a = this.client.channels.cache.get(this.channelId)) != null ? _a : null;
|
|
1618
|
+
}
|
|
1619
|
+
/**
|
|
1620
|
+
* Retrieves the user who created the invite.
|
|
1621
|
+
*
|
|
1622
|
+
* @returns {User | null} The user who created the invite, or `null` if not found.
|
|
1623
|
+
*/
|
|
1624
|
+
get inviter() {
|
|
1625
|
+
var _a;
|
|
1626
|
+
return (_a = this.client.users.cache.get(this.inviterId)) != null ? _a : null;
|
|
1627
|
+
}
|
|
1628
|
+
// toString(): string {
|
|
1629
|
+
// return this.client.api.cdn.invite(this.id);
|
|
1630
|
+
// }
|
|
1631
|
+
};
|
|
1632
|
+
|
|
1633
|
+
// src/struct/mentions.ts
|
|
1634
|
+
var Mentions = class {
|
|
1635
|
+
/**
|
|
1636
|
+
* Creates a new Mentions instance.
|
|
1637
|
+
*
|
|
1638
|
+
* @param {Message} message - The message associated with the mentions.
|
|
1639
|
+
* @param {string[]} _users - An array of user IDs mentioned in the message.
|
|
1640
|
+
*/
|
|
1641
|
+
constructor(message, _users) {
|
|
1642
|
+
this.message = message;
|
|
1643
|
+
this._users = _users;
|
|
1644
|
+
this.client = message.client;
|
|
1645
|
+
}
|
|
1646
|
+
/**
|
|
1647
|
+
* Checks if a specific user is mentioned in the message.
|
|
1648
|
+
*
|
|
1649
|
+
* @param {UserResolvable} user - The user to check.
|
|
1650
|
+
* @returns {boolean} `true` if the user is mentioned, otherwise `false`.
|
|
1651
|
+
* @throws {TypeError} Throws an error if the user cannot be resolved.
|
|
1652
|
+
*
|
|
1653
|
+
* @example
|
|
1654
|
+
* ```typescript
|
|
1655
|
+
* if (mentions.has(someUser)) {
|
|
1656
|
+
* console.log("User is mentioned!");
|
|
1657
|
+
* }
|
|
1658
|
+
* ```
|
|
1659
|
+
*/
|
|
1660
|
+
has(user) {
|
|
1661
|
+
const id = this.client.users.resolveId(user);
|
|
1662
|
+
if (!id) throw new TypeError("INVALID_TYPE");
|
|
1663
|
+
return this._users.includes(id);
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Retrieves the server members mentioned in the message.
|
|
1667
|
+
*
|
|
1668
|
+
* @returns {Map<string, ServerMember> | null} A map of user IDs to `ServerMember` instances, or `null` if the message is not in a server.
|
|
1669
|
+
*
|
|
1670
|
+
* @example
|
|
1671
|
+
* ```typescript
|
|
1672
|
+
* const members = mentions.members;
|
|
1673
|
+
* if (members) {
|
|
1674
|
+
* members.forEach(member => console.log(member.displayName));
|
|
1675
|
+
* }
|
|
1676
|
+
* ```
|
|
1677
|
+
*/
|
|
1678
|
+
get members() {
|
|
1679
|
+
const server = this.message.server;
|
|
1680
|
+
if (!server) return null;
|
|
1681
|
+
const members = /* @__PURE__ */ new Map();
|
|
1682
|
+
for (const userId of this._users) {
|
|
1683
|
+
const member = server.members.cache.get(userId);
|
|
1684
|
+
if (member) members.set(member.id, member);
|
|
1685
|
+
}
|
|
1686
|
+
return members;
|
|
1687
|
+
}
|
|
1688
|
+
/**
|
|
1689
|
+
* Retrieves the users mentioned in the message.
|
|
1690
|
+
*
|
|
1691
|
+
* @returns {Map<string, User>} A map of user IDs to `User` instances.
|
|
1692
|
+
*
|
|
1693
|
+
* @example
|
|
1694
|
+
* ```typescript
|
|
1695
|
+
* const users = mentions.users;
|
|
1696
|
+
* users.forEach(user => console.log(user.username));
|
|
1697
|
+
* ```
|
|
1698
|
+
*/
|
|
1699
|
+
get users() {
|
|
1700
|
+
const users = /* @__PURE__ */ new Map();
|
|
1701
|
+
for (const userId of this._users) {
|
|
1702
|
+
const user = this.client.users.cache.get(userId);
|
|
1703
|
+
if (user) users.set(user.id, user);
|
|
1704
|
+
}
|
|
1705
|
+
return users;
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
|
|
1709
|
+
// src/struct/messageEmbed.ts
|
|
1710
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
1711
|
+
var import_form_data = __toESM(require("form-data"), 1);
|
|
1712
|
+
var import_node_buffer = require("buffer");
|
|
1713
|
+
|
|
1714
|
+
// src/struct/notesChannel.ts
|
|
1715
|
+
var NotesChannel = class extends Channel {
|
|
1716
|
+
/**
|
|
1717
|
+
* Creates a new NotesChannel instance.
|
|
1718
|
+
*
|
|
1719
|
+
* @param {client} client - The client instance.
|
|
1720
|
+
* @param {APINotesChannel} data - The raw data for the notes channel from the API.
|
|
1721
|
+
*/
|
|
1722
|
+
constructor(client3, data) {
|
|
1723
|
+
super(client3);
|
|
1724
|
+
/** The type of the channel, which is always `NOTES` for notes channels. */
|
|
1725
|
+
this.type = "NOTES" /* NOTES */;
|
|
1726
|
+
/** The ID of the last message sent in this notes channel, if any. */
|
|
1727
|
+
this.lastMessageId = null;
|
|
1728
|
+
/** Manages the messages in this notes channel. */
|
|
1729
|
+
this.messages = new MessageManager(this);
|
|
1730
|
+
this._patch(data);
|
|
1731
|
+
}
|
|
1732
|
+
/**
|
|
1733
|
+
* Updates the notes channel instance with new data from the API.
|
|
1734
|
+
*
|
|
1735
|
+
* @param {APINotesChannel} data - The raw data for the notes channel from the API.
|
|
1736
|
+
* @returns {this} The updated notes channel instance.
|
|
1737
|
+
* @protected
|
|
1738
|
+
*/
|
|
1739
|
+
_patch(data) {
|
|
1740
|
+
super._patch(data);
|
|
1741
|
+
if (data.user) {
|
|
1742
|
+
this.userId = data.user;
|
|
1743
|
+
}
|
|
1744
|
+
return this;
|
|
1745
|
+
}
|
|
1746
|
+
/**
|
|
1747
|
+
* Sends a message to this notes channel.
|
|
1748
|
+
*
|
|
1749
|
+
* @param {MessageOptions | string} options - The message content or options for the message.
|
|
1750
|
+
* @returns {Promise<Message>} A promise that resolves with the sent message.
|
|
1751
|
+
*
|
|
1752
|
+
* @example
|
|
1753
|
+
* ```typescript
|
|
1754
|
+
* await notesChannel.send("This is a saved message.");
|
|
1755
|
+
* ```
|
|
1756
|
+
*/
|
|
1757
|
+
send(options) {
|
|
1758
|
+
return this.messages.send(options);
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Deletes multiple messages from this notes channel.
|
|
1762
|
+
*
|
|
1763
|
+
* @param {MessageResolvable[] | Map<string, Message> | number} messages - The messages to delete. This can be an array of message resolvables, a map of messages, or a number indicating how many recent messages to delete.
|
|
1764
|
+
* @returns {Promise<void>} A promise that resolves when the messages have been successfully deleted.
|
|
1765
|
+
*
|
|
1766
|
+
* @example
|
|
1767
|
+
* ```typescript
|
|
1768
|
+
* await notesChannel.bulkDelete(5); // Deletes the last 5 messages.
|
|
1769
|
+
* ```
|
|
1770
|
+
*/
|
|
1771
|
+
bulkDelete(messages) {
|
|
1772
|
+
return this.messages.bulkDelete(messages);
|
|
1773
|
+
}
|
|
1774
|
+
/**
|
|
1775
|
+
* Retrieves the last message sent in this notes channel.
|
|
1776
|
+
*
|
|
1777
|
+
* @returns {Message | null} The last message, or `null` if no message exists.
|
|
1778
|
+
*/
|
|
1779
|
+
get lastMessage() {
|
|
1780
|
+
var _a;
|
|
1781
|
+
if (!this.lastMessageId) return null;
|
|
1782
|
+
return (_a = this.messages.cache.get(this.lastMessageId)) != null ? _a : null;
|
|
1783
|
+
}
|
|
1784
|
+
/**
|
|
1785
|
+
* Retrieves the user associated with this notes channel.
|
|
1786
|
+
*
|
|
1787
|
+
* @returns {User} The user associated with the notes channel.
|
|
1788
|
+
*/
|
|
1789
|
+
get user() {
|
|
1790
|
+
return this.client.user;
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1793
|
+
|
|
1794
|
+
// src/struct/serverChannel.ts
|
|
1795
|
+
var ServerChannel = class extends Channel {
|
|
1796
|
+
/**
|
|
1797
|
+
* Creates a new ServerChannel instance.
|
|
1798
|
+
*
|
|
1799
|
+
* @param {client} client - The client instance.
|
|
1800
|
+
* @param {APIServerChannel} data - The raw data for the server channel from the API.
|
|
1801
|
+
*/
|
|
1802
|
+
constructor(client3, data) {
|
|
1803
|
+
super(client3);
|
|
1804
|
+
/** The description of the channel, or `null` if none is set. */
|
|
1805
|
+
this.description = null;
|
|
1806
|
+
/** The icon of the channel, or `null` if none is set. */
|
|
1807
|
+
this.icon = null;
|
|
1808
|
+
/** The permission overwrites for the channel. */
|
|
1809
|
+
this.overwrites = /* @__PURE__ */ new Map();
|
|
1810
|
+
/** Whether the channel is marked as NSFW (Not Safe For Work). */
|
|
1811
|
+
this.nsfw = false;
|
|
1812
|
+
this._patch(data);
|
|
1813
|
+
}
|
|
1814
|
+
/**
|
|
1815
|
+
* Updates the server channel instance with new data from the API.
|
|
1816
|
+
*
|
|
1817
|
+
* @param {APIServerChannel} data - The raw data for the server channel from the API.
|
|
1818
|
+
* @param {FieldsChannel[]} [clear=[]] - Fields to clear in the channel.
|
|
1819
|
+
* @returns {this} The updated server channel instance.
|
|
1820
|
+
* @protected
|
|
1821
|
+
*/
|
|
1822
|
+
_patch(data, clear = []) {
|
|
1823
|
+
var _a;
|
|
1824
|
+
super._patch(data);
|
|
1825
|
+
if (data.name) this.name = data.name;
|
|
1826
|
+
if (data.server) this.serverId = data.server;
|
|
1827
|
+
if ("description" in data) this.description = (_a = data.description) != null ? _a : null;
|
|
1828
|
+
if (data.icon) this.icon = new Attachment(this.client, data.icon);
|
|
1829
|
+
if (typeof data.nsfw === "boolean") this.nsfw = data.nsfw;
|
|
1830
|
+
if (data.role_permissions) {
|
|
1831
|
+
this.overwrites.clear();
|
|
1832
|
+
for (const [id, { a, d }] of Object.entries(data.role_permissions)) {
|
|
1833
|
+
this.overwrites.set(id, {
|
|
1834
|
+
allow: new FullPermissions(a),
|
|
1835
|
+
deny: new FullPermissions(d)
|
|
1836
|
+
});
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
for (const field of clear) {
|
|
1840
|
+
if (field === "Icon") this.icon = null;
|
|
1841
|
+
if (field === "Description") this.description = null;
|
|
1842
|
+
}
|
|
1843
|
+
return this;
|
|
1844
|
+
}
|
|
1845
|
+
/**
|
|
1846
|
+
* Creates an invite for the server channel.
|
|
1847
|
+
*
|
|
1848
|
+
* @returns {Promise<Invite>} A promise that resolves with the created invite.
|
|
1849
|
+
*
|
|
1850
|
+
* @example
|
|
1851
|
+
* ```typescript
|
|
1852
|
+
* const invite = await serverChannel.createInvite();
|
|
1853
|
+
* console.log(`Invite created: ${invite}`);
|
|
1854
|
+
* ```
|
|
1855
|
+
*/
|
|
1856
|
+
createInvite() {
|
|
1857
|
+
return __async(this, null, function* () {
|
|
1858
|
+
const data = yield this.client.api.post(`/channels/${this.id}/invites`, {});
|
|
1859
|
+
return new Invite(
|
|
1860
|
+
this.client,
|
|
1861
|
+
data
|
|
1862
|
+
);
|
|
1863
|
+
});
|
|
1864
|
+
}
|
|
1865
|
+
// iconURL(options?: { size: number }): string | null {
|
|
1866
|
+
// return this.icon
|
|
1867
|
+
// ? this.client.api.cdn.icon(this.icon.id, options?.size)
|
|
1868
|
+
// : null;
|
|
1869
|
+
// }
|
|
1870
|
+
/**
|
|
1871
|
+
* Retrieves the server this channel belongs to.
|
|
1872
|
+
*
|
|
1873
|
+
* @returns {Server} The server instance.
|
|
1874
|
+
*/
|
|
1875
|
+
get server() {
|
|
1876
|
+
return this.client.servers.cache.get(this.serverId);
|
|
1877
|
+
}
|
|
1878
|
+
/**
|
|
1879
|
+
* Retrieves the category this channel belongs to, if any.
|
|
1880
|
+
*
|
|
1881
|
+
* @returns {Category | null} The category instance, or `null` if the channel is not in a category.
|
|
1882
|
+
*/
|
|
1883
|
+
get category() {
|
|
1884
|
+
var _a;
|
|
1885
|
+
return (_a = Array.from(this.server.categories.values()).find(
|
|
1886
|
+
(cat) => cat.children.has(this.id)
|
|
1887
|
+
)) != null ? _a : null;
|
|
1888
|
+
}
|
|
1889
|
+
};
|
|
1890
|
+
|
|
1891
|
+
// src/struct/serverMember.ts
|
|
1892
|
+
var ServerMember3 = class extends Base {
|
|
1893
|
+
/**
|
|
1894
|
+
* Creates a new ServerMember instance.
|
|
1895
|
+
*
|
|
1896
|
+
* @param {client} client - The client instance.
|
|
1897
|
+
* @param {APIMember} data - The raw data for the server member from the API.
|
|
1898
|
+
*/
|
|
1899
|
+
constructor(client3, data) {
|
|
1900
|
+
super(client3);
|
|
1901
|
+
/** The nickname of the member, or `null` if none is set. */
|
|
1902
|
+
this.nickname = null;
|
|
1903
|
+
/** The avatar of the member, or `null` if none is set. */
|
|
1904
|
+
this.avatar = null;
|
|
1905
|
+
/** roles assigned to the member */
|
|
1906
|
+
this.roles = [];
|
|
1907
|
+
this._patch(data);
|
|
1908
|
+
}
|
|
1909
|
+
/**
|
|
1910
|
+
* Updates the server member instance with new data from the API.
|
|
1911
|
+
*
|
|
1912
|
+
* @param {APIMember} data - The raw data for the server member from the API.
|
|
1913
|
+
* @param {FieldsMember[]} [clear=[]] - Fields to clear in the server member.
|
|
1914
|
+
* @returns {this} The updated server member instance.
|
|
1915
|
+
* @protected
|
|
1916
|
+
*/
|
|
1917
|
+
_patch(data, clear = []) {
|
|
1918
|
+
var _a;
|
|
1919
|
+
super._patch(data);
|
|
1920
|
+
if ("nickname" in data) {
|
|
1921
|
+
this.nickname = (_a = data.nickname) != null ? _a : null;
|
|
1922
|
+
}
|
|
1923
|
+
if (data.avatar) {
|
|
1924
|
+
this.avatar = new Attachment(this.client, data.avatar);
|
|
1925
|
+
}
|
|
1926
|
+
if (data._id) {
|
|
1927
|
+
this.serverId = data._id.server;
|
|
1928
|
+
this.id = data._id.user;
|
|
1929
|
+
}
|
|
1930
|
+
if (Array.isArray(data.roles)) {
|
|
1931
|
+
if (!data.roles.length) this.roles = [];
|
|
1932
|
+
else {
|
|
1933
|
+
this.roles = data.roles.map((roleId) => {
|
|
1934
|
+
const role = this.server.roles.cache.get(roleId);
|
|
1935
|
+
if (!role) {
|
|
1936
|
+
throw new Error(
|
|
1937
|
+
`Role with ID ${roleId} not found in server ${this.serverId}`
|
|
1938
|
+
);
|
|
1939
|
+
}
|
|
1940
|
+
return role;
|
|
1941
|
+
});
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
for (const field of clear) {
|
|
1945
|
+
if (field === "Avatar") this.avatar = null;
|
|
1946
|
+
if (field === "Nickname") this.nickname = null;
|
|
1947
|
+
}
|
|
1948
|
+
return this;
|
|
1949
|
+
}
|
|
1950
|
+
/**
|
|
1951
|
+
* Sets the nickname of the server member.
|
|
1952
|
+
*
|
|
1953
|
+
* @param {string} [nickname] - The new nickname to set, or `undefined` to clear the nickname.
|
|
1954
|
+
* @returns {Promise<this>} A promise that resolves with the updated server member instance.
|
|
1955
|
+
*
|
|
1956
|
+
* @example
|
|
1957
|
+
* ```typescript
|
|
1958
|
+
* await member.setNickname("NewNickname");
|
|
1959
|
+
* ```
|
|
1960
|
+
*/
|
|
1961
|
+
setNickname(nickname) {
|
|
1962
|
+
return __async(this, null, function* () {
|
|
1963
|
+
yield this.server.members.edit(this, { nickname });
|
|
1964
|
+
return this;
|
|
1965
|
+
});
|
|
1966
|
+
}
|
|
1967
|
+
/**
|
|
1968
|
+
* adds a role to the server member.
|
|
1969
|
+
* @param roleId - The ID of the role to add to the member.
|
|
1970
|
+
* @returns
|
|
1971
|
+
*/
|
|
1972
|
+
addRole(roleId) {
|
|
1973
|
+
return __async(this, null, function* () {
|
|
1974
|
+
const currentRoles = this.roles.map((role) => role.id);
|
|
1975
|
+
if (currentRoles.includes(roleId)) {
|
|
1976
|
+
return this;
|
|
1977
|
+
}
|
|
1978
|
+
yield this.server.members.edit(this, {
|
|
1979
|
+
roles: [...currentRoles, roleId]
|
|
1980
|
+
});
|
|
1981
|
+
return this;
|
|
1982
|
+
});
|
|
1983
|
+
}
|
|
1984
|
+
/**
|
|
1985
|
+
* Removes a role from the server member.
|
|
1986
|
+
*
|
|
1987
|
+
* @param {string} roleId - The ID of the role to remove from the member.
|
|
1988
|
+
* @returns {Promise<this>} A promise that resolves with the updated server member instance.
|
|
1989
|
+
*
|
|
1990
|
+
* @example
|
|
1991
|
+
* ```typescript
|
|
1992
|
+
* await member.removeRole("roleId");
|
|
1993
|
+
* ```
|
|
1994
|
+
*/
|
|
1995
|
+
removeRole(roleId) {
|
|
1996
|
+
return __async(this, null, function* () {
|
|
1997
|
+
const currentRoles = this.roles.map((role) => role.id);
|
|
1998
|
+
if (!currentRoles.includes(roleId)) {
|
|
1999
|
+
return this;
|
|
2000
|
+
}
|
|
2001
|
+
yield this.server.members.edit(this, {
|
|
2002
|
+
roles: currentRoles.filter((id) => id !== roleId)
|
|
2003
|
+
});
|
|
2004
|
+
return this;
|
|
2005
|
+
});
|
|
2006
|
+
}
|
|
2007
|
+
/**
|
|
2008
|
+
* Bans the server member.
|
|
2009
|
+
*
|
|
2010
|
+
* @param {string} [reason] - The reason for the ban.
|
|
2011
|
+
* @returns {Promise<void>} A promise that resolves when the member is banned.
|
|
2012
|
+
*
|
|
2013
|
+
* @example
|
|
2014
|
+
* ```typescript
|
|
2015
|
+
* await member.ban("Violation of rules");
|
|
2016
|
+
* ```
|
|
2017
|
+
*/
|
|
2018
|
+
ban(reason) {
|
|
2019
|
+
return this.server.members.ban(this, reason);
|
|
2020
|
+
}
|
|
2021
|
+
/**
|
|
2022
|
+
* Kicks the server member.
|
|
2023
|
+
*
|
|
2024
|
+
* @returns {Promise<void>} A promise that resolves when the member is kicked.
|
|
2025
|
+
*
|
|
2026
|
+
* @example
|
|
2027
|
+
* ```typescript
|
|
2028
|
+
* await member.kick();
|
|
2029
|
+
* ```
|
|
2030
|
+
*/
|
|
2031
|
+
kick() {
|
|
2032
|
+
return this.server.members.kick(this);
|
|
2033
|
+
}
|
|
2034
|
+
/**
|
|
2035
|
+
* Leaves the server.
|
|
2036
|
+
*
|
|
2037
|
+
* @returns {Promise<void>} A promise that resolves when the member leaves the server.
|
|
2038
|
+
*
|
|
2039
|
+
* @example
|
|
2040
|
+
* ```typescript
|
|
2041
|
+
* await member.leave();
|
|
2042
|
+
* ```
|
|
2043
|
+
*/
|
|
2044
|
+
leave() {
|
|
2045
|
+
return this.client.servers.delete(this.serverId);
|
|
2046
|
+
}
|
|
2047
|
+
// async displayAvatarURL(options?: { size: number }): Promise<string> {
|
|
2048
|
+
// return await this.user.displayAvatarURL(options);
|
|
2049
|
+
// }
|
|
2050
|
+
/**
|
|
2051
|
+
* Retrieves the user associated with this server member.
|
|
2052
|
+
*
|
|
2053
|
+
* @returns {User} The user instance.
|
|
2054
|
+
*/
|
|
2055
|
+
get user() {
|
|
2056
|
+
return this.client.users.cache.get(this.id);
|
|
2057
|
+
}
|
|
2058
|
+
/**
|
|
2059
|
+
* Retrieves the server this member belongs to.
|
|
2060
|
+
*
|
|
2061
|
+
* @returns {Server} The server instance.
|
|
2062
|
+
*/
|
|
2063
|
+
get server() {
|
|
2064
|
+
return this.client.servers.cache.get(this.serverId);
|
|
2065
|
+
}
|
|
2066
|
+
/**
|
|
2067
|
+
* Converts the server member to a string representation.
|
|
2068
|
+
*
|
|
2069
|
+
* @returns {string} A string representation of the server member in the format `<@userId>`.
|
|
2070
|
+
*/
|
|
2071
|
+
toString() {
|
|
2072
|
+
return `<@${this.id}>`;
|
|
2073
|
+
}
|
|
2074
|
+
};
|
|
2075
|
+
|
|
2076
|
+
// src/struct/textChannel.ts
|
|
2077
|
+
var TextChannel2 = class extends ServerChannel {
|
|
2078
|
+
/**
|
|
2079
|
+
* Creates a new TextChannel instance.
|
|
2080
|
+
*
|
|
2081
|
+
* @param {client} client - The client instance.
|
|
2082
|
+
* @param {APITextChannel} data - The raw data for the text channel from the API.
|
|
2083
|
+
*/
|
|
2084
|
+
constructor(client3, data) {
|
|
2085
|
+
super(client3, data);
|
|
2086
|
+
/** The ID of the last message sent in this text channel, if any. */
|
|
2087
|
+
this.lastMessageId = null;
|
|
2088
|
+
/** Manages the messages in this text channel. */
|
|
2089
|
+
this.messages = new MessageManager(this);
|
|
2090
|
+
/** The type of the channel, which is always `TEXT` for text channels. */
|
|
2091
|
+
this.type = "TEXT" /* TEXT */;
|
|
2092
|
+
this._patch(data);
|
|
2093
|
+
}
|
|
2094
|
+
/**
|
|
2095
|
+
* Updates the text channel instance with new data from the API.
|
|
2096
|
+
*
|
|
2097
|
+
* @param {APITextChannel} data - The raw data for the text channel from the API.
|
|
2098
|
+
* @returns {this} The updated text channel instance.
|
|
2099
|
+
* @protected
|
|
2100
|
+
*/
|
|
2101
|
+
_patch(data) {
|
|
2102
|
+
super._patch(data);
|
|
2103
|
+
if (data.last_message_id) this.lastMessageId = data.last_message_id;
|
|
2104
|
+
return this;
|
|
2105
|
+
}
|
|
2106
|
+
/**
|
|
2107
|
+
* Retrieves the last message sent in this text channel.
|
|
2108
|
+
*
|
|
2109
|
+
* @returns {Message | null} The last message, or `null` if no message exists.
|
|
2110
|
+
*/
|
|
2111
|
+
get lastMessage() {
|
|
2112
|
+
var _a;
|
|
2113
|
+
if (!this.lastMessageId) return null;
|
|
2114
|
+
return (_a = this.messages.cache.get(this.lastMessageId)) != null ? _a : null;
|
|
2115
|
+
}
|
|
2116
|
+
/**
|
|
2117
|
+
* Sends a message to this text channel.
|
|
2118
|
+
*
|
|
2119
|
+
* @param {MessageOptions | string} options - The message content or options for the message.
|
|
2120
|
+
* @returns {Promise<Message>} A promise that resolves with the sent message.
|
|
2121
|
+
*
|
|
2122
|
+
* @example
|
|
2123
|
+
* ```typescript
|
|
2124
|
+
* await textChannel.send("Hello, world!");
|
|
2125
|
+
* ```
|
|
2126
|
+
*/
|
|
2127
|
+
send(options) {
|
|
2128
|
+
return this.messages.send(options);
|
|
2129
|
+
}
|
|
2130
|
+
/**
|
|
2131
|
+
* Deletes multiple messages from this text channel.
|
|
2132
|
+
*
|
|
2133
|
+
* @param {MessageResolvable[] | Map<string, Message> | number} messages - The messages to delete. This can be an array of message resolvables, a map of messages, or a number indicating how many recent messages to delete.
|
|
2134
|
+
* @returns {Promise<void>} A promise that resolves when the messages have been successfully deleted.
|
|
2135
|
+
*
|
|
2136
|
+
* @example
|
|
2137
|
+
* ```typescript
|
|
2138
|
+
* await textChannel.bulkDelete(10); // Deletes the last 10 messages.
|
|
2139
|
+
* ```
|
|
2140
|
+
*/
|
|
2141
|
+
bulkDelete(messages) {
|
|
2142
|
+
return this.messages.bulkDelete(messages);
|
|
2143
|
+
}
|
|
2144
|
+
};
|
|
2145
|
+
|
|
2146
|
+
// src/struct/voiceChannels.ts
|
|
2147
|
+
var VoiceChannel = class extends ServerChannel {
|
|
2148
|
+
/**
|
|
2149
|
+
* Creates a new VoiceChannel instance.
|
|
2150
|
+
*
|
|
2151
|
+
* @param {client} client - The client instance.
|
|
2152
|
+
* @param {APIVoiceChannel} data - The raw data for the voice channel from the API.
|
|
2153
|
+
*/
|
|
2154
|
+
constructor(client3, data) {
|
|
2155
|
+
super(client3, data);
|
|
2156
|
+
/** The type of the channel, which is always `VOICE` for voice channels. */
|
|
2157
|
+
this.type = "VOICE" /* VOICE */;
|
|
2158
|
+
this._patch(data);
|
|
2159
|
+
}
|
|
2160
|
+
/**
|
|
2161
|
+
* Updates the voice channel instance with new data from the API.
|
|
2162
|
+
*
|
|
2163
|
+
* @param {APIVoiceChannel} data - The raw data for the voice channel from the API.
|
|
2164
|
+
* @returns {this} The updated voice channel instance.
|
|
2165
|
+
* @protected
|
|
2166
|
+
*/
|
|
2167
|
+
_patch(data) {
|
|
2168
|
+
super._patch(data);
|
|
2169
|
+
return this;
|
|
2170
|
+
}
|
|
2171
|
+
/**
|
|
2172
|
+
* Acknowledges the voice channel.
|
|
2173
|
+
*
|
|
2174
|
+
* @throws {TypeError} Throws an error because voice channels cannot be acknowledged.
|
|
2175
|
+
*
|
|
2176
|
+
* @example
|
|
2177
|
+
* ```typescript
|
|
2178
|
+
* try {
|
|
2179
|
+
* await voiceChannel.ack();
|
|
2180
|
+
* } catch (error) {
|
|
2181
|
+
* console.error(error.message); // "Cannot ack voice channel"
|
|
2182
|
+
* }
|
|
2183
|
+
* ```
|
|
2184
|
+
*/
|
|
2185
|
+
ack() {
|
|
2186
|
+
throw new TypeError("Cannot ack voice channel");
|
|
2187
|
+
}
|
|
2188
|
+
};
|
|
2189
|
+
|
|
2190
|
+
// src/struct/category.ts
|
|
2191
|
+
var Category = class extends Base {
|
|
2192
|
+
/**
|
|
2193
|
+
* Creates a new Category instance.
|
|
2194
|
+
*
|
|
2195
|
+
* @param {Server} server - The server this category belongs to.
|
|
2196
|
+
* @param {APICategory} data - The raw data for the category from the API.
|
|
2197
|
+
*/
|
|
2198
|
+
constructor(server, data) {
|
|
2199
|
+
super(server.client);
|
|
2200
|
+
this.server = server;
|
|
2201
|
+
/** An array of channel IDs that belong to this category. */
|
|
2202
|
+
this._children = [];
|
|
2203
|
+
this._patch(data);
|
|
2204
|
+
}
|
|
2205
|
+
/**
|
|
2206
|
+
* Updates the category instance with new data from the API.
|
|
2207
|
+
*
|
|
2208
|
+
* @param {APICategory} data - The raw data for the category from the API.
|
|
2209
|
+
* @returns {this} The updated category instance.
|
|
2210
|
+
* @protected
|
|
2211
|
+
*/
|
|
2212
|
+
_patch(data) {
|
|
2213
|
+
super._patch(data);
|
|
2214
|
+
if (data.title) {
|
|
2215
|
+
this.name = data.title;
|
|
2216
|
+
}
|
|
2217
|
+
if (Array.isArray(data.channels)) {
|
|
2218
|
+
this._children = data.channels;
|
|
2219
|
+
}
|
|
2220
|
+
return this;
|
|
2221
|
+
}
|
|
2222
|
+
/**
|
|
2223
|
+
* Retrieves the channels that belong to this category.
|
|
2224
|
+
*
|
|
2225
|
+
* @returns {Map<string, ServerChannel>} A map of channel IDs to their corresponding `ServerChannel` instances.
|
|
2226
|
+
*/
|
|
2227
|
+
get children() {
|
|
2228
|
+
const coll = /* @__PURE__ */ new Map();
|
|
2229
|
+
for (const childId of this._children) {
|
|
2230
|
+
const child = this.server.channels.cache.get(childId);
|
|
2231
|
+
if (child) coll.set(child.id, child);
|
|
2232
|
+
}
|
|
2233
|
+
return coll;
|
|
2234
|
+
}
|
|
2235
|
+
/**
|
|
2236
|
+
* Converts the category to a string representation.
|
|
2237
|
+
*
|
|
2238
|
+
* @returns {string} The name of the category.
|
|
2239
|
+
*/
|
|
2240
|
+
toString() {
|
|
2241
|
+
return this.name;
|
|
2242
|
+
}
|
|
2243
|
+
};
|
|
2244
|
+
|
|
2245
|
+
// src/struct/emoji.ts
|
|
2246
|
+
var Emoji2 = class extends Base {
|
|
2247
|
+
/**
|
|
2248
|
+
* Creates a new Emoji instance.
|
|
2249
|
+
*
|
|
2250
|
+
* @param {client} client - The client instance.
|
|
2251
|
+
* @param {Emoji} data - The raw data for the emoji.
|
|
2252
|
+
*/
|
|
2253
|
+
constructor(client3, data) {
|
|
2254
|
+
super(client3);
|
|
2255
|
+
/** The parent object of the emoji, which can be a server or other entity. */
|
|
2256
|
+
this.parent = null;
|
|
2257
|
+
/** The ID of the user who created the emoji, or `null` if not available. */
|
|
2258
|
+
this.creator_id = null;
|
|
2259
|
+
/** The name of the emoji, or `null` if not set. */
|
|
2260
|
+
this.name = null;
|
|
2261
|
+
this._patch(data);
|
|
2262
|
+
}
|
|
2263
|
+
/**
|
|
2264
|
+
* Retrieves the user who created the emoji.
|
|
2265
|
+
*
|
|
2266
|
+
* @returns {User | null} The creator of the emoji, or `null` if not found.
|
|
2267
|
+
*/
|
|
2268
|
+
get creator() {
|
|
2269
|
+
var _a;
|
|
2270
|
+
return (_a = this.client.users.cache.get(this.creator_id)) != null ? _a : null;
|
|
2271
|
+
}
|
|
2272
|
+
/**
|
|
2273
|
+
* Retrieves the server associated with the emoji, if any.
|
|
2274
|
+
*
|
|
2275
|
+
* @returns {Server | null} The server instance, or `null` if the emoji is not associated with a server.
|
|
2276
|
+
*/
|
|
2277
|
+
get server() {
|
|
2278
|
+
var _a;
|
|
2279
|
+
if (!this.parent) return null;
|
|
2280
|
+
return (_a = this.client.servers.cache.get(this.parent.id)) != null ? _a : null;
|
|
2281
|
+
}
|
|
2282
|
+
};
|
|
2283
|
+
|
|
2284
|
+
// src/managers/channelManager.ts
|
|
2285
|
+
var ChannelManager = class extends BaseManager {
|
|
2286
|
+
constructor() {
|
|
2287
|
+
super(...arguments);
|
|
2288
|
+
this.holds = null;
|
|
2289
|
+
}
|
|
2290
|
+
_add(data) {
|
|
2291
|
+
let channel;
|
|
2292
|
+
switch (data.channel_type) {
|
|
2293
|
+
case "TextChannel":
|
|
2294
|
+
channel = new TextChannel2(this.client, data);
|
|
2295
|
+
break;
|
|
2296
|
+
case "VoiceChannel":
|
|
2297
|
+
channel = new VoiceChannel(this.client, data);
|
|
2298
|
+
break;
|
|
2299
|
+
case "DirectMessage":
|
|
2300
|
+
channel = new DMChannel3(this.client, data);
|
|
2301
|
+
break;
|
|
2302
|
+
case "Group":
|
|
2303
|
+
channel = new GroupChannel2(this.client, data);
|
|
2304
|
+
break;
|
|
2305
|
+
case "SavedMessages":
|
|
2306
|
+
channel = new NotesChannel(this.client, data);
|
|
2307
|
+
if (this.client.user) this.client.user.notes = channel;
|
|
2308
|
+
break;
|
|
2309
|
+
default:
|
|
2310
|
+
throw new Error(`Unknown Channel Type: ${data}`);
|
|
2311
|
+
}
|
|
2312
|
+
this.cache.set(channel.id, channel);
|
|
2313
|
+
return channel;
|
|
2314
|
+
}
|
|
2315
|
+
_remove(id) {
|
|
2316
|
+
var _a;
|
|
2317
|
+
const channel = this.cache.get(id);
|
|
2318
|
+
if (channel == null ? void 0 : channel.inServer()) {
|
|
2319
|
+
(_a = channel.server) == null ? void 0 : _a.channels.cache.delete(id);
|
|
2320
|
+
}
|
|
2321
|
+
super._remove(id);
|
|
2322
|
+
}
|
|
2323
|
+
/**
|
|
2324
|
+
* used to delete a channel
|
|
2325
|
+
*
|
|
2326
|
+
* @param channel The channel to delete
|
|
2327
|
+
* @returns A promise that resolves when the channel is deleted
|
|
2328
|
+
*/
|
|
2329
|
+
delete(channel) {
|
|
2330
|
+
return __async(this, null, function* () {
|
|
2331
|
+
const id = this.resolveId(channel);
|
|
2332
|
+
if (!id) {
|
|
2333
|
+
throw new TypeError("INVALID_TYPE");
|
|
2334
|
+
}
|
|
2335
|
+
yield this.client.api.delete(`/channels/${id}`);
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
/**
|
|
2339
|
+
* used to fetch a channel
|
|
2340
|
+
*
|
|
2341
|
+
* @param channel The channel to fetch
|
|
2342
|
+
* @param force Whether to force fetch the channel using the api or return it form cache if able
|
|
2343
|
+
* @returns A promise that resolves with the fetched channel
|
|
2344
|
+
*/
|
|
2345
|
+
fetch(_0) {
|
|
2346
|
+
return __async(this, arguments, function* (channel, { force = true } = {}) {
|
|
2347
|
+
const id = this.resolveId(channel);
|
|
2348
|
+
if (!id) {
|
|
2349
|
+
throw new TypeError("INVALID_TYPE");
|
|
2350
|
+
}
|
|
2351
|
+
if (!force) {
|
|
2352
|
+
const channel2 = this.cache.get(id);
|
|
2353
|
+
if (channel2) return channel2;
|
|
2354
|
+
}
|
|
2355
|
+
const data = yield this.client.api.get(`/channels/${id}`);
|
|
2356
|
+
return this._add(data);
|
|
2357
|
+
});
|
|
2358
|
+
}
|
|
2359
|
+
/**
|
|
2360
|
+
* resolves a channel from a string or a channel object
|
|
2361
|
+
* @param channel The channel to resolve
|
|
2362
|
+
* @returns the resolved channel or null if not found
|
|
2363
|
+
*/
|
|
2364
|
+
resolve(channel) {
|
|
2365
|
+
if (channel instanceof Channel) return channel;
|
|
2366
|
+
return super.resolve(channel);
|
|
2367
|
+
}
|
|
2368
|
+
/**
|
|
2369
|
+
* resolves a channel id from a string or a channel object
|
|
2370
|
+
* @param channel The channel to resolve
|
|
2371
|
+
* @returns the resolved channel id or null if not found
|
|
2372
|
+
*/
|
|
2373
|
+
resolveId(channel) {
|
|
2374
|
+
if (channel instanceof Channel) return channel.id;
|
|
2375
|
+
return super.resolveId(channel);
|
|
2376
|
+
}
|
|
2377
|
+
};
|
|
2378
|
+
|
|
2379
|
+
// src/managers/serverManager.ts
|
|
2380
|
+
var ServerManager = class extends BaseManager {
|
|
2381
|
+
constructor() {
|
|
2382
|
+
super(...arguments);
|
|
2383
|
+
this.holds = Server2;
|
|
2384
|
+
}
|
|
2385
|
+
_remove(id) {
|
|
2386
|
+
var _a;
|
|
2387
|
+
const server = this.cache.get(id);
|
|
2388
|
+
for (const id2 of (_a = server == null ? void 0 : server.channels.cache.keys()) != null ? _a : []) {
|
|
2389
|
+
this.client.channels._remove(id2);
|
|
2390
|
+
}
|
|
2391
|
+
return super._remove(id);
|
|
2392
|
+
}
|
|
2393
|
+
/**
|
|
2394
|
+
* edits a server
|
|
2395
|
+
* @param server The server to edit
|
|
2396
|
+
* @param options The options to edit the server with
|
|
2397
|
+
* @param options.name The name of the server
|
|
2398
|
+
* @param options.description The description of the server
|
|
2399
|
+
* @returns A promise that resolves when the server is edited
|
|
2400
|
+
*/
|
|
2401
|
+
edit(server, options) {
|
|
2402
|
+
return __async(this, null, function* () {
|
|
2403
|
+
const id = this.resolveId(server);
|
|
2404
|
+
if (!id) throw new TypeError("INVALID_TYPE");
|
|
2405
|
+
yield this.client.api.patch(`/servers/${id}`, { body: options });
|
|
2406
|
+
});
|
|
2407
|
+
}
|
|
2408
|
+
/**
|
|
2409
|
+
* leaves a server
|
|
2410
|
+
* @param server the server to leave
|
|
2411
|
+
*/
|
|
2412
|
+
delete(server) {
|
|
2413
|
+
return __async(this, null, function* () {
|
|
2414
|
+
const id = this.resolveId(server);
|
|
2415
|
+
if (!id) throw new TypeError("INVALID_TYPE");
|
|
2416
|
+
yield this.client.api.delete(`/servers/${id}`);
|
|
2417
|
+
});
|
|
2418
|
+
}
|
|
2419
|
+
fetch(_0) {
|
|
2420
|
+
return __async(this, arguments, function* (server, { force = true } = {}) {
|
|
2421
|
+
const id = this.resolveId(server);
|
|
2422
|
+
if (!id) throw new TypeError("INVALID_TYPE");
|
|
2423
|
+
if (!force) {
|
|
2424
|
+
const server2 = this.cache.get(id);
|
|
2425
|
+
if (server2) return server2;
|
|
2426
|
+
}
|
|
2427
|
+
const data = yield this.client.api.get(`/servers/${id}`);
|
|
2428
|
+
return this._add(data);
|
|
2429
|
+
});
|
|
2430
|
+
}
|
|
2431
|
+
};
|
|
2432
|
+
|
|
2433
|
+
// src/managers/userManager.ts
|
|
2434
|
+
var UserManager = class extends BaseManager {
|
|
2435
|
+
constructor() {
|
|
2436
|
+
super(...arguments);
|
|
2437
|
+
this.holds = User;
|
|
2438
|
+
}
|
|
2439
|
+
/**
|
|
2440
|
+
*
|
|
2441
|
+
* @param user The user to fetch
|
|
2442
|
+
* @returns A promise that resolves when the user is fetched
|
|
2443
|
+
*/
|
|
2444
|
+
fetch(_0) {
|
|
2445
|
+
return __async(this, arguments, function* (user, { force = false } = {}) {
|
|
2446
|
+
const id = this.resolveId(user);
|
|
2447
|
+
if (!id) throw new TypeError("INVALID_TYPE");
|
|
2448
|
+
if (!force) {
|
|
2449
|
+
const user2 = this.cache.get(id);
|
|
2450
|
+
if (user2) return user2;
|
|
2451
|
+
}
|
|
2452
|
+
const data = yield this.client.api.get(`/users/${id}`);
|
|
2453
|
+
return this._add(data);
|
|
2454
|
+
});
|
|
2455
|
+
}
|
|
2456
|
+
resolve(resolvable) {
|
|
2457
|
+
if (resolvable instanceof Message) return resolvable.author;
|
|
2458
|
+
return super.resolve(resolvable);
|
|
2459
|
+
}
|
|
2460
|
+
/**
|
|
2461
|
+
* get a user id form cache
|
|
2462
|
+
* @param resolvable The user to resolve
|
|
2463
|
+
* @returns The user id or null if it cannot be resolved
|
|
2464
|
+
*/
|
|
2465
|
+
resolveId(resolvable) {
|
|
2466
|
+
if (resolvable instanceof Message) return resolvable.authorId;
|
|
2467
|
+
return super.resolveId(resolvable);
|
|
2468
|
+
}
|
|
2469
|
+
};
|
|
2470
|
+
|
|
2471
|
+
// src/managers/messageManager.ts
|
|
2472
|
+
var import_node_buffer2 = require("buffer");
|
|
2473
|
+
var import_stream = require("stream");
|
|
2474
|
+
var import_form_data2 = __toESM(require("form-data"), 1);
|
|
2475
|
+
var import_axios2 = __toESM(require("axios"), 1);
|
|
2476
|
+
var MessageManager = class extends BaseManager {
|
|
2477
|
+
constructor(channel) {
|
|
2478
|
+
super(channel.client);
|
|
2479
|
+
this.channel = channel;
|
|
2480
|
+
this.holds = Message;
|
|
2481
|
+
}
|
|
2482
|
+
/**
|
|
2483
|
+
*
|
|
2484
|
+
* @param content The content to send. Can be a string or an object with the following properties:
|
|
2485
|
+
* - content: The content of the message
|
|
2486
|
+
* - replies: An array of message IDs to reply to
|
|
2487
|
+
* - attachments: An array of attachment URLs, Files, or ReadStreams
|
|
2488
|
+
* - embeds: An array of MessageEmbed objects
|
|
2489
|
+
* @returns Promise that resolves to the sent message
|
|
2490
|
+
*/
|
|
2491
|
+
send(content) {
|
|
2492
|
+
return __async(this, null, function* () {
|
|
2493
|
+
if (typeof content === "string") content = { content };
|
|
2494
|
+
let attachments = [];
|
|
2495
|
+
let embeds = [];
|
|
2496
|
+
if (Array.isArray(content.attachments)) {
|
|
2497
|
+
const promises = content.attachments.map((att) => __async(this, null, function* () {
|
|
2498
|
+
const data = new import_form_data2.default();
|
|
2499
|
+
if (typeof att === "string") {
|
|
2500
|
+
const readableStream = yield import_axios2.default.get(att, {
|
|
2501
|
+
responseType: "stream"
|
|
2502
|
+
});
|
|
2503
|
+
data.append("file", readableStream.data, {
|
|
2504
|
+
filename: att.split("/").pop()
|
|
2505
|
+
});
|
|
2506
|
+
}
|
|
2507
|
+
if (att instanceof import_stream.Readable) {
|
|
2508
|
+
data.append("file", att);
|
|
2509
|
+
}
|
|
2510
|
+
if (att instanceof import_node_buffer2.File) {
|
|
2511
|
+
const buffer = Buffer.from(yield att.arrayBuffer());
|
|
2512
|
+
data.append("file", buffer, { filename: att.name });
|
|
2513
|
+
}
|
|
2514
|
+
yield this.client.cdn.post("/attachments", data).then((attachment) => {
|
|
2515
|
+
const { id } = attachment;
|
|
2516
|
+
attachments.push(id);
|
|
2517
|
+
});
|
|
2518
|
+
}));
|
|
2519
|
+
yield Promise.all(promises);
|
|
2520
|
+
}
|
|
2521
|
+
if (Array.isArray(content.embeds)) {
|
|
2522
|
+
const promises = content.embeds.map((embed) => __async(this, null, function* () {
|
|
2523
|
+
const json = yield embed.toJSONWithMedia(this.client);
|
|
2524
|
+
embeds.push(json);
|
|
2525
|
+
}));
|
|
2526
|
+
yield Promise.all(promises);
|
|
2527
|
+
}
|
|
2528
|
+
const resp = yield this.client.api.post(
|
|
2529
|
+
`/channels/${this.channel.id}/messages`,
|
|
2530
|
+
{
|
|
2531
|
+
body: __spreadProps(__spreadValues({}, content), { attachments, embeds, nonce: UUID.generate() })
|
|
2532
|
+
}
|
|
2533
|
+
);
|
|
2534
|
+
return this._add(resp);
|
|
2535
|
+
});
|
|
2536
|
+
}
|
|
2537
|
+
/**
|
|
2538
|
+
* acknowledge a message to mark it as read (not important for bots)
|
|
2539
|
+
* @param message The message to acknowledge
|
|
2540
|
+
* @returns Promise that resolves when the message is acknowledged
|
|
2541
|
+
*/
|
|
2542
|
+
ack(message) {
|
|
2543
|
+
return __async(this, null, function* () {
|
|
2544
|
+
const id = this.resolveId(message);
|
|
2545
|
+
if (!id) {
|
|
2546
|
+
throw new TypeError("INVALID_TYPE");
|
|
2547
|
+
}
|
|
2548
|
+
yield this.client.api.put(`/channels/${this.channel.id}/ack/${id}`);
|
|
2549
|
+
});
|
|
2550
|
+
}
|
|
2551
|
+
/**
|
|
2552
|
+
* bulk delete messages from the channel
|
|
2553
|
+
* @param messages The messages to delete. Can be an array of message IDs or a Map of message IDs to Message objects.
|
|
2554
|
+
* @returns Promise that resolves when the messages are deleted
|
|
2555
|
+
*/
|
|
2556
|
+
bulkDelete(messages) {
|
|
2557
|
+
return __async(this, null, function* () {
|
|
2558
|
+
let ids = [];
|
|
2559
|
+
if (typeof messages === "number") {
|
|
2560
|
+
messages = yield this.fetch(messages);
|
|
2561
|
+
ids = messages instanceof Map ? [...messages.keys()] : [];
|
|
2562
|
+
} else if (messages instanceof Map) {
|
|
2563
|
+
ids = [...messages.keys()];
|
|
2564
|
+
} else {
|
|
2565
|
+
ids = messages.map((m) => this.resolveId(m)).filter(Boolean);
|
|
2566
|
+
}
|
|
2567
|
+
yield this.client.api.delete(`/channels/${this.channel.id}/messages/bulk`, {
|
|
2568
|
+
body: JSON.stringify({ ids })
|
|
2569
|
+
});
|
|
2570
|
+
});
|
|
2571
|
+
}
|
|
2572
|
+
/**
|
|
2573
|
+
* delete a message from the channel
|
|
2574
|
+
* @param message The message to delete. Can be a Message object or a message ID.
|
|
2575
|
+
* @returns Promise that resolves when the message is deleted
|
|
2576
|
+
*/
|
|
2577
|
+
delete(message) {
|
|
2578
|
+
return __async(this, null, function* () {
|
|
2579
|
+
const id = this.resolveId(message);
|
|
2580
|
+
if (!id) {
|
|
2581
|
+
throw new TypeError("INVALID_TYPE");
|
|
2582
|
+
}
|
|
2583
|
+
yield this.client.api.delete(`/channels/${this.channel.id}/messages/${id}`);
|
|
2584
|
+
});
|
|
2585
|
+
}
|
|
2586
|
+
/**
|
|
2587
|
+
* edit a message in the channel
|
|
2588
|
+
* @param message The message to edit. Can be a Message object or a message ID.
|
|
2589
|
+
* @param options The options to edit the message with. Can be a string or an object with the following properties:
|
|
2590
|
+
* - content: The new content of the message
|
|
2591
|
+
* - attachments: An array of attachment URLs
|
|
2592
|
+
* - embeds: An array of MessageEmbed objects
|
|
2593
|
+
* @returns Promise that resolves when the message is edited
|
|
2594
|
+
*/
|
|
2595
|
+
edit(message, options) {
|
|
2596
|
+
return __async(this, null, function* () {
|
|
2597
|
+
const id = this.resolveId(message);
|
|
2598
|
+
if (!id) {
|
|
2599
|
+
throw new TypeError("INVALID_TYPE");
|
|
2600
|
+
}
|
|
2601
|
+
if (typeof options === "string") options = { content: options };
|
|
2602
|
+
yield this.client.api.patch(`/channels/${this.channel.id}/messages/${id}`, {
|
|
2603
|
+
body: options
|
|
2604
|
+
});
|
|
2605
|
+
});
|
|
2606
|
+
}
|
|
2607
|
+
/**
|
|
2608
|
+
* search for messages in the channel
|
|
2609
|
+
* @param query The query to search for. Can be a string or an object with the following properties:
|
|
2610
|
+
* - query: The query to search for
|
|
2611
|
+
* - limit: The maximum number of messages to return
|
|
2612
|
+
* - before: The message ID to start searching from (exclusive)
|
|
2613
|
+
* - after: The message ID to stop searching at (exclusive)
|
|
2614
|
+
* - sort: The sort order of the results (asc or desc)
|
|
2615
|
+
* @returns Promise that resolves to a Map of message IDs to Message objects
|
|
2616
|
+
*/
|
|
2617
|
+
search(query) {
|
|
2618
|
+
return __async(this, null, function* () {
|
|
2619
|
+
if (typeof query === "string") query = { query };
|
|
2620
|
+
const response = yield this.client.api.post(
|
|
2621
|
+
`/channels/${this.channel.id}/search`,
|
|
2622
|
+
{
|
|
2623
|
+
query
|
|
2624
|
+
}
|
|
2625
|
+
);
|
|
2626
|
+
return response.reduce((coll, cur) => {
|
|
2627
|
+
const msg = this._add(cur);
|
|
2628
|
+
coll.set(msg.id, msg);
|
|
2629
|
+
return coll;
|
|
2630
|
+
}, /* @__PURE__ */ new Map());
|
|
2631
|
+
});
|
|
2632
|
+
}
|
|
2633
|
+
fetch(query) {
|
|
2634
|
+
return __async(this, null, function* () {
|
|
2635
|
+
const id = this.resolveId(query);
|
|
2636
|
+
if (id) {
|
|
2637
|
+
const data = yield this.client.api.get(
|
|
2638
|
+
`/channels/${this.channel.id}/messages/${id}`
|
|
2639
|
+
);
|
|
2640
|
+
return this._add(data);
|
|
2641
|
+
}
|
|
2642
|
+
if (typeof query === "number") query = { limit: query };
|
|
2643
|
+
else if (typeof query === "undefined") query = { limit: 100 };
|
|
2644
|
+
const messages = yield this.client.api.get(
|
|
2645
|
+
`/channels/${this.channel.id}/messages`,
|
|
2646
|
+
{ query: JSON.stringify(query) }
|
|
2647
|
+
);
|
|
2648
|
+
return messages.reduce((coll, cur) => {
|
|
2649
|
+
const msg = this._add(cur);
|
|
2650
|
+
coll.set(msg.id, msg);
|
|
2651
|
+
return coll;
|
|
2652
|
+
}, /* @__PURE__ */ new Map());
|
|
2653
|
+
});
|
|
2654
|
+
}
|
|
2655
|
+
/**
|
|
2656
|
+
* add a reaction to a message
|
|
2657
|
+
* @param message The message to react to. Can be a Message object or a message ID.
|
|
2658
|
+
* @param emoji emoji to react with. Can be a string or an Emoji object.
|
|
2659
|
+
* @returns Promise that resolves when the reaction is added
|
|
2660
|
+
*/
|
|
2661
|
+
addReaction(message, emoji) {
|
|
2662
|
+
return __async(this, null, function* () {
|
|
2663
|
+
const id = this.resolveId(message);
|
|
2664
|
+
if (!id) {
|
|
2665
|
+
throw new TypeError("INVALID_TYPE");
|
|
2666
|
+
}
|
|
2667
|
+
if (emoji instanceof Emoji2) emoji = emoji.id;
|
|
2668
|
+
else if (typeof emoji !== "string") {
|
|
2669
|
+
throw new TypeError("INVALID_TYPE");
|
|
2670
|
+
}
|
|
2671
|
+
yield this.client.api.put(
|
|
2672
|
+
`/channels/${this.channel.id}/messages/${id}/reactions/${emoji}`
|
|
2673
|
+
);
|
|
2674
|
+
});
|
|
2675
|
+
}
|
|
2676
|
+
/**
|
|
2677
|
+
*
|
|
2678
|
+
* @param message The message to unreact. Can be a Message object or a message ID.
|
|
2679
|
+
* @param emoji the emoji to unreact with. Can be a string or an Emoji object.
|
|
2680
|
+
* @param user_id The user ID to remove the reaction for. If not provided, removes the reaction for the current user.
|
|
2681
|
+
* @param remove_all Whether to remove all of the specified reaction for the message. Defaults to false.
|
|
2682
|
+
* @returns Promise that resolves when the reaction is removed
|
|
2683
|
+
*/
|
|
2684
|
+
removeReaction(message, emoji, user_id, remove_all = false) {
|
|
2685
|
+
return __async(this, null, function* () {
|
|
2686
|
+
const id = this.resolveId(message);
|
|
2687
|
+
if (!id) {
|
|
2688
|
+
throw new TypeError("INVALID_TYPE");
|
|
2689
|
+
}
|
|
2690
|
+
if (emoji instanceof Emoji2) emoji = emoji.id;
|
|
2691
|
+
else if (typeof emoji !== "string") {
|
|
2692
|
+
throw new TypeError("INVALID_TYPE");
|
|
2693
|
+
}
|
|
2694
|
+
const queryString = user_id ? `?user_id=${user_id}&remove_all=${remove_all}` : `?remove_all=${remove_all}`;
|
|
2695
|
+
yield this.client.api.delete(
|
|
2696
|
+
`/channels/${this.channel.id}/messages/${id}/reactions/${emoji}${queryString}`
|
|
2697
|
+
);
|
|
2698
|
+
});
|
|
2699
|
+
}
|
|
2700
|
+
/**
|
|
2701
|
+
* remove all reactions from a message
|
|
2702
|
+
* @param message The message to remove reactions from. Can be a Message object or a message ID.
|
|
2703
|
+
* @returns Promise that resolves when the reactions are removed
|
|
2704
|
+
*/
|
|
2705
|
+
removeAllReactions(message) {
|
|
2706
|
+
return __async(this, null, function* () {
|
|
2707
|
+
const id = this.resolveId(message);
|
|
2708
|
+
if (!id) {
|
|
2709
|
+
throw new TypeError("INVALID_TYPE");
|
|
2710
|
+
}
|
|
2711
|
+
yield this.client.api.delete(
|
|
2712
|
+
`/channels/${this.channel.id}/messages/${id}/reactions`
|
|
2713
|
+
);
|
|
2714
|
+
});
|
|
2715
|
+
}
|
|
2716
|
+
};
|
|
2717
|
+
|
|
2718
|
+
// src/managers/roleManager.ts
|
|
2719
|
+
var RoleManager = class extends BaseManager {
|
|
2720
|
+
constructor(server) {
|
|
2721
|
+
super(server.client);
|
|
2722
|
+
this.server = server;
|
|
2723
|
+
this.holds = Role;
|
|
2724
|
+
}
|
|
2725
|
+
_add(data) {
|
|
2726
|
+
const role = new Role(this.server, data);
|
|
2727
|
+
this.cache.set(role.id, role);
|
|
2728
|
+
return role;
|
|
2729
|
+
}
|
|
2730
|
+
/**
|
|
2731
|
+
* creates a new role in the server
|
|
2732
|
+
* @param name The name of the role to create
|
|
2733
|
+
* @returns
|
|
2734
|
+
*/
|
|
2735
|
+
create(name) {
|
|
2736
|
+
return __async(this, null, function* () {
|
|
2737
|
+
const { id, role } = yield this.client.api.post(`/servers/${this.server.id}/roles`, { body: { name } });
|
|
2738
|
+
return this._add(Object.assign(role, { id }));
|
|
2739
|
+
});
|
|
2740
|
+
}
|
|
2741
|
+
/**
|
|
2742
|
+
* deletes a role from the server
|
|
2743
|
+
* @param role the role to delete
|
|
2744
|
+
* @returns A promise that resolves when the role is deleted
|
|
2745
|
+
*/
|
|
2746
|
+
delete(role) {
|
|
2747
|
+
return __async(this, null, function* () {
|
|
2748
|
+
const id = this.resolveId(role);
|
|
2749
|
+
if (!id) throw new TypeError("INVALID_TYPE");
|
|
2750
|
+
yield this.client.api.delete(`/servers/${this.server.id}/roles/${id}`);
|
|
2751
|
+
});
|
|
2752
|
+
}
|
|
2753
|
+
/**
|
|
2754
|
+
*
|
|
2755
|
+
* @param role the role to edit
|
|
2756
|
+
* @param data data to edit the role with
|
|
2757
|
+
* @param data.permissions The permissions to set for the role, in the format { a: allow, d: deny }
|
|
2758
|
+
* @param data.name The name of the role
|
|
2759
|
+
* @param data.colour The color of the role, or `null` if no color is set
|
|
2760
|
+
* @param data.hoist Whether the role is displayed separately in the member list
|
|
2761
|
+
* @param data.rank The rank of the role, used for ordering
|
|
2762
|
+
* @param data.remove Fields to remove from the role
|
|
2763
|
+
* @returns Role
|
|
2764
|
+
* @throws {TypeError} If the role ID is invalid
|
|
2765
|
+
*/
|
|
2766
|
+
edit(role, data) {
|
|
2767
|
+
return __async(this, null, function* () {
|
|
2768
|
+
var _a, _b;
|
|
2769
|
+
const id = this.resolveId(role);
|
|
2770
|
+
if (!id) throw new TypeError("INVALID_TYPE");
|
|
2771
|
+
if (data.permissions) {
|
|
2772
|
+
const permissions = {
|
|
2773
|
+
allow: new FullPermissions(((_a = data.permissions) == null ? void 0 : _a.a) || []).bitfield,
|
|
2774
|
+
deny: new FullPermissions(((_b = data.permissions) == null ? void 0 : _b.d) || []).bitfield
|
|
2775
|
+
};
|
|
2776
|
+
yield this.client.api.put(
|
|
2777
|
+
`/servers/${this.server.id}/permissions/${id}`,
|
|
2778
|
+
{ body: { permissions } }
|
|
2779
|
+
);
|
|
2780
|
+
}
|
|
2781
|
+
delete data.permissions;
|
|
2782
|
+
const updatedRole = yield this.client.api.patch(
|
|
2783
|
+
`/servers/${this.server.id}/roles/${id}`,
|
|
2784
|
+
{ body: data }
|
|
2785
|
+
);
|
|
2786
|
+
return this._add(Object.assign(updatedRole, { id }));
|
|
2787
|
+
});
|
|
2788
|
+
}
|
|
2789
|
+
};
|
|
2790
|
+
|
|
2791
|
+
// src/managers/serverChannelManager.ts
|
|
2792
|
+
var ServerChannelManager = class extends BaseManager {
|
|
2793
|
+
constructor(server) {
|
|
2794
|
+
super(server.client);
|
|
2795
|
+
this.server = server;
|
|
2796
|
+
this.holds = ServerChannel;
|
|
2797
|
+
}
|
|
2798
|
+
_add(data) {
|
|
2799
|
+
let channel;
|
|
2800
|
+
switch (data.channel_type) {
|
|
2801
|
+
case "TextChannel":
|
|
2802
|
+
channel = new TextChannel2(this.client, data);
|
|
2803
|
+
break;
|
|
2804
|
+
case "VoiceChannel":
|
|
2805
|
+
channel = new VoiceChannel(this.client, data);
|
|
2806
|
+
break;
|
|
2807
|
+
default:
|
|
2808
|
+
throw new Error(
|
|
2809
|
+
`Unknown channel type: ${data.channel_type}`
|
|
2810
|
+
);
|
|
2811
|
+
}
|
|
2812
|
+
this.cache.set(channel.id, channel);
|
|
2813
|
+
return channel;
|
|
2814
|
+
}
|
|
2815
|
+
/**
|
|
2816
|
+
* creates a new channel in the server
|
|
2817
|
+
* @param name The name of the channel to create
|
|
2818
|
+
* @param type The type of the channel to create. Can be "Text" or "Voice". Defaults to "Text".
|
|
2819
|
+
* @param description The description of the channel to create. Only used for voice channels.
|
|
2820
|
+
* @returns A promise that resolves to the created channel
|
|
2821
|
+
*/
|
|
2822
|
+
create(_0) {
|
|
2823
|
+
return __async(this, arguments, function* ({
|
|
2824
|
+
name,
|
|
2825
|
+
type = "Text",
|
|
2826
|
+
description
|
|
2827
|
+
}) {
|
|
2828
|
+
const data = yield this.client.api.post(
|
|
2829
|
+
`/servers/${this.server.id}/channels`,
|
|
2830
|
+
{
|
|
2831
|
+
body: {
|
|
2832
|
+
name,
|
|
2833
|
+
type,
|
|
2834
|
+
description,
|
|
2835
|
+
nonce: UUID.generate()
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
);
|
|
2839
|
+
return this._add(data);
|
|
2840
|
+
});
|
|
2841
|
+
}
|
|
2842
|
+
/**
|
|
2843
|
+
* fetch a channel from the server
|
|
2844
|
+
* @param channel The channel to fetch. Can be a string, a channel object, or an API channel object.
|
|
2845
|
+
* @param force Whether to force fetch the channel from the API. Defaults to true.
|
|
2846
|
+
* If set to false, the method will return the channel from the cache if it exists.
|
|
2847
|
+
* @returns A promise that resolves to the fetched channel
|
|
2848
|
+
*/
|
|
2849
|
+
fetch(_0) {
|
|
2850
|
+
return __async(this, arguments, function* (channel, { force = true } = {}) {
|
|
2851
|
+
const id = this.resolveId(channel);
|
|
2852
|
+
if (!id) {
|
|
2853
|
+
throw new TypeError("INVALID_ID");
|
|
2854
|
+
}
|
|
2855
|
+
if (!force) {
|
|
2856
|
+
const channel2 = this.cache.get(id);
|
|
2857
|
+
if (channel2) return channel2;
|
|
2858
|
+
}
|
|
2859
|
+
const data = yield this.client.api.get(
|
|
2860
|
+
`/servers/${this.server.id}/channels/${id}`
|
|
2861
|
+
);
|
|
2862
|
+
return this._add(data);
|
|
2863
|
+
});
|
|
2864
|
+
}
|
|
2865
|
+
};
|
|
2866
|
+
|
|
2867
|
+
// src/managers/serverMemberManager.ts
|
|
2868
|
+
var ServerMemberManager = class extends BaseManager {
|
|
2869
|
+
constructor(server) {
|
|
2870
|
+
super(server.client);
|
|
2871
|
+
this.server = server;
|
|
2872
|
+
this.holds = ServerMember3;
|
|
2873
|
+
}
|
|
2874
|
+
/**
|
|
2875
|
+
* edit selected member in the server
|
|
2876
|
+
* @param member The member to edit
|
|
2877
|
+
* @param options The options to edit the member with
|
|
2878
|
+
* @param options.nickname The nickname of the member to set
|
|
2879
|
+
* @param options.avatar The avatar of the member to set
|
|
2880
|
+
* @param options.roles The roles of the member to set
|
|
2881
|
+
* @returns A promise that resolves when the member is edited
|
|
2882
|
+
*/
|
|
2883
|
+
edit(member, options) {
|
|
2884
|
+
return __async(this, null, function* () {
|
|
2885
|
+
const id = this.resolveId(member);
|
|
2886
|
+
if (!id) {
|
|
2887
|
+
throw new TypeError("INVALID_TYPE");
|
|
2888
|
+
}
|
|
2889
|
+
yield this.client.api.patch(`/servers/${this.server.id}/members/${id}`, {
|
|
2890
|
+
body: __spreadValues({}, options)
|
|
2891
|
+
});
|
|
2892
|
+
});
|
|
2893
|
+
}
|
|
2894
|
+
/**
|
|
2895
|
+
* ban selected member in the server
|
|
2896
|
+
* @param member The member to ban
|
|
2897
|
+
* @param reason the reason for the ban
|
|
2898
|
+
* @returns A promise that resolves when the member is banned
|
|
2899
|
+
*/
|
|
2900
|
+
ban(member, reason) {
|
|
2901
|
+
return __async(this, null, function* () {
|
|
2902
|
+
const id = this.resolveId(member);
|
|
2903
|
+
if (!id) {
|
|
2904
|
+
throw new TypeError("INVALID_TYPE");
|
|
2905
|
+
}
|
|
2906
|
+
yield this.client.api.put(`/servers/${this.server.id}/bans/${id}`, {
|
|
2907
|
+
body: { reason }
|
|
2908
|
+
});
|
|
2909
|
+
});
|
|
2910
|
+
}
|
|
2911
|
+
/**
|
|
2912
|
+
* kick selected member in the server
|
|
2913
|
+
* @param member The member to kick
|
|
2914
|
+
* @returns A promise that resolves when the member is kicked
|
|
2915
|
+
*/
|
|
2916
|
+
kick(member) {
|
|
2917
|
+
return __async(this, null, function* () {
|
|
2918
|
+
const id = this.resolveId(member);
|
|
2919
|
+
if (!id) {
|
|
2920
|
+
throw new TypeError("INVALID_TYPE");
|
|
2921
|
+
}
|
|
2922
|
+
yield this.client.api.delete(`/servers/${this.server.id}/members/${id}`);
|
|
2923
|
+
});
|
|
2924
|
+
}
|
|
2925
|
+
/**
|
|
2926
|
+
* unban selected member in the server
|
|
2927
|
+
* @param member The member to unban
|
|
2928
|
+
* @returns A promise that resolves when the member is unbanned
|
|
2929
|
+
*/
|
|
2930
|
+
unban(member) {
|
|
2931
|
+
return __async(this, null, function* () {
|
|
2932
|
+
const id = this.resolveId(member);
|
|
2933
|
+
if (!id) {
|
|
2934
|
+
throw new TypeError("INVALID_TYPE");
|
|
2935
|
+
}
|
|
2936
|
+
yield this.client.api.delete(`/servers/${this.server.id}/bans/${id}`);
|
|
2937
|
+
});
|
|
2938
|
+
}
|
|
2939
|
+
fetch(member) {
|
|
2940
|
+
return __async(this, null, function* () {
|
|
2941
|
+
if (typeof member !== "undefined") {
|
|
2942
|
+
const id = this.resolveId(member);
|
|
2943
|
+
if (!id) {
|
|
2944
|
+
throw new TypeError("INVALID_TYPE");
|
|
2945
|
+
}
|
|
2946
|
+
const data = yield this.client.api.get(
|
|
2947
|
+
`/servers/${this.server.id}/members/${id}`
|
|
2948
|
+
);
|
|
2949
|
+
return this._add(data);
|
|
2950
|
+
}
|
|
2951
|
+
const { users, members } = yield this.client.api.get(`/servers/${this.server.id}/members`);
|
|
2952
|
+
users.reduce((coll, cur) => {
|
|
2953
|
+
const user = this.client.users._add(cur);
|
|
2954
|
+
coll.set(user.id, user);
|
|
2955
|
+
return coll;
|
|
2956
|
+
}, this.client.users.cache);
|
|
2957
|
+
return members.reduce((coll, cur) => {
|
|
2958
|
+
const member2 = this._add(cur);
|
|
2959
|
+
coll.set(member2.id, member2);
|
|
2960
|
+
return coll;
|
|
2961
|
+
}, /* @__PURE__ */ new Map());
|
|
2962
|
+
});
|
|
2963
|
+
}
|
|
2964
|
+
/**
|
|
2965
|
+
* resolves a member from a string or a member object
|
|
2966
|
+
* @param member The member to resolve
|
|
2967
|
+
* @returns The id of the member or null if it cannot be resolved
|
|
2968
|
+
*/
|
|
2969
|
+
resolveId(member) {
|
|
2970
|
+
if (member == null) return null;
|
|
2971
|
+
if (member instanceof ServerMember3 || member instanceof User) {
|
|
2972
|
+
return member.id;
|
|
2973
|
+
}
|
|
2974
|
+
if (typeof member === "string") return member;
|
|
2975
|
+
if ("_id" in member) return member._id.user;
|
|
2976
|
+
return null;
|
|
2977
|
+
}
|
|
2978
|
+
};
|
|
2979
|
+
|
|
2980
|
+
// src/client/baseClient.ts
|
|
2981
|
+
var import_node_events = require("events");
|
|
2982
|
+
|
|
2983
|
+
// src/rest/restClient.ts
|
|
2984
|
+
var import_axios4 = require("axios");
|
|
2985
|
+
|
|
2986
|
+
// package.json
|
|
2987
|
+
var version = "0.0.15-build-test";
|
|
2988
|
+
|
|
2989
|
+
// src/rest/restUtils/rateLimitQueue.ts
|
|
2990
|
+
var import_axios3 = __toESM(require("axios"), 1);
|
|
2991
|
+
var RateLimitQueue = class {
|
|
2992
|
+
constructor() {
|
|
2993
|
+
this.bucketMap = /* @__PURE__ */ new Map();
|
|
2994
|
+
this.pathToBucket = /* @__PURE__ */ new Map();
|
|
2995
|
+
}
|
|
2996
|
+
request(config) {
|
|
2997
|
+
return __async(this, null, function* () {
|
|
2998
|
+
const path = config.url;
|
|
2999
|
+
const bucketId = this.pathToBucket.get(path);
|
|
3000
|
+
let bucket = bucketId ? this.bucketMap.get(bucketId) : void 0;
|
|
3001
|
+
if (bucket && bucket.remaining <= 0 && Date.now() < bucket.resetAfter) {
|
|
3002
|
+
return new Promise((resolve, reject) => {
|
|
3003
|
+
bucket.queue.push(() => __async(this, null, function* () {
|
|
3004
|
+
try {
|
|
3005
|
+
const res = yield this._doRequest(config, path);
|
|
3006
|
+
resolve(res);
|
|
3007
|
+
} catch (e) {
|
|
3008
|
+
reject(e);
|
|
3009
|
+
}
|
|
3010
|
+
}));
|
|
3011
|
+
});
|
|
3012
|
+
} else {
|
|
3013
|
+
return this._doRequest(config, path);
|
|
3014
|
+
}
|
|
3015
|
+
});
|
|
3016
|
+
}
|
|
3017
|
+
_doRequest(config, path) {
|
|
3018
|
+
return __async(this, null, function* () {
|
|
3019
|
+
const response = yield (0, import_axios3.default)(config);
|
|
3020
|
+
this._updateRateLimit(path, response);
|
|
3021
|
+
return response;
|
|
3022
|
+
});
|
|
3023
|
+
}
|
|
3024
|
+
_updateRateLimit(path, response) {
|
|
3025
|
+
const headers = response.headers;
|
|
3026
|
+
const limit = parseInt(headers["x-ratelimit-limit"]);
|
|
3027
|
+
const remaining = parseInt(headers["x-ratelimit-remaining"]);
|
|
3028
|
+
const resetAfter = parseFloat(headers["x-ratelimit-reset-after"]) * 1e3 + Date.now();
|
|
3029
|
+
const bucket = headers["x-ratelimit-bucket"];
|
|
3030
|
+
const resetIn = parseInt(headers["x-ratelimit-reset-after"]);
|
|
3031
|
+
if (!bucket) return;
|
|
3032
|
+
this.pathToBucket.set(path, bucket);
|
|
3033
|
+
let state = this.bucketMap.get(bucket);
|
|
3034
|
+
if (!state) {
|
|
3035
|
+
state = {
|
|
3036
|
+
limit,
|
|
3037
|
+
remaining,
|
|
3038
|
+
resetAfter,
|
|
3039
|
+
bucket,
|
|
3040
|
+
resetIn,
|
|
3041
|
+
queue: [],
|
|
3042
|
+
lastPath: path
|
|
3043
|
+
};
|
|
3044
|
+
this.bucketMap.set(bucket, state);
|
|
3045
|
+
} else {
|
|
3046
|
+
state.limit = limit;
|
|
3047
|
+
state.remaining = remaining;
|
|
3048
|
+
state.resetAfter = resetAfter;
|
|
3049
|
+
state.lastPath = path;
|
|
3050
|
+
}
|
|
3051
|
+
if (remaining <= 0) {
|
|
3052
|
+
if (state.resetTimeout) clearTimeout(state.resetTimeout);
|
|
3053
|
+
const delay = resetIn;
|
|
3054
|
+
state.resetTimeout = setTimeout(() => {
|
|
3055
|
+
state.remaining = state.limit;
|
|
3056
|
+
state.resetTimeout = void 0;
|
|
3057
|
+
while (state.queue.length > 0 && state.remaining > 0) {
|
|
3058
|
+
const fn = state.queue.shift();
|
|
3059
|
+
if (fn) {
|
|
3060
|
+
state.remaining--;
|
|
3061
|
+
fn();
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
}, delay);
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
};
|
|
3068
|
+
|
|
3069
|
+
// src/rest/restClient.ts
|
|
3070
|
+
var RestClient = class {
|
|
3071
|
+
constructor(client3) {
|
|
3072
|
+
this.client = client3;
|
|
3073
|
+
this.rateLimitQueue = new RateLimitQueue();
|
|
3074
|
+
}
|
|
3075
|
+
/**
|
|
3076
|
+
* Helper function to handle API requests.
|
|
3077
|
+
* @param method The HTTP method (GET, POST, PATCH, PUT, DELETE).
|
|
3078
|
+
* @param url The URL for the request.
|
|
3079
|
+
* @param body The request body (if applicable).
|
|
3080
|
+
* @param query Query parameters (if applicable).
|
|
3081
|
+
* @returns The API response.
|
|
3082
|
+
*/
|
|
3083
|
+
request(method, url, body, query, retry) {
|
|
3084
|
+
return __async(this, null, function* () {
|
|
3085
|
+
var _a;
|
|
3086
|
+
try {
|
|
3087
|
+
if (!this.client.token) throw new Error("Token is required");
|
|
3088
|
+
const authHeader = this.client.bot ? "X-Bot-Token" : "X-Session-Token";
|
|
3089
|
+
const config = __spreadProps(__spreadValues({}, {
|
|
3090
|
+
method,
|
|
3091
|
+
url: `${apiUrl}${url}`,
|
|
3092
|
+
params: query,
|
|
3093
|
+
data: body == null ? void 0 : body.body,
|
|
3094
|
+
headers: {
|
|
3095
|
+
[authHeader]: this.client.token,
|
|
3096
|
+
"User-Agent": `RevBot.js/${version}`
|
|
3097
|
+
}
|
|
3098
|
+
}), {
|
|
3099
|
+
url: `${apiUrl}${url}`
|
|
3100
|
+
});
|
|
3101
|
+
const response = yield this.rateLimitQueue.request(config);
|
|
3102
|
+
return response.data;
|
|
3103
|
+
} catch (error) {
|
|
3104
|
+
if (retry) throw typeof error;
|
|
3105
|
+
if (error instanceof import_axios4.AxiosError) {
|
|
3106
|
+
if (error.status && (error.status === 429 || error.status >= 500)) {
|
|
3107
|
+
return this.retryRequest(0, method, url, body, query);
|
|
3108
|
+
}
|
|
3109
|
+
if (error.status) {
|
|
3110
|
+
throw new Error(
|
|
3111
|
+
`API call failed with status ${error.status}: ${(_a = error.response) == null ? void 0 : _a.statusText}`
|
|
3112
|
+
);
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
throw new Error(
|
|
3116
|
+
`API call failed: ${error instanceof Error ? error.message : error}`
|
|
3117
|
+
);
|
|
3118
|
+
}
|
|
3119
|
+
});
|
|
3120
|
+
}
|
|
3121
|
+
retryRequest(attempt = 0, method, url, body, query) {
|
|
3122
|
+
return __async(this, null, function* () {
|
|
3123
|
+
var _a, _b;
|
|
3124
|
+
if (attempt >= ((_b = (_a = this.client.options.rest) == null ? void 0 : _a.retries) != null ? _b : 3)) {
|
|
3125
|
+
throw new Error("Max retries reached");
|
|
3126
|
+
}
|
|
3127
|
+
try {
|
|
3128
|
+
return yield this.request(method, url, body, query, true);
|
|
3129
|
+
} catch (error) {
|
|
3130
|
+
console.warn(`Attempt ${attempt + 1} failed:`, error);
|
|
3131
|
+
yield new Promise(
|
|
3132
|
+
(resolve) => {
|
|
3133
|
+
var _a2, _b2, _c;
|
|
3134
|
+
return setTimeout(
|
|
3135
|
+
resolve,
|
|
3136
|
+
(_c = (_a2 = this.client.options.rest) == null ? void 0 : _a2.timeout) != null ? _c : (_b2 = DEFAULT_CLIENT_OPTIONS.rest) == null ? void 0 : _b2.timeout
|
|
3137
|
+
);
|
|
3138
|
+
}
|
|
3139
|
+
);
|
|
3140
|
+
return this.retryRequest(attempt + 1, method, url, body, query);
|
|
3141
|
+
}
|
|
3142
|
+
});
|
|
3143
|
+
}
|
|
3144
|
+
/**
|
|
3145
|
+
* GET request.
|
|
3146
|
+
* @param url The URL for the request.
|
|
3147
|
+
* @param query Query parameters (if applicable).
|
|
3148
|
+
* @returns The API response.
|
|
3149
|
+
*/
|
|
3150
|
+
get(url, query) {
|
|
3151
|
+
return __async(this, null, function* () {
|
|
3152
|
+
return this.request("GET", url, void 0, query);
|
|
3153
|
+
});
|
|
3154
|
+
}
|
|
3155
|
+
/**
|
|
3156
|
+
* POST request.
|
|
3157
|
+
* @param url The URL for the request.
|
|
3158
|
+
* @param body The request body.
|
|
3159
|
+
* @param query Query parameters (if applicable).
|
|
3160
|
+
* @returns The API response.
|
|
3161
|
+
*/
|
|
3162
|
+
post(url, body, query) {
|
|
3163
|
+
return __async(this, null, function* () {
|
|
3164
|
+
return this.request("POST", url, body, query);
|
|
3165
|
+
});
|
|
3166
|
+
}
|
|
3167
|
+
/**
|
|
3168
|
+
* PATCH request.
|
|
3169
|
+
* @param url The URL for the request.
|
|
3170
|
+
* @param body The request body.
|
|
3171
|
+
* @param query Query parameters (if applicable).
|
|
3172
|
+
* @returns The API response.
|
|
3173
|
+
*/
|
|
3174
|
+
patch(url, body, query) {
|
|
3175
|
+
return __async(this, null, function* () {
|
|
3176
|
+
return this.request("PATCH", url, body, query);
|
|
3177
|
+
});
|
|
3178
|
+
}
|
|
3179
|
+
/**
|
|
3180
|
+
* PUT request.
|
|
3181
|
+
* @param url The URL for the request.
|
|
3182
|
+
* @param body The request body.
|
|
3183
|
+
* @param query Query parameters (if applicable).
|
|
3184
|
+
* @returns The API response.
|
|
3185
|
+
*/
|
|
3186
|
+
put(url, body, query) {
|
|
3187
|
+
return __async(this, null, function* () {
|
|
3188
|
+
return this.request("PUT", url, body, query);
|
|
3189
|
+
});
|
|
3190
|
+
}
|
|
3191
|
+
/**
|
|
3192
|
+
* DELETE request.
|
|
3193
|
+
* @param url The URL for the request.
|
|
3194
|
+
* @param query Query parameters (if applicable).
|
|
3195
|
+
* @returns The API response.
|
|
3196
|
+
*/
|
|
3197
|
+
delete(url, body, query) {
|
|
3198
|
+
return __async(this, null, function* () {
|
|
3199
|
+
return this.request("DELETE", url, body, query);
|
|
3200
|
+
});
|
|
3201
|
+
}
|
|
3202
|
+
};
|
|
3203
|
+
|
|
3204
|
+
// src/rest/CDNClient.ts
|
|
3205
|
+
var import_axios5 = require("axios");
|
|
3206
|
+
var CDNClient = class {
|
|
3207
|
+
constructor(client3) {
|
|
3208
|
+
this.client = client3;
|
|
3209
|
+
this.rateLimitQueue = new RateLimitQueue();
|
|
3210
|
+
}
|
|
3211
|
+
/**
|
|
3212
|
+
* Helper function to handle API requests.
|
|
3213
|
+
* @param method The HTTP method (GET, POST, PATCH, PUT, DELETE).
|
|
3214
|
+
* @param url The URL for the request.
|
|
3215
|
+
* @param body The request body (if applicable).
|
|
3216
|
+
* @param query Query parameters (if applicable).
|
|
3217
|
+
* @returns The API response.
|
|
3218
|
+
*/
|
|
3219
|
+
request(method, url, data, query, retry) {
|
|
3220
|
+
return __async(this, null, function* () {
|
|
3221
|
+
try {
|
|
3222
|
+
if (!this.client.token) throw new Error("Token is required");
|
|
3223
|
+
const authHeader = this.client.bot ? "X-Bot-Token" : "X-Session-Token";
|
|
3224
|
+
const config = __spreadProps(__spreadValues({}, {
|
|
3225
|
+
method,
|
|
3226
|
+
url: `${cdnUrl}${url}`,
|
|
3227
|
+
params: query,
|
|
3228
|
+
data,
|
|
3229
|
+
maxBodyLength: Infinity,
|
|
3230
|
+
headers: __spreadValues({
|
|
3231
|
+
[authHeader]: this.client.token,
|
|
3232
|
+
"Content-Type": "multipart/form-data",
|
|
3233
|
+
"User-Agent": `RevBot.js/${version}`
|
|
3234
|
+
}, data.getHeaders())
|
|
3235
|
+
}), {
|
|
3236
|
+
url: `${cdnUrl}${url}`
|
|
3237
|
+
});
|
|
3238
|
+
const response = yield this.rateLimitQueue.request(config);
|
|
3239
|
+
return response.data;
|
|
3240
|
+
} catch (error) {
|
|
3241
|
+
if (retry) throw typeof error;
|
|
3242
|
+
if (error instanceof import_axios5.AxiosError) {
|
|
3243
|
+
if (error.status && (error.status === 429 || error.status >= 500)) {
|
|
3244
|
+
return this.retryRequest(0, method, url, data, query);
|
|
3245
|
+
}
|
|
3246
|
+
if (error.status) {
|
|
3247
|
+
console.error(`API call failed with status ${error.status}:`, error);
|
|
3248
|
+
throw new Error(
|
|
3249
|
+
`API call failed with status ${error.status}: ${error.message}`
|
|
3250
|
+
);
|
|
3251
|
+
}
|
|
3252
|
+
}
|
|
3253
|
+
throw new Error(
|
|
3254
|
+
`API call failed: ${error instanceof Error ? error.message : error}`
|
|
3255
|
+
);
|
|
3256
|
+
}
|
|
3257
|
+
});
|
|
3258
|
+
}
|
|
3259
|
+
retryRequest(attempt = 0, method, url, body, query) {
|
|
3260
|
+
return __async(this, null, function* () {
|
|
3261
|
+
var _a, _b;
|
|
3262
|
+
if (attempt >= ((_b = (_a = this.client.options.rest) == null ? void 0 : _a.retries) != null ? _b : 3)) {
|
|
3263
|
+
throw new Error("Max retries reached");
|
|
3264
|
+
}
|
|
3265
|
+
try {
|
|
3266
|
+
return yield this.request(method, url, body, query, true);
|
|
3267
|
+
} catch (error) {
|
|
3268
|
+
console.warn(`Attempt ${attempt + 1} failed:`, error);
|
|
3269
|
+
yield new Promise(
|
|
3270
|
+
(resolve) => {
|
|
3271
|
+
var _a2, _b2, _c;
|
|
3272
|
+
return setTimeout(
|
|
3273
|
+
resolve,
|
|
3274
|
+
(_c = (_a2 = this.client.options.rest) == null ? void 0 : _a2.timeout) != null ? _c : (_b2 = DEFAULT_CLIENT_OPTIONS.rest) == null ? void 0 : _b2.timeout
|
|
3275
|
+
);
|
|
3276
|
+
}
|
|
3277
|
+
);
|
|
3278
|
+
return this.retryRequest(attempt + 1, method, url, body, query);
|
|
3279
|
+
}
|
|
3280
|
+
});
|
|
3281
|
+
}
|
|
3282
|
+
/**
|
|
3283
|
+
* POST request.
|
|
3284
|
+
* @param url The URL for the request.
|
|
3285
|
+
* @param data The request body.
|
|
3286
|
+
* @param query Query parameters (if applicable).
|
|
3287
|
+
* @returns The API response.
|
|
3288
|
+
*/
|
|
3289
|
+
post(url, data) {
|
|
3290
|
+
return __async(this, null, function* () {
|
|
3291
|
+
return this.request("POST", url, data);
|
|
3292
|
+
});
|
|
3293
|
+
}
|
|
3294
|
+
};
|
|
3295
|
+
|
|
3296
|
+
// src/client/baseClient.ts
|
|
3297
|
+
var _token;
|
|
3298
|
+
var BaseClient = class extends import_node_events.EventEmitter {
|
|
3299
|
+
/**
|
|
3300
|
+
* Creates a new BaseClient instance.
|
|
3301
|
+
*
|
|
3302
|
+
* @param {clientOptions} [options={}] - The options for configuring the client.
|
|
3303
|
+
*/
|
|
3304
|
+
constructor(options = {}) {
|
|
3305
|
+
var _a;
|
|
3306
|
+
super();
|
|
3307
|
+
/** The authentication token for the client. */
|
|
3308
|
+
__privateAdd(this, _token, null);
|
|
3309
|
+
/** Whether the client is a bot. */
|
|
3310
|
+
this.bot = true;
|
|
3311
|
+
this.options = __spreadValues(__spreadValues({}, DEFAULT_CLIENT_OPTIONS), options);
|
|
3312
|
+
this.bot = (_a = this.options.isBot) != null ? _a : true;
|
|
3313
|
+
this.api = new RestClient(this);
|
|
3314
|
+
this.cdn = new CDNClient(this);
|
|
3315
|
+
}
|
|
3316
|
+
/**
|
|
3317
|
+
* Emits a debug message.
|
|
3318
|
+
*
|
|
3319
|
+
* @param {unknown} msg - The debug message to emit.
|
|
3320
|
+
*/
|
|
3321
|
+
debug(msg) {
|
|
3322
|
+
this.emit("debug" /* DEBUG */, msg);
|
|
3323
|
+
}
|
|
3324
|
+
/**
|
|
3325
|
+
* Sets the authentication token for the client.
|
|
3326
|
+
*
|
|
3327
|
+
* @param {string | null} token - The authentication token.
|
|
3328
|
+
*/
|
|
3329
|
+
set token(token) {
|
|
3330
|
+
__privateSet(this, _token, token);
|
|
3331
|
+
}
|
|
3332
|
+
/**
|
|
3333
|
+
* Gets the authentication token for the client.
|
|
3334
|
+
*
|
|
3335
|
+
* @returns {string | null} The authentication token, or `null` if not set.
|
|
3336
|
+
*/
|
|
3337
|
+
get token() {
|
|
3338
|
+
return __privateGet(this, _token);
|
|
3339
|
+
}
|
|
3340
|
+
};
|
|
3341
|
+
_token = new WeakMap();
|
|
3342
|
+
|
|
3343
|
+
// src/client/events/index.ts
|
|
3344
|
+
var events_exports = {};
|
|
3345
|
+
__export(events_exports, {
|
|
3346
|
+
BulkMessageDelete: () => BulkMessageDelete,
|
|
3347
|
+
ChannelCreate: () => ChannelCreate,
|
|
3348
|
+
ChannelDelete: () => ChannelDelete,
|
|
3349
|
+
ChannelGroupJoin: () => ChannelGroupJoin,
|
|
3350
|
+
ChannelGroupLeave: () => ChannelGroupLeave,
|
|
3351
|
+
ChannelStartTyping: () => ChannelStartTyping,
|
|
3352
|
+
ChannelStopTyping: () => ChannelStopTyping,
|
|
3353
|
+
ChannelUpdate: () => ChannelUpdate,
|
|
3354
|
+
Message: () => Message6,
|
|
3355
|
+
MessageDelete: () => MessageDelete,
|
|
3356
|
+
MessageReact: () => MessageReact,
|
|
3357
|
+
MessageUnreact: () => MessageUnreact,
|
|
3358
|
+
MessageUpdate: () => MessageUpdate,
|
|
3359
|
+
ServerCreate: () => ServerCreate,
|
|
3360
|
+
ServerDelete: () => ServerDelete,
|
|
3361
|
+
ServerMemberJoin: () => ServerMemberJoin,
|
|
3362
|
+
ServerMemberLeave: () => ServerMemberLeave,
|
|
3363
|
+
ServerMemberUpdate: () => ServerMemberUpdate,
|
|
3364
|
+
ServerRoleDelete: () => ServerRoleDelete,
|
|
3365
|
+
ServerRoleUpdate: () => ServerRoleUpdate,
|
|
3366
|
+
ServerUpdate: () => ServerUpdate,
|
|
3367
|
+
UserUpdate: () => UserUpdate
|
|
3368
|
+
});
|
|
3369
|
+
|
|
3370
|
+
// src/client/events/event.ts
|
|
3371
|
+
var Event = class {
|
|
3372
|
+
/**
|
|
3373
|
+
* Creates a new Event instance.
|
|
3374
|
+
*
|
|
3375
|
+
* @param {client} client - The client instance.
|
|
3376
|
+
*/
|
|
3377
|
+
constructor(client3) {
|
|
3378
|
+
this.client = client3;
|
|
3379
|
+
}
|
|
3380
|
+
};
|
|
3381
|
+
|
|
3382
|
+
// src/client/events/bulkMessageDelete.ts
|
|
3383
|
+
var BulkMessageDelete = class extends Event {
|
|
3384
|
+
/**
|
|
3385
|
+
* Handles the bulk message delete event.
|
|
3386
|
+
*
|
|
3387
|
+
* @param {{ ids: string[] }} data - The data for the event, containing the IDs of the deleted messages.
|
|
3388
|
+
*/
|
|
3389
|
+
handle(data) {
|
|
3390
|
+
this.client.emit("messageDeleteBulk" /* MESSAGE_DELETE_BULK */, data.ids);
|
|
3391
|
+
}
|
|
3392
|
+
};
|
|
3393
|
+
|
|
3394
|
+
// src/client/events/channelCreate.ts
|
|
3395
|
+
var ChannelCreate = class extends Event {
|
|
3396
|
+
/**
|
|
3397
|
+
* Handles the channel creation event.
|
|
3398
|
+
*
|
|
3399
|
+
* @param {API.Channel} data - The raw data for the created channel from the API.
|
|
3400
|
+
* @returns {Promise<{ channel: unknown }>} A promise that resolves with the created channel.
|
|
3401
|
+
*/
|
|
3402
|
+
handle(data) {
|
|
3403
|
+
return __async(this, null, function* () {
|
|
3404
|
+
var _a;
|
|
3405
|
+
const channel = this.client.channels._add(data);
|
|
3406
|
+
if (channel) {
|
|
3407
|
+
if (channel.inServer()) {
|
|
3408
|
+
const server = (_a = channel.server) != null ? _a : yield this.client.servers.fetch(channel.serverId);
|
|
3409
|
+
server.channels.cache.set(channel.id, channel);
|
|
3410
|
+
}
|
|
3411
|
+
this.client.emit("channelCreate" /* CHANNEL_CREATE */, channel);
|
|
3412
|
+
}
|
|
3413
|
+
return { channel };
|
|
3414
|
+
});
|
|
3415
|
+
}
|
|
3416
|
+
};
|
|
3417
|
+
|
|
3418
|
+
// src/client/events/channelDelete.ts
|
|
3419
|
+
var ChannelDelete = class extends Event {
|
|
3420
|
+
/**
|
|
3421
|
+
* Handles the channel deletion event.
|
|
3422
|
+
*
|
|
3423
|
+
* @param {{ id: string }} data - The data for the event, containing the ID of the deleted channel.
|
|
3424
|
+
* @returns {{ channel: unknown }} An object containing the deleted channel, or `undefined` if not found.
|
|
3425
|
+
*/
|
|
3426
|
+
handle(data) {
|
|
3427
|
+
var _a;
|
|
3428
|
+
const channel = this.client.channels.cache.get(data.id);
|
|
3429
|
+
if (channel) {
|
|
3430
|
+
if (channel.inServer()) {
|
|
3431
|
+
(_a = channel.server) == null ? void 0 : _a.channels.cache.delete(channel.id);
|
|
3432
|
+
}
|
|
3433
|
+
this.client.emit("channelDelete" /* CHANNEL_DELETE */, channel);
|
|
3434
|
+
}
|
|
3435
|
+
return { channel };
|
|
3436
|
+
}
|
|
3437
|
+
};
|
|
3438
|
+
|
|
3439
|
+
// src/client/events/channelGroupJoin.ts
|
|
3440
|
+
var ChannelGroupJoin = class extends Event {
|
|
3441
|
+
/**
|
|
3442
|
+
* Handles the group channel join event.
|
|
3443
|
+
*
|
|
3444
|
+
* @param {{ id: string; user: string }} data - The data for the event, containing the channel ID and user ID.
|
|
3445
|
+
* @returns {Promise<{ channel: unknown; user: unknown }>} A promise that resolves with the updated channel and user.
|
|
3446
|
+
*/
|
|
3447
|
+
handle(data) {
|
|
3448
|
+
return __async(this, null, function* () {
|
|
3449
|
+
const channel = this.client.channels.cache.get(data.id);
|
|
3450
|
+
const user = yield this.client.users.fetch(data.user, { force: false });
|
|
3451
|
+
if (channel == null ? void 0 : channel.isGroup()) {
|
|
3452
|
+
channel.users.set(user.id, user);
|
|
3453
|
+
this.client.emit("groupJoin" /* GROUP_JOIN */, channel, user);
|
|
3454
|
+
}
|
|
3455
|
+
return { channel, user };
|
|
3456
|
+
});
|
|
3457
|
+
}
|
|
3458
|
+
};
|
|
3459
|
+
|
|
3460
|
+
// src/client/events/channelGroupLeave.ts
|
|
3461
|
+
var ChannelGroupLeave = class extends Event {
|
|
3462
|
+
/**
|
|
3463
|
+
* Handles the group channel leave event.
|
|
3464
|
+
*
|
|
3465
|
+
* @param {{ id: string; user: string }} data - The data for the event, containing the channel ID and user ID.
|
|
3466
|
+
* @returns {Promise<{ channel: unknown; user: unknown }>} A promise that resolves with the updated channel and user.
|
|
3467
|
+
*/
|
|
3468
|
+
handle(data) {
|
|
3469
|
+
return __async(this, null, function* () {
|
|
3470
|
+
const channel = this.client.channels.cache.get(data.id);
|
|
3471
|
+
const user = yield this.client.users.fetch(data.user, { force: false });
|
|
3472
|
+
if (channel == null ? void 0 : channel.isGroup()) {
|
|
3473
|
+
channel.users.delete(data.user);
|
|
3474
|
+
this.client.emit("groupLeave" /* GROUP_LEAVE */, channel, user);
|
|
3475
|
+
}
|
|
3476
|
+
return { channel, user };
|
|
3477
|
+
});
|
|
3478
|
+
}
|
|
3479
|
+
};
|
|
3480
|
+
|
|
3481
|
+
// src/client/events/channelStarttyping.ts
|
|
3482
|
+
var ChannelStartTyping = class extends Event {
|
|
3483
|
+
/**
|
|
3484
|
+
* Handles the typing start event.
|
|
3485
|
+
*
|
|
3486
|
+
* @param {{ id: string; user: string }} data - The data for the event, containing the channel ID and user ID.
|
|
3487
|
+
* @returns {{ channel: unknown; user: unknown }} An object containing the channel and user involved in the event.
|
|
3488
|
+
*/
|
|
3489
|
+
handle(data) {
|
|
3490
|
+
const channel = this.client.channels.cache.get(data.id);
|
|
3491
|
+
const user = this.client.users.cache.get(data.user);
|
|
3492
|
+
if ((channel == null ? void 0 : channel.isText()) && user) {
|
|
3493
|
+
this.client.emit("typingStart" /* TYPING_START */, channel, user);
|
|
3494
|
+
}
|
|
3495
|
+
return { channel, user };
|
|
3496
|
+
}
|
|
3497
|
+
};
|
|
3498
|
+
|
|
3499
|
+
// src/client/events/channelStopTyping.ts
|
|
3500
|
+
var ChannelStopTyping = class extends Event {
|
|
3501
|
+
/**
|
|
3502
|
+
* Handles the typing stop event.
|
|
3503
|
+
*
|
|
3504
|
+
* @param {{ id: string; user: string }} data - The data for the event, containing the channel ID and user ID.
|
|
3505
|
+
* @returns {{ channel: unknown; user: unknown }} An object containing the channel and user involved in the event.
|
|
3506
|
+
*/
|
|
3507
|
+
handle(data) {
|
|
3508
|
+
const channel = this.client.channels.cache.get(data.id);
|
|
3509
|
+
const user = this.client.users.cache.get(data.user);
|
|
3510
|
+
if ((channel == null ? void 0 : channel.isText()) && user) {
|
|
3511
|
+
this.client.emit("typingStop" /* TYPING_STOP */, channel, user);
|
|
3512
|
+
}
|
|
3513
|
+
return { channel, user };
|
|
3514
|
+
}
|
|
3515
|
+
};
|
|
3516
|
+
|
|
3517
|
+
// src/client/events/channelUpdate.ts
|
|
3518
|
+
var ChannelUpdate = class extends Event {
|
|
3519
|
+
/**
|
|
3520
|
+
* Handles the channel update event.
|
|
3521
|
+
*
|
|
3522
|
+
* @param {{ id: string; data: API.Channel; clear: API.FieldsChannel }} data - The data for the event, containing the channel ID, updated data, and fields to clear.
|
|
3523
|
+
* @returns {void}
|
|
3524
|
+
*/
|
|
3525
|
+
handle(data) {
|
|
3526
|
+
const channel = this.client.channels.cache.get(data.id);
|
|
3527
|
+
const oldChannel = channel == null ? void 0 : channel._update(data.data);
|
|
3528
|
+
if (channel && oldChannel && !channel.equals(oldChannel)) {
|
|
3529
|
+
this.client.emit("channelUpdate" /* CHANNEL_UPDATE */, oldChannel, channel);
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
};
|
|
3533
|
+
|
|
3534
|
+
// src/client/events/message.ts
|
|
3535
|
+
var Message6 = class extends Event {
|
|
3536
|
+
/**
|
|
3537
|
+
* Handles the message event.
|
|
3538
|
+
*
|
|
3539
|
+
* @param {API.Message} data - The raw data for the message from the API.
|
|
3540
|
+
* @returns {Promise<{ message: unknown }>} A promise that resolves with the created message, or an empty object if the channel is not text-based.
|
|
3541
|
+
*/
|
|
3542
|
+
handle(data) {
|
|
3543
|
+
return __async(this, null, function* () {
|
|
3544
|
+
const channel = this.client.channels.cache.get(data.channel);
|
|
3545
|
+
if (channel == null ? void 0 : channel.isText()) {
|
|
3546
|
+
const message = channel.messages._add(data);
|
|
3547
|
+
if (data.author !== SYSTEM_USER_ID && !data.webhook) {
|
|
3548
|
+
yield this.client.users.fetch(data.author, { force: false });
|
|
3549
|
+
}
|
|
3550
|
+
this.client.emit("message" /* MESSAGE */, message);
|
|
3551
|
+
return { message };
|
|
3552
|
+
}
|
|
3553
|
+
return {};
|
|
3554
|
+
});
|
|
3555
|
+
}
|
|
3556
|
+
};
|
|
3557
|
+
|
|
3558
|
+
// src/client/events/messageDelete.ts
|
|
3559
|
+
var MessageDelete = class extends Event {
|
|
3560
|
+
/**
|
|
3561
|
+
* Handles the message deletion event.
|
|
3562
|
+
*
|
|
3563
|
+
* @param {{ id: string; channel: string }} data - The data for the event, containing the message ID and channel ID.
|
|
3564
|
+
* @returns {{ message: unknown } | {}} An object containing the deleted message, or an empty object if the channel is not text-based or the message is not found.
|
|
3565
|
+
*/
|
|
3566
|
+
handle(data) {
|
|
3567
|
+
const channel = this.client.channels.cache.get(data.channel);
|
|
3568
|
+
if (channel == null ? void 0 : channel.isText()) {
|
|
3569
|
+
const message = channel.messages.cache.get(data.id);
|
|
3570
|
+
if (message) {
|
|
3571
|
+
channel.messages._remove(message.id);
|
|
3572
|
+
this.client.emit("messageDelete" /* MESSAGE_DELETE */, message);
|
|
3573
|
+
}
|
|
3574
|
+
return { message };
|
|
3575
|
+
}
|
|
3576
|
+
return {};
|
|
3577
|
+
}
|
|
3578
|
+
};
|
|
3579
|
+
|
|
3580
|
+
// src/client/events/messageUpdate.ts
|
|
3581
|
+
var MessageUpdate = class extends Event {
|
|
3582
|
+
/**
|
|
3583
|
+
* Handles the message update event.
|
|
3584
|
+
*
|
|
3585
|
+
* @param {{ id: string; channel: string; data: API.Message }} data - The data for the event, containing the message ID, channel ID, and updated message data.
|
|
3586
|
+
* @returns {void}
|
|
3587
|
+
*/
|
|
3588
|
+
handle(data) {
|
|
3589
|
+
const channel = this.client.channels.cache.get(data.channel);
|
|
3590
|
+
if (!(channel == null ? void 0 : channel.isText())) return;
|
|
3591
|
+
const message = channel == null ? void 0 : channel.messages.cache.get(data.id);
|
|
3592
|
+
const oldMessage = message == null ? void 0 : message._update(data.data);
|
|
3593
|
+
if (oldMessage && message && !message.equals(oldMessage)) {
|
|
3594
|
+
this.client.emit("messageUpdate" /* MESSAGE_UPDATE */, oldMessage, message);
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
};
|
|
3598
|
+
|
|
3599
|
+
// src/client/events/serverCreate.ts
|
|
3600
|
+
var ServerCreate = class extends Event {
|
|
3601
|
+
/**
|
|
3602
|
+
* Handles the server creation event.
|
|
3603
|
+
*
|
|
3604
|
+
* @param {API.Server} data - The raw data for the created server from the API.
|
|
3605
|
+
* @returns {Promise<void>} A promise that resolves when the server is added and members are optionally fetched.
|
|
3606
|
+
*/
|
|
3607
|
+
handle(data) {
|
|
3608
|
+
return __async(this, null, function* () {
|
|
3609
|
+
const server = this.client.servers._add(data);
|
|
3610
|
+
if (this.client.options.fetchMembers) {
|
|
3611
|
+
yield server.members.fetch();
|
|
3612
|
+
}
|
|
3613
|
+
this.client.emit("serverCreate" /* SERVER_CREATE */, server);
|
|
3614
|
+
});
|
|
3615
|
+
}
|
|
3616
|
+
};
|
|
3617
|
+
|
|
3618
|
+
// src/client/events/serverDelete.ts
|
|
3619
|
+
var ServerDelete = class extends Event {
|
|
3620
|
+
/**
|
|
3621
|
+
* Handles the server deletion event.
|
|
3622
|
+
*
|
|
3623
|
+
* @param {API.Server} data - The raw data for the deleted server from the API.
|
|
3624
|
+
* @returns {{ server: unknown }} An object containing the deleted server, or `undefined` if not found.
|
|
3625
|
+
*/
|
|
3626
|
+
handle(data) {
|
|
3627
|
+
const server = this.client.servers.cache.get(data._id);
|
|
3628
|
+
if (server) {
|
|
3629
|
+
this.client.servers._remove(server.id);
|
|
3630
|
+
this.client.emit("serverDelete" /* SERVER_DELETE */, server);
|
|
3631
|
+
}
|
|
3632
|
+
return { server };
|
|
3633
|
+
}
|
|
3634
|
+
};
|
|
3635
|
+
|
|
3636
|
+
// src/client/events/serverMemberJoin.ts
|
|
3637
|
+
var ServerMemberJoin = class extends Event {
|
|
3638
|
+
/**
|
|
3639
|
+
* Handles the server member join event.
|
|
3640
|
+
*
|
|
3641
|
+
* @param {{ id: string; user: string }} data - The data for the event, containing the server ID and user ID.
|
|
3642
|
+
* @returns {Promise<{ member: unknown }>} A promise that resolves with the joined member.
|
|
3643
|
+
*/
|
|
3644
|
+
handle(data) {
|
|
3645
|
+
return __async(this, null, function* () {
|
|
3646
|
+
let server = this.client.servers.cache.get(data.id);
|
|
3647
|
+
if (!server) {
|
|
3648
|
+
server = yield this.client.servers.fetch(data.id);
|
|
3649
|
+
this.client.emit("serverCreate" /* SERVER_CREATE */, server);
|
|
3650
|
+
}
|
|
3651
|
+
const member = yield server.members.fetch(data.user);
|
|
3652
|
+
server.members.cache.set(member.id, member);
|
|
3653
|
+
this.client.emit("serverMemberJoin" /* SERVER_MEMBER_JOIN */, member);
|
|
3654
|
+
return { member };
|
|
3655
|
+
});
|
|
3656
|
+
}
|
|
3657
|
+
};
|
|
3658
|
+
|
|
3659
|
+
// src/client/events/serverMemberLeave.ts
|
|
3660
|
+
var ServerMemberLeave = class extends Event {
|
|
3661
|
+
/**
|
|
3662
|
+
* Handles the server member leave event.
|
|
3663
|
+
*
|
|
3664
|
+
* @param {{ id: string; user: string }} data - The data for the event, containing the server ID and user ID.
|
|
3665
|
+
* @returns {{ server: unknown; member?: unknown }} An object containing the server and the member who left, or just the server if the member is not found.
|
|
3666
|
+
*/
|
|
3667
|
+
handle(data) {
|
|
3668
|
+
const server = this.client.servers.cache.get(data.id);
|
|
3669
|
+
if (server) {
|
|
3670
|
+
const member = server.members.cache.get(data.user);
|
|
3671
|
+
if (member) {
|
|
3672
|
+
server.members._remove(member.id);
|
|
3673
|
+
this.client.emit("serverMemberLeave" /* SERVER_MEMBER_LEAVE */, member);
|
|
3674
|
+
}
|
|
3675
|
+
return { server, member };
|
|
3676
|
+
}
|
|
3677
|
+
return { server };
|
|
3678
|
+
}
|
|
3679
|
+
};
|
|
3680
|
+
|
|
3681
|
+
// src/client/events/serverMemberUpdate.ts
|
|
3682
|
+
var ServerMemberUpdate = class extends Event {
|
|
3683
|
+
/**
|
|
3684
|
+
* Handles the server member update event.
|
|
3685
|
+
*
|
|
3686
|
+
* @param {{ id: string; data: API.Member }} data - The data for the event, containing the server ID and updated member data.
|
|
3687
|
+
* @returns {void}
|
|
3688
|
+
*/
|
|
3689
|
+
handle(data) {
|
|
3690
|
+
const updateData = __spreadProps(__spreadValues({}, data.data), {
|
|
3691
|
+
_id: { server: data.id.server, user: data.id.user }
|
|
3692
|
+
});
|
|
3693
|
+
const server = this.client.servers.cache.get(data.id.server);
|
|
3694
|
+
const member = server == null ? void 0 : server.members.cache.get(data.id.user);
|
|
3695
|
+
const oldMember = member == null ? void 0 : member._update(updateData);
|
|
3696
|
+
if (oldMember && member && (!member.equals(oldMember) || areRolesDifferent(member.roles, oldMember.roles))) {
|
|
3697
|
+
this.client.emit("serverMemberUpdate" /* SERVER_MEMBER_UPDATE */, oldMember, member);
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
3700
|
+
};
|
|
3701
|
+
function areRolesDifferent(rolesA, rolesB) {
|
|
3702
|
+
const idsA = rolesA.map((role) => role.id).sort();
|
|
3703
|
+
const idsB = rolesB.map((role) => role.id).sort();
|
|
3704
|
+
return idsA.length !== idsB.length || !idsA.every((id, index) => id === idsB[index]);
|
|
3705
|
+
}
|
|
3706
|
+
|
|
3707
|
+
// src/client/events/serverRoleDelete.ts
|
|
3708
|
+
var ServerRoleDelete = class extends Event {
|
|
3709
|
+
/**
|
|
3710
|
+
* Handles the server role deletion event.
|
|
3711
|
+
*
|
|
3712
|
+
* @param {{ id: string; role_id: string }} data - The data for the event, containing the server ID and role ID.
|
|
3713
|
+
* @returns {{ role: unknown } | {}} An object containing the deleted role, or an empty object if the role or server is not found.
|
|
3714
|
+
*/
|
|
3715
|
+
handle(data) {
|
|
3716
|
+
const server = this.client.servers.cache.get(data.id);
|
|
3717
|
+
if (server) {
|
|
3718
|
+
const role = server.roles.cache.get(data.role_id);
|
|
3719
|
+
if (role) {
|
|
3720
|
+
server.roles._remove(role.id);
|
|
3721
|
+
this.client.emit("roleDelete" /* ROLE_DELETE */, role);
|
|
3722
|
+
}
|
|
3723
|
+
return { role };
|
|
3724
|
+
}
|
|
3725
|
+
return {};
|
|
3726
|
+
}
|
|
3727
|
+
};
|
|
3728
|
+
|
|
3729
|
+
// src/client/events/serverRoleUpdate.ts
|
|
3730
|
+
var ServerRoleUpdate = class extends Event {
|
|
3731
|
+
/**
|
|
3732
|
+
* Handles the server role update event.
|
|
3733
|
+
*
|
|
3734
|
+
* @param {{ id: string; role_id: string; data: API.Role & { _id: string }; clear: API.FieldsRole[] }} data - The data for the event, containing the server ID, role ID, updated role data, and fields to clear.
|
|
3735
|
+
* @returns {void}
|
|
3736
|
+
*/
|
|
3737
|
+
handle(data) {
|
|
3738
|
+
const server = this.client.servers.cache.get(data.id);
|
|
3739
|
+
if (!server) return;
|
|
3740
|
+
const role = server.roles.cache.get(data.role_id);
|
|
3741
|
+
const oldRole = role == null ? void 0 : role._update(data.data, data.clear);
|
|
3742
|
+
if (role && oldRole && !role.equals(oldRole)) {
|
|
3743
|
+
this.client.emit("roleUpdate" /* ROLE_UPDATE */, oldRole, role);
|
|
3744
|
+
}
|
|
3745
|
+
}
|
|
3746
|
+
};
|
|
3747
|
+
|
|
3748
|
+
// src/client/events/serverupdate.ts
|
|
3749
|
+
var ServerUpdate = class extends Event {
|
|
3750
|
+
/**
|
|
3751
|
+
* Handles the server update event.
|
|
3752
|
+
*
|
|
3753
|
+
* @param {{ id: string; data: API.Server; clear: API.FieldsServer[] }} data - The data for the event, containing the server ID, updated server data, and fields to clear.
|
|
3754
|
+
* @returns {void}
|
|
3755
|
+
*/
|
|
3756
|
+
handle(data) {
|
|
3757
|
+
const server = this.client.servers.cache.get(data.id);
|
|
3758
|
+
const oldServer = server == null ? void 0 : server._update(data.data, data.clear);
|
|
3759
|
+
if (oldServer && server && !oldServer.equals(server)) {
|
|
3760
|
+
this.client.emit("serverUpdate" /* SERVER_UPDATE */, oldServer, server);
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3763
|
+
};
|
|
3764
|
+
|
|
3765
|
+
// src/client/events/userUpdate.ts
|
|
3766
|
+
var UserUpdate = class extends Event {
|
|
3767
|
+
/**
|
|
3768
|
+
* Handles the user update event.
|
|
3769
|
+
*
|
|
3770
|
+
* @param {{ id: string; data: API.User; clear: API.FieldsUser[] }} data - The data for the event, containing the user ID, updated user data, and fields to clear.
|
|
3771
|
+
* @returns {void}
|
|
3772
|
+
*/
|
|
3773
|
+
handle(data) {
|
|
3774
|
+
const user = data.id === this.client.user.id ? this.client.user : this.client.users.cache.get(data.id);
|
|
3775
|
+
const oldUser = user == null ? void 0 : user._update(data.data, data.clear);
|
|
3776
|
+
if (user && oldUser && !user.equals(oldUser)) {
|
|
3777
|
+
this.client.emit("userUpdate" /* USER_UPDATE */, oldUser, user);
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
};
|
|
3781
|
+
|
|
3782
|
+
// src/client/events/messageReact.ts
|
|
3783
|
+
var MessageReact = class extends Event {
|
|
3784
|
+
/**
|
|
3785
|
+
* Handles the message reaction event.
|
|
3786
|
+
*
|
|
3787
|
+
* @param {MessageReactData} data - The data for the event, containing the message ID, channel ID, user ID, and emoji ID.
|
|
3788
|
+
* @returns {Promise<unknown>} A promise that resolves with an empty object.
|
|
3789
|
+
*/
|
|
3790
|
+
handle(data) {
|
|
3791
|
+
return __async(this, null, function* () {
|
|
3792
|
+
var _a, _b;
|
|
3793
|
+
const channel = this.client.channels.cache.get(data.channel_id);
|
|
3794
|
+
if (channel == null ? void 0 : channel.isText()) {
|
|
3795
|
+
let message = channel.messages.cache.get(data.id) ? channel.messages.cache.get(data.id) : yield channel.messages.fetch(data.id);
|
|
3796
|
+
if (message) {
|
|
3797
|
+
if ((_a = message.reactions.get(data.emoji_id)) == null ? void 0 : _a.indexOf(data.user_id)) return;
|
|
3798
|
+
if (!((_b = message.reactions.get(data.emoji_id)) == null ? void 0 : _b.push(data.user_id)))
|
|
3799
|
+
message.reactions.set(data.emoji_id, [data.user_id]);
|
|
3800
|
+
this.client.emit("messageReact" /* MESSAGE_REACT */, message);
|
|
3801
|
+
}
|
|
3802
|
+
}
|
|
3803
|
+
return {};
|
|
3804
|
+
});
|
|
3805
|
+
}
|
|
3806
|
+
};
|
|
3807
|
+
|
|
3808
|
+
// src/client/events/messageUnreact.ts
|
|
3809
|
+
var MessageUnreact = class extends Event {
|
|
3810
|
+
/**
|
|
3811
|
+
* Handles the message reaction removal event.
|
|
3812
|
+
*
|
|
3813
|
+
* @param {MessageReactData} data - The data for the event, containing the message ID, channel ID, user ID, and emoji ID.
|
|
3814
|
+
* @returns {Promise<unknown>} A promise that resolves with an empty object.
|
|
3815
|
+
*/
|
|
3816
|
+
handle(data) {
|
|
3817
|
+
return __async(this, null, function* () {
|
|
3818
|
+
const channel = this.client.channels.cache.get(data.channel_id);
|
|
3819
|
+
if (channel == null ? void 0 : channel.isText()) {
|
|
3820
|
+
let message = channel.messages.cache.get(data.id) ? channel.messages.cache.get(data.id) : yield channel.messages.fetch(data.id);
|
|
3821
|
+
if (message) {
|
|
3822
|
+
const reaction = message.reactions.get(data.emoji_id);
|
|
3823
|
+
if (reaction) {
|
|
3824
|
+
const index = reaction.indexOf(data.user_id);
|
|
3825
|
+
if (index !== -1) {
|
|
3826
|
+
reaction.splice(index, 1);
|
|
3827
|
+
}
|
|
3828
|
+
if (reaction.length === 0) {
|
|
3829
|
+
message.reactions.delete(data.emoji_id);
|
|
3830
|
+
}
|
|
3831
|
+
}
|
|
3832
|
+
this.client.emit("messageUnreact" /* MESSAGE_REACT_REMOVE */, message);
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3835
|
+
return {};
|
|
3836
|
+
});
|
|
3837
|
+
}
|
|
3838
|
+
};
|
|
3839
|
+
|
|
3840
|
+
// src/client/events/eventManager.ts
|
|
3841
|
+
var _events;
|
|
3842
|
+
var EventManager = class {
|
|
3843
|
+
/**
|
|
3844
|
+
* Creates a new EventManager instance.
|
|
3845
|
+
*
|
|
3846
|
+
* @param {client} client - The client instance.
|
|
3847
|
+
*/
|
|
3848
|
+
constructor(client3) {
|
|
3849
|
+
this.client = client3;
|
|
3850
|
+
/** A map of registered events, keyed by their names. */
|
|
3851
|
+
__privateAdd(this, _events, /* @__PURE__ */ new Map());
|
|
3852
|
+
for (const Event2 of Object.values(events_exports)) {
|
|
3853
|
+
this.register(Event2);
|
|
3854
|
+
}
|
|
3855
|
+
}
|
|
3856
|
+
/**
|
|
3857
|
+
* Registers an event with the manager.
|
|
3858
|
+
*
|
|
3859
|
+
* @param {new (client: client) => CustomEvent} Event - The event class to register.
|
|
3860
|
+
*/
|
|
3861
|
+
register(Event2) {
|
|
3862
|
+
__privateGet(this, _events).set(Event2.name.replace(/Events$/, ""), new Event2(this.client));
|
|
3863
|
+
}
|
|
3864
|
+
/**
|
|
3865
|
+
* Retrieves a registered event by its name.
|
|
3866
|
+
*
|
|
3867
|
+
* @param {string} name - The name of the event to retrieve.
|
|
3868
|
+
* @returns {CustomEvent | null} The event instance, or `null` if not found.
|
|
3869
|
+
*/
|
|
3870
|
+
get(name) {
|
|
3871
|
+
var _a;
|
|
3872
|
+
return (_a = __privateGet(this, _events).get(name)) != null ? _a : null;
|
|
3873
|
+
}
|
|
3874
|
+
};
|
|
3875
|
+
_events = new WeakMap();
|
|
3876
|
+
|
|
3877
|
+
// src/struct/clientUser.ts
|
|
3878
|
+
var ClientUser = class extends User {
|
|
3879
|
+
constructor() {
|
|
3880
|
+
super(...arguments);
|
|
3881
|
+
/** The notes channel associated with the client user, if any. */
|
|
3882
|
+
this.notes = null;
|
|
3883
|
+
}
|
|
3884
|
+
/**
|
|
3885
|
+
* Updates the username of the client user.
|
|
3886
|
+
*
|
|
3887
|
+
* @param {string} username - The new username to set.
|
|
3888
|
+
* @param {string} [password] - The current password of the user (required for non-bot accounts).
|
|
3889
|
+
* @returns {Promise<void>} A promise that resolves when the username has been successfully updated.
|
|
3890
|
+
* @throws {Error} Throws an error if the client user is a bot and a password is provided.
|
|
3891
|
+
*
|
|
3892
|
+
* @example
|
|
3893
|
+
* ```typescript
|
|
3894
|
+
* await clientUser.setUsername("NewUsername", "CurrentPassword");
|
|
3895
|
+
* ```
|
|
3896
|
+
*/
|
|
3897
|
+
setUsername(username, password) {
|
|
3898
|
+
return __async(this, null, function* () {
|
|
3899
|
+
if (this.bot && password) {
|
|
3900
|
+
throw new Error("Bots do not have passwords");
|
|
3901
|
+
}
|
|
3902
|
+
yield this.client.api.patch("/users/@me/username", {
|
|
3903
|
+
body: { username, password }
|
|
3904
|
+
});
|
|
3905
|
+
});
|
|
3906
|
+
}
|
|
3907
|
+
/**
|
|
3908
|
+
* Updates the status of the client user.
|
|
3909
|
+
*
|
|
3910
|
+
* @param {string | null} text - The status text to set, or `null` to clear the status.
|
|
3911
|
+
* @param {Status} [presence] - The presence status (e.g., online, idle, etc.).
|
|
3912
|
+
* @returns {Promise<void>} A promise that resolves when the status has been successfully updated.
|
|
3913
|
+
*
|
|
3914
|
+
* @example
|
|
3915
|
+
* ```typescript
|
|
3916
|
+
* await clientUser.setStatus("Available", "online");
|
|
3917
|
+
* ```
|
|
3918
|
+
*/
|
|
3919
|
+
setStatus(text, presence) {
|
|
3920
|
+
return __async(this, null, function* () {
|
|
3921
|
+
yield this.client.api.patch("/users/@me", {
|
|
3922
|
+
body: { status: { text, presence } }
|
|
3923
|
+
});
|
|
3924
|
+
});
|
|
3925
|
+
}
|
|
3926
|
+
};
|
|
3927
|
+
|
|
3928
|
+
// src/client/webSocket.ts
|
|
3929
|
+
var WebSocketClient = class {
|
|
3930
|
+
/**
|
|
3931
|
+
* Creates a new WebSocketClient instance.
|
|
3932
|
+
*
|
|
3933
|
+
* @param {client} client - The client instance.
|
|
3934
|
+
*/
|
|
3935
|
+
constructor(client3) {
|
|
3936
|
+
this.client = client3;
|
|
3937
|
+
/** Whether the last pong acknowledgment was received. */
|
|
3938
|
+
this.lastPongAck = false;
|
|
3939
|
+
/** Whether the WebSocket client is connected. */
|
|
3940
|
+
this.connected = false;
|
|
3941
|
+
/** A promise representing the reconnecting process, or `null` if not reconnecting. */
|
|
3942
|
+
this.reconnecting = null;
|
|
3943
|
+
/** Whether the WebSocket client is ready. */
|
|
3944
|
+
this.ready = false;
|
|
3945
|
+
}
|
|
3946
|
+
/**
|
|
3947
|
+
* Logs a debug message.
|
|
3948
|
+
*
|
|
3949
|
+
* @param {unknown} message - The message to log.
|
|
3950
|
+
* @private
|
|
3951
|
+
*/
|
|
3952
|
+
debug(message) {
|
|
3953
|
+
this.client.debug(`[WS] ${message}`);
|
|
3954
|
+
}
|
|
3955
|
+
/**
|
|
3956
|
+
* Sends data through the WebSocket connection.
|
|
3957
|
+
*
|
|
3958
|
+
* @param {unknown} data - The data to send.
|
|
3959
|
+
* @returns {Promise<void>} A promise that resolves when the data is sent.
|
|
3960
|
+
* @throws {Error} Throws an error if the WebSocket is not open.
|
|
3961
|
+
*/
|
|
3962
|
+
send(data) {
|
|
3963
|
+
return __async(this, null, function* () {
|
|
3964
|
+
var _a;
|
|
3965
|
+
if (this.reconnecting) {
|
|
3966
|
+
this.debug("Reconnecting, waiting to send message.");
|
|
3967
|
+
yield this.reconnecting;
|
|
3968
|
+
}
|
|
3969
|
+
if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN) {
|
|
3970
|
+
this.socket.send(JSON.stringify(data));
|
|
3971
|
+
} else {
|
|
3972
|
+
this.debug("Socket is not open, cannot send message.");
|
|
3973
|
+
throw new Error("Socket is not open");
|
|
3974
|
+
}
|
|
3975
|
+
});
|
|
3976
|
+
}
|
|
3977
|
+
/**
|
|
3978
|
+
* Handles the WebSocket connection opening.
|
|
3979
|
+
*
|
|
3980
|
+
* @private
|
|
3981
|
+
*/
|
|
3982
|
+
onOpen() {
|
|
3983
|
+
if (!this.client.token) throw new Error("Token is required");
|
|
3984
|
+
this.send({
|
|
3985
|
+
type: "Authenticate" /* AUTHENTICATE */,
|
|
3986
|
+
token: this.client.token
|
|
3987
|
+
});
|
|
3988
|
+
}
|
|
3989
|
+
/**
|
|
3990
|
+
* Gets the current ping (latency) of the WebSocket connection.
|
|
3991
|
+
*
|
|
3992
|
+
* @returns {number} The ping in milliseconds, or `-0` if the WebSocket is not connected.
|
|
3993
|
+
*/
|
|
3994
|
+
get ping() {
|
|
3995
|
+
if (!this.socket) return -0;
|
|
3996
|
+
return Date.now() - this.lastPingTimestamp;
|
|
3997
|
+
}
|
|
3998
|
+
/**
|
|
3999
|
+
* Sets the heartbeat interval for the WebSocket connection.
|
|
4000
|
+
*
|
|
4001
|
+
* @param {number} time - The interval time in milliseconds. Use `-1` to clear the interval.
|
|
4002
|
+
*/
|
|
4003
|
+
setHeartbeatTimer(time) {
|
|
4004
|
+
this.debug(`Setting a heartbeat interval for ${time}ms.`);
|
|
4005
|
+
if (this.heartbeatInterval) {
|
|
4006
|
+
clearInterval(this.heartbeatInterval);
|
|
4007
|
+
}
|
|
4008
|
+
if (time !== -1) {
|
|
4009
|
+
this.heartbeatInterval = setInterval(() => this.sendHeartbeat(), time);
|
|
4010
|
+
}
|
|
4011
|
+
}
|
|
4012
|
+
/**
|
|
4013
|
+
* Sends a heartbeat to the server to keep the connection alive.
|
|
4014
|
+
*/
|
|
4015
|
+
sendHeartbeat() {
|
|
4016
|
+
var _a;
|
|
4017
|
+
this.debug("Sending heartbeat.");
|
|
4018
|
+
if (!this.lastPongAck) {
|
|
4019
|
+
this.debug("Did not receive a pong ack.");
|
|
4020
|
+
if ((_a = this.client.options.ws) == null ? void 0 : _a.reconnect) {
|
|
4021
|
+
this.reconnecting = this.destroy().then(() => this.connect()).then(() => this.reconnecting = null);
|
|
4022
|
+
}
|
|
4023
|
+
}
|
|
4024
|
+
const now = Date.now();
|
|
4025
|
+
this.send({ type: "Ping" /* PING */, data: now });
|
|
4026
|
+
this.lastPongAck = false;
|
|
4027
|
+
this.lastPingTimestamp = now;
|
|
4028
|
+
}
|
|
4029
|
+
/**
|
|
4030
|
+
* Handles WebSocket errors.
|
|
4031
|
+
*
|
|
4032
|
+
* @param {unknown} event - The error event.
|
|
4033
|
+
* @private
|
|
4034
|
+
*/
|
|
4035
|
+
onError(event) {
|
|
4036
|
+
this.client.emit("error" /* ERROR */, event);
|
|
4037
|
+
}
|
|
4038
|
+
/**
|
|
4039
|
+
* Handles incoming WebSocket messages.
|
|
4040
|
+
*
|
|
4041
|
+
* @param {{ data: unknown }} param0 - The message event containing the data.
|
|
4042
|
+
* @private
|
|
4043
|
+
*/
|
|
4044
|
+
onMessage({ data }) {
|
|
4045
|
+
let packet;
|
|
4046
|
+
try {
|
|
4047
|
+
packet = JSON.parse(String(data));
|
|
4048
|
+
} catch (err) {
|
|
4049
|
+
this.client.emit("error" /* ERROR */, err);
|
|
4050
|
+
return;
|
|
4051
|
+
}
|
|
4052
|
+
this.client.emit("raw" /* RAW */, packet);
|
|
4053
|
+
this.onPacket(packet).catch((e) => this.client.emit("error" /* ERROR */, e));
|
|
4054
|
+
}
|
|
4055
|
+
/**
|
|
4056
|
+
* Handles the WebSocket connection closing.
|
|
4057
|
+
*
|
|
4058
|
+
* @param {{ code: number; reason: string }} event - The close event containing the code and reason.
|
|
4059
|
+
* @private
|
|
4060
|
+
*/
|
|
4061
|
+
onClose(event) {
|
|
4062
|
+
this.debug(`Closed with reason: ${event.reason}, code: ${event.code}`);
|
|
4063
|
+
this.destroy();
|
|
4064
|
+
}
|
|
4065
|
+
/**
|
|
4066
|
+
* Handles incoming WebSocket packets.
|
|
4067
|
+
*
|
|
4068
|
+
* @param {any} packet - The packet data.
|
|
4069
|
+
* @private
|
|
4070
|
+
*/
|
|
4071
|
+
onPacket(packet) {
|
|
4072
|
+
return __async(this, null, function* () {
|
|
4073
|
+
var _a, _b, _c, _d;
|
|
4074
|
+
if (!packet) {
|
|
4075
|
+
this.debug(`Received broken packet: '${packet}'.`);
|
|
4076
|
+
return;
|
|
4077
|
+
}
|
|
4078
|
+
switch (packet.type) {
|
|
4079
|
+
case "Bulk" /* BULK */:
|
|
4080
|
+
yield Promise.all(packet.v.map((p) => this.onPacket(p)));
|
|
4081
|
+
break;
|
|
4082
|
+
case "Authenticated" /* AUTHENTICATED */:
|
|
4083
|
+
this.connected = true;
|
|
4084
|
+
break;
|
|
4085
|
+
case "Pong" /* PONG */:
|
|
4086
|
+
this.debug(`Received a heartbeat.`);
|
|
4087
|
+
this.lastPongAck = true;
|
|
4088
|
+
break;
|
|
4089
|
+
case "Error" /* ERROR */:
|
|
4090
|
+
this.client.emit("error" /* ERROR */, packet.error);
|
|
4091
|
+
break;
|
|
4092
|
+
case "Ready" /* READY */: {
|
|
4093
|
+
this.lastPongAck = true;
|
|
4094
|
+
const promises = [];
|
|
4095
|
+
for (const user of packet.users) {
|
|
4096
|
+
if (user.relationship === "User" && !this.client.user) {
|
|
4097
|
+
this.client.user = new ClientUser(this.client, user);
|
|
4098
|
+
} else {
|
|
4099
|
+
this.client.users._add(user);
|
|
4100
|
+
}
|
|
4101
|
+
}
|
|
4102
|
+
for (const server of packet.servers) {
|
|
4103
|
+
const s = this.client.servers._add(server);
|
|
4104
|
+
if (this.client.options.fetchMembers) {
|
|
4105
|
+
promises.push(s.members.fetch());
|
|
4106
|
+
}
|
|
4107
|
+
}
|
|
4108
|
+
for (const channel of packet.channels) {
|
|
4109
|
+
this.client.channels._add(channel);
|
|
4110
|
+
}
|
|
4111
|
+
for (const member of packet.members) {
|
|
4112
|
+
(_a = this.client.servers.cache.get(member._id.server)) == null ? void 0 : _a.members._add(member);
|
|
4113
|
+
}
|
|
4114
|
+
for (const emoji of packet.emojis) {
|
|
4115
|
+
(_b = this.client.servers.cache.get(emoji.parent.id)) == null ? void 0 : _b.emojis.set(emoji._id, __spreadProps(__spreadValues({}, emoji), { _id: emoji._id }));
|
|
4116
|
+
}
|
|
4117
|
+
this.setHeartbeatTimer(
|
|
4118
|
+
(_d = (_c = this.client.options.ws) == null ? void 0 : _c.heartbeatInterval) != null ? _d : 3e4
|
|
4119
|
+
);
|
|
4120
|
+
yield Promise.all(promises);
|
|
4121
|
+
this.ready = true;
|
|
4122
|
+
this.client.emit("ready" /* READY */, this.client);
|
|
4123
|
+
break;
|
|
4124
|
+
}
|
|
4125
|
+
default: {
|
|
4126
|
+
const action = this.client.events.get(packet.type);
|
|
4127
|
+
if (action) {
|
|
4128
|
+
yield action.handle(packet);
|
|
4129
|
+
} else {
|
|
4130
|
+
this.debug(`Received unknown packet "${packet.type}"`);
|
|
4131
|
+
}
|
|
4132
|
+
break;
|
|
4133
|
+
}
|
|
4134
|
+
}
|
|
4135
|
+
});
|
|
4136
|
+
}
|
|
4137
|
+
/**
|
|
4138
|
+
* Connects to the WebSocket server.
|
|
4139
|
+
*
|
|
4140
|
+
* @returns {Promise<this>} A promise that resolves when the connection is established.
|
|
4141
|
+
*/
|
|
4142
|
+
connect() {
|
|
4143
|
+
return new Promise((resolve) => {
|
|
4144
|
+
var _a, _b;
|
|
4145
|
+
if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN && this.ready) {
|
|
4146
|
+
return resolve(this);
|
|
4147
|
+
}
|
|
4148
|
+
if (typeof this.client.options === "undefined") {
|
|
4149
|
+
throw new Error("MISSING_CONFIGURATION_SYNC");
|
|
4150
|
+
}
|
|
4151
|
+
if (typeof this.client.token !== "string") {
|
|
4152
|
+
throw new Error("INVALID_TOKEN");
|
|
4153
|
+
}
|
|
4154
|
+
const ws = this.socket = (_b = this.socket) != null ? _b : new WebSocket(`${wsUrl}`);
|
|
4155
|
+
ws.onopen = this.onOpen.bind(this);
|
|
4156
|
+
ws.onmessage = this.onMessage.bind(this);
|
|
4157
|
+
ws.onerror = this.onError.bind(this);
|
|
4158
|
+
ws.onclose = this.onClose.bind(this);
|
|
4159
|
+
ws.addEventListener("open", () => resolve(this));
|
|
4160
|
+
});
|
|
4161
|
+
}
|
|
4162
|
+
/**
|
|
4163
|
+
* Destroys the WebSocket connection and clears its state.
|
|
4164
|
+
*
|
|
4165
|
+
* @returns {Promise<void>} A promise that resolves when the connection is destroyed.
|
|
4166
|
+
*/
|
|
4167
|
+
destroy() {
|
|
4168
|
+
return new Promise((resolve) => {
|
|
4169
|
+
var _a;
|
|
4170
|
+
this.setHeartbeatTimer(-1);
|
|
4171
|
+
this.connected = false;
|
|
4172
|
+
this.ready = false;
|
|
4173
|
+
if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN) {
|
|
4174
|
+
this.socket.addEventListener("close", () => {
|
|
4175
|
+
this.socket = null;
|
|
4176
|
+
resolve();
|
|
4177
|
+
});
|
|
4178
|
+
this.socket.close();
|
|
4179
|
+
} else {
|
|
4180
|
+
this.socket = null;
|
|
4181
|
+
resolve();
|
|
4182
|
+
}
|
|
4183
|
+
});
|
|
4184
|
+
}
|
|
4185
|
+
};
|
|
4186
|
+
|
|
4187
|
+
// src/client/client.ts
|
|
4188
|
+
var client = class extends BaseClient {
|
|
4189
|
+
constructor() {
|
|
4190
|
+
super(...arguments);
|
|
4191
|
+
/** The WebSocket client used for real-time communication. */
|
|
4192
|
+
this.ws = new WebSocketClient(this);
|
|
4193
|
+
/** Manages the channels in the client. */
|
|
4194
|
+
this.channels = new ChannelManager(this);
|
|
4195
|
+
/** Manages the servers in the client. */
|
|
4196
|
+
this.servers = new ServerManager(this);
|
|
4197
|
+
/** Manages the users in the client. */
|
|
4198
|
+
this.users = new UserManager(this);
|
|
4199
|
+
/** Manages the events in the client. */
|
|
4200
|
+
this.events = new EventManager(this);
|
|
4201
|
+
/** The authenticated user, or `null` if not logged in. */
|
|
4202
|
+
this.user = null;
|
|
4203
|
+
/** The timestamp when the client became ready, or `null` if not ready. */
|
|
4204
|
+
this.readyAt = null;
|
|
4205
|
+
}
|
|
4206
|
+
/**
|
|
4207
|
+
* Gets the timestamp when the client became ready.
|
|
4208
|
+
*
|
|
4209
|
+
* @returns {number | null} The ready timestamp in milliseconds, or `null` if not ready.
|
|
4210
|
+
*/
|
|
4211
|
+
get readyTimestamp() {
|
|
4212
|
+
return this.readyAt ? this.readyAt.getTime() : null;
|
|
4213
|
+
}
|
|
4214
|
+
/**
|
|
4215
|
+
* Gets the uptime of the client in milliseconds.
|
|
4216
|
+
*
|
|
4217
|
+
* @returns {number | null} The uptime in milliseconds, or `null` if the client is not ready.
|
|
4218
|
+
*/
|
|
4219
|
+
get upTime() {
|
|
4220
|
+
return this.readyAt ? Date.now() - this.readyAt.getTime() : null;
|
|
4221
|
+
}
|
|
4222
|
+
/**
|
|
4223
|
+
* Logs the client into the API using the provided token.
|
|
4224
|
+
*
|
|
4225
|
+
* @param {string} token - The authentication token.
|
|
4226
|
+
* @returns {Promise<void>} A promise that resolves when the client is logged in.
|
|
4227
|
+
* @throws {Error} Throws an error if the token is not provided or if the WebSocket connection fails.
|
|
4228
|
+
*
|
|
4229
|
+
* @example
|
|
4230
|
+
* ```typescript
|
|
4231
|
+
* await client.login("your-token-here");
|
|
4232
|
+
* ```
|
|
4233
|
+
*/
|
|
4234
|
+
login(token) {
|
|
4235
|
+
return __async(this, null, function* () {
|
|
4236
|
+
if (!token) throw new Error("Token is required");
|
|
4237
|
+
this.token = token;
|
|
4238
|
+
this.debug("Logging in...");
|
|
4239
|
+
try {
|
|
4240
|
+
yield this.ws.connect();
|
|
4241
|
+
} catch (error) {
|
|
4242
|
+
this.debug(`Error connecting to WebSocket: ${error}`);
|
|
4243
|
+
throw error;
|
|
4244
|
+
}
|
|
4245
|
+
this.readyAt = /* @__PURE__ */ new Date();
|
|
4246
|
+
});
|
|
4247
|
+
}
|
|
4248
|
+
/**
|
|
4249
|
+
* Destroys the client, disconnecting it from the API and clearing its state.
|
|
4250
|
+
*
|
|
4251
|
+
* @returns {Promise<void>} A promise that resolves when the client is destroyed.
|
|
4252
|
+
*
|
|
4253
|
+
* @example
|
|
4254
|
+
* ```typescript
|
|
4255
|
+
* await client.destroy();
|
|
4256
|
+
* ```
|
|
4257
|
+
*/
|
|
4258
|
+
destroy() {
|
|
4259
|
+
return __async(this, null, function* () {
|
|
4260
|
+
this.token = null;
|
|
4261
|
+
this.user = null;
|
|
4262
|
+
this.readyAt = null;
|
|
4263
|
+
yield this.ws.destroy();
|
|
4264
|
+
});
|
|
4265
|
+
}
|
|
4266
|
+
/**
|
|
4267
|
+
* Checks if the client is ready.
|
|
4268
|
+
*
|
|
4269
|
+
* @returns {boolean} `true` if the client is ready, otherwise `false`.
|
|
4270
|
+
*
|
|
4271
|
+
* @example
|
|
4272
|
+
* ```typescript
|
|
4273
|
+
* if (client.isReady()) {
|
|
4274
|
+
* console.log("Client is ready!");
|
|
4275
|
+
* }
|
|
4276
|
+
* ```
|
|
4277
|
+
*/
|
|
4278
|
+
isReady() {
|
|
4279
|
+
return this.readyAt !== null;
|
|
4280
|
+
}
|
|
4281
|
+
};
|
|
4282
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
4283
|
+
0 && (module.exports = {
|
|
4284
|
+
client
|
|
4285
|
+
});
|
|
4286
|
+
//# sourceMappingURL=client.cjs.map
|