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