seyfert 1.4.0 → 2.0.0

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 (433) hide show
  1. package/LICENSE +21 -190
  2. package/README.md +22 -14
  3. package/lib/api/Router.js +5 -3
  4. package/lib/api/Routes/applications.d.ts +23 -1
  5. package/lib/api/Routes/channels.d.ts +1 -1
  6. package/lib/api/Routes/gateway.d.ts +1 -1
  7. package/lib/api/Routes/guilds.d.ts +8 -2
  8. package/lib/api/Routes/interactions.d.ts +1 -1
  9. package/lib/api/Routes/invites.d.ts +1 -1
  10. package/lib/api/Routes/stage-instances.d.ts +1 -1
  11. package/lib/api/Routes/stickers.d.ts +2 -2
  12. package/lib/api/Routes/users.d.ts +1 -1
  13. package/lib/api/Routes/voice.d.ts +1 -1
  14. package/lib/api/Routes/webhooks.d.ts +2 -2
  15. package/lib/api/api.d.ts +2 -2
  16. package/lib/api/api.js +2 -14
  17. package/lib/api/bucket.d.ts +0 -1
  18. package/lib/api/shared.d.ts +0 -1
  19. package/lib/api/utils/constants.d.ts +2 -5
  20. package/lib/api/utils/constants.js +3 -7
  21. package/lib/api/utils/utils.d.ts +1 -2
  22. package/lib/api/utils/utils.js +2 -3
  23. package/lib/builders/ActionRow.d.ts +1 -1
  24. package/lib/builders/ActionRow.js +3 -3
  25. package/lib/builders/Attachment.d.ts +2 -3
  26. package/lib/builders/Attachment.js +12 -13
  27. package/lib/builders/Base.d.ts +2 -2
  28. package/lib/builders/Base.js +1 -1
  29. package/lib/builders/Button.d.ts +7 -7
  30. package/lib/builders/Button.js +11 -9
  31. package/lib/builders/Embed.d.ts +1 -1
  32. package/lib/builders/Modal.d.ts +1 -1
  33. package/lib/builders/Modal.js +2 -2
  34. package/lib/builders/Poll.d.ts +2 -2
  35. package/lib/builders/Poll.js +5 -6
  36. package/lib/builders/SelectMenu.d.ts +1 -1
  37. package/lib/builders/SelectMenu.js +17 -18
  38. package/lib/builders/index.d.ts +1 -1
  39. package/lib/builders/index.js +10 -11
  40. package/lib/cache/adapters/default.d.ts +16 -9
  41. package/lib/cache/adapters/default.js +42 -31
  42. package/lib/cache/adapters/index.d.ts +0 -1
  43. package/lib/cache/adapters/index.js +0 -1
  44. package/lib/cache/adapters/limited.d.ts +17 -12
  45. package/lib/cache/adapters/limited.js +80 -36
  46. package/lib/cache/adapters/types.d.ts +6 -7
  47. package/lib/cache/adapters/workeradapter.d.ts +6 -6
  48. package/lib/cache/adapters/workeradapter.js +13 -0
  49. package/lib/cache/index.d.ts +24 -11
  50. package/lib/cache/index.js +335 -19
  51. package/lib/cache/resources/bans.d.ts +15 -0
  52. package/lib/cache/resources/bans.js +44 -0
  53. package/lib/cache/resources/channels.d.ts +6 -4
  54. package/lib/cache/resources/channels.js +13 -7
  55. package/lib/cache/resources/default/base.d.ts +7 -7
  56. package/lib/cache/resources/default/base.js +2 -2
  57. package/lib/cache/resources/default/guild-based.d.ts +6 -6
  58. package/lib/cache/resources/default/guild-based.js +6 -6
  59. package/lib/cache/resources/default/guild-related.d.ts +7 -7
  60. package/lib/cache/resources/default/guild-related.js +10 -8
  61. package/lib/cache/resources/emojis.d.ts +15 -6
  62. package/lib/cache/resources/emojis.js +13 -4
  63. package/lib/cache/resources/guilds.d.ts +9 -6
  64. package/lib/cache/resources/guilds.js +27 -6
  65. package/lib/cache/resources/members.d.ts +9 -6
  66. package/lib/cache/resources/members.js +24 -8
  67. package/lib/cache/resources/messages.d.ts +11 -7
  68. package/lib/cache/resources/messages.js +25 -11
  69. package/lib/cache/resources/overwrites.d.ts +11 -2
  70. package/lib/cache/resources/overwrites.js +9 -0
  71. package/lib/cache/resources/presence.d.ts +3 -2
  72. package/lib/cache/resources/roles.d.ts +9 -6
  73. package/lib/cache/resources/roles.js +13 -4
  74. package/lib/cache/resources/stage-instances.d.ts +2 -2
  75. package/lib/cache/resources/stickers.d.ts +9 -6
  76. package/lib/cache/resources/stickers.js +13 -4
  77. package/lib/cache/resources/threads.d.ts +9 -6
  78. package/lib/cache/resources/threads.js +13 -4
  79. package/lib/cache/resources/users.d.ts +9 -6
  80. package/lib/cache/resources/users.js +13 -4
  81. package/lib/cache/resources/voice-states.d.ts +11 -8
  82. package/lib/cache/resources/voice-states.js +15 -4
  83. package/lib/client/base.d.ts +32 -20
  84. package/lib/client/base.js +51 -30
  85. package/lib/client/client.d.ts +12 -9
  86. package/lib/client/client.js +43 -49
  87. package/lib/client/collectors.d.ts +36 -0
  88. package/lib/client/collectors.js +110 -0
  89. package/lib/client/httpclient.d.ts +8 -13
  90. package/lib/client/httpclient.js +27 -218
  91. package/lib/client/index.d.ts +1 -0
  92. package/lib/client/index.js +1 -0
  93. package/lib/client/transformers.d.ts +68 -0
  94. package/lib/client/transformers.js +99 -0
  95. package/lib/client/types.d.ts +5 -0
  96. package/lib/client/types.js +2 -0
  97. package/lib/client/workerclient.d.ts +18 -15
  98. package/lib/client/workerclient.js +148 -110
  99. package/lib/collection.d.ts +2 -2
  100. package/lib/collection.js +2 -2
  101. package/lib/commands/applications/chat.d.ts +40 -38
  102. package/lib/commands/applications/chat.js +22 -12
  103. package/lib/commands/applications/chatcontext.d.ts +17 -17
  104. package/lib/commands/applications/chatcontext.js +5 -5
  105. package/lib/commands/applications/menu.d.ts +9 -9
  106. package/lib/commands/applications/menu.js +5 -7
  107. package/lib/commands/applications/menucontext.d.ts +14 -13
  108. package/lib/commands/applications/menucontext.js +9 -9
  109. package/lib/commands/applications/options.d.ts +1 -1
  110. package/lib/commands/applications/options.js +20 -21
  111. package/lib/commands/applications/shared.d.ts +14 -0
  112. package/lib/commands/decorators.d.ts +47 -35
  113. package/lib/commands/decorators.js +19 -27
  114. package/lib/commands/handle.d.ts +64 -0
  115. package/lib/commands/handle.js +685 -0
  116. package/lib/commands/handler.d.ts +27 -18
  117. package/lib/commands/handler.js +296 -160
  118. package/lib/commands/optionresolver.d.ts +13 -13
  119. package/lib/commands/optionresolver.js +23 -28
  120. package/lib/common/bot/watcher.d.ts +4 -33
  121. package/lib/common/bot/watcher.js +0 -109
  122. package/lib/common/index.d.ts +2 -0
  123. package/lib/common/index.js +4 -1
  124. package/lib/common/it/colors.js +48 -49
  125. package/lib/common/it/formatter.d.ts +187 -0
  126. package/lib/common/it/formatter.js +226 -0
  127. package/lib/common/it/logger.d.ts +0 -1
  128. package/lib/common/it/logger.js +8 -8
  129. package/lib/common/it/utils.d.ts +15 -2
  130. package/lib/common/it/utils.js +80 -21
  131. package/lib/common/shorters/application.d.ts +56 -0
  132. package/lib/common/shorters/application.js +81 -0
  133. package/lib/common/shorters/bans.d.ts +42 -0
  134. package/lib/common/shorters/bans.js +78 -0
  135. package/lib/common/shorters/channels.d.ts +7 -6
  136. package/lib/common/shorters/channels.js +19 -15
  137. package/lib/common/shorters/emojis.d.ts +5 -6
  138. package/lib/common/shorters/emojis.js +8 -7
  139. package/lib/common/shorters/guilds.d.ts +18 -16
  140. package/lib/common/shorters/guilds.js +31 -26
  141. package/lib/common/shorters/interaction.d.ts +6 -6
  142. package/lib/common/shorters/interaction.js +12 -9
  143. package/lib/common/shorters/members.d.ts +29 -12
  144. package/lib/common/shorters/members.js +55 -16
  145. package/lib/common/shorters/messages.d.ts +7 -8
  146. package/lib/common/shorters/messages.js +10 -9
  147. package/lib/common/shorters/reactions.d.ts +3 -3
  148. package/lib/common/shorters/reactions.js +11 -11
  149. package/lib/common/shorters/roles.d.ts +9 -7
  150. package/lib/common/shorters/roles.js +26 -7
  151. package/lib/common/shorters/templates.d.ts +7 -8
  152. package/lib/common/shorters/templates.js +7 -7
  153. package/lib/common/shorters/threads.d.ts +6 -7
  154. package/lib/common/shorters/threads.js +6 -9
  155. package/lib/common/shorters/users.d.ts +4 -4
  156. package/lib/common/shorters/users.js +8 -4
  157. package/lib/common/shorters/webhook.d.ts +10 -10
  158. package/lib/common/shorters/webhook.js +12 -11
  159. package/lib/common/types/resolvables.d.ts +2 -2
  160. package/lib/common/types/util.d.ts +3 -1
  161. package/lib/common/types/write.d.ts +1 -1
  162. package/lib/components/ActionRow.d.ts +1 -1
  163. package/lib/components/BaseComponent.d.ts +1 -1
  164. package/lib/components/BaseComponent.js +1 -1
  165. package/lib/components/BaseSelectMenuComponent.d.ts +1 -1
  166. package/lib/components/ButtonComponent.d.ts +17 -7
  167. package/lib/components/ButtonComponent.js +19 -2
  168. package/lib/components/ChannelSelectMenuComponent.d.ts +3 -3
  169. package/lib/components/MentionableSelectMenuComponent.d.ts +2 -2
  170. package/lib/components/RoleSelectMenuComponent.d.ts +2 -2
  171. package/lib/components/StringSelectMenuComponent.d.ts +2 -2
  172. package/lib/components/TextInputComponent.d.ts +2 -2
  173. package/lib/components/UserSelectMenuComponent.d.ts +2 -2
  174. package/lib/components/componentcommand.d.ts +3 -2
  175. package/lib/components/componentcommand.js +4 -3
  176. package/lib/components/componentcontext.d.ts +11 -10
  177. package/lib/components/componentcontext.js +8 -8
  178. package/lib/components/handler.d.ts +16 -15
  179. package/lib/components/handler.js +101 -108
  180. package/lib/components/index.d.ts +3 -3
  181. package/lib/components/index.js +12 -10
  182. package/lib/components/modalcommand.d.ts +2 -1
  183. package/lib/components/modalcommand.js +1 -0
  184. package/lib/components/modalcontext.d.ts +13 -12
  185. package/lib/components/modalcontext.js +2 -2
  186. package/lib/deps/mixer.d.ts +8 -0
  187. package/lib/deps/mixer.js +66 -0
  188. package/lib/events/event.d.ts +4 -3
  189. package/lib/events/handler.d.ts +40 -15
  190. package/lib/events/handler.js +99 -21
  191. package/lib/events/hooks/application_command.d.ts +2 -2
  192. package/lib/events/hooks/auto_moderation.d.ts +6 -7
  193. package/lib/events/hooks/auto_moderation.js +4 -4
  194. package/lib/events/hooks/channel.d.ts +2 -2
  195. package/lib/events/hooks/channel.js +4 -7
  196. package/lib/events/hooks/custom.d.ts +3 -3
  197. package/lib/events/hooks/dispatch.d.ts +3 -4
  198. package/lib/events/hooks/dispatch.js +2 -2
  199. package/lib/events/hooks/entitlement.d.ts +5 -37
  200. package/lib/events/hooks/entitlement.js +7 -7
  201. package/lib/events/hooks/guild.d.ts +126 -181
  202. package/lib/events/hooks/guild.js +13 -15
  203. package/lib/events/hooks/integration.d.ts +71 -15
  204. package/lib/events/hooks/integration.js +3 -3
  205. package/lib/events/hooks/interactions.d.ts +2 -2
  206. package/lib/events/hooks/invite.d.ts +18 -14
  207. package/lib/events/hooks/message.d.ts +72 -52
  208. package/lib/events/hooks/message.js +4 -8
  209. package/lib/events/hooks/presence.d.ts +21 -16
  210. package/lib/events/hooks/stage.d.ts +4 -4
  211. package/lib/events/hooks/thread.d.ts +140 -60
  212. package/lib/events/hooks/thread.js +4 -4
  213. package/lib/events/hooks/typing.d.ts +28 -5
  214. package/lib/events/hooks/typing.js +2 -2
  215. package/lib/events/hooks/user.d.ts +3 -3
  216. package/lib/events/hooks/user.js +2 -2
  217. package/lib/events/hooks/voice.d.ts +28 -3
  218. package/lib/events/hooks/voice.js +8 -4
  219. package/lib/events/hooks/webhook.d.ts +1 -1
  220. package/lib/index.d.ts +6 -15
  221. package/lib/index.js +8 -12
  222. package/lib/langs/handler.d.ts +14 -10
  223. package/lib/langs/handler.js +40 -9
  224. package/lib/structures/AutoModerationRule.d.ts +4 -4
  225. package/lib/structures/AutoModerationRule.js +1 -2
  226. package/lib/structures/ClientUser.d.ts +1 -1
  227. package/lib/structures/Entitlement.d.ts +10 -0
  228. package/lib/structures/Entitlement.js +16 -0
  229. package/lib/structures/Guild.d.ts +37 -30
  230. package/lib/structures/Guild.js +7 -2
  231. package/lib/structures/GuildBan.d.ts +25 -0
  232. package/lib/structures/GuildBan.js +37 -0
  233. package/lib/structures/GuildEmoji.d.ts +4 -4
  234. package/lib/structures/GuildEmoji.js +3 -2
  235. package/lib/structures/GuildMember.d.ts +27 -19
  236. package/lib/structures/GuildMember.js +21 -11
  237. package/lib/structures/GuildPreview.d.ts +1 -1
  238. package/lib/structures/GuildRole.d.ts +5 -3
  239. package/lib/structures/GuildRole.js +8 -1
  240. package/lib/structures/GuildTemplate.d.ts +2 -2
  241. package/lib/structures/GuildTemplate.js +1 -1
  242. package/lib/structures/Interaction.d.ts +56 -38
  243. package/lib/structures/Interaction.js +134 -86
  244. package/lib/structures/Message.d.ts +80 -20
  245. package/lib/structures/Message.js +67 -26
  246. package/lib/structures/Poll.d.ts +4 -3
  247. package/lib/structures/Poll.js +6 -2
  248. package/lib/structures/Sticker.d.ts +10 -10
  249. package/lib/structures/Sticker.js +7 -7
  250. package/lib/structures/User.d.ts +6 -4
  251. package/lib/structures/User.js +6 -2
  252. package/lib/structures/VoiceState.d.ts +15 -11
  253. package/lib/structures/VoiceState.js +35 -17
  254. package/lib/structures/Webhook.d.ts +6 -7
  255. package/lib/structures/Webhook.js +6 -7
  256. package/lib/structures/channels.d.ts +14 -10
  257. package/lib/structures/channels.js +97 -62
  258. package/lib/structures/extra/BaseGuild.d.ts +1 -1
  259. package/lib/structures/extra/BaseGuild.js +3 -3
  260. package/lib/structures/extra/BitField.d.ts +1 -1
  261. package/lib/structures/extra/BitField.js +3 -2
  262. package/lib/structures/extra/DiscordBase.js +2 -2
  263. package/lib/structures/extra/Permissions.d.ts +3 -1
  264. package/lib/structures/extra/Permissions.js +8 -3
  265. package/lib/types/gateway.d.ts +1537 -0
  266. package/lib/types/gateway.js +4 -0
  267. package/lib/types/index.d.ts +9 -1
  268. package/lib/types/index.js +28 -1
  269. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/attachment.d.ts +5 -0
  270. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/attachment.js +2 -0
  271. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/base.d.ts +22 -0
  272. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/base.js +2 -0
  273. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/boolean.d.ts +4 -0
  274. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/boolean.js +2 -0
  275. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/channel.d.ts +7 -0
  276. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/channel.js +2 -0
  277. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/integer.d.ts +17 -0
  278. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/integer.js +2 -0
  279. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/mentionable.d.ts +5 -0
  280. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/mentionable.js +2 -0
  281. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/number.d.ts +17 -0
  282. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/number.js +2 -0
  283. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/role.d.ts +5 -0
  284. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/role.js +2 -0
  285. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/shared.d.ts +25 -0
  286. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/shared.js +20 -0
  287. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/string.d.ts +17 -0
  288. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/string.js +2 -0
  289. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/subcommand.d.ts +11 -0
  290. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/subcommand.js +2 -0
  291. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/subcommandGroup.d.ts +11 -0
  292. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/subcommandGroup.js +2 -0
  293. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/user.d.ts +5 -0
  294. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/user.js +2 -0
  295. package/lib/types/payloads/_interactions/_applicationCommands/chatInput.d.ts +60 -0
  296. package/lib/types/payloads/_interactions/_applicationCommands/chatInput.js +29 -0
  297. package/lib/types/payloads/_interactions/_applicationCommands/contextMenu.d.ts +65 -0
  298. package/lib/types/payloads/_interactions/_applicationCommands/contextMenu.js +2 -0
  299. package/lib/types/payloads/_interactions/_applicationCommands/internals.d.ts +8 -0
  300. package/lib/types/payloads/_interactions/_applicationCommands/internals.js +2 -0
  301. package/lib/types/payloads/_interactions/_applicationCommands/permissions.d.ts +54 -0
  302. package/lib/types/payloads/_interactions/_applicationCommands/permissions.js +20 -0
  303. package/lib/types/payloads/_interactions/applicationCommands.d.ts +153 -0
  304. package/lib/types/payloads/_interactions/applicationCommands.js +61 -0
  305. package/lib/types/payloads/_interactions/autocomplete.d.ts +10 -0
  306. package/lib/types/payloads/_interactions/autocomplete.js +2 -0
  307. package/lib/types/payloads/_interactions/base.d.ts +197 -0
  308. package/lib/types/payloads/_interactions/base.js +2 -0
  309. package/lib/types/payloads/_interactions/messageComponents.d.ts +41 -0
  310. package/lib/types/payloads/_interactions/messageComponents.js +2 -0
  311. package/lib/types/payloads/_interactions/modalSubmit.d.ts +35 -0
  312. package/lib/types/payloads/_interactions/modalSubmit.js +2 -0
  313. package/lib/types/payloads/_interactions/ping.d.ts +3 -0
  314. package/lib/types/payloads/_interactions/ping.js +2 -0
  315. package/lib/types/payloads/_interactions/responses.d.ts +112 -0
  316. package/lib/types/payloads/_interactions/responses.js +54 -0
  317. package/lib/types/payloads/application.d.ts +292 -0
  318. package/lib/types/payloads/application.js +117 -0
  319. package/lib/types/payloads/auditLog.d.ts +644 -0
  320. package/lib/types/payloads/auditLog.js +80 -0
  321. package/lib/types/payloads/autoModeration.d.ts +219 -0
  322. package/lib/types/payloads/autoModeration.js +87 -0
  323. package/lib/types/payloads/channel.d.ts +1708 -0
  324. package/lib/types/payloads/channel.js +372 -0
  325. package/lib/types/payloads/emoji.d.ts +48 -0
  326. package/lib/types/payloads/emoji.js +5 -0
  327. package/lib/types/payloads/gateway.d.ts +373 -0
  328. package/lib/types/payloads/gateway.js +82 -0
  329. package/lib/types/payloads/guild.d.ts +1060 -0
  330. package/lib/types/payloads/guild.js +324 -0
  331. package/lib/types/payloads/guildScheduledEvent.d.ts +138 -0
  332. package/lib/types/payloads/guildScheduledEvent.js +32 -0
  333. package/lib/types/payloads/index.d.ts +64 -0
  334. package/lib/types/payloads/index.js +37 -0
  335. package/lib/types/payloads/interactions.d.ts +24 -0
  336. package/lib/types/payloads/interactions.js +23 -0
  337. package/lib/types/payloads/invite.d.ts +121 -0
  338. package/lib/types/payloads/invite.js +23 -0
  339. package/lib/types/payloads/monetization.d.ts +150 -0
  340. package/lib/types/payloads/monetization.js +79 -0
  341. package/lib/types/payloads/oauth2.d.ts +131 -0
  342. package/lib/types/payloads/oauth2.js +135 -0
  343. package/lib/types/payloads/permissions.d.ts +97 -0
  344. package/lib/types/payloads/permissions.js +16 -0
  345. package/lib/types/payloads/poll.d.ts +104 -0
  346. package/lib/types/payloads/poll.js +16 -0
  347. package/lib/types/payloads/stageInstance.d.ts +77 -0
  348. package/lib/types/payloads/stageInstance.js +19 -0
  349. package/lib/types/payloads/sticker.d.ts +123 -0
  350. package/lib/types/payloads/sticker.js +30 -0
  351. package/lib/types/payloads/teams.d.ts +78 -0
  352. package/lib/types/payloads/teams.js +23 -0
  353. package/lib/types/payloads/template.d.ts +62 -0
  354. package/lib/types/payloads/template.js +5 -0
  355. package/lib/types/payloads/user.d.ts +337 -0
  356. package/lib/types/payloads/user.js +167 -0
  357. package/lib/types/payloads/voice.d.ts +89 -0
  358. package/lib/types/payloads/voice.js +5 -0
  359. package/lib/types/payloads/webhook.d.ts +76 -0
  360. package/lib/types/payloads/webhook.js +21 -0
  361. package/lib/types/rest/application.d.ts +57 -0
  362. package/lib/types/rest/application.js +2 -0
  363. package/lib/types/rest/auditLog.d.ts +30 -0
  364. package/lib/types/rest/auditLog.js +2 -0
  365. package/lib/types/rest/autoModeration.d.ts +66 -0
  366. package/lib/types/rest/autoModeration.js +2 -0
  367. package/lib/types/rest/channel.d.ts +712 -0
  368. package/lib/types/rest/channel.js +11 -0
  369. package/lib/types/rest/emoji.d.ts +54 -0
  370. package/lib/types/rest/emoji.js +2 -0
  371. package/lib/types/rest/gateway.d.ts +9 -0
  372. package/lib/types/rest/gateway.js +2 -0
  373. package/lib/types/rest/guild.d.ts +865 -0
  374. package/lib/types/rest/guild.js +2 -0
  375. package/lib/types/rest/guildScheduledEvent.d.ts +126 -0
  376. package/lib/types/rest/guildScheduledEvent.js +2 -0
  377. package/lib/types/rest/index.d.ts +296 -0
  378. package/lib/types/rest/index.js +292 -0
  379. package/lib/types/rest/interactions.d.ts +194 -0
  380. package/lib/types/rest/interactions.js +2 -0
  381. package/lib/types/rest/invite.d.ts +24 -0
  382. package/lib/types/rest/invite.js +2 -0
  383. package/lib/types/rest/monetization.d.ts +82 -0
  384. package/lib/types/rest/monetization.js +11 -0
  385. package/lib/types/rest/oauth2.d.ts +172 -0
  386. package/lib/types/rest/oauth2.js +2 -0
  387. package/lib/types/rest/poll.d.ts +44 -0
  388. package/lib/types/rest/poll.js +2 -0
  389. package/lib/types/rest/stageInstance.d.ts +58 -0
  390. package/lib/types/rest/stageInstance.js +2 -0
  391. package/lib/types/rest/sticker.d.ts +77 -0
  392. package/lib/types/rest/sticker.js +2 -0
  393. package/lib/types/rest/template.d.ts +62 -0
  394. package/lib/types/rest/template.js +2 -0
  395. package/lib/types/rest/user.d.ts +120 -0
  396. package/lib/types/rest/user.js +2 -0
  397. package/lib/types/rest/voice.d.ts +17 -0
  398. package/lib/types/rest/voice.js +2 -0
  399. package/lib/types/rest/webhook.d.ts +250 -0
  400. package/lib/types/rest/webhook.js +2 -0
  401. package/lib/types/utils/index.d.ts +797 -0
  402. package/lib/types/utils/index.js +799 -0
  403. package/lib/websocket/SharedTypes.d.ts +4 -3
  404. package/lib/websocket/SharedTypes.js +1 -1
  405. package/lib/websocket/constants/index.d.ts +0 -1
  406. package/lib/websocket/discord/basesocket.d.ts +7 -6
  407. package/lib/websocket/discord/basesocket.js +35 -6
  408. package/lib/websocket/discord/events/memberUpdate.d.ts +1 -6
  409. package/lib/websocket/discord/events/memberUpdate.js +2 -1
  410. package/lib/websocket/discord/events/presenceUpdate.d.ts +5 -18
  411. package/lib/websocket/discord/events/presenceUpdate.js +5 -6
  412. package/lib/websocket/discord/shard.d.ts +9 -8
  413. package/lib/websocket/discord/shard.js +65 -47
  414. package/lib/websocket/discord/sharder.d.ts +6 -5
  415. package/lib/websocket/discord/sharder.js +11 -10
  416. package/lib/websocket/discord/shared.d.ts +13 -5
  417. package/lib/websocket/discord/socket/custom.d.ts +52 -0
  418. package/lib/websocket/discord/socket/custom.js +283 -0
  419. package/lib/websocket/discord/worker.d.ts +5 -10
  420. package/lib/websocket/discord/workermanager.d.ts +8 -15
  421. package/lib/websocket/discord/workermanager.js +35 -39
  422. package/lib/websocket/structures/index.d.ts +0 -1
  423. package/lib/websocket/structures/index.js +1 -1
  424. package/lib/websocket/structures/timeout.d.ts +0 -1
  425. package/package.json +65 -74
  426. package/lib/cache/adapters/redis.d.ts +0 -37
  427. package/lib/cache/adapters/redis.js +0 -218
  428. package/lib/client/oninteractioncreate.d.ts +0 -4
  429. package/lib/client/oninteractioncreate.js +0 -198
  430. package/lib/client/onmessagecreate.d.ts +0 -3
  431. package/lib/client/onmessagecreate.js +0 -395
  432. package/lib/structures/extra/functions.d.ts +0 -12
  433. package/lib/structures/extra/functions.js +0 -70
@@ -1,21 +1,25 @@
1
- import { type GatewayDispatchPayload, type GatewayPresenceUpdateData } from 'discord-api-types/v10';
2
- import type { Command, CommandContext, Message, SubCommand } from '..';
3
- import { type DeepPartial, type If } from '../common';
1
+ import { type GatewayDispatchPayload, type GatewayPresenceUpdateData } from '../types';
2
+ import type { CommandContext, Message } from '..';
3
+ import { type Awaitable, type DeepPartial, type If } from '../common';
4
4
  import { EventHandler } from '../events';
5
- import { ClientUser } from '../structures';
6
5
  import { ShardManager, type ShardManagerOptions } from '../websocket';
7
6
  import { MemberUpdateHandler } from '../websocket/discord/events/memberUpdate';
8
7
  import { PresenceUpdateHandler } from '../websocket/discord/events/presenceUpdate';
9
8
  import type { BaseClientOptions, ServicesOptions, StartOptions } from './base';
10
9
  import { BaseClient } from './base';
10
+ import { Collectors } from './collectors';
11
+ import { type ClientUserStructure, type MessageStructure } from './transformers';
11
12
  export declare class Client<Ready extends boolean = boolean> extends BaseClient {
12
13
  private __handleGuilds?;
13
14
  gateway: ShardManager;
14
- events?: EventHandler | undefined;
15
- me: If<Ready, ClientUser>;
16
- options: ClientOptions;
15
+ me: If<Ready, ClientUserStructure>;
16
+ options: Omit<ClientOptions, 'commands'> & {
17
+ commands: NonNullable<ClientOptions['commands']>;
18
+ };
17
19
  memberUpdateHandler: MemberUpdateHandler;
18
20
  presenceUpdateHandler: PresenceUpdateHandler;
21
+ collectors: Collectors;
22
+ events?: EventHandler | undefined;
19
23
  constructor(options?: ClientOptions);
20
24
  setServices({ gateway, ...rest }: ServicesOptions & {
21
25
  gateway?: ShardManager;
@@ -43,10 +47,9 @@ export interface ClientOptions extends BaseClientOptions {
43
47
  compress?: ShardManagerOptions['compress'];
44
48
  };
45
49
  commands?: BaseClientOptions['commands'] & {
46
- prefix?: (message: Message) => Promise<string[]> | string[];
50
+ prefix?: (message: MessageStructure) => Awaitable<string[]>;
47
51
  deferReplyResponse?: (ctx: CommandContext) => Parameters<Message['write']>[0];
48
52
  reply?: (ctx: CommandContext) => boolean;
49
- argsParser?: (content: string, command: SubCommand | Command, message: Message) => Record<string, string>;
50
53
  };
51
54
  handlePayload?: ShardManagerOptions['handlePayload'];
52
55
  }
@@ -1,24 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Client = void 0;
4
- const v10_1 = require("discord-api-types/v10");
4
+ const types_1 = require("../types");
5
5
  const common_1 = require("../common");
6
6
  const events_1 = require("../events");
7
- const structures_1 = require("../structures");
8
7
  const websocket_1 = require("../websocket");
9
8
  const memberUpdate_1 = require("../websocket/discord/events/memberUpdate");
10
9
  const presenceUpdate_1 = require("../websocket/discord/events/presenceUpdate");
11
10
  const base_1 = require("./base");
12
- const oninteractioncreate_1 = require("./oninteractioncreate");
13
- const onmessagecreate_1 = require("./onmessagecreate");
11
+ const collectors_1 = require("./collectors");
12
+ const transformers_1 = require("./transformers");
14
13
  let parentPort;
15
14
  class Client extends base_1.BaseClient {
16
15
  __handleGuilds = new Set();
17
16
  gateway;
18
- events = new events_1.EventHandler(this.logger);
19
17
  me;
20
18
  memberUpdateHandler = new memberUpdate_1.MemberUpdateHandler();
21
19
  presenceUpdateHandler = new presenceUpdate_1.PresenceUpdateHandler();
20
+ collectors = new collectors_1.Collectors();
21
+ events = new events_1.EventHandler(this);
22
22
  constructor(options) {
23
23
  super(options);
24
24
  }
@@ -38,10 +38,7 @@ class Client extends base_1.BaseClient {
38
38
  this.events = undefined;
39
39
  }
40
40
  else if (typeof rest.handlers.events === 'function') {
41
- this.events = new events_1.EventHandler(this.logger);
42
- this.events.setHandlers({
43
- callback: rest.handlers.events,
44
- });
41
+ this.events = new events_1.EventHandler(this);
45
42
  }
46
43
  else {
47
44
  this.events = rest.handlers.events;
@@ -61,10 +58,7 @@ class Client extends base_1.BaseClient {
61
58
  if (worker_threads?.parentPort) {
62
59
  parentPort = worker_threads.parentPort;
63
60
  }
64
- if (!worker_threads?.workerData?.__USING_WATCHER__) {
65
- await this.gateway.spawnShards();
66
- }
67
- else {
61
+ if (worker_threads?.workerData?.__USING_WATCHER__) {
68
62
  parentPort?.on('message', (data) => {
69
63
  switch (data.type) {
70
64
  case 'PAYLOAD':
@@ -76,6 +70,9 @@ class Client extends base_1.BaseClient {
76
70
  }
77
71
  });
78
72
  }
73
+ else {
74
+ await this.gateway.spawnShards();
75
+ }
79
76
  }
80
77
  async start(options = {}, execute = true) {
81
78
  await super.start(options);
@@ -98,7 +95,10 @@ class Client extends base_1.BaseClient {
98
95
  shardStart: this.options?.shards?.start,
99
96
  shardEnd: this.options?.shards?.end ?? this.options?.shards?.total,
100
97
  totalShards: this.options?.shards?.total ?? this.options?.shards?.end,
101
- properties: { ...this.options?.gateway?.properties, ...websocket_1.properties },
98
+ properties: {
99
+ ...websocket_1.properties,
100
+ ...this.options?.gateway?.properties,
101
+ },
102
102
  compress: this.options?.gateway?.compress,
103
103
  });
104
104
  }
@@ -111,7 +111,10 @@ class Client extends base_1.BaseClient {
111
111
  }
112
112
  }
113
113
  async onPacket(shardId, packet) {
114
- await this.events?.runEvent('RAW', this, packet, shardId);
114
+ Promise.allSettled([
115
+ this.events?.runEvent('RAW', this, packet, shardId, false),
116
+ this.collectors.run('RAW', packet, this),
117
+ ]); //ignore promise
115
118
  switch (packet.t) {
116
119
  //// Cases where we must obtain the old data before updating
117
120
  case 'GUILD_MEMBER_UPDATE':
@@ -119,72 +122,63 @@ class Client extends base_1.BaseClient {
119
122
  return;
120
123
  }
121
124
  await this.events?.execute(packet.t, packet, this, shardId);
122
- await this.cache.onPacket(packet);
123
125
  break;
124
126
  case 'PRESENCE_UPDATE':
125
127
  if (!this.presenceUpdateHandler.check(packet.d)) {
126
128
  return;
127
129
  }
128
130
  await this.events?.execute(packet.t, packet, this, shardId);
129
- await this.cache.onPacket(packet);
130
131
  break;
131
- case 'MESSAGE_UPDATE':
132
- case 'MESSAGE_DELETE_BULK':
133
- case 'MESSAGE_DELETE':
134
132
  case 'GUILD_DELETE':
135
- case 'CHANNEL_UPDATE':
136
- case 'GUILD_EMOJIS_UPDATE':
137
- case 'GUILD_UPDATE':
138
- case 'GUILD_ROLE_UPDATE':
139
- case 'GUILD_ROLE_DELETE':
140
- case 'THREAD_UPDATE':
141
- case 'USER_UPDATE':
142
- case 'VOICE_STATE_UPDATE':
143
- case 'STAGE_INSTANCE_UPDATE':
144
- case 'GUILD_STICKERS_UPDATE':
133
+ case 'GUILD_CREATE': {
134
+ if (this.__handleGuilds?.has(packet.d.id)) {
135
+ this.__handleGuilds?.delete(packet.d.id);
136
+ if (!this.__handleGuilds?.size && [...this.gateway.values()].every(shard => shard.data.session_id)) {
137
+ delete this.__handleGuilds;
138
+ await this.cache.onPacket?.(packet);
139
+ return this.events?.runEvent('BOT_READY', this, this.me, -1);
140
+ }
141
+ if (!this.__handleGuilds?.size)
142
+ delete this.__handleGuilds;
143
+ return this.cache.onPacket?.(packet);
144
+ }
145
145
  await this.events?.execute(packet.t, packet, this, shardId);
146
- await this.cache.onPacket(packet);
147
146
  break;
147
+ }
148
148
  //rest of the events
149
149
  default: {
150
- await this.cache.onPacket(packet);
151
150
  switch (packet.t) {
152
151
  case 'INTERACTION_CREATE':
153
- await (0, oninteractioncreate_1.onInteractionCreate)(this, packet.d, shardId);
152
+ await this.events?.execute(packet.t, packet, this, shardId);
153
+ await this.handleCommand.interaction(packet.d, shardId);
154
154
  break;
155
155
  case 'MESSAGE_CREATE':
156
- await (0, onmessagecreate_1.onMessageCreate)(this, packet.d, shardId);
156
+ await this.events?.execute(packet.t, packet, this, shardId);
157
+ await this.handleCommand.message(packet.d, shardId);
157
158
  break;
158
159
  case 'READY':
160
+ if (!this.__handleGuilds)
161
+ this.__handleGuilds = new Set();
159
162
  for (const g of packet.d.guilds) {
160
163
  this.__handleGuilds?.add(g.id);
161
164
  }
162
165
  this.botId = packet.d.user.id;
163
166
  this.applicationId = packet.d.application.id;
164
- this.me = new structures_1.ClientUser(this, packet.d.user, packet.d.application);
165
- if (!this.__handleGuilds?.size ||
166
- !((this.gateway.options.intents & v10_1.GatewayIntentBits.Guilds) === v10_1.GatewayIntentBits.Guilds)) {
167
+ this.me = transformers_1.Transformers.ClientUser(this, packet.d.user, packet.d.application);
168
+ if (!(this.__handleGuilds?.size &&
169
+ (this.gateway.options.intents & types_1.GatewayIntentBits.Guilds) === types_1.GatewayIntentBits.Guilds)) {
167
170
  if ([...this.gateway.values()].every(shard => shard.data.session_id)) {
168
171
  await this.events?.runEvent('BOT_READY', this, this.me, -1);
169
172
  }
170
173
  delete this.__handleGuilds;
171
174
  }
172
175
  this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`);
176
+ await this.events?.execute(packet.t, packet, this, shardId);
173
177
  break;
174
- case 'GUILD_CREATE': {
175
- if (this.__handleGuilds?.has(packet.d.id)) {
176
- this.__handleGuilds.delete(packet.d.id);
177
- if (!this.__handleGuilds.size && [...this.gateway.values()].every(shard => shard.data.session_id)) {
178
- await this.events?.runEvent('BOT_READY', this, this.me, -1);
179
- }
180
- if (!this.__handleGuilds.size)
181
- delete this.__handleGuilds;
182
- return;
183
- }
178
+ default:
179
+ await this.events?.execute(packet.t, packet, this, shardId);
184
180
  break;
185
- }
186
181
  }
187
- await this.events?.execute(packet.t, packet, this, shardId);
188
182
  break;
189
183
  }
190
184
  }
@@ -0,0 +1,36 @@
1
+ import type { Awaitable, CamelCase } from '../common';
2
+ import type { CallbackEventHandler, CustomEventsKeys, GatewayEvents } from '../events';
3
+ export type AllClientEvents = CustomEventsKeys | GatewayEvents;
4
+ export type ParseClientEventName<T extends AllClientEvents> = T extends CustomEventsKeys ? T : CamelCase<T>;
5
+ export type CollectorRunPameters<T extends AllClientEvents> = Awaited<Parameters<CallbackEventHandler[ParseClientEventName<T>]>[0]>;
6
+ type RunData<T extends AllClientEvents> = {
7
+ options: {
8
+ event: T;
9
+ idle?: number;
10
+ timeout?: number;
11
+ onStop?: (reason: string) => unknown;
12
+ onStopError?: (reason: string, error: unknown) => unknown;
13
+ filter: (arg: CollectorRunPameters<T>) => Awaitable<boolean>;
14
+ run: (arg: CollectorRunPameters<T>, stop: (reason?: string) => void) => unknown;
15
+ onRunError?: (arg: CollectorRunPameters<T>, error: unknown, stop: (reason?: string) => void) => unknown;
16
+ };
17
+ idle?: NodeJS.Timeout;
18
+ timeout?: NodeJS.Timeout;
19
+ nonce: string;
20
+ };
21
+ export declare class Collectors {
22
+ readonly values: Map<AllClientEvents, RunData<any>[]>;
23
+ private generateRandomUUID;
24
+ create<T extends AllClientEvents>(options: RunData<T>['options']): {
25
+ event: T;
26
+ idle?: number;
27
+ timeout?: number;
28
+ onStop?: (reason: string) => unknown;
29
+ onStopError?: (reason: string, error: unknown) => unknown;
30
+ filter: (arg: Awaited<Parameters<CallbackEventHandler[ParseClientEventName<T>]>[0]>) => Awaitable<boolean>;
31
+ run: (arg: Awaited<Parameters<CallbackEventHandler[ParseClientEventName<T>]>[0]>, stop: (reason?: string) => void) => unknown;
32
+ onRunError?: ((arg: Awaited<Parameters<CallbackEventHandler[ParseClientEventName<T>]>[0]>, error: unknown, stop: (reason?: string) => void) => unknown) | undefined;
33
+ };
34
+ private delete;
35
+ }
36
+ export {};
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Collectors = void 0;
27
+ const node_crypto_1 = require("node:crypto");
28
+ const node_console_1 = require("node:console");
29
+ const RawEvents = __importStar(require("../events/hooks"));
30
+ class Collectors {
31
+ values = new Map();
32
+ generateRandomUUID(name) {
33
+ const collectors = this.values.get(name);
34
+ if (!collectors)
35
+ return '*';
36
+ let nonce = (0, node_crypto_1.randomUUID)();
37
+ while (collectors.find(x => x.nonce === nonce)) {
38
+ nonce = (0, node_crypto_1.randomUUID)();
39
+ }
40
+ return nonce;
41
+ }
42
+ create(options) {
43
+ const nonce = this.generateRandomUUID(options.event);
44
+ if (!this.values.has(options.event)) {
45
+ this.values.set(options.event, []);
46
+ }
47
+ this.values.get(options.event).push({
48
+ options: {
49
+ ...options,
50
+ name: options.event,
51
+ },
52
+ idle: options.idle && options.idle > 0
53
+ ? setTimeout(() => {
54
+ return this.delete(options.event, nonce, 'idle');
55
+ }, options.idle)
56
+ : undefined,
57
+ timeout: options.timeout && options.timeout > 0
58
+ ? setTimeout(() => {
59
+ return this.delete(options.event, nonce, 'timeout');
60
+ }, options.timeout)
61
+ : undefined,
62
+ nonce,
63
+ });
64
+ return options;
65
+ }
66
+ async delete(name, nonce, reason = 'unknown') {
67
+ const collectors = this.values.get(name);
68
+ if (!collectors?.length) {
69
+ if (collectors)
70
+ this.values.delete(name);
71
+ return;
72
+ }
73
+ const index = collectors.findIndex(x => x.nonce === nonce);
74
+ if (index === -1)
75
+ return;
76
+ const collector = collectors[index];
77
+ clearTimeout(collector.idle);
78
+ clearTimeout(collector.timeout);
79
+ collectors.splice(index, 1);
80
+ try {
81
+ await collector.options.onStop?.(reason);
82
+ }
83
+ catch (e) {
84
+ await collector.options.onStopError?.(reason, node_console_1.error);
85
+ }
86
+ }
87
+ /**@internal */
88
+ async run(name, raw, client) {
89
+ const collectors = this.values.get(name);
90
+ if (!collectors)
91
+ return;
92
+ const data = (await RawEvents[name]?.(client, raw)) ?? raw;
93
+ for (const i of collectors) {
94
+ if (await i.options.filter(data)) {
95
+ i.idle?.refresh();
96
+ const stop = (reason = 'unknown') => {
97
+ return this.delete(i.options.event, i.nonce, reason);
98
+ };
99
+ try {
100
+ await i.options.run(data, stop);
101
+ }
102
+ catch (e) {
103
+ await i.options.onRunError?.(data, e, stop);
104
+ }
105
+ break;
106
+ }
107
+ }
108
+ }
109
+ }
110
+ exports.Collectors = Collectors;
@@ -1,19 +1,14 @@
1
- /// <reference types="node" />
2
- import { type APIInteraction } from 'discord-api-types/v10';
3
- import type { HttpRequest, HttpResponse } from 'uWebSockets.js';
4
- import { type DeepPartial } from '../common';
1
+ import type { APIInteractionResponse, APIInteraction } from '../types';
2
+ import type { DeepPartial } from '../common';
5
3
  import type { BaseClientOptions, StartOptions } from './base';
6
4
  import { BaseClient } from './base';
7
5
  export declare class HttpClient extends BaseClient {
8
- app?: ReturnType<typeof import('uWebSockets.js').App>;
9
- publicKey: string;
10
- publicKeyHex: Buffer;
11
6
  constructor(options?: BaseClientOptions);
12
- protected static readJson<T extends Record<string, any>>(res: HttpResponse): Promise<T>;
13
- protected execute(options: DeepPartial<StartOptions['httpConnection']>): Promise<void>;
14
7
  start(options?: DeepPartial<Omit<StartOptions, 'connection' | 'eventsDir'>>): Promise<void>;
15
- protected verifySignatureGenericRequest(req: Request): Promise<APIInteraction | undefined>;
16
- protected verifySignature(res: HttpResponse, req: HttpRequest): Promise<APIInteraction | undefined>;
17
- fetch(req: Request): Promise<Response>;
18
- protected onPacket(res: HttpResponse, req: HttpRequest): Promise<void>;
8
+ onPacket(rawBody: APIInteraction): Promise<{
9
+ headers: {
10
+ 'Content-Type'?: string;
11
+ };
12
+ response: APIInteractionResponse | FormData;
13
+ }>;
19
14
  }
@@ -1,237 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpClient = void 0;
4
- const v10_1 = require("discord-api-types/v10");
5
- const magic_bytes_js_1 = require("magic-bytes.js");
6
- const api_1 = require("../api");
7
4
  const utils_1 = require("../api/utils/utils");
8
- const common_1 = require("../common");
9
5
  const base_1 = require("./base");
10
- const oninteractioncreate_1 = require("./oninteractioncreate");
11
- let UWS;
12
- let nacl;
13
- try {
14
- UWS = require('uWebSockets.js');
15
- }
16
- catch {
17
- // easter egg #1
18
- }
19
- try {
20
- nacl = require('tweetnacl');
21
- }
22
- catch {
23
- // I always cum
24
- }
25
6
  class HttpClient extends base_1.BaseClient {
26
- app;
27
- publicKey;
28
- publicKeyHex;
29
7
  constructor(options) {
30
8
  super(options);
31
- // if (!UWS) {
32
- // throw new Error('No uws installed.');
33
- // }
34
- if (!nacl) {
35
- throw new Error('No tweetnacl installed.');
36
- }
37
9
  }
38
- static readJson(res) {
39
- return new Promise((cb, err) => {
40
- let buffer;
41
- res.onData((ab, isLast) => {
42
- const chunk = Buffer.from(ab);
43
- if (isLast) {
44
- let json;
45
- try {
46
- json = JSON.parse(buffer ? Buffer.concat([buffer, chunk]).toString() : chunk.toString());
10
+ async start(options = {}) {
11
+ await super.start(options);
12
+ return this.execute(options.httpConnection ?? {});
13
+ }
14
+ async onPacket(rawBody) {
15
+ return new Promise(async (r) => {
16
+ await this.handleCommand.interaction(rawBody, -1, async ({ body, files }) => {
17
+ let response;
18
+ const headers = {};
19
+ if (files) {
20
+ response = new FormData();
21
+ for (const [index, file] of files.entries()) {
22
+ const fileKey = file.key ?? `files[${index}]`;
23
+ if ((0, utils_1.isBufferLike)(file.data)) {
24
+ response.append(fileKey, new Blob([file.data], { type: file.contentType }), file.name);
25
+ }
26
+ else {
27
+ response.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name);
28
+ }
47
29
  }
48
- catch (e) {
49
- res.close();
50
- return;
30
+ if (body) {
31
+ response.append('payload_json', JSON.stringify(body));
51
32
  }
52
- cb(json);
53
33
  }
54
34
  else {
55
- buffer = Buffer.concat(buffer ? [buffer, chunk] : [chunk]);
35
+ response = body ?? {};
36
+ headers['Content-Type'] = 'application/json';
56
37
  }
38
+ return r({
39
+ headers,
40
+ response,
41
+ });
57
42
  });
58
- res.onAborted(err);
59
43
  });
60
44
  }
61
- async execute(options) {
62
- await super.execute();
63
- const { publicKey: publicKeyRC, port: portRC, applicationId: applicationIdRC, } = await this.getRC();
64
- const publicKey = options.publicKey ?? publicKeyRC;
65
- const port = options.port ?? portRC;
66
- if (!publicKey) {
67
- throw new Error('Expected a publicKey, check your config file');
68
- }
69
- if (!port) {
70
- throw new Error('Expected a port, check your config file');
71
- }
72
- if (applicationIdRC) {
73
- this.applicationId = applicationIdRC;
74
- }
75
- this.publicKey = publicKey;
76
- this.publicKeyHex = Buffer.from(this.publicKey, 'hex');
77
- if (UWS && options.useUWS) {
78
- this.app = UWS.App();
79
- this.app.post('/interactions', (res, req) => {
80
- return this.onPacket(res, req);
81
- });
82
- this.app.listen(port, () => {
83
- this.logger.info(`Listening to <url>:${port}/interactions`);
84
- });
85
- }
86
- else {
87
- if (options.useUWS)
88
- return this.logger.warn('No uWebSockets installed.');
89
- this.logger.info('Use your preferred http server and invoke <HttpClient>.fetch(<Request>) to get started');
90
- }
91
- }
92
- async start(options = {}) {
93
- await super.start(options);
94
- return this.execute((0, common_1.MergeOptions)({ useUWS: true }, options.httpConnection));
95
- }
96
- async verifySignatureGenericRequest(req) {
97
- const timestamp = req.headers.get('x-signature-timestamp');
98
- const ed25519 = req.headers.get('x-signature-ed25519') ?? '';
99
- const body = (await req.json());
100
- if (nacl.sign.detached.verify(Buffer.from(timestamp + JSON.stringify(body)), Buffer.from(ed25519, 'hex'), this.publicKeyHex)) {
101
- return body;
102
- }
103
- return;
104
- }
105
- // https://discord.com/developers/docs/interactions/receiving-and-responding#security-and-authorization
106
- async verifySignature(res, req) {
107
- const timestamp = req.getHeader('x-signature-timestamp');
108
- const ed25519 = req.getHeader('x-signature-ed25519');
109
- const body = await HttpClient.readJson(res);
110
- if (nacl.sign.detached.verify(Buffer.from(timestamp + JSON.stringify(body)), Buffer.from(ed25519, 'hex'), this.publicKeyHex)) {
111
- return body;
112
- }
113
- return;
114
- }
115
- async fetch(req) {
116
- const rawBody = await this.verifySignatureGenericRequest(req);
117
- if (!rawBody) {
118
- this.debugger?.debug('Invalid request/No info, returning 418 status.');
119
- // I'm a teapot
120
- return new Response('', { status: 418 });
121
- }
122
- switch (rawBody.type) {
123
- case v10_1.InteractionType.Ping:
124
- this.debugger?.debug('Ping interaction received, responding.');
125
- return Response.json({ type: v10_1.InteractionResponseType.Pong }, {
126
- headers: {
127
- 'Content-Type': 'application/json',
128
- },
129
- });
130
- default:
131
- return new Promise(r => {
132
- if ((0, common_1.isCloudfareWorker)())
133
- return (0, oninteractioncreate_1.onInteractionCreate)(this, rawBody, -1)
134
- .then(() => r(new Response()))
135
- .catch(() => r(new Response()));
136
- return (0, oninteractioncreate_1.onInteractionCreate)(this, rawBody, -1, async ({ body, files }) => {
137
- let response;
138
- const headers = {};
139
- if (files) {
140
- response = new FormData();
141
- for (const [index, file] of files.entries()) {
142
- const fileKey = file.key ?? `files[${index}]`;
143
- if ((0, utils_1.isBufferLike)(file.data)) {
144
- let contentType = file.contentType;
145
- if (!contentType) {
146
- const [parsedType] = (0, magic_bytes_js_1.filetypeinfo)(file.data);
147
- if (parsedType) {
148
- contentType =
149
- api_1.OverwrittenMimeTypes[parsedType.mime] ??
150
- parsedType.mime ??
151
- 'application/octet-stream';
152
- }
153
- }
154
- response.append(fileKey, new Blob([file.data], { type: contentType }), file.name);
155
- }
156
- else {
157
- response.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name);
158
- }
159
- }
160
- if (body) {
161
- response.append('payload_json', JSON.stringify(body));
162
- }
163
- }
164
- else {
165
- response = body ?? {};
166
- headers['Content-Type'] = 'application/json';
167
- }
168
- r(response instanceof FormData
169
- ? new Response(response, { headers })
170
- : Response.json(response, {
171
- headers,
172
- }));
173
- });
174
- });
175
- }
176
- }
177
- async onPacket(res, req) {
178
- const rawBody = await this.verifySignature(res, req);
179
- if (!rawBody) {
180
- this.debugger?.debug('Invalid request/No info, returning 418 status.');
181
- // I'm a teapot
182
- res.writeStatus('418').end();
183
- }
184
- else {
185
- switch (rawBody.type) {
186
- case v10_1.InteractionType.Ping:
187
- this.debugger?.debug('Ping interaction received, responding.');
188
- res
189
- .writeHeader('Content-Type', 'application/json')
190
- .end(JSON.stringify({ type: v10_1.InteractionResponseType.Pong }));
191
- break;
192
- default:
193
- await (0, oninteractioncreate_1.onInteractionCreate)(this, rawBody, -1, async ({ body, files }) => {
194
- res.cork(() => {
195
- let response;
196
- const headers = {};
197
- if (files) {
198
- response = new FormData();
199
- for (const [index, file] of files.entries()) {
200
- const fileKey = file.key ?? `files[${index}]`;
201
- if ((0, utils_1.isBufferLike)(file.data)) {
202
- let contentType = file.contentType;
203
- if (!contentType) {
204
- const [parsedType] = (0, magic_bytes_js_1.filetypeinfo)(file.data);
205
- if (parsedType) {
206
- contentType =
207
- api_1.OverwrittenMimeTypes[parsedType.mime] ??
208
- parsedType.mime ??
209
- 'application/octet-stream';
210
- }
211
- }
212
- response.append(fileKey, new Blob([file.data], { type: contentType }), file.name);
213
- }
214
- else {
215
- response.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name);
216
- }
217
- }
218
- if (body) {
219
- response.append('payload_json', JSON.stringify(body));
220
- }
221
- }
222
- else {
223
- response = body ?? {};
224
- headers['Content-Type'] = 'application/json';
225
- }
226
- for (const i in headers) {
227
- res.writeHeader(i, headers[i]);
228
- }
229
- return res.end(JSON.stringify(response));
230
- });
231
- });
232
- break;
233
- }
234
- }
235
- }
236
45
  }
237
46
  exports.HttpClient = HttpClient;