commandkit 1.0.0-dev.20250529020123 → 1.0.0-dev.20250530015910

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 (391) hide show
  1. package/dist/ActionRow-CmTHbo2t.js +25 -0
  2. package/dist/ActionRow-CmTHbo2t.js.map +1 -0
  3. package/dist/ActionRow-D0wafJhZ.d.ts +16 -0
  4. package/dist/Button-Bl5nbwTS.d.ts +32 -0
  5. package/dist/ButtonKit-BSI7lCI0.d.ts +68 -0
  6. package/dist/ChannelSelectMenuKit-L15A2jpT.d.ts +51 -0
  7. package/dist/CommandKit-CDlCsGCx.d.ts +926 -0
  8. package/dist/CommandKit-DDrQtQns.js +3281 -0
  9. package/dist/CommandKit-DDrQtQns.js.map +1 -0
  10. package/dist/CommandKit.d.ts +33 -13
  11. package/dist/CommandKit.js +46 -16
  12. package/dist/CommandKitEventsChannel-B6LKgxmv.js +44 -0
  13. package/dist/CommandKitEventsChannel-B6LKgxmv.js.map +1 -0
  14. package/dist/CommandsRouter-BHaPno8o.js +127 -0
  15. package/dist/CommandsRouter-BHaPno8o.js.map +1 -0
  16. package/dist/CommandsRouter-C7X-eXE2.d.ts +67 -0
  17. package/dist/CompilerPlugin-XzuGixkC.js +32 -0
  18. package/dist/CompilerPlugin-XzuGixkC.js.map +1 -0
  19. package/dist/CompilerPluginRuntime-zFCCw1kM.js +70 -0
  20. package/dist/CompilerPluginRuntime-zFCCw1kM.js.map +1 -0
  21. package/dist/DefaultLogger-D3G0rGnV.d.ts +30 -0
  22. package/dist/EventInterceptor-D_oEWSnF.d.ts +84 -0
  23. package/dist/EventInterceptor-DtRINyTP.js +140 -0
  24. package/dist/EventInterceptor-DtRINyTP.js.map +1 -0
  25. package/dist/EventWorkerContext-C0e23GNY.d.ts +19 -0
  26. package/dist/EventWorkerContext-XZGSHn5F.js +45 -0
  27. package/dist/EventWorkerContext-XZGSHn5F.js.map +1 -0
  28. package/dist/EventsRouter-BacqK6z3.d.ts +90 -0
  29. package/dist/EventsRouter-CqnrlbjN.js +133 -0
  30. package/dist/EventsRouter-CqnrlbjN.js.map +1 -0
  31. package/dist/ILogger-BTMQuall.d.ts +11 -0
  32. package/dist/ILogger-DucYb0bG.js +0 -0
  33. package/dist/Logger-A3wjB7L1.d.ts +17 -0
  34. package/dist/MentionableSelectMenuKit-BiUSKUtZ.d.ts +51 -0
  35. package/dist/MessageCommandParser-B13Pkwo9.js +200 -0
  36. package/dist/MessageCommandParser-B13Pkwo9.js.map +1 -0
  37. package/dist/MessageCommandParser-tzroBwij.d.ts +62 -0
  38. package/dist/Modal-Cxm6cs5c.d.ts +58 -0
  39. package/dist/ModalKit-CKtQ8eXW.d.ts +66 -0
  40. package/dist/PluginCommon-DPqnQngK.js +48 -0
  41. package/dist/PluginCommon-DPqnQngK.js.map +1 -0
  42. package/dist/RoleSelectMenuKit-BSMKkru2.d.ts +51 -0
  43. package/dist/RuntimePlugin-CKsd83M3.js +130 -0
  44. package/dist/RuntimePlugin-CKsd83M3.js.map +1 -0
  45. package/dist/SelectMenu-b7jgrkjO.d.ts +36 -0
  46. package/dist/StringSelectMenuKit-B9FHTe48.d.ts +51 -0
  47. package/dist/UserSelectMenuKit-DiP0imyo.d.ts +51 -0
  48. package/dist/app/commands/AppCommandRunner.d.ts +33 -13
  49. package/dist/app/commands/AppCommandRunner.js +38 -3
  50. package/dist/app/commands/Context.d.ts +33 -13
  51. package/dist/app/commands/Context.js +40 -3
  52. package/dist/app/commands/MessageCommandParser.d.ts +2 -60
  53. package/dist/app/commands/MessageCommandParser.js +5 -2
  54. package/dist/app/commands/helpers.d.ts +2 -7
  55. package/dist/app/commands/helpers.js +4 -2
  56. package/dist/app/events/EventWorkerContext.d.ts +34 -28
  57. package/dist/app/events/EventWorkerContext.js +6 -2
  58. package/dist/app/handlers/AppCommandHandler.d.ts +33 -13
  59. package/dist/app/handlers/AppCommandHandler.js +38 -8
  60. package/dist/app/handlers/AppEventsHandler.d.ts +33 -13
  61. package/dist/app/handlers/AppEventsHandler.js +38 -3
  62. package/dist/app/index.d.ts +33 -15
  63. package/dist/app/index.js +51 -8
  64. package/dist/app/middleware/signals.d.ts +2 -18
  65. package/dist/app/middleware/signals.js +6 -2
  66. package/dist/app/register/CommandRegistrar.d.ts +33 -13
  67. package/dist/app/register/CommandRegistrar.js +38 -3
  68. package/dist/app/router/CommandsRouter.d.ts +2 -65
  69. package/dist/app/router/CommandsRouter.js +3 -2
  70. package/dist/app/router/EventsRouter.d.ts +2 -88
  71. package/dist/app/router/EventsRouter.js +3 -2
  72. package/dist/app/router/index.d.ts +4 -3
  73. package/dist/app/router/index.js +6 -2
  74. package/dist/app-CXCbKsPz.js +0 -0
  75. package/dist/app-process-uCX52YaE.js +48 -0
  76. package/dist/app-process-uCX52YaE.js.map +1 -0
  77. package/dist/build-Bkb5t3XA.js +122 -0
  78. package/dist/build-Bkb5t3XA.js.map +1 -0
  79. package/dist/chunk-nOFOJqeH.js +30 -0
  80. package/dist/cli/app-process.d.ts +5 -3
  81. package/dist/cli/app-process.js +8 -3
  82. package/dist/cli/build.d.ts +46 -21
  83. package/dist/cli/build.js +40 -48
  84. package/dist/cli/common.d.ts +39 -19
  85. package/dist/cli/common.js +13 -10
  86. package/dist/cli/development.d.ts +3 -1
  87. package/dist/cli/development.js +185 -50
  88. package/dist/cli/development.js.map +1 -1
  89. package/dist/cli/env.d.ts +7 -5
  90. package/dist/cli/env.js +9 -2
  91. package/dist/cli/generators.d.ts +3 -1
  92. package/dist/cli/generators.js +64 -15
  93. package/dist/cli/generators.js.map +1 -1
  94. package/dist/cli/information.d.ts +3 -1
  95. package/dist/cli/information.js +110 -5
  96. package/dist/cli/information.js.map +1 -1
  97. package/dist/cli/init.d.ts +2 -10
  98. package/dist/cli/init.js +4 -99
  99. package/dist/cli/parse-env.d.ts +3 -1
  100. package/dist/cli/parse-env.js +53 -1
  101. package/dist/cli/parse-env.js.map +1 -1
  102. package/dist/cli/production.d.ts +5 -3
  103. package/dist/cli/production.js +68 -46
  104. package/dist/cli/production.js.map +1 -1
  105. package/dist/cli/type-checker.d.ts +3 -1
  106. package/dist/cli/type-checker.js +7 -5
  107. package/dist/cli/utils.d.ts +4 -2
  108. package/dist/cli/utils.js +3 -2
  109. package/dist/colors-Cd4Oz-r-.js +14 -0
  110. package/dist/colors-Cd4Oz-r-.js.map +1 -0
  111. package/dist/common-CcfjYnPG.js +0 -0
  112. package/dist/common-CeO-vn8Y.js +14 -0
  113. package/dist/common-CeO-vn8Y.js.map +1 -0
  114. package/dist/common-DirpDCa6.js +182 -0
  115. package/dist/common-DirpDCa6.js.map +1 -0
  116. package/dist/common-pvPJVTfe.d.ts +25 -0
  117. package/dist/components/common/EventInterceptor.d.ts +2 -82
  118. package/dist/components/common/EventInterceptor.js +3 -2
  119. package/dist/components/common/element.d.ts +5 -29
  120. package/dist/components/common/element.js +10 -2
  121. package/dist/components/common/types.d.ts +2 -3
  122. package/dist/components/common/types.js +1 -2
  123. package/dist/components/index.d.ts +24 -22
  124. package/dist/components/index.js +72 -16
  125. package/dist/components/v1/action-row/ActionRow.d.ts +6 -18
  126. package/dist/components/v1/action-row/ActionRow.js +3 -2
  127. package/dist/components/v1/button/Button.d.ts +7 -31
  128. package/dist/components/v1/button/Button.js +38 -16
  129. package/dist/components/v1/button/ButtonKit.d.ts +3 -66
  130. package/dist/components/v1/button/ButtonKit.js +38 -16
  131. package/dist/components/v1/modal/Modal.d.ts +7 -57
  132. package/dist/components/v1/modal/Modal.js +41 -16
  133. package/dist/components/v1/modal/ModalKit.d.ts +3 -64
  134. package/dist/components/v1/modal/ModalKit.js +38 -16
  135. package/dist/components/v1/select-menu/ChannelSelectMenuKit.d.ts +4 -49
  136. package/dist/components/v1/select-menu/ChannelSelectMenuKit.js +38 -16
  137. package/dist/components/v1/select-menu/MentionableSelectMenuKit.d.ts +4 -49
  138. package/dist/components/v1/select-menu/MentionableSelectMenuKit.js +38 -16
  139. package/dist/components/v1/select-menu/RoleSelectMenuKit.d.ts +4 -49
  140. package/dist/components/v1/select-menu/RoleSelectMenuKit.js +38 -16
  141. package/dist/components/v1/select-menu/SelectMenu.d.ts +10 -40
  142. package/dist/components/v1/select-menu/SelectMenu.js +43 -16
  143. package/dist/components/v1/select-menu/StringSelectMenuKit.d.ts +4 -49
  144. package/dist/components/v1/select-menu/StringSelectMenuKit.js +38 -16
  145. package/dist/components/v1/select-menu/UserSelectMenuKit.d.ts +4 -49
  146. package/dist/components/v1/select-menu/UserSelectMenuKit.js +38 -16
  147. package/dist/components/v1/select-menu/common.d.ts +3 -23
  148. package/dist/components/v1/select-menu/common.js +1 -2
  149. package/dist/components/v2/common.d.ts +5 -3
  150. package/dist/components/v2/common.js +3 -2
  151. package/dist/components/v2/container.d.ts +2 -8
  152. package/dist/components/v2/container.js +4 -2
  153. package/dist/components/v2/file.d.ts +2 -8
  154. package/dist/components/v2/file.js +3 -2
  155. package/dist/components/v2/index.d.ts +8 -7
  156. package/dist/components/v2/index.js +17 -2
  157. package/dist/components/v2/media-gallery.d.ts +2 -15
  158. package/dist/components/v2/media-gallery.js +5 -2
  159. package/dist/components/v2/section.d.ts +2 -16
  160. package/dist/components/v2/section.js +5 -2
  161. package/dist/components/v2/separator.d.ts +2 -7
  162. package/dist/components/v2/separator.js +3 -2
  163. package/dist/components/v2/text-display.d.ts +2 -10
  164. package/dist/components/v2/text-display.js +3 -2
  165. package/dist/config/config.d.ts +36 -28
  166. package/dist/config/config.js +39 -3
  167. package/dist/config/default.d.ts +37 -17
  168. package/dist/config/default.js +38 -3
  169. package/dist/config/loader.d.ts +37 -17
  170. package/dist/config/loader.js +39 -11
  171. package/dist/config/types.d.ts +34 -83
  172. package/dist/config/types.js +0 -2
  173. package/dist/config/utils.d.ts +35 -26
  174. package/dist/config/utils.js +15 -1
  175. package/dist/config/utils.js.map +1 -1
  176. package/dist/config-Dyb-zl9w.d.ts +17 -0
  177. package/dist/constants-Ce6w4OFe.d.ts +17 -0
  178. package/dist/constants-DOPSzXI0.js +47 -0
  179. package/dist/constants-DOPSzXI0.js.map +1 -0
  180. package/dist/container-CpuiLsZM.js +33 -0
  181. package/dist/container-CpuiLsZM.js.map +1 -0
  182. package/dist/container-CwEATQy2.d.ts +10 -0
  183. package/dist/context/async-context.d.ts +33 -13
  184. package/dist/context/async-context.js +44 -16
  185. package/dist/context/environment.d.ts +33 -13
  186. package/dist/context/environment.js +41 -3
  187. package/dist/element-D_nyVwgB.d.ts +30 -0
  188. package/dist/element-hdSqnIpC.js +62 -0
  189. package/dist/element-hdSqnIpC.js.map +1 -0
  190. package/dist/env-DKFSgEcR.js +68 -0
  191. package/dist/env-DKFSgEcR.js.map +1 -0
  192. package/dist/error-codes-C_UO39jz.js +53 -0
  193. package/dist/error-codes-C_UO39jz.js.map +1 -0
  194. package/dist/events/CommandKitEventsChannel.d.ts +33 -13
  195. package/dist/events/CommandKitEventsChannel.js +3 -2
  196. package/dist/feature-flags-BJp6kYmi.js +85 -0
  197. package/dist/feature-flags-BJp6kYmi.js.map +1 -0
  198. package/dist/file-BdyYwkaI.d.ts +10 -0
  199. package/dist/file-DE69SSOP.js +18 -0
  200. package/dist/file-DE69SSOP.js.map +1 -0
  201. package/dist/flags/feature-flags.d.ts +33 -13
  202. package/dist/flags/feature-flags.js +40 -16
  203. package/dist/flags/store.d.ts +33 -13
  204. package/dist/flags/store.js +3 -2
  205. package/dist/helpers-CswC9gKF.js +25 -0
  206. package/dist/helpers-CswC9gKF.js.map +1 -0
  207. package/dist/helpers-DAmE106r.d.ts +9 -0
  208. package/dist/index-CUPkUUOR.d.ts +1 -0
  209. package/dist/index-Dw5cCt-A.d.ts +1 -0
  210. package/dist/index-E7Wvm5uX.d.ts +1 -0
  211. package/dist/index.d.ts +43 -51
  212. package/dist/index.js +147 -102
  213. package/dist/index.js.map +1 -1
  214. package/dist/init--p1nl1NO.d.ts +13 -0
  215. package/dist/init-D2me-V0n.js +67 -0
  216. package/dist/init-D2me-V0n.js.map +1 -0
  217. package/dist/logger/DefaultLogger.d.ts +3 -28
  218. package/dist/logger/DefaultLogger.js +38 -3
  219. package/dist/logger/ILogger.d.ts +2 -9
  220. package/dist/logger/ILogger.js +1 -2
  221. package/dist/logger/Logger.d.ts +3 -15
  222. package/dist/logger/Logger.js +39 -3
  223. package/dist/media-gallery-DCu02VXc.d.ts +17 -0
  224. package/dist/media-gallery-nUEHqKVF.js +36 -0
  225. package/dist/media-gallery-nUEHqKVF.js.map +1 -0
  226. package/dist/plugins/CompilerPlugin.d.ts +33 -13
  227. package/dist/plugins/CompilerPlugin.js +5 -2
  228. package/dist/plugins/PluginCommon.d.ts +33 -13
  229. package/dist/plugins/PluginCommon.js +5 -2
  230. package/dist/plugins/RuntimePlugin.d.ts +33 -13
  231. package/dist/plugins/RuntimePlugin.js +5 -2
  232. package/dist/plugins/index.d.ts +33 -15
  233. package/dist/plugins/index.js +44 -3
  234. package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.d.ts +33 -13
  235. package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.js +38 -3
  236. package/dist/plugins/plugin-runtime/CompilerPluginRuntime.d.ts +33 -13
  237. package/dist/plugins/plugin-runtime/CompilerPluginRuntime.js +3 -3
  238. package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.d.ts +33 -26
  239. package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.js +38 -3
  240. package/dist/plugins/plugin-runtime/builtin/MacroPlugin.d.ts +40 -19
  241. package/dist/plugins/plugin-runtime/builtin/MacroPlugin.js +38 -3
  242. package/dist/plugins/plugin-runtime/runtime.d.ts +33 -13
  243. package/dist/plugins/plugin-runtime/runtime.js +1 -2
  244. package/dist/plugins/plugin-runtime/types.d.ts +2 -72
  245. package/dist/plugins/plugin-runtime/types.js +1 -2
  246. package/dist/plugins/types.d.ts +33 -13
  247. package/dist/plugins/types.js +1 -2
  248. package/dist/resolve-file-url-pO9_rLft.js +23 -0
  249. package/dist/resolve-file-url-pO9_rLft.js.map +1 -0
  250. package/dist/router-Dn35v30f.js +0 -0
  251. package/dist/runtime-ByJtSXs_.js +0 -0
  252. package/dist/section-D6t7tyEZ.js +40 -0
  253. package/dist/section-D6t7tyEZ.js.map +1 -0
  254. package/dist/section-fktaECHL.d.ts +18 -0
  255. package/dist/separator-CuesaLrC.d.ts +8 -0
  256. package/dist/separator-DYAFK-Jj.js +17 -0
  257. package/dist/separator-DYAFK-Jj.js.map +1 -0
  258. package/dist/signals-Bp0bzjE6.js +46 -0
  259. package/dist/signals-Bp0bzjE6.js.map +1 -0
  260. package/dist/signals-DUoWkeZ7.d.ts +20 -0
  261. package/dist/store-Ci6ib2C9.js +14 -0
  262. package/dist/store-Ci6ib2C9.js.map +1 -0
  263. package/dist/text-display-DNMwmGHJ.d.ts +12 -0
  264. package/dist/text-display-Dy6JHB5X.js +19 -0
  265. package/dist/text-display-Dy6JHB5X.js.map +1 -0
  266. package/dist/type-checker-FOYNSGX0.js +84 -0
  267. package/dist/type-checker-FOYNSGX0.js.map +1 -0
  268. package/dist/types-0ADL_reY.d.ts +73 -0
  269. package/dist/types-B5VPP9ig.js +0 -0
  270. package/dist/types-BDwNROY2.d.ts +74 -0
  271. package/dist/types-Bq0EWaM3.js +0 -0
  272. package/dist/types-CJ-XvOFN.d.ts +5 -0
  273. package/dist/types-Cdh4uaFR.js +0 -0
  274. package/dist/types-package-DRhFn59I.js +66 -0
  275. package/dist/types-package-DRhFn59I.js.map +1 -0
  276. package/dist/types.d.ts +33 -13
  277. package/dist/types.js +0 -2
  278. package/dist/utilities-5Jw5BdE1.d.ts +42 -0
  279. package/dist/utils/clone.d.ts +3 -1
  280. package/dist/utils/clone.js +8 -1
  281. package/dist/utils/clone.js.map +1 -1
  282. package/dist/utils/colors.d.ts +5 -3
  283. package/dist/utils/colors.js +4 -2
  284. package/dist/utils/constants.d.ts +2 -15
  285. package/dist/utils/constants.js +7 -2
  286. package/dist/utils/dev-hooks.d.ts +33 -13
  287. package/dist/utils/dev-hooks.js +38 -3
  288. package/dist/utils/error-codes.d.ts +9 -7
  289. package/dist/utils/error-codes.js +6 -2
  290. package/dist/utils/get-paths.d.ts +3 -1
  291. package/dist/utils/get-paths.js +33 -1
  292. package/dist/utils/get-paths.js.map +1 -1
  293. package/dist/utils/resolve-file-url.d.ts +3 -1
  294. package/dist/utils/resolve-file-url.js +3 -2
  295. package/dist/utils/types-package.d.ts +3 -1
  296. package/dist/utils/types-package.js +5 -14
  297. package/dist/utils/utilities.d.ts +2 -40
  298. package/dist/utils/utilities.js +44 -3
  299. package/dist/utils/warn-unstable.d.ts +3 -1
  300. package/dist/utils/warn-unstable.js +4 -2
  301. package/dist/utils-C0V7zD7R.d.ts +10 -0
  302. package/dist/utils-IYtoeTur.js +19 -0
  303. package/dist/utils-IYtoeTur.js.map +1 -0
  304. package/dist/v2-DofkPKHs.js +0 -0
  305. package/dist/version-DnRxh8U8.js +15 -0
  306. package/dist/version-DnRxh8U8.js.map +1 -0
  307. package/dist/version-SMsmj3M1.d.ts +8 -0
  308. package/dist/version.d.ts +2 -6
  309. package/dist/version.js +3 -2
  310. package/dist/warn-unstable-V20WCBDd.js +26 -0
  311. package/dist/warn-unstable-V20WCBDd.js.map +1 -0
  312. package/package.json +5 -4
  313. package/dist/CommandKit-jZCy9fZX.d.ts +0 -914
  314. package/dist/CommandKit.js.map +0 -1
  315. package/dist/app/commands/AppCommandRunner.js.map +0 -1
  316. package/dist/app/commands/Context.js.map +0 -1
  317. package/dist/app/commands/MessageCommandParser.js.map +0 -1
  318. package/dist/app/commands/helpers.js.map +0 -1
  319. package/dist/app/events/EventWorkerContext.js.map +0 -1
  320. package/dist/app/handlers/AppCommandHandler.js.map +0 -1
  321. package/dist/app/handlers/AppEventsHandler.js.map +0 -1
  322. package/dist/app/index.js.map +0 -1
  323. package/dist/app/middleware/signals.js.map +0 -1
  324. package/dist/app/register/CommandRegistrar.js.map +0 -1
  325. package/dist/app/router/CommandsRouter.js.map +0 -1
  326. package/dist/app/router/EventsRouter.js.map +0 -1
  327. package/dist/app/router/index.js.map +0 -1
  328. package/dist/cli/app-process.js.map +0 -1
  329. package/dist/cli/build.js.map +0 -1
  330. package/dist/cli/common.js.map +0 -1
  331. package/dist/cli/env.js.map +0 -1
  332. package/dist/cli/init.js.map +0 -1
  333. package/dist/cli/type-checker.js.map +0 -1
  334. package/dist/cli/utils.js.map +0 -1
  335. package/dist/components/common/EventInterceptor.js.map +0 -1
  336. package/dist/components/common/element.js.map +0 -1
  337. package/dist/components/common/types.js.map +0 -1
  338. package/dist/components/index.js.map +0 -1
  339. package/dist/components/v1/action-row/ActionRow.js.map +0 -1
  340. package/dist/components/v1/button/Button.js.map +0 -1
  341. package/dist/components/v1/button/ButtonKit.js.map +0 -1
  342. package/dist/components/v1/modal/Modal.js.map +0 -1
  343. package/dist/components/v1/modal/ModalKit.js.map +0 -1
  344. package/dist/components/v1/select-menu/ChannelSelectMenuKit.js.map +0 -1
  345. package/dist/components/v1/select-menu/MentionableSelectMenuKit.js.map +0 -1
  346. package/dist/components/v1/select-menu/RoleSelectMenuKit.js.map +0 -1
  347. package/dist/components/v1/select-menu/SelectMenu.js.map +0 -1
  348. package/dist/components/v1/select-menu/StringSelectMenuKit.js.map +0 -1
  349. package/dist/components/v1/select-menu/UserSelectMenuKit.js.map +0 -1
  350. package/dist/components/v1/select-menu/common.js.map +0 -1
  351. package/dist/components/v2/common.js.map +0 -1
  352. package/dist/components/v2/container.js.map +0 -1
  353. package/dist/components/v2/file.js.map +0 -1
  354. package/dist/components/v2/index.js.map +0 -1
  355. package/dist/components/v2/media-gallery.js.map +0 -1
  356. package/dist/components/v2/section.js.map +0 -1
  357. package/dist/components/v2/separator.js.map +0 -1
  358. package/dist/components/v2/text-display.js.map +0 -1
  359. package/dist/config/config.js.map +0 -1
  360. package/dist/config/default.js.map +0 -1
  361. package/dist/config/loader.js.map +0 -1
  362. package/dist/config/types.js.map +0 -1
  363. package/dist/context/async-context.js.map +0 -1
  364. package/dist/context/environment.js.map +0 -1
  365. package/dist/events/CommandKitEventsChannel.js.map +0 -1
  366. package/dist/flags/feature-flags.js.map +0 -1
  367. package/dist/flags/store.js.map +0 -1
  368. package/dist/logger/DefaultLogger.js.map +0 -1
  369. package/dist/logger/ILogger.js.map +0 -1
  370. package/dist/logger/Logger.js.map +0 -1
  371. package/dist/plugins/CompilerPlugin.js.map +0 -1
  372. package/dist/plugins/PluginCommon.js.map +0 -1
  373. package/dist/plugins/RuntimePlugin.js.map +0 -1
  374. package/dist/plugins/index.js.map +0 -1
  375. package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.js.map +0 -1
  376. package/dist/plugins/plugin-runtime/CompilerPluginRuntime.js.map +0 -1
  377. package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.js.map +0 -1
  378. package/dist/plugins/plugin-runtime/builtin/MacroPlugin.js.map +0 -1
  379. package/dist/plugins/plugin-runtime/runtime.js.map +0 -1
  380. package/dist/plugins/plugin-runtime/types.js.map +0 -1
  381. package/dist/plugins/types.js.map +0 -1
  382. package/dist/types.js.map +0 -1
  383. package/dist/utils/colors.js.map +0 -1
  384. package/dist/utils/constants.js.map +0 -1
  385. package/dist/utils/dev-hooks.js.map +0 -1
  386. package/dist/utils/error-codes.js.map +0 -1
  387. package/dist/utils/resolve-file-url.js.map +0 -1
  388. package/dist/utils/types-package.js.map +0 -1
  389. package/dist/utils/utilities.js.map +0 -1
  390. package/dist/utils/warn-unstable.js.map +0 -1
  391. package/dist/version.js.map +0 -1
@@ -0,0 +1,3281 @@
1
+ const require_chunk = require('./chunk-nOFOJqeH.js');
2
+ const require_colors = require('./colors-Cd4Oz-r-.js');
3
+ const require_error_codes = require('./error-codes-C_UO39jz.js');
4
+ const require_element = require('./element-hdSqnIpC.js');
5
+ const require_EventInterceptor = require('./EventInterceptor-DtRINyTP.js');
6
+ const require_constants = require('./constants-DOPSzXI0.js');
7
+ const require_CompilerPlugin = require('./CompilerPlugin-XzuGixkC.js');
8
+ const require_RuntimePlugin = require('./RuntimePlugin-CKsd83M3.js');
9
+ const require_EventWorkerContext = require('./EventWorkerContext-XZGSHn5F.js');
10
+ const require_resolve_file_url = require('./resolve-file-url-pO9_rLft.js');
11
+ const require_MessageCommandParser = require('./MessageCommandParser-B13Pkwo9.js');
12
+ const require_signals = require('./signals-Bp0bzjE6.js');
13
+ const require_types_package = require('./types-package-DRhFn59I.js');
14
+ const require_CommandsRouter = require('./CommandsRouter-BHaPno8o.js');
15
+ const require_EventsRouter = require('./EventsRouter-CqnrlbjN.js');
16
+ const require_common = require('./common-DirpDCa6.js');
17
+ const require_CommandKitEventsChannel = require('./CommandKitEventsChannel-B6LKgxmv.js');
18
+ const require_store = require('./store-Ci6ib2C9.js');
19
+ const node_events = require_chunk.__toESM(require("node:events"));
20
+ const discord_js = require_chunk.__toESM(require("discord.js"));
21
+ const node_async_hooks = require_chunk.__toESM(require("node:async_hooks"));
22
+ const node_fs = require_chunk.__toESM(require("node:fs"));
23
+ const node_path = require_chunk.__toESM(require("node:path"));
24
+ const node_crypto = require_chunk.__toESM(require("node:crypto"));
25
+ const __rollup_plugin_json = require_chunk.__toESM(require("@rollup/plugin-json"));
26
+
27
+ //#region src/context/async-context.ts
28
+ const kCommandWorker = Symbol("commandkitCommandWorker");
29
+ const context = new node_async_hooks.AsyncLocalStorage();
30
+ function isCommandWorkerContext(worker) {
31
+ return worker && Reflect.get(worker, kCommandWorker) === true;
32
+ }
33
+ function exitContext(fn) {
34
+ return context.exit(fn);
35
+ }
36
+ function provideContext(value, receiver) {
37
+ Reflect.set(value, kCommandWorker, true);
38
+ return context.run(value, receiver);
39
+ }
40
+ /**
41
+ * Returns a context-aware version of the given function.
42
+ * @param env - The commandkit environment data.
43
+ * @param fn - The target function.
44
+ * @param finalizer - An optional finalizer function to run after the target function. This function will be context-aware.
45
+ * @internal
46
+ */
47
+ function makeContextAwareFunction(env, fn, finalizer) {
48
+ const _fn = (...args) => {
49
+ return provideContext(env, async () => {
50
+ try {
51
+ const result = await fn(...args);
52
+ return result;
53
+ } catch (e) {
54
+ if (!require_error_codes.isCommandKitError(e)) env.setExecutionError(e);
55
+ } finally {
56
+ if (typeof finalizer === "function") setImmediate(async () => {
57
+ try {
58
+ await finalizer(...args);
59
+ } catch {}
60
+ });
61
+ }
62
+ });
63
+ };
64
+ return _fn;
65
+ }
66
+ function getCommandKit(strict = false) {
67
+ var _context$getStore;
68
+ const kit = ((_context$getStore = context.getStore()) === null || _context$getStore === void 0 ? void 0 : _context$getStore.commandkit) ?? CommandKit.instance;
69
+ if (!kit && strict) throw new Error("CommandKit instance not found.");
70
+ return kit;
71
+ }
72
+ /**
73
+ * Get the current commandkit context.
74
+ * @internal
75
+ */
76
+ function getContext() {
77
+ const ctx = context.getStore();
78
+ return ctx;
79
+ }
80
+ /**
81
+ * Use current commandkit context. Throws an error if no context is found.
82
+ */
83
+ function useEnvironment() {
84
+ const ctx = context.getStore();
85
+ if (!ctx) throw new Error("No commandkit environment found. Please make sure you are inside commandkit handler.");
86
+ return ctx;
87
+ }
88
+
89
+ //#endregion
90
+ //#region src/components/v1/button/ButtonKit.ts
91
+ var ButtonKit = class extends discord_js.ButtonBuilder {
92
+ #onClickHandler = null;
93
+ #contextData = {
94
+ autoReset: true,
95
+ time: 5 * 60 * 1e3,
96
+ once: false
97
+ };
98
+ #unsub = null;
99
+ #getEventInterceptor() {
100
+ const ctx = getContext();
101
+ if (!ctx) return getCommandKit(true).eventInterceptor;
102
+ return exitContext(() => ctx.commandkit.eventInterceptor);
103
+ }
104
+ /**
105
+ * Sets up an inline interaction collector for this button. This collector by default allows as many interactions as possible if it is actively used.
106
+ * If unused, this expires after 24 hours or custom time if specified.
107
+ * @param handler The handler to run when the button is clicked
108
+ * @param data The context data to use for the interaction collector
109
+ * @returns This button
110
+ * @example
111
+ * ```ts
112
+ * const button = new ButtonKit()
113
+ * .setLabel('Click me')
114
+ * .setStyle(ButtonStyle.Primary)
115
+ * .setCustomId('click_me')
116
+ * .filter((interaction) => interaction.user.id === '1234567890')
117
+ * .onClick(async (interaction) => {
118
+ * await interaction.reply('You clicked me!');
119
+ * });
120
+ *
121
+ * const row = new ActionRowBuilder().addComponents(button);
122
+ *
123
+ * const message = await channel.send({ content: 'Click the button', components: [row] });
124
+ *
125
+ * // Remove onClick handler and destroy the interaction collector
126
+ * button.onClick(null);
127
+ * ```
128
+ */
129
+ onClick(handler, data) {
130
+ if (this.data.style === discord_js.ButtonStyle.Link) throw new TypeError("Cannot setup \"onClick\" handler on link buttons.");
131
+ if (!handler) throw new TypeError("Cannot setup \"onClick\" without a handler function parameter.");
132
+ if (this.#onClickHandler) this.#destroyCollector();
133
+ this.#onClickHandler = handler;
134
+ if (data) {
135
+ var _this$contextData, _this$contextData2, _this$contextData3, _this$contextData4;
136
+ this.#contextData = {
137
+ autoReset: data.autoReset ?? ((_this$contextData = this.#contextData) === null || _this$contextData === void 0 ? void 0 : _this$contextData.autoReset) ?? true,
138
+ time: data.time ?? ((_this$contextData2 = this.#contextData) === null || _this$contextData2 === void 0 ? void 0 : _this$contextData2.time) ?? 5 * 60 * 1e3,
139
+ filter: data.filter ?? ((_this$contextData3 = this.#contextData) === null || _this$contextData3 === void 0 ? void 0 : _this$contextData3.filter),
140
+ onEnd: data.onEnd ?? ((_this$contextData4 = this.#contextData) === null || _this$contextData4 === void 0 ? void 0 : _this$contextData4.onEnd)
141
+ };
142
+ }
143
+ this.#setupInteractionCollector();
144
+ return this;
145
+ }
146
+ onEnd(handler) {
147
+ if (this.data.style === discord_js.ButtonStyle.Link) throw new TypeError("Cannot setup \"onEnd\" handler on link buttons.");
148
+ if (!handler) throw new TypeError("Cannot setup \"onEnd\" without a handler function parameter.");
149
+ this.#contextData ??= {};
150
+ this.#contextData.onEnd = handler;
151
+ return this;
152
+ }
153
+ /**
154
+ * Sets the handler to run when the interaction collector ends.
155
+ * @param handler - The handler to run when the interaction collector ends.
156
+ * @returns This instance of the modal builder.
157
+ */
158
+ onError(handler) {
159
+ if (!handler) throw new TypeError("Cannot setup \"onError\" without a handler function parameter.");
160
+ this.#contextData ??= {};
161
+ this.#contextData.onError = handler;
162
+ return this;
163
+ }
164
+ /**
165
+ * Sets a filter for the interaction collector.
166
+ * @param predicate The filter to use for the interaction collector
167
+ */
168
+ filter(predicate) {
169
+ this.#contextData ??= {
170
+ autoReset: true,
171
+ time: 5 * 60 * 1e3
172
+ };
173
+ this.#contextData.filter = predicate;
174
+ return this;
175
+ }
176
+ get customId() {
177
+ return this.data.custom_id ?? this.data.customId;
178
+ }
179
+ #setupInteractionCollector() {
180
+ if (this.data.style === discord_js.ButtonStyle.Link || !this.#contextData || !this.#onClickHandler) return;
181
+ const myCustomId = this.customId ?? null;
182
+ if (myCustomId === null) throw new TypeError("Cannot setup \"onClick\" handler on a button without a custom id.");
183
+ const interceptor = this.#getEventInterceptor();
184
+ this.#unsub = interceptor.subscribe(discord_js.Events.InteractionCreate, async (interaction) => {
185
+ var _this$contextData5, _this$unsub;
186
+ if (!interaction.isButton()) return;
187
+ const myCustomId$1 = this.customId ?? null;
188
+ const interactionCustomId = interaction.customId;
189
+ if (myCustomId$1 && interactionCustomId !== myCustomId$1) return;
190
+ const filter = (_this$contextData5 = this.#contextData) === null || _this$contextData5 === void 0 ? void 0 : _this$contextData5.filter;
191
+ if (filter && !await filter(interaction)) return;
192
+ const handler = this.#onClickHandler;
193
+ if (!handler) return (_this$unsub = this.#unsub) === null || _this$unsub === void 0 ? void 0 : _this$unsub.call(this);
194
+ return handler(interaction, this);
195
+ }, this.#contextData);
196
+ }
197
+ dispose() {
198
+ this.#destroyCollector();
199
+ return this;
200
+ }
201
+ #destroyCollector() {
202
+ var _this$unsub2;
203
+ (_this$unsub2 = this.#unsub) === null || _this$unsub2 === void 0 || _this$unsub2.call(this);
204
+ this.#unsub = null;
205
+ this.#contextData = null;
206
+ this.#onClickHandler = null;
207
+ }
208
+ };
209
+
210
+ //#endregion
211
+ //#region src/components/v1/button/Button.ts
212
+ /**
213
+ * The button component.
214
+ * @param props The button properties.
215
+ * @returns The commandkit element.
216
+ * @example <Button style={ButtonStyle.Primary} customId="click_me">Click Me</Button>
217
+ */
218
+ function Button(props) {
219
+ const button = new ButtonKit();
220
+ props.style ??= discord_js.ButtonStyle.Primary;
221
+ if (props.onClick) props.customId ??= `buttonkit::${crypto.randomUUID()}`;
222
+ if (props.customId) button.setCustomId(props.customId);
223
+ if (props.onClick) button.onClick(props.onClick, props.options);
224
+ if (props.disabled) button.setDisabled(props.disabled);
225
+ if (props.emoji) button.setEmoji(props.emoji);
226
+ if (props.skuId) button.setSKUId(props.skuId);
227
+ if (props.url) button.setURL(props.url);
228
+ if (props.style) button.setStyle(props.style);
229
+ const label = props.label || props.children;
230
+ if (label) button.setLabel(Array.isArray(label) ? label.join(" ") : typeof label === "string" ? label : String(label));
231
+ if (props.onEnd) button.onEnd(props.onEnd);
232
+ if (props.onError) button.onError(props.onError);
233
+ return button;
234
+ }
235
+
236
+ //#endregion
237
+ //#region src/components/v1/modal/ModalKit.ts
238
+ var ModalKit = class extends discord_js.ModalBuilder {
239
+ #onSubmitHandler = null;
240
+ #contextData = {
241
+ autoReset: false,
242
+ time: 5 * 60 * 1e3,
243
+ once: true
244
+ };
245
+ #unsub = null;
246
+ #getEventInterceptor() {
247
+ const ctx = getContext();
248
+ if (!ctx) return getCommandKit(true).eventInterceptor;
249
+ return exitContext(() => ctx.commandkit.eventInterceptor);
250
+ }
251
+ /**
252
+ * Sets the handler to run when the modal is submitted.
253
+ * @param handler - The handler to run when the modal is submitted.
254
+ * @param data - The context data for the interaction collector.
255
+ * @returns This instance of the modal builder.
256
+ * @example
257
+ * ```ts
258
+ * const modal = new ModalKit()
259
+ * .setTitle('My Modal')
260
+ * .setCustomId('my-modal')
261
+ * .filter((interaction) => interaction.user.id === '1234567890')
262
+ * .onSubmit(async (interaction) => {
263
+ * await interaction.reply('You submitted the modal!');
264
+ * })
265
+ * .addComponents(actionRow1, actionRow2);
266
+ * ```
267
+ */
268
+ onSubmit(handler, data) {
269
+ if (!handler) throw new TypeError("Cannot setup \"onClick\" without a handler function parameter.");
270
+ if (this.#onSubmitHandler) this.#destroyCollector();
271
+ this.#onSubmitHandler = handler;
272
+ if (data) {
273
+ var _this$contextData, _this$contextData2, _this$contextData3, _this$contextData4;
274
+ this.#contextData = {
275
+ autoReset: data.autoReset ?? ((_this$contextData = this.#contextData) === null || _this$contextData === void 0 ? void 0 : _this$contextData.autoReset) ?? true,
276
+ time: data.time ?? ((_this$contextData2 = this.#contextData) === null || _this$contextData2 === void 0 ? void 0 : _this$contextData2.time) ?? 5 * 60 * 1e3,
277
+ filter: data.filter ?? ((_this$contextData3 = this.#contextData) === null || _this$contextData3 === void 0 ? void 0 : _this$contextData3.filter),
278
+ onEnd: data.onEnd ?? ((_this$contextData4 = this.#contextData) === null || _this$contextData4 === void 0 ? void 0 : _this$contextData4.onEnd)
279
+ };
280
+ }
281
+ this.#setupCollector();
282
+ return this;
283
+ }
284
+ /**
285
+ * Sets the handler to run when the interaction collector ends.
286
+ * @param handler - The handler to run when the interaction collector ends.
287
+ * @returns This instance of the modal builder.
288
+ */
289
+ onEnd(handler) {
290
+ if (!handler) throw new TypeError("Cannot setup \"onEnd\" without a handler function parameter.");
291
+ this.#contextData ??= {};
292
+ this.#contextData.onEnd = handler;
293
+ return this;
294
+ }
295
+ /**
296
+ * Sets the handler to run when the interaction collector ends.
297
+ * @param handler - The handler to run when the interaction collector ends.
298
+ * @returns This instance of the modal builder.
299
+ */
300
+ onError(handler) {
301
+ if (!handler) throw new TypeError("Cannot setup \"onError\" without a handler function parameter.");
302
+ this.#contextData ??= {};
303
+ this.#contextData.onError = handler;
304
+ return this;
305
+ }
306
+ /**
307
+ * Sets a filter for the interaction collector.
308
+ * @param predicate - The filter to use for the interaction collector.
309
+ * @returns This instance of the modal builder.
310
+ */
311
+ filter(predicate) {
312
+ this.#contextData ??= {
313
+ autoReset: true,
314
+ time: 5 * 60 * 1e3
315
+ };
316
+ this.#contextData.filter = predicate;
317
+ return this;
318
+ }
319
+ get customId() {
320
+ return this.data.custom_id ?? this.data.customId;
321
+ }
322
+ #setupCollector() {
323
+ if (!this.#contextData) return;
324
+ if (!this.customId) throw new TypeError("Cannot setup an modal collector without a custom ID.");
325
+ const interceptor = this.#getEventInterceptor();
326
+ if (!interceptor) return;
327
+ this.#unsub = interceptor.subscribe(discord_js.Events.InteractionCreate, async (interaction) => {
328
+ var _this$contextData5, _this$unsub;
329
+ if (!interaction.isModalSubmit()) return;
330
+ const myCustomId = this.customId ?? null;
331
+ const interactionCustomId = interaction.customId;
332
+ if (myCustomId && interactionCustomId !== myCustomId) return;
333
+ const filter = (_this$contextData5 = this.#contextData) === null || _this$contextData5 === void 0 ? void 0 : _this$contextData5.filter;
334
+ if (filter && !await filter(interaction)) return;
335
+ const handler = this.#onSubmitHandler;
336
+ if (!handler) return (_this$unsub = this.#unsub) === null || _this$unsub === void 0 ? void 0 : _this$unsub.call(this);
337
+ return handler(interaction, this);
338
+ }, this.#contextData);
339
+ }
340
+ dispose() {
341
+ this.#destroyCollector();
342
+ return this;
343
+ }
344
+ #destroyCollector() {
345
+ var _this$unsub2;
346
+ (_this$unsub2 = this.#unsub) === null || _this$unsub2 === void 0 || _this$unsub2.call(this);
347
+ this.#unsub = null;
348
+ this.#onSubmitHandler = null;
349
+ this.#contextData = null;
350
+ }
351
+ };
352
+
353
+ //#endregion
354
+ //#region src/components/v1/modal/Modal.ts
355
+ /**
356
+ * The modal component.
357
+ * @param props The modal properties.
358
+ * @returns The commandkit element.
359
+ * @example <Modal title="My Modal" onSubmit={onSubmit}>...</Modal>
360
+ */
361
+ function Modal(props) {
362
+ const modal = new ModalKit();
363
+ if (props.title) modal.setTitle(props.title);
364
+ if (props.onSubmit) props.customId ??= `modalkit::${crypto.randomUUID()}`;
365
+ if (props.customId) modal.setCustomId(props.customId);
366
+ if (props.onSubmit) modal.onSubmit(props.onSubmit, props.options);
367
+ if (props.children) {
368
+ const childs = (Array.isArray(props.children) ? props.children : [props.children]).map((c) => {
369
+ if (c instanceof discord_js.ActionRowBuilder) return c;
370
+ if (c instanceof discord_js.TextInputBuilder) return new discord_js.ActionRowBuilder().addComponents(c);
371
+ }).filter((c) => c != null);
372
+ modal.addComponents(childs);
373
+ }
374
+ if (props.onEnd) modal.onEnd(props.onEnd);
375
+ if (props.onError) modal.onError(props.onError);
376
+ return modal;
377
+ }
378
+ /**
379
+ * The text input component.
380
+ * @param props The text input properties.
381
+ * @returns The commandkit element.
382
+ * @example <TextInput customId="input" label="Input" style={TextInputStyle.Short} />
383
+ */
384
+ function TextInput(props) {
385
+ const input = new discord_js.TextInputBuilder().setStyle(props.style);
386
+ if (props.customId) input.setCustomId(props.customId);
387
+ if (props.label) input.setLabel(props.label);
388
+ if (props.placeholder) input.setPlaceholder(props.placeholder);
389
+ if (props.maxLength) input.setMaxLength(props.maxLength);
390
+ if (props.minLength) input.setMinLength(props.minLength);
391
+ if (props.value) input.setValue(props.value);
392
+ if (props.required) input.setRequired(props.required);
393
+ return input;
394
+ }
395
+ /**
396
+ * The short text input component.
397
+ * @param props The text input properties.
398
+ * @returns The commandkit element.
399
+ * @example <ShortInput customId="input" label="Input" />
400
+ */
401
+ function ShortInput(props) {
402
+ return TextInput({
403
+ ...props,
404
+ style: discord_js.TextInputStyle.Short
405
+ });
406
+ }
407
+ /**
408
+ * The paragraph text input component.
409
+ * @param props The text input properties.
410
+ * @returns The commandkit element.
411
+ * @example <ParagraphInput customId="input" label="Input" />
412
+ */
413
+ function ParagraphInput(props) {
414
+ return TextInput({
415
+ ...props,
416
+ style: discord_js.TextInputStyle.Paragraph
417
+ });
418
+ }
419
+
420
+ //#endregion
421
+ //#region src/components/v1/select-menu/StringSelectMenuKit.ts
422
+ var StringSelectMenuKit = class extends discord_js.StringSelectMenuBuilder {
423
+ #onSelectHandler = null;
424
+ #contextData = {
425
+ autoReset: false,
426
+ time: 5 * 60 * 1e3,
427
+ once: true
428
+ };
429
+ #unsub = null;
430
+ #getEventInterceptor() {
431
+ const ctx = getContext();
432
+ if (!ctx) return getCommandKit(true).eventInterceptor;
433
+ return exitContext(() => ctx.commandkit.eventInterceptor);
434
+ }
435
+ /**
436
+ * Sets the handler to run when the modal is submitted.
437
+ * @param handler - The handler to run when the modal is submitted.
438
+ * @param data - The context data for the interaction collector.
439
+ * @returns This instance of the modal builder.
440
+ * @example
441
+ * ```ts
442
+ * const modal = new StringSelectMenuKit()
443
+ * .setTitle('My Modal')
444
+ * .setCustomId('my-modal')
445
+ * .filter((interaction) => interaction.user.id === '1234567890')
446
+ * .onSelect(async (interaction) => {
447
+ * await interaction.reply('You submitted the modal!');
448
+ * })
449
+ * .addComponents(actionRow1, actionRow2);
450
+ * ```
451
+ */
452
+ onSelect(handler, data) {
453
+ if (!handler) throw new TypeError("Cannot setup \"onClick\" without a handler function parameter.");
454
+ if (this.#onSelectHandler) this.#destroyCollector();
455
+ this.#onSelectHandler = handler;
456
+ if (data) {
457
+ var _this$contextData, _this$contextData2, _this$contextData3, _this$contextData4;
458
+ this.#contextData = {
459
+ autoReset: data.autoReset ?? ((_this$contextData = this.#contextData) === null || _this$contextData === void 0 ? void 0 : _this$contextData.autoReset) ?? true,
460
+ time: data.time ?? ((_this$contextData2 = this.#contextData) === null || _this$contextData2 === void 0 ? void 0 : _this$contextData2.time) ?? 5 * 60 * 1e3,
461
+ filter: data.filter ?? ((_this$contextData3 = this.#contextData) === null || _this$contextData3 === void 0 ? void 0 : _this$contextData3.filter),
462
+ onEnd: data.onEnd ?? ((_this$contextData4 = this.#contextData) === null || _this$contextData4 === void 0 ? void 0 : _this$contextData4.onEnd)
463
+ };
464
+ }
465
+ this.#setupCollector();
466
+ return this;
467
+ }
468
+ /**
469
+ * Sets the handler to run when the interaction collector ends.
470
+ * @param handler - The handler to run when the interaction collector ends.
471
+ * @returns This instance of the modal builder.
472
+ */
473
+ onEnd(handler) {
474
+ if (!handler) throw new TypeError("Cannot setup \"onEnd\" without a handler function parameter.");
475
+ this.#contextData ??= {};
476
+ this.#contextData.onEnd = handler;
477
+ return this;
478
+ }
479
+ /**
480
+ * Sets the handler to run when the interaction collector ends.
481
+ * @param handler - The handler to run when the interaction collector ends.
482
+ * @returns This instance of the modal builder.
483
+ */
484
+ onError(handler) {
485
+ if (!handler) throw new TypeError("Cannot setup \"onError\" without a handler function parameter.");
486
+ this.#contextData ??= {};
487
+ this.#contextData.onError = handler;
488
+ return this;
489
+ }
490
+ /**
491
+ * Sets a filter for the interaction collector.
492
+ * @param predicate - The filter to use for the interaction collector.
493
+ * @returns This instance of the modal builder.
494
+ */
495
+ filter(predicate) {
496
+ this.#contextData ??= {
497
+ autoReset: true,
498
+ time: 5 * 60 * 1e3
499
+ };
500
+ this.#contextData.filter = predicate;
501
+ return this;
502
+ }
503
+ get customId() {
504
+ return this.data.custom_id ?? this.data.customId;
505
+ }
506
+ #setupCollector() {
507
+ if (!this.#contextData) return;
508
+ if (!this.customId) throw new TypeError("Cannot setup an modal collector without a custom ID.");
509
+ const interceptor = this.#getEventInterceptor();
510
+ if (!interceptor) return;
511
+ this.#unsub = interceptor.subscribe(discord_js.Events.InteractionCreate, async (interaction) => {
512
+ var _this$contextData5, _this$unsub;
513
+ if (!interaction.isStringSelectMenu()) return;
514
+ const myCustomId = this.customId ?? null;
515
+ const interactionCustomId = interaction.customId;
516
+ if (myCustomId && interactionCustomId !== myCustomId) return;
517
+ const filter = (_this$contextData5 = this.#contextData) === null || _this$contextData5 === void 0 ? void 0 : _this$contextData5.filter;
518
+ if (filter && !await filter(interaction)) return;
519
+ const handler = this.#onSelectHandler;
520
+ if (!handler) return (_this$unsub = this.#unsub) === null || _this$unsub === void 0 ? void 0 : _this$unsub.call(this);
521
+ return handler(interaction, this);
522
+ }, this.#contextData);
523
+ }
524
+ dispose() {
525
+ this.#destroyCollector();
526
+ return this;
527
+ }
528
+ #destroyCollector() {
529
+ var _this$unsub2;
530
+ (_this$unsub2 = this.#unsub) === null || _this$unsub2 === void 0 || _this$unsub2.call(this);
531
+ this.#unsub = null;
532
+ this.#onSelectHandler = null;
533
+ this.#contextData = null;
534
+ }
535
+ };
536
+
537
+ //#endregion
538
+ //#region src/components/v1/select-menu/ChannelSelectMenuKit.ts
539
+ var ChannelSelectMenuKit = class extends discord_js.ChannelSelectMenuBuilder {
540
+ #onSelectHandler = null;
541
+ #contextData = {
542
+ autoReset: false,
543
+ time: 5 * 60 * 1e3,
544
+ once: true
545
+ };
546
+ #unsub = null;
547
+ #getEventInterceptor() {
548
+ const ctx = getContext();
549
+ if (!ctx) return getCommandKit(true).eventInterceptor;
550
+ return exitContext(() => ctx.commandkit.eventInterceptor);
551
+ }
552
+ /**
553
+ * Sets the handler to run when the modal is submitted.
554
+ * @param handler - The handler to run when the modal is submitted.
555
+ * @param data - The context data for the interaction collector.
556
+ * @returns This instance of the modal builder.
557
+ * @example
558
+ * ```ts
559
+ * const modal = new ChannelSelectMenuKit()
560
+ * .setTitle('My Modal')
561
+ * .setCustomId('my-modal')
562
+ * .filter((interaction) => interaction.Channel.id === '1234567890')
563
+ * .onSelect(async (interaction) => {
564
+ * await interaction.reply('You submitted the modal!');
565
+ * })
566
+ * .addComponents(actionRow1, actionRow2);
567
+ * ```
568
+ */
569
+ onSelect(handler, data) {
570
+ if (!handler) throw new TypeError("Cannot setup \"onClick\" without a handler function parameter.");
571
+ if (this.#onSelectHandler) this.#destroyCollector();
572
+ this.#onSelectHandler = handler;
573
+ if (data) {
574
+ var _this$contextData, _this$contextData2, _this$contextData3, _this$contextData4;
575
+ this.#contextData = {
576
+ autoReset: data.autoReset ?? ((_this$contextData = this.#contextData) === null || _this$contextData === void 0 ? void 0 : _this$contextData.autoReset) ?? true,
577
+ time: data.time ?? ((_this$contextData2 = this.#contextData) === null || _this$contextData2 === void 0 ? void 0 : _this$contextData2.time) ?? 5 * 60 * 1e3,
578
+ filter: data.filter ?? ((_this$contextData3 = this.#contextData) === null || _this$contextData3 === void 0 ? void 0 : _this$contextData3.filter),
579
+ onEnd: data.onEnd ?? ((_this$contextData4 = this.#contextData) === null || _this$contextData4 === void 0 ? void 0 : _this$contextData4.onEnd)
580
+ };
581
+ }
582
+ this.#setupCollector();
583
+ return this;
584
+ }
585
+ /**
586
+ * Sets the handler to run when the interaction collector ends.
587
+ * @param handler - The handler to run when the interaction collector ends.
588
+ * @returns This instance of the modal builder.
589
+ */
590
+ onEnd(handler) {
591
+ if (!handler) throw new TypeError("Cannot setup \"onEnd\" without a handler function parameter.");
592
+ this.#contextData ??= {};
593
+ this.#contextData.onEnd = handler;
594
+ return this;
595
+ }
596
+ /**
597
+ * Sets the handler to run when the interaction collector ends.
598
+ * @param handler - The handler to run when the interaction collector ends.
599
+ * @returns This instance of the modal builder.
600
+ */
601
+ onError(handler) {
602
+ if (!handler) throw new TypeError("Cannot setup \"onError\" without a handler function parameter.");
603
+ this.#contextData ??= {};
604
+ this.#contextData.onError = handler;
605
+ return this;
606
+ }
607
+ /**
608
+ * Sets a filter for the interaction collector.
609
+ * @param predicate - The filter to use for the interaction collector.
610
+ * @returns This instance of the modal builder.
611
+ */
612
+ filter(predicate) {
613
+ this.#contextData ??= {
614
+ autoReset: true,
615
+ time: 5 * 60 * 1e3
616
+ };
617
+ this.#contextData.filter = predicate;
618
+ return this;
619
+ }
620
+ get customId() {
621
+ return this.data.custom_id ?? this.data.customId;
622
+ }
623
+ #setupCollector() {
624
+ if (!this.#contextData) return;
625
+ if (!this.customId) throw new TypeError("Cannot setup an modal collector without a custom ID.");
626
+ const interceptor = this.#getEventInterceptor();
627
+ if (!interceptor) return;
628
+ this.#unsub = interceptor.subscribe(discord_js.Events.InteractionCreate, async (interaction) => {
629
+ var _this$contextData5, _this$unsub;
630
+ if (!interaction.isChannelSelectMenu()) return;
631
+ const myCustomId = this.customId ?? null;
632
+ const interactionCustomId = interaction.customId;
633
+ if (myCustomId && interactionCustomId !== myCustomId) return;
634
+ const filter = (_this$contextData5 = this.#contextData) === null || _this$contextData5 === void 0 ? void 0 : _this$contextData5.filter;
635
+ if (filter && !await filter(interaction)) return;
636
+ const handler = this.#onSelectHandler;
637
+ if (!handler) return (_this$unsub = this.#unsub) === null || _this$unsub === void 0 ? void 0 : _this$unsub.call(this);
638
+ return handler(interaction, this);
639
+ }, this.#contextData);
640
+ }
641
+ dispose() {
642
+ this.#destroyCollector();
643
+ return this;
644
+ }
645
+ #destroyCollector() {
646
+ var _this$unsub2;
647
+ (_this$unsub2 = this.#unsub) === null || _this$unsub2 === void 0 || _this$unsub2.call(this);
648
+ this.#unsub = null;
649
+ this.#onSelectHandler = null;
650
+ this.#contextData = null;
651
+ }
652
+ };
653
+
654
+ //#endregion
655
+ //#region src/components/v1/select-menu/MentionableSelectMenuKit.ts
656
+ var MentionableSelectMenuKit = class extends discord_js.MentionableSelectMenuBuilder {
657
+ #onSelectHandler = null;
658
+ #contextData = {
659
+ autoReset: false,
660
+ time: 5 * 60 * 1e3,
661
+ once: true
662
+ };
663
+ #unsub = null;
664
+ #getEventInterceptor() {
665
+ const ctx = getContext();
666
+ if (!ctx) return getCommandKit(true).eventInterceptor;
667
+ return exitContext(() => ctx.commandkit.eventInterceptor);
668
+ }
669
+ /**
670
+ * Sets the handler to run when the modal is submitted.
671
+ * @param handler - The handler to run when the modal is submitted.
672
+ * @param data - The context data for the interaction collector.
673
+ * @returns This instance of the modal builder.
674
+ * @example
675
+ * ```ts
676
+ * const modal = new MentionableSelectMenuKit()
677
+ * .setTitle('My Modal')
678
+ * .setCustomId('my-modal')
679
+ * .filter((interaction) => interaction.Mentionable.id === '1234567890')
680
+ * .onSelect(async (interaction) => {
681
+ * await interaction.reply('You submitted the modal!');
682
+ * })
683
+ * .addComponents(actionRow1, actionRow2);
684
+ * ```
685
+ */
686
+ onSelect(handler, data) {
687
+ if (!handler) throw new TypeError("Cannot setup \"onClick\" without a handler function parameter.");
688
+ if (this.#onSelectHandler) this.#destroyCollector();
689
+ this.#onSelectHandler = handler;
690
+ if (data) {
691
+ var _this$contextData, _this$contextData2, _this$contextData3, _this$contextData4;
692
+ this.#contextData = {
693
+ autoReset: data.autoReset ?? ((_this$contextData = this.#contextData) === null || _this$contextData === void 0 ? void 0 : _this$contextData.autoReset) ?? true,
694
+ time: data.time ?? ((_this$contextData2 = this.#contextData) === null || _this$contextData2 === void 0 ? void 0 : _this$contextData2.time) ?? 5 * 60 * 1e3,
695
+ filter: data.filter ?? ((_this$contextData3 = this.#contextData) === null || _this$contextData3 === void 0 ? void 0 : _this$contextData3.filter),
696
+ onEnd: data.onEnd ?? ((_this$contextData4 = this.#contextData) === null || _this$contextData4 === void 0 ? void 0 : _this$contextData4.onEnd)
697
+ };
698
+ }
699
+ this.#setupCollector();
700
+ return this;
701
+ }
702
+ /**
703
+ * Sets the handler to run when the interaction collector ends.
704
+ * @param handler - The handler to run when the interaction collector ends.
705
+ * @returns This instance of the modal builder.
706
+ */
707
+ onEnd(handler) {
708
+ if (!handler) throw new TypeError("Cannot setup \"onEnd\" without a handler function parameter.");
709
+ this.#contextData ??= {};
710
+ this.#contextData.onEnd = handler;
711
+ return this;
712
+ }
713
+ /**
714
+ * Sets the handler to run when the interaction collector ends.
715
+ * @param handler - The handler to run when the interaction collector ends.
716
+ * @returns This instance of the modal builder.
717
+ */
718
+ onError(handler) {
719
+ if (!handler) throw new TypeError("Cannot setup \"onError\" without a handler function parameter.");
720
+ this.#contextData ??= {};
721
+ this.#contextData.onError = handler;
722
+ return this;
723
+ }
724
+ /**
725
+ * Sets a filter for the interaction collector.
726
+ * @param predicate - The filter to use for the interaction collector.
727
+ * @returns This instance of the modal builder.
728
+ */
729
+ filter(predicate) {
730
+ this.#contextData ??= {
731
+ autoReset: true,
732
+ time: 5 * 60 * 1e3
733
+ };
734
+ this.#contextData.filter = predicate;
735
+ return this;
736
+ }
737
+ get customId() {
738
+ return this.data.custom_id ?? this.data.customId;
739
+ }
740
+ #setupCollector() {
741
+ if (!this.#contextData) return;
742
+ if (!this.customId) throw new TypeError("Cannot setup an modal collector without a custom ID.");
743
+ const interceptor = this.#getEventInterceptor();
744
+ if (!interceptor) return;
745
+ this.#unsub = interceptor.subscribe(discord_js.Events.InteractionCreate, async (interaction) => {
746
+ var _this$contextData5, _this$unsub;
747
+ if (!interaction.isMentionableSelectMenu()) return;
748
+ const myCustomId = this.customId ?? null;
749
+ const interactionCustomId = interaction.customId;
750
+ if (myCustomId && interactionCustomId !== myCustomId) return;
751
+ const filter = (_this$contextData5 = this.#contextData) === null || _this$contextData5 === void 0 ? void 0 : _this$contextData5.filter;
752
+ if (filter && !await filter(interaction)) return;
753
+ const handler = this.#onSelectHandler;
754
+ if (!handler) return (_this$unsub = this.#unsub) === null || _this$unsub === void 0 ? void 0 : _this$unsub.call(this);
755
+ return handler(interaction, this);
756
+ }, this.#contextData);
757
+ }
758
+ dispose() {
759
+ this.#destroyCollector();
760
+ return this;
761
+ }
762
+ #destroyCollector() {
763
+ var _this$unsub2;
764
+ (_this$unsub2 = this.#unsub) === null || _this$unsub2 === void 0 || _this$unsub2.call(this);
765
+ this.#unsub = null;
766
+ this.#onSelectHandler = null;
767
+ this.#contextData = null;
768
+ }
769
+ };
770
+
771
+ //#endregion
772
+ //#region src/components/v1/select-menu/UserSelectMenuKit.ts
773
+ var UserSelectMenuKit = class extends discord_js.UserSelectMenuBuilder {
774
+ #onSelectHandler = null;
775
+ #contextData = {
776
+ autoReset: false,
777
+ time: 5 * 60 * 1e3,
778
+ once: true
779
+ };
780
+ #unsub = null;
781
+ #getEventInterceptor() {
782
+ const ctx = getContext();
783
+ if (!ctx) return getCommandKit(true).eventInterceptor;
784
+ return exitContext(() => ctx.commandkit.eventInterceptor);
785
+ }
786
+ /**
787
+ * Sets the handler to run when the modal is submitted.
788
+ * @param handler - The handler to run when the modal is submitted.
789
+ * @param data - The context data for the interaction collector.
790
+ * @returns This instance of the modal builder.
791
+ * @example
792
+ * ```ts
793
+ * const modal = new UserSelectMenuKit()
794
+ * .setTitle('My Modal')
795
+ * .setCustomId('my-modal')
796
+ * .filter((interaction) => interaction.user.id === '1234567890')
797
+ * .onSelect(async (interaction) => {
798
+ * await interaction.reply('You submitted the modal!');
799
+ * })
800
+ * .addComponents(actionRow1, actionRow2);
801
+ * ```
802
+ */
803
+ onSelect(handler, data) {
804
+ if (!handler) throw new TypeError("Cannot setup \"onClick\" without a handler function parameter.");
805
+ if (this.#onSelectHandler) this.#destroyCollector();
806
+ this.#onSelectHandler = handler;
807
+ if (data) {
808
+ var _this$contextData, _this$contextData2, _this$contextData3, _this$contextData4;
809
+ this.#contextData = {
810
+ autoReset: data.autoReset ?? ((_this$contextData = this.#contextData) === null || _this$contextData === void 0 ? void 0 : _this$contextData.autoReset) ?? true,
811
+ time: data.time ?? ((_this$contextData2 = this.#contextData) === null || _this$contextData2 === void 0 ? void 0 : _this$contextData2.time) ?? 5 * 60 * 1e3,
812
+ filter: data.filter ?? ((_this$contextData3 = this.#contextData) === null || _this$contextData3 === void 0 ? void 0 : _this$contextData3.filter),
813
+ onEnd: data.onEnd ?? ((_this$contextData4 = this.#contextData) === null || _this$contextData4 === void 0 ? void 0 : _this$contextData4.onEnd)
814
+ };
815
+ }
816
+ this.#setupCollector();
817
+ return this;
818
+ }
819
+ /**
820
+ * Sets the handler to run when the interaction collector ends.
821
+ * @param handler - The handler to run when the interaction collector ends.
822
+ * @returns This instance of the modal builder.
823
+ */
824
+ onEnd(handler) {
825
+ if (!handler) throw new TypeError("Cannot setup \"onEnd\" without a handler function parameter.");
826
+ this.#contextData ??= {};
827
+ this.#contextData.onEnd = handler;
828
+ return this;
829
+ }
830
+ /**
831
+ * Sets the handler to run when the interaction collector ends.
832
+ * @param handler - The handler to run when the interaction collector ends.
833
+ * @returns This instance of the modal builder.
834
+ */
835
+ onError(handler) {
836
+ if (!handler) throw new TypeError("Cannot setup \"onError\" without a handler function parameter.");
837
+ this.#contextData ??= {};
838
+ this.#contextData.onError = handler;
839
+ return this;
840
+ }
841
+ /**
842
+ * Sets a filter for the interaction collector.
843
+ * @param predicate - The filter to use for the interaction collector.
844
+ * @returns This instance of the modal builder.
845
+ */
846
+ filter(predicate) {
847
+ this.#contextData ??= {
848
+ autoReset: true,
849
+ time: 5 * 60 * 1e3
850
+ };
851
+ this.#contextData.filter = predicate;
852
+ return this;
853
+ }
854
+ get customId() {
855
+ return this.data.custom_id ?? this.data.customId;
856
+ }
857
+ #setupCollector() {
858
+ if (!this.#contextData) return;
859
+ if (!this.customId) throw new TypeError("Cannot setup an modal collector without a custom ID.");
860
+ const interceptor = this.#getEventInterceptor();
861
+ if (!interceptor) return;
862
+ this.#unsub = interceptor.subscribe(discord_js.Events.InteractionCreate, async (interaction) => {
863
+ var _this$contextData5, _this$unsub;
864
+ if (!interaction.isUserSelectMenu()) return;
865
+ const myCustomId = this.customId ?? null;
866
+ const interactionCustomId = interaction.customId;
867
+ if (myCustomId && interactionCustomId !== myCustomId) return;
868
+ const filter = (_this$contextData5 = this.#contextData) === null || _this$contextData5 === void 0 ? void 0 : _this$contextData5.filter;
869
+ if (filter && !await filter(interaction)) return;
870
+ const handler = this.#onSelectHandler;
871
+ if (!handler) return (_this$unsub = this.#unsub) === null || _this$unsub === void 0 ? void 0 : _this$unsub.call(this);
872
+ return handler(interaction, this);
873
+ }, this.#contextData);
874
+ }
875
+ dispose() {
876
+ this.#destroyCollector();
877
+ return this;
878
+ }
879
+ #destroyCollector() {
880
+ var _this$unsub2;
881
+ (_this$unsub2 = this.#unsub) === null || _this$unsub2 === void 0 || _this$unsub2.call(this);
882
+ this.#unsub = null;
883
+ this.#onSelectHandler = null;
884
+ this.#contextData = null;
885
+ }
886
+ };
887
+
888
+ //#endregion
889
+ //#region src/components/v1/select-menu/RoleSelectMenuKit.ts
890
+ var RoleSelectMenuKit = class extends discord_js.RoleSelectMenuBuilder {
891
+ #onSelectHandler = null;
892
+ #contextData = {
893
+ autoReset: false,
894
+ time: 5 * 60 * 1e3,
895
+ once: true
896
+ };
897
+ #unsub = null;
898
+ #getEventInterceptor() {
899
+ const ctx = getContext();
900
+ if (!ctx) return getCommandKit(true).eventInterceptor;
901
+ return exitContext(() => ctx.commandkit.eventInterceptor);
902
+ }
903
+ /**
904
+ * Sets the handler to run when the modal is submitted.
905
+ * @param handler - The handler to run when the modal is submitted.
906
+ * @param data - The context data for the interaction collector.
907
+ * @returns This instance of the modal builder.
908
+ * @example
909
+ * ```ts
910
+ * const modal = new RoleSelectMenuKit()
911
+ * .setTitle('My Modal')
912
+ * .setCustomId('my-modal')
913
+ * .filter((interaction) => interaction.Role.id === '1234567890')
914
+ * .onSelect(async (interaction) => {
915
+ * await interaction.reply('You submitted the modal!');
916
+ * })
917
+ * .addComponents(actionRow1, actionRow2);
918
+ * ```
919
+ */
920
+ onSelect(handler, data) {
921
+ if (!handler) throw new TypeError("Cannot setup \"onClick\" without a handler function parameter.");
922
+ if (this.#onSelectHandler) this.#destroyCollector();
923
+ this.#onSelectHandler = handler;
924
+ if (data) {
925
+ var _this$contextData, _this$contextData2, _this$contextData3, _this$contextData4;
926
+ this.#contextData = {
927
+ autoReset: data.autoReset ?? ((_this$contextData = this.#contextData) === null || _this$contextData === void 0 ? void 0 : _this$contextData.autoReset) ?? true,
928
+ time: data.time ?? ((_this$contextData2 = this.#contextData) === null || _this$contextData2 === void 0 ? void 0 : _this$contextData2.time) ?? 5 * 60 * 1e3,
929
+ filter: data.filter ?? ((_this$contextData3 = this.#contextData) === null || _this$contextData3 === void 0 ? void 0 : _this$contextData3.filter),
930
+ onEnd: data.onEnd ?? ((_this$contextData4 = this.#contextData) === null || _this$contextData4 === void 0 ? void 0 : _this$contextData4.onEnd)
931
+ };
932
+ }
933
+ this.#setupCollector();
934
+ return this;
935
+ }
936
+ /**
937
+ * Sets the handler to run when the interaction collector ends.
938
+ * @param handler - The handler to run when the interaction collector ends.
939
+ * @returns This instance of the modal builder.
940
+ */
941
+ onEnd(handler) {
942
+ if (!handler) throw new TypeError("Cannot setup \"onEnd\" without a handler function parameter.");
943
+ this.#contextData ??= {};
944
+ this.#contextData.onEnd = handler;
945
+ return this;
946
+ }
947
+ /**
948
+ * Sets the handler to run when the interaction collector ends.
949
+ * @param handler - The handler to run when the interaction collector ends.
950
+ * @returns This instance of the modal builder.
951
+ */
952
+ onError(handler) {
953
+ if (!handler) throw new TypeError("Cannot setup \"onError\" without a handler function parameter.");
954
+ this.#contextData ??= {};
955
+ this.#contextData.onError = handler;
956
+ return this;
957
+ }
958
+ /**
959
+ * Sets a filter for the interaction collector.
960
+ * @param predicate - The filter to use for the interaction collector.
961
+ * @returns This instance of the modal builder.
962
+ */
963
+ filter(predicate) {
964
+ this.#contextData ??= {
965
+ autoReset: true,
966
+ time: 5 * 60 * 1e3
967
+ };
968
+ this.#contextData.filter = predicate;
969
+ return this;
970
+ }
971
+ get customId() {
972
+ return this.data.custom_id ?? this.data.customId;
973
+ }
974
+ #setupCollector() {
975
+ if (!this.#contextData) return;
976
+ if (!this.customId) throw new TypeError("Cannot setup an modal collector without a custom ID.");
977
+ const interceptor = this.#getEventInterceptor();
978
+ if (!interceptor) return;
979
+ this.#unsub = interceptor.subscribe(discord_js.Events.InteractionCreate, async (interaction) => {
980
+ var _this$contextData5, _this$unsub;
981
+ if (!interaction.isRoleSelectMenu()) return;
982
+ const myCustomId = this.customId ?? null;
983
+ const interactionCustomId = interaction.customId;
984
+ if (myCustomId && interactionCustomId !== myCustomId) return;
985
+ const filter = (_this$contextData5 = this.#contextData) === null || _this$contextData5 === void 0 ? void 0 : _this$contextData5.filter;
986
+ if (filter && !await filter(interaction)) return;
987
+ const handler = this.#onSelectHandler;
988
+ if (!handler) return (_this$unsub = this.#unsub) === null || _this$unsub === void 0 ? void 0 : _this$unsub.call(this);
989
+ return handler(interaction, this);
990
+ }, this.#contextData);
991
+ }
992
+ dispose() {
993
+ this.#destroyCollector();
994
+ return this;
995
+ }
996
+ #destroyCollector() {
997
+ var _this$unsub2;
998
+ (_this$unsub2 = this.#unsub) === null || _this$unsub2 === void 0 || _this$unsub2.call(this);
999
+ this.#unsub = null;
1000
+ this.#onSelectHandler = null;
1001
+ this.#contextData = null;
1002
+ }
1003
+ };
1004
+
1005
+ //#endregion
1006
+ //#region src/components/v1/select-menu/SelectMenu.ts
1007
+ function applyPropsToBuilder(builder, props) {
1008
+ builder.setCustomId(props.customId ?? `select-menu::${crypto.randomUUID()}`);
1009
+ if (props.maxValues != null) builder.setMaxValues(props.maxValues);
1010
+ if (props.minValues != null) builder.setMinValues(props.minValues);
1011
+ if (props.placeholder) builder.setPlaceholder(props.placeholder);
1012
+ if (props.disabled) builder.setDisabled(props.disabled);
1013
+ if (props.onEnd) builder.onEnd(props.onEnd);
1014
+ if (props.onError) builder.onError(props.onError);
1015
+ if (props.onSelect) builder.onSelect(props.onSelect, props.options);
1016
+ }
1017
+ function StringSelectMenu(props) {
1018
+ const builder = new StringSelectMenuKit();
1019
+ applyPropsToBuilder(builder, props);
1020
+ if (props.children) builder.setOptions(Array.isArray(props.children) ? props.children : [props.children]);
1021
+ if (props.children) builder.setOptions(Array.isArray(props.children) ? props.children : [props.children]);
1022
+ return builder;
1023
+ }
1024
+ function StringSelectMenuOption(props) {
1025
+ return new discord_js.StringSelectMenuOptionBuilder(props);
1026
+ }
1027
+ function UserSelectMenu(props) {
1028
+ const builder = new UserSelectMenuKit();
1029
+ applyPropsToBuilder(builder, props);
1030
+ if (props.defaultValues) builder.setDefaultUsers(Array.isArray(props.defaultValues) ? props.defaultValues : [props.defaultValues]);
1031
+ return builder;
1032
+ }
1033
+ function RoleSelectMenu(props) {
1034
+ const builder = new RoleSelectMenuKit();
1035
+ applyPropsToBuilder(builder, props);
1036
+ if (props.defaultValues) builder.setDefaultRoles(Array.isArray(props.defaultValues) ? props.defaultValues : [props.defaultValues]);
1037
+ return builder;
1038
+ }
1039
+ function MentionableSelectMenu(props) {
1040
+ const builder = new MentionableSelectMenuKit();
1041
+ applyPropsToBuilder(builder, props);
1042
+ if (props.defaultValues) builder.setDefaultValues(Array.isArray(props.defaultValues) ? props.defaultValues : [props.defaultValues]);
1043
+ return builder;
1044
+ }
1045
+ function ChannelSelectMenu(props) {
1046
+ const builder = new ChannelSelectMenuKit();
1047
+ applyPropsToBuilder(builder, props);
1048
+ if (props.defaultValues) builder.setDefaultChannels(Array.isArray(props.defaultValues) ? props.defaultValues : [props.defaultValues]);
1049
+ if (props.channelTypes) builder.setChannelTypes(Array.isArray(props.channelTypes) ? props.channelTypes : [props.channelTypes]);
1050
+ return builder;
1051
+ }
1052
+
1053
+ //#endregion
1054
+ //#region src/logger/DefaultLogger.ts
1055
+ var LogLevel = /* @__PURE__ */ function(LogLevel$1) {
1056
+ LogLevel$1[LogLevel$1["DEBUG"] = 0] = "DEBUG";
1057
+ LogLevel$1[LogLevel$1["INFO"] = 1] = "INFO";
1058
+ LogLevel$1[LogLevel$1["WARN"] = 2] = "WARN";
1059
+ LogLevel$1[LogLevel$1["ERROR"] = 3] = "ERROR";
1060
+ LogLevel$1[LogLevel$1["DEFAULT"] = 4] = "DEFAULT";
1061
+ return LogLevel$1;
1062
+ }(LogLevel || {});
1063
+ const execHandlerKind = {
1064
+ autocomplete: "Autocomplete",
1065
+ messageContextMenu: "MessageContextMenu",
1066
+ userContextMenu: "UserContextMenu",
1067
+ chatInput: "ChatInputCommand",
1068
+ message: "Message"
1069
+ };
1070
+ const TextColorMap = {
1071
+ [LogLevel.DEBUG]: require_colors.colors_default.blue,
1072
+ [LogLevel.INFO]: require_colors.colors_default.green,
1073
+ [LogLevel.WARN]: require_colors.colors_default.yellow,
1074
+ [LogLevel.ERROR]: require_colors.colors_default.red,
1075
+ [LogLevel.DEFAULT]: require_colors.colors_default.white
1076
+ };
1077
+ const TextBgColorMap = {
1078
+ [LogLevel.DEBUG]: require_colors.colors_default.bgBlue,
1079
+ [LogLevel.INFO]: require_colors.colors_default.bgGreen,
1080
+ [LogLevel.WARN]: require_colors.colors_default.bgYellow,
1081
+ [LogLevel.ERROR]: require_colors.colors_default.bgRed,
1082
+ [LogLevel.DEFAULT]: require_colors.colors_default.bgWhite
1083
+ };
1084
+ const BoxChars = {
1085
+ vertical: "│",
1086
+ horizontalDown: "┬",
1087
+ horizontalUp: "┴",
1088
+ verticalRight: "├",
1089
+ corner: "└"
1090
+ };
1091
+ var DefaultLogger = class {
1092
+ logger;
1093
+ constructor(stdout = process.stdout, stderr = process.stderr) {
1094
+ this.stdout = stdout;
1095
+ this.stderr = stderr;
1096
+ this.logger = new console.Console(this.stdout, this.stderr);
1097
+ }
1098
+ _formatTime(date) {
1099
+ const hours = date.getHours().toString().padStart(2, "0");
1100
+ const minutes = date.getMinutes().toString().padStart(2, "0");
1101
+ const seconds = date.getSeconds().toString().padStart(2, "0");
1102
+ const millis = date.getMilliseconds().toString().padStart(3, "0");
1103
+ return `${hours}:${minutes}:${seconds}.${millis}`;
1104
+ }
1105
+ _getContext() {
1106
+ const ctx = getContext();
1107
+ if (!ctx) return "";
1108
+ const kind = ctx.variables.get("execHandlerKind");
1109
+ const commandHandler = ctx.variables.get("commandHandlerType");
1110
+ const command = ctx.variables.get("currentCommandName");
1111
+ if (!kind && !commandHandler) return "";
1112
+ const h = execHandlerKind[kind];
1113
+ if (!h && !commandHandler) return "";
1114
+ const forwardedBy = ctx.variables.get("forwardedBy");
1115
+ const forwardedTo = ctx.variables.get("forwardedTo");
1116
+ const cmdText = command ? require_colors.colors_default.magenta(`/${command}`) + " " : "";
1117
+ const forward = forwardedTo ? `${require_colors.colors_default.yellowBright(`(${forwardedBy || command} → ${forwardedTo})`)} ` : "";
1118
+ return require_colors.colors_default.dim(`${BoxChars.vertical} `) + require_colors.colors_default.cyanBright(`${cmdText}${forward}${h ? require_colors.colors_default.gray(`[${h}]`) : ""}`.trim());
1119
+ }
1120
+ _getLevelLabel(level) {
1121
+ let label;
1122
+ switch (level) {
1123
+ case LogLevel.DEBUG:
1124
+ label = "[DEBUG]";
1125
+ break;
1126
+ case LogLevel.INFO:
1127
+ label = "[INFO]";
1128
+ break;
1129
+ case LogLevel.WARN:
1130
+ label = "[WARN]";
1131
+ break;
1132
+ case LogLevel.ERROR:
1133
+ label = "[ERROR]";
1134
+ break;
1135
+ default: label = "[LOG]";
1136
+ }
1137
+ const coloredLabel = TextBgColorMap[level](require_colors.colors_default.whiteBright(` ${label} `));
1138
+ return `${coloredLabel} `;
1139
+ }
1140
+ _getPrefix(level) {
1141
+ const timestamp = this._formatTime(new Date());
1142
+ const label = this._getLevelLabel(level);
1143
+ return `${label}${require_colors.colors_default.dim(BoxChars.vertical)} ${require_colors.colors_default.dim(timestamp)}`;
1144
+ }
1145
+ _log(level, ...args) {
1146
+ const prefix = this._getPrefix(level);
1147
+ const context$1 = this._getContext();
1148
+ const colorFn = TextColorMap[level];
1149
+ if (context$1) this.logger.log(`${prefix}\n${context$1} ${require_colors.colors_default.dim(BoxChars.corner)}`, ...args.map((arg) => colorFn(arg)));
1150
+ else this.logger.log(`${prefix} ${require_colors.colors_default.dim(BoxChars.corner)}`, ...args.map((arg) => colorFn(arg)));
1151
+ }
1152
+ debug(...args) {
1153
+ this._log(LogLevel.DEBUG, ...args);
1154
+ }
1155
+ error(...args) {
1156
+ this._log(LogLevel.ERROR, ...args);
1157
+ }
1158
+ log(...args) {
1159
+ this._log(LogLevel.DEFAULT, ...args);
1160
+ }
1161
+ info(...args) {
1162
+ this._log(LogLevel.INFO, ...args);
1163
+ }
1164
+ warn(...args) {
1165
+ this._log(LogLevel.WARN, ...args);
1166
+ }
1167
+ };
1168
+
1169
+ //#endregion
1170
+ //#region src/logger/Logger.ts
1171
+ function createLogger(options) {
1172
+ let opt = options;
1173
+ if (!(opt === null || opt === void 0 ? void 0 : opt.provider)) throw new Error("A logger provider must be provided.");
1174
+ const methods = [
1175
+ "log",
1176
+ "error",
1177
+ "warn",
1178
+ "info",
1179
+ "debug"
1180
+ ];
1181
+ const impl = { configure(options$1) {
1182
+ opt = options$1;
1183
+ } };
1184
+ for (const method of methods) impl[method] = (...args) => {
1185
+ opt.provider[method](...args);
1186
+ };
1187
+ return impl;
1188
+ }
1189
+ const Logger = createLogger({ provider: new DefaultLogger() });
1190
+
1191
+ //#endregion
1192
+ //#region src/plugins/plugin-runtime/CommandKitPluginRuntime.ts
1193
+ var CommandKitPluginRuntime = class {
1194
+ plugins = new discord_js.Collection();
1195
+ constructor(commandkit$1) {
1196
+ this.commandkit = commandkit$1;
1197
+ }
1198
+ getPlugins() {
1199
+ return this.plugins;
1200
+ }
1201
+ getPlugin(pluginName) {
1202
+ return this.plugins.get(pluginName) ?? null;
1203
+ }
1204
+ async softRegisterPlugin(plugin) {
1205
+ const pluginName = plugin.name;
1206
+ if (this.plugins.has(pluginName)) return;
1207
+ try {
1208
+ await plugin.activate(this);
1209
+ this.plugins.set(pluginName, plugin);
1210
+ } catch (e) {
1211
+ throw new Error(`Failed to activate plugin "${pluginName}": ${(e === null || e === void 0 ? void 0 : e.stack) || e}`);
1212
+ }
1213
+ }
1214
+ async registerPlugin(plugin) {
1215
+ const pluginName = plugin.name;
1216
+ if (this.plugins.has(pluginName)) throw new Error(`Plugin with name "${pluginName}" already exists.`);
1217
+ try {
1218
+ await plugin.activate(this);
1219
+ this.plugins.set(pluginName, plugin);
1220
+ } catch (e) {
1221
+ throw new Error(`Failed to activate plugin "${pluginName}": ${(e === null || e === void 0 ? void 0 : e.stack) || e}`);
1222
+ }
1223
+ }
1224
+ async unregisterPlugin(plugin) {
1225
+ const pluginName = plugin.name;
1226
+ if (!this.plugins.has(pluginName)) throw new Error(`Plugin with name "${pluginName}" does not exist.`);
1227
+ this.plugins.delete(pluginName);
1228
+ try {
1229
+ await plugin.deactivate(this);
1230
+ } catch (e) {
1231
+ throw new Error(`Failed to deactivate plugin "${pluginName}": ${(e === null || e === void 0 ? void 0 : e.stack) || e}`);
1232
+ }
1233
+ }
1234
+ async unregisterAllPlugins() {
1235
+ for (const plugin of this.plugins.values()) await this.unregisterPlugin(plugin);
1236
+ }
1237
+ capture() {
1238
+ throw require_error_codes.createCommandKitError(require_error_codes.CommandKitErrorCodes.PluginCaptureHandle);
1239
+ }
1240
+ async execute(f) {
1241
+ let result;
1242
+ for (const plugin of this.plugins.values()) try {
1243
+ result = await f(this, plugin);
1244
+ } catch (e) {
1245
+ if (require_error_codes.isErrorType(e, require_error_codes.CommandKitErrorCodes.PluginCaptureHandle)) return true;
1246
+ Logger.error(`Plugin "${plugin.name}" failed`, (e === null || e === void 0 ? void 0 : e.stack) || e);
1247
+ }
1248
+ return result;
1249
+ }
1250
+ };
1251
+
1252
+ //#endregion
1253
+ //#region src/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.ts
1254
+ var CommonDirectiveTransformer = class extends require_CompilerPlugin.CompilerPlugin {
1255
+ transformer = null;
1256
+ async activate(ctx) {
1257
+ const { createDirectiveTransformer } = await import("directive-to-hof");
1258
+ this.transformer = createDirectiveTransformer(this.options);
1259
+ }
1260
+ async deactivate(ctx) {
1261
+ this.transformer = null;
1262
+ }
1263
+ async transform(params) {
1264
+ if (!this.options.enabled) return null;
1265
+ if (!this.transformer) return null;
1266
+ if (/\.json$/.test(params.id)) return null;
1267
+ const result = await this.transformer(params.code.toString(), params.id);
1268
+ return {
1269
+ code: result.contents,
1270
+ map: null
1271
+ };
1272
+ }
1273
+ };
1274
+
1275
+ //#endregion
1276
+ //#region src/plugins/plugin-runtime/builtin/MacroPlugin.ts
1277
+ var MacroPlugin = class extends require_CompilerPlugin.CompilerPlugin {
1278
+ name = "MacroPlugin";
1279
+ macroTransformer;
1280
+ async activate() {
1281
+ const transform = await import("use-macro");
1282
+ this.macroTransformer = new transform.MacroTransformer();
1283
+ }
1284
+ async deactivate() {
1285
+ this.macroTransformer = null;
1286
+ }
1287
+ async transform(params) {
1288
+ if (!this.options.enabled) return null;
1289
+ if (/\.json$/.test(params.id)) return null;
1290
+ const { contents } = await this.macroTransformer.transform(params.code, params.id);
1291
+ return {
1292
+ code: typeof contents === "string" ? contents : new TextDecoder().decode(contents),
1293
+ map: null
1294
+ };
1295
+ }
1296
+ };
1297
+
1298
+ //#endregion
1299
+ //#region src/config/default.ts
1300
+ const defaultConfig = {
1301
+ plugins: [new MacroPlugin({ enabled: true })],
1302
+ rolldownPlugins: [(0, __rollup_plugin_json.default)()],
1303
+ compilerOptions: { macro: { development: false } },
1304
+ static: true,
1305
+ typescript: { ignoreBuildErrors: false },
1306
+ distDir: "dist",
1307
+ env: {},
1308
+ sourceMap: {
1309
+ development: true,
1310
+ production: true
1311
+ },
1312
+ typedCommands: true
1313
+ };
1314
+
1315
+ //#endregion
1316
+ //#region src/config/config.ts
1317
+ let defined = defaultConfig;
1318
+ /**
1319
+ * Get the defined configuration for CommandKit.
1320
+ */
1321
+ function getConfig() {
1322
+ return defined;
1323
+ }
1324
+ /**
1325
+ * Define the configuration for CommandKit.
1326
+ * @param config The configuration to use.
1327
+ */
1328
+ function defineConfig(config = {}) {
1329
+ var _config$compilerOptio;
1330
+ defined = {
1331
+ compilerOptions: { macro: {
1332
+ ...defaultConfig.compilerOptions.macro,
1333
+ ...(_config$compilerOptio = config.compilerOptions) === null || _config$compilerOptio === void 0 ? void 0 : _config$compilerOptio.macro
1334
+ } },
1335
+ distDir: config.distDir ?? defaultConfig.distDir,
1336
+ env: {
1337
+ ...defaultConfig.env,
1338
+ ...config.env
1339
+ },
1340
+ rolldownPlugins: [...config.rolldownPlugins ?? [], ...defaultConfig.rolldownPlugins ?? []],
1341
+ plugins: [...config.plugins ?? [], ...defaultConfig.plugins ?? []].flat(Infinity),
1342
+ sourceMap: {
1343
+ ...defaultConfig.sourceMap,
1344
+ ...config.sourceMap
1345
+ },
1346
+ static: config.static ?? defaultConfig.static,
1347
+ typedCommands: config.typedCommands ?? defaultConfig.typedCommands,
1348
+ typescript: {
1349
+ ...defaultConfig.typescript,
1350
+ ...config.typescript
1351
+ }
1352
+ };
1353
+ return defined;
1354
+ }
1355
+
1356
+ //#endregion
1357
+ //#region src/utils/utilities.ts
1358
+ let appDir = null;
1359
+ let currentDir = null;
1360
+ function getCurrentDirectory() {
1361
+ if (currentDir) return currentDir;
1362
+ let root = (0, node_path.join)(process.cwd(), require_constants.COMMANDKIT_IS_DEV ? ".commandkit" : getConfig().distDir);
1363
+ if (!(0, node_fs.existsSync)(root)) root = process.cwd();
1364
+ currentDir = root;
1365
+ return root;
1366
+ }
1367
+ function getSourceDirectories() {
1368
+ const dist = getConfig().distDir;
1369
+ const locations = [
1370
+ "src",
1371
+ ".commandkit",
1372
+ dist
1373
+ ].map((dir) => (0, node_path.join)(process.cwd(), dir));
1374
+ return locations;
1375
+ }
1376
+ /**
1377
+ * Returns the path to the app directory.
1378
+ * @returns The path to the app directory or `null` if not found.
1379
+ */
1380
+ function findAppDirectory() {
1381
+ if (appDir) return appDir;
1382
+ let root = (0, node_path.join)(process.cwd(), require_constants.COMMANDKIT_IS_DEV ? ".commandkit" : getConfig().distDir);
1383
+ if (!(0, node_fs.existsSync)(root)) root = process.cwd();
1384
+ const dirs = ["app"].map((dir) => (0, node_path.join)(root, dir));
1385
+ for (const dir of dirs) if ((0, node_fs.existsSync)(dir)) {
1386
+ appDir = dir;
1387
+ return dir;
1388
+ }
1389
+ return null;
1390
+ }
1391
+ /**
1392
+ * Debounces a function.
1393
+ * @param fn The function to debounce.
1394
+ * @param ms The debounce time in milliseconds.
1395
+ * @returns The debounced function.
1396
+ */
1397
+ function debounce(fn, ms) {
1398
+ let timer = null;
1399
+ let resolve = null;
1400
+ return (...args) => {
1401
+ if (timer) {
1402
+ clearTimeout(timer);
1403
+ if (resolve) resolve(null);
1404
+ }
1405
+ return new Promise((res) => {
1406
+ resolve = res;
1407
+ timer = setTimeout(() => {
1408
+ const result = fn(...args);
1409
+ res(result);
1410
+ timer = null;
1411
+ resolve = null;
1412
+ }, ms);
1413
+ });
1414
+ };
1415
+ }
1416
+ /**
1417
+ * Creates a function from the given function that runs only in development mode.
1418
+ * @param fn The function to run in development mode.
1419
+ * @returns The function that runs only in development mode.
1420
+ * @example
1421
+ * ```ts
1422
+ * const devOnlyFn = devOnly(() => {
1423
+ * console.log('This function runs only in development mode');
1424
+ * });
1425
+ * devOnlyFn(); // This will log the message only in development mode
1426
+ * ```
1427
+ */
1428
+ function devOnly(fn) {
1429
+ const f = (...args) => {
1430
+ if (require_constants.COMMANDKIT_IS_DEV) return fn(...args);
1431
+ };
1432
+ return f;
1433
+ }
1434
+ /**
1435
+ * Custom error for stopping event propagation.
1436
+ */
1437
+ var StopEventPropagationError = class extends Error {
1438
+ constructor() {
1439
+ super("Event propagation stopped");
1440
+ this.name = "StopEventPropagationError";
1441
+ }
1442
+ };
1443
+ /**
1444
+ * Stops event propagation.
1445
+ * @throws {StopEventPropagationError}
1446
+ */
1447
+ function stopEvents() {
1448
+ if (!require_EventWorkerContext.eventWorkerContext.getStore()) throw new Error("stopEvents() may only be called inside an event handler");
1449
+ throw new StopEventPropagationError();
1450
+ }
1451
+
1452
+ //#endregion
1453
+ //#region src/app/register/CommandRegistrar.ts
1454
+ var CommandRegistrar = class {
1455
+ api = new discord_js.REST();
1456
+ /**
1457
+ * Creates an instance of CommandRegistrar.
1458
+ * @param commandkit The commandkit instance.
1459
+ */
1460
+ constructor(commandkit$1) {
1461
+ this.commandkit = commandkit$1;
1462
+ this.api.setToken(this.commandkit.client.token ?? process.env.DISCORD_TOKEN ?? process.env.TOKEN ?? "");
1463
+ }
1464
+ /**
1465
+ * Gets the commands data.
1466
+ */
1467
+ getCommandsData() {
1468
+ const handler = this.commandkit.commandHandler;
1469
+ const commands = handler.getCommandsArray();
1470
+ return commands.flatMap((cmd) => {
1471
+ const json$1 = "toJSON" in cmd.data.command ? cmd.data.command.toJSON() : cmd.data.command;
1472
+ const collections = [json$1];
1473
+ if (cmd.data.userContextMenu && json$1.type !== discord_js.ApplicationCommandType.User) collections.push({
1474
+ ...json$1,
1475
+ type: discord_js.ApplicationCommandType.User,
1476
+ options: void 0,
1477
+ description_localizations: void 0,
1478
+ description: void 0
1479
+ });
1480
+ if (cmd.data.messageContextMenu && json$1.type !== discord_js.ApplicationCommandType.Message) collections.push({
1481
+ ...json$1,
1482
+ type: discord_js.ApplicationCommandType.Message,
1483
+ description_localizations: void 0,
1484
+ description: void 0,
1485
+ options: void 0
1486
+ });
1487
+ return collections;
1488
+ });
1489
+ }
1490
+ /**
1491
+ * Registers loaded commands.
1492
+ */
1493
+ async register() {
1494
+ const commands = this.getCommandsData();
1495
+ let preRegistrationPrevented = false;
1496
+ const preRegisterEvent = {
1497
+ preventDefault() {
1498
+ preRegistrationPrevented = true;
1499
+ },
1500
+ commands
1501
+ };
1502
+ await this.commandkit.plugins.execute(async (ctx, plugin) => {
1503
+ if (preRegistrationPrevented) return;
1504
+ return plugin.onBeforeRegisterCommands(ctx, preRegisterEvent);
1505
+ });
1506
+ if (preRegistrationPrevented) return;
1507
+ if (!this.commandkit.client.isReady()) throw new Error("Cannot register commands before the client is ready");
1508
+ const guildCommands = commands.filter((command) => {
1509
+ var _command$guilds;
1510
+ return (_command$guilds = command.guilds) === null || _command$guilds === void 0 ? void 0 : _command$guilds.filter(Boolean).length;
1511
+ }).map((c) => {
1512
+ var _c$guilds;
1513
+ return {
1514
+ ...c,
1515
+ guilds: Array.from(new Set((_c$guilds = c.guilds) === null || _c$guilds === void 0 ? void 0 : _c$guilds.filter(Boolean)))
1516
+ };
1517
+ });
1518
+ const globalCommands = commands.filter((command) => {
1519
+ var _command$guilds2;
1520
+ return !((_command$guilds2 = command.guilds) === null || _command$guilds2 === void 0 ? void 0 : _command$guilds2.filter(Boolean).length);
1521
+ });
1522
+ await this.updateGlobalCommands(globalCommands);
1523
+ await this.updateGuildCommands(guildCommands);
1524
+ }
1525
+ /**
1526
+ * Updates the global commands.
1527
+ */
1528
+ async updateGlobalCommands(commands) {
1529
+ if (!commands.length) return;
1530
+ let prevented = false;
1531
+ const preRegisterEvent = {
1532
+ preventDefault() {
1533
+ prevented = true;
1534
+ },
1535
+ commands
1536
+ };
1537
+ await this.commandkit.plugins.execute(async (ctx, plugin) => {
1538
+ if (prevented) return;
1539
+ return plugin.onBeforeRegisterGlobalCommands(ctx, preRegisterEvent);
1540
+ });
1541
+ try {
1542
+ const data = await this.api.put(discord_js.Routes.applicationCommands(this.commandkit.client.user.id), { body: commands.map((c) => ({
1543
+ ...c,
1544
+ guilds: void 0
1545
+ })) });
1546
+ Logger.info(`✨ Refreshed ${data.length} global application (/) commands`);
1547
+ } catch (e) {
1548
+ Logger.error("Failed to update global application (/) commands", e);
1549
+ }
1550
+ }
1551
+ /**
1552
+ * Updates the guild commands.
1553
+ */
1554
+ async updateGuildCommands(commands) {
1555
+ if (!commands.length) return;
1556
+ let prevented = false;
1557
+ const preRegisterEvent = {
1558
+ preventDefault() {
1559
+ prevented = true;
1560
+ },
1561
+ commands
1562
+ };
1563
+ await this.commandkit.plugins.execute(async (ctx, plugin) => {
1564
+ if (prevented) return;
1565
+ return plugin.onBeforePrepareGuildCommandsRegistration(ctx, preRegisterEvent);
1566
+ });
1567
+ if (prevented) return;
1568
+ try {
1569
+ const guildCommandsMap = new Map();
1570
+ commands.forEach((command) => {
1571
+ var _command$guilds3;
1572
+ if (!((_command$guilds3 = command.guilds) === null || _command$guilds3 === void 0 ? void 0 : _command$guilds3.length)) return;
1573
+ command.guilds.forEach((guild) => {
1574
+ if (!guildCommandsMap.has(guild)) guildCommandsMap.set(guild, []);
1575
+ guildCommandsMap.get(guild).push(command);
1576
+ });
1577
+ });
1578
+ if (!guildCommandsMap.size) return;
1579
+ let count = 0;
1580
+ for (const [guild, guildCommands] of guildCommandsMap) {
1581
+ let prevented$1 = false;
1582
+ const preRegisterEvent$1 = {
1583
+ preventDefault() {
1584
+ prevented$1 = true;
1585
+ },
1586
+ commands: guildCommands
1587
+ };
1588
+ await this.commandkit.plugins.execute(async (ctx, plugin) => {
1589
+ if (prevented$1) return;
1590
+ return plugin.onBeforeRegisterGuildCommands(ctx, preRegisterEvent$1);
1591
+ });
1592
+ if (prevented$1) continue;
1593
+ const data = await this.api.put(discord_js.Routes.applicationGuildCommands(this.commandkit.client.user.id, guild), { body: guildCommands.map((b) => ({
1594
+ ...b,
1595
+ guilds: void 0
1596
+ })) });
1597
+ count += data.length;
1598
+ }
1599
+ Logger.info(`✨ Refreshed ${count} guild application (/) commands`);
1600
+ } catch (e) {
1601
+ Logger.error("Failed to update guild application (/) commands", e);
1602
+ }
1603
+ }
1604
+ };
1605
+
1606
+ //#endregion
1607
+ //#region src/context/environment.ts
1608
+ var CommandKitEnvironment = class {
1609
+ #data = {
1610
+ executionError: null,
1611
+ type: null,
1612
+ variables: new Map(),
1613
+ deferredFunctions: new Map(),
1614
+ marker: "",
1615
+ markStart: 0,
1616
+ markEnd: 0,
1617
+ context: null
1618
+ };
1619
+ /**
1620
+ * Creates the commandkit execution environment.
1621
+ * @param commandkit - The commandkit instance.
1622
+ */
1623
+ constructor(commandkit$1) {
1624
+ this.commandkit = commandkit$1;
1625
+ }
1626
+ /**
1627
+ * Set the context.
1628
+ * @param context - The context to set.
1629
+ */
1630
+ setContext(context$1) {
1631
+ this.#data.context = context$1;
1632
+ }
1633
+ /**
1634
+ * Get the context. `null` if not set.
1635
+ * @internal
1636
+ */
1637
+ get context() {
1638
+ return this.#data.context;
1639
+ }
1640
+ /**
1641
+ * Get the execution error.
1642
+ * @internal
1643
+ */
1644
+ getExecutionError() {
1645
+ return this.#data.executionError;
1646
+ }
1647
+ /**
1648
+ * Set the execution error.
1649
+ * @param error - The error to set.
1650
+ * @internal
1651
+ */
1652
+ setExecutionError(error) {
1653
+ if (this.#data.executionError) throw new Error("Execution error already set.");
1654
+ this.#data.executionError = error;
1655
+ }
1656
+ /**
1657
+ * Get the environment type.
1658
+ */
1659
+ getType() {
1660
+ const type = this.#data.type;
1661
+ if (!type) throw new Error("Environment type not set.");
1662
+ return type;
1663
+ }
1664
+ /**
1665
+ * Set the environment type.
1666
+ * @param type - The environment type to set.
1667
+ * @internal
1668
+ */
1669
+ setType(type) {
1670
+ this.#data.type = type;
1671
+ }
1672
+ /**
1673
+ * The variables store for this environment.
1674
+ */
1675
+ get variables() {
1676
+ return this.#data.variables;
1677
+ }
1678
+ /**
1679
+ * Register a deferred function.
1680
+ * @param fn - The deferred function to register.
1681
+ * @returns The deferred function id.
1682
+ * @internal
1683
+ */
1684
+ registerDeferredFunction(fn) {
1685
+ const id = (0, node_crypto.randomUUID)();
1686
+ this.#data.deferredFunctions.set(id, fn);
1687
+ return id;
1688
+ }
1689
+ /**
1690
+ * Clear a deferred function by id.
1691
+ * @param id - The deferred function id to clear.
1692
+ * @internal
1693
+ */
1694
+ clearDeferredFunction(id) {
1695
+ this.#data.deferredFunctions.delete(id);
1696
+ }
1697
+ /**
1698
+ * Run all deferred functions sequentially.
1699
+ * @internal
1700
+ */
1701
+ async runDeferredFunctions() {
1702
+ for (const [id, fn] of this.#data.deferredFunctions) try {
1703
+ await fn(this);
1704
+ } catch (e) {
1705
+ this.commandkit.emit("unhandledDeferredFunctionRejection", e);
1706
+ } finally {
1707
+ this.clearDeferredFunction(id);
1708
+ }
1709
+ }
1710
+ /**
1711
+ * Clear all deferred functions.
1712
+ * @internal
1713
+ */
1714
+ clearAllDeferredFunctions() {
1715
+ this.#data.deferredFunctions.clear();
1716
+ }
1717
+ /**
1718
+ * Mark the start of a command execution.
1719
+ * @param marker - The marker to set.
1720
+ * @internal
1721
+ */
1722
+ markStart(marker) {
1723
+ this.#data.marker = marker;
1724
+ this.#data.markStart = performance.now();
1725
+ }
1726
+ /**
1727
+ * Mark the end of a command execution.
1728
+ * @internal
1729
+ */
1730
+ markEnd() {
1731
+ if (!this.#data.markEnd) this.#data.markEnd = performance.now();
1732
+ }
1733
+ /**
1734
+ * Get the marker.
1735
+ * @internal
1736
+ */
1737
+ getMarker() {
1738
+ return this.#data.marker;
1739
+ }
1740
+ /**
1741
+ * Get the execution time in milliseconds.
1742
+ * @internal
1743
+ */
1744
+ getExecutionTime() {
1745
+ return Math.abs(this.#data.markEnd - this.#data.markStart);
1746
+ }
1747
+ };
1748
+ let CommandKitEnvironmentType = /* @__PURE__ */ function(CommandKitEnvironmentType$1) {
1749
+ CommandKitEnvironmentType$1["CommandHandler"] = "COMMAND_HANDLER";
1750
+ return CommandKitEnvironmentType$1;
1751
+ }({});
1752
+ /**
1753
+ * Runs the given function after the current command has finished executing.
1754
+ * @param fn The function to run after the current command.
1755
+ * @returns The deferred function id. This can be used to cancel the deferred function.
1756
+ */
1757
+ function after(fn) {
1758
+ const env = getContext();
1759
+ if (!env) throw new Error("after must be called inside commandkit handler.");
1760
+ return env.registerDeferredFunction(fn);
1761
+ }
1762
+ /**
1763
+ * Cancels a deferred function registered with `after`.
1764
+ * @param id The deferred function id to cancel.
1765
+ */
1766
+ function cancelAfter(id) {
1767
+ const env = getContext();
1768
+ if (!env) throw new Error("cancelAfter must be called inside commandkit handler.");
1769
+ env.clearDeferredFunction(id);
1770
+ }
1771
+
1772
+ //#endregion
1773
+ //#region src/app/commands/Context.ts
1774
+ const CommandExecutionMode = {
1775
+ ChatInputCommand: "chatInput",
1776
+ MessageContextMenu: "messageContextMenu",
1777
+ UserContextMenu: "userContextMenu",
1778
+ Autocomplete: "autocomplete",
1779
+ Message: "message"
1780
+ };
1781
+ var Context = class Context {
1782
+ /**
1783
+ * The interaction that triggered the command.
1784
+ */
1785
+ interaction;
1786
+ /**
1787
+ * The message that triggered the command.
1788
+ */
1789
+ message;
1790
+ /**
1791
+ * The guild where the command was triggered.
1792
+ */
1793
+ guild;
1794
+ /**
1795
+ * The guild ID where the command was triggered.
1796
+ */
1797
+ guildId;
1798
+ /**
1799
+ * The channel where the command was triggered.
1800
+ */
1801
+ channel;
1802
+ /**
1803
+ * The channel id where the command was triggered.
1804
+ */
1805
+ channelId;
1806
+ /**
1807
+ * The client instance.
1808
+ */
1809
+ client;
1810
+ /**
1811
+ * The command that this context belongs to.
1812
+ */
1813
+ command;
1814
+ #store;
1815
+ _locale = null;
1816
+ /**
1817
+ * Creates a new command context.
1818
+ * @param commandkit The command kit instance.
1819
+ * @param config The context parameters.
1820
+ */
1821
+ constructor(commandkit$1, config) {
1822
+ this.commandkit = commandkit$1;
1823
+ this.config = config;
1824
+ this.interaction = config.interaction;
1825
+ this.message = config.message;
1826
+ this.client = commandkit$1.client;
1827
+ this.#store = config.store ?? new Map();
1828
+ this.command = config.command;
1829
+ if (config.interaction) {
1830
+ this.guild = config.interaction.guild;
1831
+ this.guildId = config.interaction.guildId;
1832
+ this.channel = config.interaction.channel;
1833
+ this.channelId = config.interaction.channelId;
1834
+ }
1835
+ if (config.message) {
1836
+ this.guild = config.message.guild;
1837
+ this.guildId = config.message.guildId;
1838
+ this.channel = config.message.channel;
1839
+ this.channelId = config.message.channelId;
1840
+ }
1841
+ if (this.config.environment) this.config.environment.setContext(this);
1842
+ }
1843
+ /**
1844
+ * The shared key-value store for this context. This can be used to store data that needs to be shared between middlewares or commands.
1845
+ * This store is shared across all contexts in the same command execution, including the cloned contexts and middleware contexts.
1846
+ */
1847
+ get store() {
1848
+ return this.#store;
1849
+ }
1850
+ get commandName() {
1851
+ if (this.isInteraction()) return this.interaction.commandName;
1852
+ else return this.config.messageCommandParser.getCommand();
1853
+ }
1854
+ get options() {
1855
+ if (this.isMessage()) {
1856
+ const parser = this.config.messageCommandParser;
1857
+ return parser.options;
1858
+ } else {
1859
+ const interaction = this.interaction;
1860
+ return interaction.options;
1861
+ }
1862
+ }
1863
+ /**
1864
+ * Whether this context was forwarded from another context. This happens when a command forwards its context to another command.
1865
+ */
1866
+ get forwarded() {
1867
+ return this.config.forwarded ?? false;
1868
+ }
1869
+ /**
1870
+ * Forwards the context to another command. The target handler will be the same as current handler.
1871
+ * @param command The command to forward to.
1872
+ */
1873
+ async forwardCommand(command) {
1874
+ const target = await this.commandkit.commandHandler.prepareCommandRun(this.isInteraction() ? this.interaction : this.message, command);
1875
+ if (!target) throw new Error(`Command ${command} not found`);
1876
+ const env = this.config.environment ?? getContext();
1877
+ if (!env) throw new Error("No commandkit environment found.");
1878
+ const handlers = {
1879
+ chatInput: target.command.data.chatInput,
1880
+ autocomplete: target.command.data.autocomplete,
1881
+ message: target.command.data.message,
1882
+ messageContextMenu: target.command.data.messageContextMenu,
1883
+ userContextMenu: target.command.data.userContextMenu
1884
+ };
1885
+ const handlerKind = env.variables.get("execHandlerKind");
1886
+ if (!handlerKind) throw new Error("No execution handler kind found.");
1887
+ const handler = handlers[handlerKind];
1888
+ if (!handler) throw new Error(`No handler found for ${handlerKind}`);
1889
+ env.variables.set("forwardedBy", this.commandName);
1890
+ env.variables.set("forwardedTo", command);
1891
+ await handler(this.clone({ forwarded: true }));
1892
+ require_signals.redirect();
1893
+ }
1894
+ /**
1895
+ * The execution mode of the command.
1896
+ */
1897
+ get executionMode() {
1898
+ return this.config.executionMode;
1899
+ }
1900
+ /**
1901
+ * Whether the command was triggered by an interaction.
1902
+ */
1903
+ isInteraction() {
1904
+ return this.executionMode === CommandExecutionMode.ChatInputCommand || this.executionMode === CommandExecutionMode.Autocomplete || this.executionMode === CommandExecutionMode.MessageContextMenu || this.executionMode === CommandExecutionMode.UserContextMenu;
1905
+ }
1906
+ /**
1907
+ * Whether the command was triggered by a slash command interaction.
1908
+ */
1909
+ isChatInputCommand() {
1910
+ return this.executionMode === CommandExecutionMode.ChatInputCommand;
1911
+ }
1912
+ /**
1913
+ * Whether the command was triggered by an autocomplete interaction.
1914
+ */
1915
+ isAutocomplete() {
1916
+ return this.executionMode === CommandExecutionMode.Autocomplete;
1917
+ }
1918
+ /**
1919
+ * Whether the command was triggered by a message context menu interaction.
1920
+ */
1921
+ isMessageContextMenu() {
1922
+ return this.executionMode === CommandExecutionMode.MessageContextMenu;
1923
+ }
1924
+ /**
1925
+ * Whether the command was triggered by a user context menu interaction.
1926
+ */
1927
+ isUserContextMenu() {
1928
+ return this.executionMode === CommandExecutionMode.UserContextMenu;
1929
+ }
1930
+ /**
1931
+ * Whether the command was triggered by a message.
1932
+ */
1933
+ isMessage() {
1934
+ return this.executionMode === CommandExecutionMode.Message;
1935
+ }
1936
+ /**
1937
+ * Returns the command identifier.
1938
+ */
1939
+ getCommandIdentifier() {
1940
+ if (this.isInteraction()) return this.interaction.commandName;
1941
+ else return this.message.content.split(" ")[0].slice(1);
1942
+ }
1943
+ /**
1944
+ * Returns the locale of the guild where this command was triggered.
1945
+ */
1946
+ getGuildLocale() {
1947
+ if (this.isInteraction()) return this.interaction.guildLocale;
1948
+ else {
1949
+ var _this$message$guild;
1950
+ return ((_this$message$guild = this.message.guild) === null || _this$message$guild === void 0 ? void 0 : _this$message$guild.preferredLocale) ?? null;
1951
+ }
1952
+ }
1953
+ /**
1954
+ * Returns the locale of the user who triggered this command.
1955
+ */
1956
+ getUserLocale() {
1957
+ if (this.isInteraction()) return this.interaction.locale;
1958
+ else return null;
1959
+ }
1960
+ /**
1961
+ * Returns the locale for this command.
1962
+ * @param preferUser Whether to prefer the user's locale over the guild's locale.
1963
+ * @returns The locale for this command. If no locale is found, the default locale is returned.
1964
+ */
1965
+ getLocale(preferUser = false) {
1966
+ if (this._locale) return this._locale;
1967
+ const locale = preferUser ? this.getUserLocale() : this.getGuildLocale();
1968
+ if (!locale) return this.commandkit.config.defaultLocale;
1969
+ return locale;
1970
+ }
1971
+ /**
1972
+ * Sets the locale for this command.
1973
+ * @param locale The locale to set.
1974
+ */
1975
+ setLocale(locale) {
1976
+ this._locale = locale;
1977
+ }
1978
+ /**
1979
+ * Creates a clone of this context
1980
+ */
1981
+ clone(config) {
1982
+ if (!config) return new Context(this.commandkit, this.config);
1983
+ const ctx = new Context(this.commandkit, {
1984
+ ...this.config,
1985
+ ...config,
1986
+ store: this.#store
1987
+ });
1988
+ return ctx;
1989
+ }
1990
+ isMiddleware() {
1991
+ return this instanceof MiddlewareContext;
1992
+ }
1993
+ args() {
1994
+ if (this.isMessage()) return this.config.messageCommandParser.getArgs();
1995
+ return [];
1996
+ }
1997
+ /**
1998
+ * Stops upcoming middleware or current command execution.
1999
+ * If this is called inside pre-stage middleware, the next run will be the actual command, skipping all other pre-stage middlewares.
2000
+ * If this is called inside a command itself, it will skip all post-stage middlewares.
2001
+ * If this is called inside post-stage middleware, it will skip all other post-stage middlewares.
2002
+ */
2003
+ exit() {
2004
+ require_signals.exitMiddleware();
2005
+ }
2006
+ };
2007
+ var MiddlewareContext = class extends Context {
2008
+ #cancel = false;
2009
+ /**
2010
+ * Whether the command execution was cancelled.
2011
+ */
2012
+ get cancelled() {
2013
+ return this.#cancel;
2014
+ }
2015
+ /**
2016
+ * Cancels the command execution.
2017
+ */
2018
+ cancel() {
2019
+ this.#cancel = true;
2020
+ }
2021
+ /**
2022
+ * Sets command runner function to wrap the command execution.
2023
+ * @param fn The function to set.
2024
+ * @example ctx.setCommandRunner(async (execute) => {
2025
+ * // do something before command execution
2026
+ * await execute();
2027
+ * // do something after command execution
2028
+ * })
2029
+ */
2030
+ setCommandRunner(fn) {
2031
+ var _this$config$customAr, _this$config$customAr2;
2032
+ (_this$config$customAr = this.config.customArgs) === null || _this$config$customAr === void 0 || (_this$config$customAr2 = _this$config$customAr.setCommandRunner) === null || _this$config$customAr2 === void 0 || _this$config$customAr2.call(_this$config$customAr, fn);
2033
+ }
2034
+ };
2035
+
2036
+ //#endregion
2037
+ //#region src/app/commands/AppCommandRunner.ts
2038
+ var AppCommandRunner = class {
2039
+ constructor(handler) {
2040
+ this.handler = handler;
2041
+ }
2042
+ async runCommand(prepared, source) {
2043
+ const { commandkit: commandkit$1 } = this.handler;
2044
+ const executionMode = this.getExecutionMode(source);
2045
+ let runCommand = null;
2046
+ const env = new CommandKitEnvironment(commandkit$1);
2047
+ env.setType(CommandKitEnvironmentType.CommandHandler);
2048
+ env.variables.set("commandHandlerType", "app");
2049
+ env.variables.set("currentCommandName", prepared.command.command.name);
2050
+ env.variables.set("execHandlerKind", executionMode);
2051
+ const ctx = new MiddlewareContext(commandkit$1, {
2052
+ command: prepared.command,
2053
+ environment: env,
2054
+ executionMode,
2055
+ interaction: !(source instanceof discord_js.Message) ? source : null,
2056
+ message: source instanceof discord_js.Message ? source : null,
2057
+ forwarded: false,
2058
+ customArgs: { setCommandRunner: (fn) => {
2059
+ runCommand = fn;
2060
+ } },
2061
+ messageCommandParser: prepared.messageCommandParser
2062
+ });
2063
+ let middlewaresCanceled = false;
2064
+ if (prepared.middlewares.length) await provideContext(env, async () => {
2065
+ for (const middleware of prepared.middlewares) {
2066
+ if (!middleware.data.beforeExecute) continue;
2067
+ try {
2068
+ await middleware.data.beforeExecute(ctx);
2069
+ } catch (e) {
2070
+ if (require_error_codes.isErrorType(e, require_error_codes.CommandKitErrorCodes.ExitMiddleware)) {
2071
+ middlewaresCanceled = true;
2072
+ return;
2073
+ }
2074
+ if (require_error_codes.isErrorType(e, [require_error_codes.CommandKitErrorCodes.ForwardedCommand, require_error_codes.CommandKitErrorCodes.InvalidCommandPrefix])) continue;
2075
+ throw e;
2076
+ }
2077
+ }
2078
+ });
2079
+ if (!ctx.cancelled) {
2080
+ const targetData = prepared.command.data;
2081
+ const fn = targetData[executionMode];
2082
+ if (!fn) Logger.warn(`Command ${prepared.command.command.name} has no handler for ${executionMode}`);
2083
+ if (fn) try {
2084
+ const _executeCommand = makeContextAwareFunction(env, async () => {
2085
+ env.registerDeferredFunction((env$1) => {
2086
+ env$1.markEnd();
2087
+ const error = env$1.getExecutionError();
2088
+ const marker = env$1.getMarker();
2089
+ const time = `${env$1.getExecutionTime().toFixed(2)}ms`;
2090
+ if (error) {
2091
+ Logger.error(`[${marker} - ${time}] Error executing command: ${error.stack || error}`);
2092
+ return;
2093
+ }
2094
+ Logger.info(`[${marker} - ${time}] Command executed successfully`);
2095
+ });
2096
+ return fn(ctx.clone());
2097
+ }, this.#finalizer.bind(this));
2098
+ const executeCommand = runCommand != null ? runCommand(_executeCommand) : _executeCommand;
2099
+ env.markStart(prepared.command.data.command.name);
2100
+ const res = await commandkit$1.plugins.execute(async (ctx$1, plugin) => {
2101
+ return plugin.executeCommand(ctx$1, env, source, prepared, executeCommand);
2102
+ });
2103
+ if (!res) await executeCommand();
2104
+ } catch (e) {
2105
+ if (require_error_codes.isErrorType(e, require_error_codes.CommandKitErrorCodes.ExitMiddleware)) middlewaresCanceled = true;
2106
+ if (!require_error_codes.isErrorType(e, [require_error_codes.CommandKitErrorCodes.ForwardedCommand, require_error_codes.CommandKitErrorCodes.ExitMiddleware])) Logger.error(e);
2107
+ }
2108
+ }
2109
+ if (!middlewaresCanceled && prepared.middlewares.length) await provideContext(env, async () => {
2110
+ for (const middleware of prepared.middlewares) {
2111
+ if (!middleware.data.afterExecute) continue;
2112
+ try {
2113
+ await middleware.data.afterExecute(ctx);
2114
+ } catch (e) {
2115
+ if (require_error_codes.isErrorType(e, require_error_codes.CommandKitErrorCodes.ExitMiddleware)) return;
2116
+ throw e;
2117
+ }
2118
+ }
2119
+ });
2120
+ }
2121
+ async #finalizer() {
2122
+ const env = useEnvironment();
2123
+ await env.runDeferredFunctions();
2124
+ env.clearAllDeferredFunctions();
2125
+ await this.handler.commandkit.plugins.execute(async (ctx, plugin) => {
2126
+ await plugin.onAfterCommand(ctx, env);
2127
+ });
2128
+ }
2129
+ getExecutionMode(source) {
2130
+ if (source instanceof discord_js.Message) return CommandExecutionMode.Message;
2131
+ if (source.isChatInputCommand()) return CommandExecutionMode.ChatInputCommand;
2132
+ if (source.isAutocomplete()) return CommandExecutionMode.Autocomplete;
2133
+ if (source.isMessageContextMenuCommand()) return CommandExecutionMode.MessageContextMenu;
2134
+ if (source.isUserContextMenuCommand()) return CommandExecutionMode.UserContextMenu;
2135
+ return null;
2136
+ }
2137
+ };
2138
+
2139
+ //#endregion
2140
+ //#region src/app/handlers/AppCommandHandler.ts
2141
+ const commandDataSchema = {
2142
+ command: (c) => c instanceof discord_js.SlashCommandBuilder || c instanceof discord_js.ContextMenuCommandBuilder || c && typeof c === "object",
2143
+ chatInput: (c) => typeof c === "function",
2144
+ autocomplete: (c) => typeof c === "function",
2145
+ message: (c) => typeof c === "function",
2146
+ messageContextMenu: (c) => typeof c === "function",
2147
+ userContextMenu: (c) => typeof c === "function"
2148
+ };
2149
+ const middlewareDataSchema = {
2150
+ beforeExecute: (c) => typeof c === "function",
2151
+ afterExecute: (c) => typeof c === "function"
2152
+ };
2153
+ var AppCommandHandler = class {
2154
+ loadedCommands = new discord_js.Collection();
2155
+ loadedMiddlewares = new discord_js.Collection();
2156
+ commandNameToId = new Map();
2157
+ subcommandPathToId = new Map();
2158
+ registrar;
2159
+ onInteraction = null;
2160
+ onMessageCreate = null;
2161
+ commandRunner = new AppCommandRunner(this);
2162
+ externalCommandData = new discord_js.Collection();
2163
+ externalMiddlewareData = new discord_js.Collection();
2164
+ constructor(commandkit$1) {
2165
+ this.commandkit = commandkit$1;
2166
+ this.registrar = new CommandRegistrar(this.commandkit);
2167
+ }
2168
+ printBanner() {
2169
+ const uncategorized = crypto.randomUUID();
2170
+ const categorizedCommands = this.getCommandsArray().reduce((acc, cmd) => {
2171
+ const category = cmd.command.category || uncategorized;
2172
+ acc[category] = acc[category] || [];
2173
+ acc[category].push(cmd);
2174
+ return acc;
2175
+ }, {});
2176
+ console.log(require_colors.colors_default.green(`Loaded ${require_colors.colors_default.magenta(this.loadedCommands.size.toString())} commands:`));
2177
+ const categories = Object.keys(categorizedCommands).sort();
2178
+ const categoryTree = {};
2179
+ categories.forEach((category) => {
2180
+ if (category === uncategorized) return;
2181
+ if (category.includes(":")) {
2182
+ const parts = category.split(":");
2183
+ let bestParent = null;
2184
+ for (let i = parts.length - 1; i > 0; i--) {
2185
+ const potentialParent = parts.slice(0, i).join(":");
2186
+ if (categories.includes(potentialParent)) {
2187
+ bestParent = potentialParent;
2188
+ break;
2189
+ }
2190
+ }
2191
+ if (bestParent) {
2192
+ categoryTree[bestParent] = categoryTree[bestParent] || [];
2193
+ categoryTree[bestParent].push(category);
2194
+ }
2195
+ }
2196
+ });
2197
+ const processedCategories = new Set();
2198
+ const printCategory = (category, indent = "", isLast = false, parentPrefix = "") => {
2199
+ if (processedCategories.has(category)) return;
2200
+ processedCategories.add(category);
2201
+ const commands = categorizedCommands[category];
2202
+ const hasChildren = categoryTree[category] && categoryTree[category].length > 0;
2203
+ const thisPrefix = isLast ? "└─" : "├─";
2204
+ const childIndent = parentPrefix + (isLast ? " " : "│ ");
2205
+ if (category !== uncategorized) {
2206
+ const displayName = category.includes(":") ? category.split(":").pop() : category;
2207
+ console.log(require_colors.colors_default.cyan(`${indent}${thisPrefix} ${require_colors.colors_default.bold(displayName)}`));
2208
+ }
2209
+ commands.forEach((cmd, cmdIndex) => {
2210
+ const cmdIsLast = cmdIndex === commands.length - 1 && !hasChildren;
2211
+ const cmdPrefix = cmdIsLast ? "└─" : "├─";
2212
+ const cmdIndent = category !== uncategorized ? childIndent : indent;
2213
+ const name = cmd.data.command.name;
2214
+ const hasMw = cmd.command.middlewares.length > 0;
2215
+ const middlewareIcon = hasMw ? require_colors.colors_default.magenta(" (λ)") : "";
2216
+ console.log(`${require_colors.colors_default.green(`${cmdIndent}${cmdPrefix}`)} ${require_colors.colors_default.yellow(name)}${middlewareIcon}`);
2217
+ });
2218
+ if (hasChildren) {
2219
+ const children = categoryTree[category].sort();
2220
+ children.forEach((childCategory, idx) => {
2221
+ const childIsLast = idx === children.length - 1;
2222
+ printCategory(childCategory, childIndent, childIsLast, childIndent);
2223
+ });
2224
+ }
2225
+ };
2226
+ const topLevelCategories = categories.filter((category) => {
2227
+ if (category === uncategorized) return true;
2228
+ if (category.includes(":")) {
2229
+ const parts = category.split(":");
2230
+ for (let i = 1; i < parts.length; i++) {
2231
+ const parentPath = parts.slice(0, i).join(":");
2232
+ if (categories.includes(parentPath)) return false;
2233
+ }
2234
+ return true;
2235
+ }
2236
+ return true;
2237
+ }).sort();
2238
+ topLevelCategories.forEach((category, index) => {
2239
+ const isLast = index === topLevelCategories.length - 1;
2240
+ printCategory(category, "", isLast);
2241
+ });
2242
+ }
2243
+ getCommandsArray() {
2244
+ return Array.from(this.loadedCommands.values());
2245
+ }
2246
+ registerCommandHandler() {
2247
+ this.onInteraction ??= async (interaction) => {
2248
+ const success = await this.commandkit.plugins.execute(async (ctx, plugin) => {
2249
+ return plugin.onBeforeInteraction(ctx, interaction);
2250
+ });
2251
+ if (success) return;
2252
+ const isCommandLike = interaction.isCommand() || interaction.isAutocomplete() || interaction.isUserContextMenuCommand() || interaction.isMessageContextMenuCommand();
2253
+ if (!isCommandLike) return;
2254
+ const prepared = await this.prepareCommandRun(interaction);
2255
+ if (!prepared) return;
2256
+ return this.commandRunner.runCommand(prepared, interaction);
2257
+ };
2258
+ this.onMessageCreate ??= async (message) => {
2259
+ const success = await this.commandkit.plugins.execute(async (ctx, plugin) => {
2260
+ return plugin.onBeforeMessageCommand(ctx, message);
2261
+ });
2262
+ if (success) return;
2263
+ if (message.author.bot) return;
2264
+ const prepared = await this.prepareCommandRun(message);
2265
+ if (!prepared) return;
2266
+ return this.commandRunner.runCommand(prepared, message);
2267
+ };
2268
+ this.commandkit.client.on(discord_js.Events.InteractionCreate, this.onInteraction);
2269
+ this.commandkit.client.on(discord_js.Events.MessageCreate, this.onMessageCreate);
2270
+ }
2271
+ async prepareCommandRun(source, cmdName) {
2272
+ var _loadedCommand$guilds2;
2273
+ let parser;
2274
+ if (!cmdName) if (source instanceof discord_js.Message) {
2275
+ if (source.author.bot) return null;
2276
+ const prefix = await this.commandkit.config.getMessageCommandPrefix(source);
2277
+ parser = new require_MessageCommandParser.MessageCommandParser(source, Array.isArray(prefix) ? prefix : [prefix], (command) => {
2278
+ var _loadedCommand$guilds, _json$options;
2279
+ const commandId$1 = this.commandNameToId.get(command);
2280
+ if (!commandId$1) return null;
2281
+ const loadedCommand$1 = this.loadedCommands.get(commandId$1);
2282
+ if (!loadedCommand$1) return null;
2283
+ if (source.guildId && ((_loadedCommand$guilds = loadedCommand$1.guilds) === null || _loadedCommand$guilds === void 0 ? void 0 : _loadedCommand$guilds.length) && !loadedCommand$1.guilds.includes(source.guildId)) return null;
2284
+ const json$1 = "toJSON" in loadedCommand$1.data.command ? loadedCommand$1.data.command.toJSON() : loadedCommand$1.data.command;
2285
+ return ((_json$options = json$1.options) === null || _json$options === void 0 ? void 0 : _json$options.reduce((acc, opt) => {
2286
+ acc[opt.name] = opt.type;
2287
+ return acc;
2288
+ }, {})) ?? {};
2289
+ });
2290
+ try {
2291
+ const fullCommand = parser.getFullCommand();
2292
+ const parts = fullCommand.split(" ");
2293
+ cmdName = parts[0];
2294
+ } catch (e) {
2295
+ if (require_error_codes.isErrorType(e, require_error_codes.CommandKitErrorCodes.InvalidCommandPrefix)) return null;
2296
+ Logger.error(e);
2297
+ return null;
2298
+ }
2299
+ } else {
2300
+ const isAnyCommand = source.isChatInputCommand() || source.isAutocomplete() || source.isContextMenuCommand();
2301
+ if (!isAnyCommand) return null;
2302
+ cmdName = source.commandName;
2303
+ }
2304
+ const commandId = this.commandNameToId.get(cmdName);
2305
+ if (!commandId) return null;
2306
+ const loadedCommand = this.loadedCommands.get(commandId);
2307
+ if (!loadedCommand) return null;
2308
+ if ((source instanceof discord_js.CommandInteraction || source instanceof discord_js.AutocompleteInteraction) && source.guildId && ((_loadedCommand$guilds2 = loadedCommand.guilds) === null || _loadedCommand$guilds2 === void 0 ? void 0 : _loadedCommand$guilds2.length) && !loadedCommand.guilds.includes(source.guildId)) return null;
2309
+ const middlewares = [];
2310
+ for (const middlewareId of loadedCommand.command.middlewares) {
2311
+ const middleware = this.loadedMiddlewares.get(middlewareId);
2312
+ if (middleware) middlewares.push(middleware);
2313
+ }
2314
+ return {
2315
+ command: loadedCommand,
2316
+ middlewares,
2317
+ messageCommandParser: parser
2318
+ };
2319
+ }
2320
+ async reloadCommands() {
2321
+ this.loadedCommands.clear();
2322
+ this.loadedMiddlewares.clear();
2323
+ this.commandNameToId.clear();
2324
+ this.subcommandPathToId.clear();
2325
+ this.externalCommandData.clear();
2326
+ this.externalMiddlewareData.clear();
2327
+ await this.loadCommands();
2328
+ }
2329
+ async addExternalMiddleware(data) {
2330
+ for (const middleware of data) {
2331
+ if (!middleware.id) continue;
2332
+ this.externalMiddlewareData.set(middleware.id, middleware);
2333
+ }
2334
+ }
2335
+ async addExternalCommands(data) {
2336
+ for (const command of data) {
2337
+ if (!command.id) continue;
2338
+ this.externalCommandData.set(command.id, command);
2339
+ }
2340
+ }
2341
+ async registerExternalLoadedMiddleware(data) {
2342
+ for (const middleware of data) this.loadedMiddlewares.set(middleware.middleware.id, middleware);
2343
+ }
2344
+ async registerExternalLoadedCommands(data) {
2345
+ for (const command of data) {
2346
+ this.loadedCommands.set(command.command.id, command);
2347
+ this.commandNameToId.set(command.command.name, command.command.id);
2348
+ }
2349
+ }
2350
+ async loadCommands() {
2351
+ await this.commandkit.plugins.execute((ctx, plugin) => {
2352
+ return plugin.onBeforeCommandsLoad(ctx);
2353
+ });
2354
+ const commandsRouter = this.commandkit.commandsRouter;
2355
+ if (!commandsRouter) throw new Error("Commands router has not yet initialized");
2356
+ const { commands, middlewares } = commandsRouter.getData();
2357
+ const combinedCommands = this.externalCommandData.size ? commands.concat(this.externalCommandData) : commands;
2358
+ const combinedMiddlewares = this.externalMiddlewareData.size ? middlewares.concat(this.externalMiddlewareData) : middlewares;
2359
+ for (const [id, middleware] of combinedMiddlewares) await this.loadMiddleware(id, middleware);
2360
+ for (const [id, command] of combinedCommands) await this.loadCommand(id, command);
2361
+ if (require_constants.COMMANDKIT_IS_DEV) await require_types_package.rewriteCommandDeclaration(`type CommandTypeData = ${Array.from(this.loadedCommands.mapValues((v) => JSON.stringify(v.command.name)).values()).join(" | ")}`);
2362
+ await this.commandkit.plugins.execute((ctx, plugin) => {
2363
+ return plugin.onAfterCommandsLoad(ctx);
2364
+ });
2365
+ }
2366
+ async loadMiddleware(id, middleware) {
2367
+ try {
2368
+ const data = await import(`${require_resolve_file_url.toFileURL(middleware.path)}?t=${Date.now()}`);
2369
+ let handlerCount = 0;
2370
+ for (const [key, validator] of Object.entries(middlewareDataSchema)) {
2371
+ if (data[key] && !await validator(data[key])) throw new Error(`Invalid export for middleware ${id}: ${key} does not match expected value`);
2372
+ if (data[key]) handlerCount++;
2373
+ }
2374
+ if (handlerCount === 0) throw new Error(`Invalid export for middleware ${id}: at least one handler function must be provided`);
2375
+ this.loadedMiddlewares.set(id, {
2376
+ middleware,
2377
+ data
2378
+ });
2379
+ } catch (error) {
2380
+ Logger.error(`Failed to load middleware ${id}`, error);
2381
+ }
2382
+ }
2383
+ async loadCommand(id, command) {
2384
+ try {
2385
+ if (command.path === null) {
2386
+ this.loadedCommands.set(id, {
2387
+ command,
2388
+ data: { command: {
2389
+ name: command.name,
2390
+ description: `${command.name} commands`,
2391
+ type: 1
2392
+ } }
2393
+ });
2394
+ return;
2395
+ }
2396
+ const data = await import(`${require_resolve_file_url.toFileURL(command.path)}?t=${Date.now()}`);
2397
+ if (!data.command) throw new Error(`Invalid export for command ${command.name}: no command definition found`);
2398
+ let handlerCount = 0;
2399
+ for (const [key, validator] of Object.entries(commandDataSchema)) {
2400
+ if (key !== "command" && data[key]) handlerCount++;
2401
+ if (data[key] && !await validator(data[key])) throw new Error(`Invalid export for command ${command.name}: ${key} does not match expected value`);
2402
+ }
2403
+ if (handlerCount === 0) throw new Error(`Invalid export for command ${command.name}: at least one handler function must be provided`);
2404
+ let lastUpdated = data.command;
2405
+ await this.commandkit.plugins.execute(async (ctx, plugin) => {
2406
+ const res = await plugin.prepareCommand(ctx, lastUpdated);
2407
+ if (res) lastUpdated = res;
2408
+ });
2409
+ this.loadedCommands.set(id, {
2410
+ command,
2411
+ guilds: data.guilds,
2412
+ data: {
2413
+ ...data,
2414
+ command: "toJSON" in lastUpdated ? lastUpdated.toJSON() : lastUpdated
2415
+ }
2416
+ });
2417
+ this.commandNameToId.set(command.name, id);
2418
+ } catch (error) {
2419
+ Logger.error(`Failed to load command ${command.name} (${id})`, error);
2420
+ }
2421
+ }
2422
+ };
2423
+
2424
+ //#endregion
2425
+ //#region src/app/handlers/AppEventsHandler.ts
2426
+ var AppEventsHandler = class {
2427
+ loadedEvents = new discord_js.Collection();
2428
+ constructor(commandkit$1) {
2429
+ this.commandkit = commandkit$1;
2430
+ }
2431
+ getEvents() {
2432
+ if (this.loadedEvents.size === 0) return [];
2433
+ const events = this.loadedEvents.toJSON();
2434
+ return events.map((event) => ({
2435
+ name: event.name,
2436
+ namespace: event.namespace,
2437
+ onceListeners: event.listeners.filter((listener) => listener.once).length,
2438
+ regularListeners: event.listeners.filter((listener) => !listener.once).length,
2439
+ metadata: event.event
2440
+ }));
2441
+ }
2442
+ async reloadEvents() {
2443
+ this.unregisterAll();
2444
+ await this.loadEvents();
2445
+ }
2446
+ async loadEvents() {
2447
+ await this.commandkit.plugins.execute((ctx, plugin) => {
2448
+ return plugin.onBeforeEventsLoad(ctx);
2449
+ });
2450
+ const router = this.commandkit.eventsRouter;
2451
+ const events = await router.scan();
2452
+ for (const event of Object.values(events)) {
2453
+ const listeners = [];
2454
+ for (const listener of event.listeners) {
2455
+ const handler = await import(require_resolve_file_url.toFileURL(listener, true));
2456
+ if (!handler.default || typeof handler.default !== "function") Logger.error(`Event handler for ${event.event}${event.namespace ? ` of namespace ${event.namespace}` : ""} does not have a default export or is not a function`);
2457
+ listeners.push({
2458
+ handler: handler.default,
2459
+ once: !!handler.once
2460
+ });
2461
+ }
2462
+ const len = listeners.length;
2463
+ if (!len) Logger.warn(`Event ${event.event}${event.namespace ? ` of namespace ${event.namespace}` : ""} does not have any listeners`);
2464
+ const key = `${event.namespace ? `${event.namespace}:` : ""}${event.event}`;
2465
+ this.loadedEvents.set(key, {
2466
+ name: event.event,
2467
+ namespace: event.namespace,
2468
+ event,
2469
+ listeners
2470
+ });
2471
+ Logger.info(`✨ Loaded event ${event.event}${event.namespace ? ` of namespace ${event.namespace}` : ""} with ${len} listener${len === 1 ? "" : "s"}`);
2472
+ }
2473
+ this.registerAllClientEvents();
2474
+ await this.commandkit.plugins.execute((ctx, plugin) => {
2475
+ return plugin.onAfterEventsLoad(ctx);
2476
+ });
2477
+ }
2478
+ unregisterAll() {
2479
+ this.unregisterAllClientListeners();
2480
+ this.loadedEvents.clear();
2481
+ }
2482
+ registerAllClientEvents() {
2483
+ const client = this.commandkit.client;
2484
+ for (const [key, data] of this.loadedEvents.entries()) {
2485
+ const { name, listeners, namespace } = data;
2486
+ const onceListeners = listeners.filter((listener) => listener.once);
2487
+ const onListeners = listeners.filter((listener) => !listener.once);
2488
+ const executedOnceListeners = new Set();
2489
+ const mainHandler = async (...args) => {
2490
+ let accepted = false;
2491
+ const event = {
2492
+ name,
2493
+ args,
2494
+ namespace: namespace ?? null,
2495
+ once: false,
2496
+ metadata: data.event,
2497
+ accept() {
2498
+ if (accepted) return;
2499
+ accepted = true;
2500
+ }
2501
+ };
2502
+ await this.commandkit.plugins.execute(async (ctx, plugin) => {
2503
+ var _plugin$willEmitEvent;
2504
+ if (accepted) return;
2505
+ return (_plugin$willEmitEvent = plugin.willEmitEvent) === null || _plugin$willEmitEvent === void 0 ? void 0 : _plugin$willEmitEvent.call(plugin, ctx, event);
2506
+ }).catch(Object);
2507
+ await require_EventWorkerContext.runInEventWorkerContext({
2508
+ event: name,
2509
+ namespace: namespace ?? null,
2510
+ data: data.event,
2511
+ commandkit: this.commandkit,
2512
+ arguments: args
2513
+ }, async () => {
2514
+ for (const listener of onListeners) try {
2515
+ await listener.handler(...args);
2516
+ } catch (e) {
2517
+ if (e instanceof StopEventPropagationError) {
2518
+ Logger.debug(`Event propagation stopped for ${name}${namespace ? ` of namespace ${namespace}` : ""}`);
2519
+ break;
2520
+ }
2521
+ Logger.error(`Error handling event ${name}${namespace ? ` of namespace ${namespace}` : ""}`, e);
2522
+ }
2523
+ });
2524
+ };
2525
+ const onceHandler = async (...args) => {
2526
+ let broken = false;
2527
+ let accepted = false;
2528
+ const event = {
2529
+ name,
2530
+ args,
2531
+ namespace: namespace ?? null,
2532
+ once: true,
2533
+ metadata: data.event,
2534
+ accept() {
2535
+ if (accepted) return;
2536
+ accepted = true;
2537
+ }
2538
+ };
2539
+ await this.commandkit.plugins.execute(async (ctx, plugin) => {
2540
+ var _plugin$willEmitEvent2;
2541
+ if (accepted) return;
2542
+ return (_plugin$willEmitEvent2 = plugin.willEmitEvent) === null || _plugin$willEmitEvent2 === void 0 ? void 0 : _plugin$willEmitEvent2.call(plugin, ctx, event);
2543
+ }).catch(Object);
2544
+ for (const listener of onceListeners) {
2545
+ if (broken) break;
2546
+ await require_EventWorkerContext.runInEventWorkerContext({
2547
+ event: name,
2548
+ namespace: namespace ?? null,
2549
+ data: data.event,
2550
+ commandkit: this.commandkit,
2551
+ arguments: args
2552
+ }, async () => {
2553
+ try {
2554
+ if (executedOnceListeners.has(listener.handler)) return;
2555
+ await listener.handler(...args);
2556
+ executedOnceListeners.add(listener.handler);
2557
+ } catch (e) {
2558
+ if (e instanceof StopEventPropagationError) {
2559
+ Logger.debug(`Event propagation stopped for ${name}${namespace ? ` of namespace ${namespace}` : ""}`);
2560
+ broken = true;
2561
+ }
2562
+ Logger.error(`Error handling event ${name}${namespace ? ` of namespace ${namespace}` : ""}`, e);
2563
+ }
2564
+ });
2565
+ }
2566
+ if (executedOnceListeners.size === onceListeners.length && onListeners.length === 0) {
2567
+ this.loadedEvents.delete(key);
2568
+ Logger.info(`🧹 Cleaned up completed once-only event ${name}${namespace ? ` of namespace ${namespace}` : ""}`);
2569
+ }
2570
+ };
2571
+ this.loadedEvents.set(key, {
2572
+ ...data,
2573
+ mainListener: onListeners.length > 0 ? {
2574
+ handler: mainHandler,
2575
+ once: false
2576
+ } : void 0,
2577
+ executedOnceListeners
2578
+ });
2579
+ if (namespace) {
2580
+ if (onListeners.length > 0) this.commandkit.events.on(namespace, name, mainHandler);
2581
+ if (onceListeners.length > 0) this.commandkit.events.once(namespace, name, onceHandler);
2582
+ } else {
2583
+ if (onListeners.length > 0) client.on(name, mainHandler);
2584
+ if (onceListeners.length > 0) client.once(name, onceHandler);
2585
+ }
2586
+ Logger.info(`🔌 Registered event ${name}${namespace ? ` of namespace ${namespace}` : ""} (${onListeners.length} regular, ${onceListeners.length} once-only)`);
2587
+ }
2588
+ }
2589
+ unregisterAllClientListeners() {
2590
+ const client = this.commandkit.client;
2591
+ for (const [key, { name, mainListener, namespace }] of this.loadedEvents.entries()) {
2592
+ if (mainListener) if (namespace) this.commandkit.events.off(namespace, name, mainListener.handler);
2593
+ else client.off(name, mainListener.handler);
2594
+ else if (namespace) this.commandkit.events.removeAllListeners(namespace, name);
2595
+ else client.removeAllListeners(name);
2596
+ this.loadedEvents.delete(key);
2597
+ Logger.info(`🗑️ Unregistered event ${name}${namespace ? ` of namespace ${namespace}` : ""}`);
2598
+ }
2599
+ }
2600
+ };
2601
+
2602
+ //#endregion
2603
+ //#region src/config/loader.ts
2604
+ const CONFIG_FILE_NAMES = [
2605
+ "commandkit.config.js",
2606
+ "commandkit.config.mjs",
2607
+ "commandkit.config.cjs",
2608
+ "commandkit.config.ts"
2609
+ ];
2610
+ function getPossibleConfigPaths(root) {
2611
+ return CONFIG_FILE_NAMES.map((name) => (0, node_path.join)(root, name));
2612
+ }
2613
+ function findConfigFile(cwd) {
2614
+ const locations = getPossibleConfigPaths(cwd);
2615
+ for (const location of locations) if ((0, node_fs.existsSync)(location)) return {
2616
+ path: location,
2617
+ isTypeScript: /\.ts$/.test(location)
2618
+ };
2619
+ return null;
2620
+ }
2621
+ let loadedConfig = null;
2622
+ /**
2623
+ * Load the configuration file from the given entrypoint.
2624
+ * @param entrypoint The entrypoint to load the configuration file from. Defaults to the current working directory.
2625
+ */
2626
+ async function loadConfigFile(entrypoint = process.cwd()) {
2627
+ if (loadedConfig) return loadedConfig;
2628
+ const filePath = findConfigFile(entrypoint);
2629
+ if (!filePath) return getConfig();
2630
+ const config = await require_common.loadConfigFileFromPath(filePath.path);
2631
+ loadedConfig = config;
2632
+ return config;
2633
+ }
2634
+
2635
+ //#endregion
2636
+ //#region src/utils/dev-hooks.ts
2637
+ function registerDevHooks(commandkit$1) {
2638
+ if (!require_constants.COMMANDKIT_IS_DEV) return;
2639
+ process.on("message", async (message) => {
2640
+ if (typeof message !== "object" || message === null) return;
2641
+ const { event, path, id } = message;
2642
+ if (!event) return;
2643
+ if (process.env.COMMANDKIT_DEBUG_HMR === "true") Logger.info(`Received HMR event: ${event}${path ? ` for ${path}` : ""}`);
2644
+ let accepted = false, prevented = false, handled = false;
2645
+ const hmrEvent = {
2646
+ accept() {
2647
+ accepted = true;
2648
+ },
2649
+ preventDefault() {
2650
+ prevented = true;
2651
+ },
2652
+ path,
2653
+ event
2654
+ };
2655
+ try {
2656
+ await commandkit$1.plugins.execute(async (ctx, plugin) => {
2657
+ var _plugin$performHMR;
2658
+ if (accepted) return;
2659
+ await ((_plugin$performHMR = plugin.performHMR) === null || _plugin$performHMR === void 0 ? void 0 : _plugin$performHMR.call(plugin, ctx, hmrEvent));
2660
+ });
2661
+ if (prevented) return;
2662
+ switch (event) {
2663
+ case require_constants.HMREventType.ReloadCommands:
2664
+ commandkit$1.commandHandler.reloadCommands();
2665
+ handled = true;
2666
+ break;
2667
+ case require_constants.HMREventType.ReloadEvents:
2668
+ commandkit$1.eventHandler.reloadEvents();
2669
+ handled = true;
2670
+ break;
2671
+ case require_constants.HMREventType.Unknown:
2672
+ handled = false;
2673
+ break;
2674
+ default: break;
2675
+ }
2676
+ } finally {
2677
+ if (id && process.send) process.send({
2678
+ type: "commandkit-hmr-ack",
2679
+ id,
2680
+ handled: handled || accepted
2681
+ });
2682
+ }
2683
+ });
2684
+ }
2685
+
2686
+ //#endregion
2687
+ //#region src/CommandKit.ts
2688
+ let commandkit;
2689
+ const bootstrapHooks = new Set();
2690
+ const onApplicationBootstrapHooks = new Set();
2691
+ /**
2692
+ * Registers a bootstrap hook that will be called when the CommandKit instance is created.
2693
+ * This is useful for plugins that need to run some code after the CommandKit instance is fully initialized.
2694
+ * Note that not all commandkit dependiencs are available at this point. It is recommended to use the `onApplicationBootstrap` hook instead,
2695
+ * if you need access to the commandkit dependencies.
2696
+ * @param fn The bootstrap function to register.
2697
+ * @example ```ts
2698
+ * import { onBootstrap } from 'commandkit';
2699
+ *
2700
+ * onBootstrap(async (commandkit) => {
2701
+ * // Do something with the commandkit instance
2702
+ * })
2703
+ * ```
2704
+ */
2705
+ function onBootstrap(fn) {
2706
+ bootstrapHooks.add(fn);
2707
+ }
2708
+ /**
2709
+ * Registers a bootstrap hook that will be called when the CommandKit instance is created.
2710
+ * This is useful for plugins that need to run some code after the CommandKit instance is fully initialized.
2711
+ * @param fn The bootstrap function to register.
2712
+ * @example ```ts
2713
+ * import { onApplicationBootstrap } from 'commandkit';
2714
+ *
2715
+ * onApplicationBootstrap(async (commandkit) => {
2716
+ * // Do something with the commandkit instance
2717
+ * })
2718
+ * ```
2719
+ */
2720
+ function onApplicationBootstrap(fn) {
2721
+ onApplicationBootstrapHooks.add(fn);
2722
+ }
2723
+ var CommandKit = class CommandKit extends node_events.default {
2724
+ #started = false;
2725
+ options;
2726
+ eventInterceptor;
2727
+ static createElement = require_element.createElement;
2728
+ static Fragment = require_element.Fragment;
2729
+ config = {
2730
+ defaultLocale: discord_js.Locale.EnglishUS,
2731
+ getMessageCommandPrefix: () => "!"
2732
+ };
2733
+ store = new Map();
2734
+ flags = new require_store.FlagStore();
2735
+ commandsRouter;
2736
+ eventsRouter;
2737
+ commandHandler;
2738
+ eventHandler;
2739
+ plugins;
2740
+ events;
2741
+ static instance = void 0;
2742
+ /**
2743
+ * Create a new command and event handler with CommandKit.
2744
+ *
2745
+ * @param options - The default CommandKit configuration.
2746
+ * @see {@link https://commandkit.js.org/docs/guide/commandkit-setup}
2747
+ */
2748
+ constructor(options) {
2749
+ if (CommandKit.instance) process.emitWarning("CommandKit instance already exists. Having multiple instance in same project is discouraged and it may lead to unexpected behavior.", { code: "MultiInstanceWarning" });
2750
+ if (!options.client) throw new Error(require_colors.colors_default.red("\"client\" is required when instantiating CommandKit."));
2751
+ super();
2752
+ this.options = options;
2753
+ if (!CommandKit.instance) CommandKit.instance = this;
2754
+ this.plugins = new CommandKitPluginRuntime(this);
2755
+ commandkit = CommandKit.instance;
2756
+ this.#bootstrapHooks();
2757
+ }
2758
+ async #bootstrapHooks() {
2759
+ for (const hook of bootstrapHooks) try {
2760
+ await hook(this);
2761
+ } catch (e) {
2762
+ Logger.error("Error while executing bootstrap hook: ", e);
2763
+ } finally {
2764
+ bootstrapHooks.delete(hook);
2765
+ }
2766
+ bootstrapHooks.clear();
2767
+ }
2768
+ async #applicationBootstrapHooks() {
2769
+ for (const hook of onApplicationBootstrapHooks) try {
2770
+ await hook(this);
2771
+ } catch (e) {
2772
+ Logger.error("Error while executing application bootstrap hook: ", e);
2773
+ } finally {
2774
+ onApplicationBootstrapHooks.delete(hook);
2775
+ }
2776
+ onApplicationBootstrapHooks.clear();
2777
+ }
2778
+ /**
2779
+ * Starts the commandkit application.
2780
+ * @param token The application token to connect to the discord gateway. If not provided, it will use the `TOKEN` or `DISCORD_TOKEN` environment variable. If set to `false`, it will not login.
2781
+ */
2782
+ async start(token) {
2783
+ if (this.#started) return;
2784
+ if (!this.options.client) throw new Error(require_colors.colors_default.red("\"client\" is required when starting CommandKit."));
2785
+ this.eventInterceptor = new require_EventInterceptor.EventInterceptor(this.client);
2786
+ if (require_constants.COMMANDKIT_IS_DEV) try {
2787
+ registerDevHooks(this);
2788
+ await require_types_package.generateTypesPackage();
2789
+ } catch (e) {
2790
+ if (process.env.COMMANDKIT_DEBUG_TYPEGEN) Logger.error(e);
2791
+ }
2792
+ await this.loadPlugins();
2793
+ await this.#init();
2794
+ this.commandHandler.registerCommandHandler();
2795
+ this.incrementClientListenersCount();
2796
+ if (token !== false && !this.options.client.isReady()) {
2797
+ this.client.once(discord_js.Events.ClientReady, async () => {
2798
+ await this.commandHandler.registrar.register();
2799
+ });
2800
+ await this.plugins.execute((ctx, plugin) => {
2801
+ var _plugin$onBeforeClien;
2802
+ return (_plugin$onBeforeClien = plugin.onBeforeClientLogin) === null || _plugin$onBeforeClien === void 0 ? void 0 : _plugin$onBeforeClien.call(plugin, ctx);
2803
+ });
2804
+ const botToken = token ?? this.options.client.token ?? process.env.TOKEN ?? process.env.DISCORD_TOKEN;
2805
+ await this.options.client.login(botToken);
2806
+ await this.plugins.execute((ctx, plugin) => {
2807
+ var _plugin$onAfterClient;
2808
+ return (_plugin$onAfterClient = plugin.onAfterClientLogin) === null || _plugin$onAfterClient === void 0 ? void 0 : _plugin$onAfterClient.call(plugin, ctx);
2809
+ });
2810
+ } else if (this.options.client.isReady()) await this.commandHandler.registrar.register();
2811
+ this.#started = true;
2812
+ await this.#applicationBootstrapHooks();
2813
+ }
2814
+ /**
2815
+ * Loads all the plugins.
2816
+ */
2817
+ async loadPlugins() {
2818
+ const config = await loadConfigFile();
2819
+ const plugins = config.plugins.flat(2).filter((p) => require_RuntimePlugin.isRuntimePlugin(p));
2820
+ if (!plugins.length) return;
2821
+ for (const plugin of plugins) await this.plugins.softRegisterPlugin(plugin);
2822
+ }
2823
+ /**
2824
+ * Whether or not the commandkit application has started.
2825
+ */
2826
+ get started() {
2827
+ return this.#started;
2828
+ }
2829
+ /**
2830
+ * Sets the prefix resolver for the command handler.
2831
+ * @param resolver The resolver function.
2832
+ */
2833
+ setPrefixResolver(resolver) {
2834
+ this.config.getMessageCommandPrefix = resolver;
2835
+ return this;
2836
+ }
2837
+ /**
2838
+ * Sets the default locale for the command handler.
2839
+ * @param locale The default locale.
2840
+ */
2841
+ setDefaultLocale(locale) {
2842
+ this.config.defaultLocale = locale;
2843
+ return this;
2844
+ }
2845
+ /**
2846
+ * Get the client attached to this CommandKit instance.
2847
+ */
2848
+ get client() {
2849
+ return this.options.client;
2850
+ }
2851
+ async #init() {
2852
+ const appDir$1 = this.getAppDirectory();
2853
+ if (!appDir$1) return;
2854
+ const commandsPath = this.getPath("commands");
2855
+ const events = this.getPath("events");
2856
+ this.commandHandler = new AppCommandHandler(this);
2857
+ this.eventHandler = new AppEventsHandler(this);
2858
+ this.events = new require_CommandKitEventsChannel.CommandKitEventsChannel(this);
2859
+ this.commandsRouter = new require_CommandsRouter.CommandsRouter({ entrypoint: commandsPath });
2860
+ await this.plugins.execute((ctx, plugin) => {
2861
+ return plugin.onCommandsRouterInit(ctx);
2862
+ });
2863
+ this.eventsRouter = new require_EventsRouter.EventsRouter({ entrypoints: [events] });
2864
+ await this.plugins.execute((ctx, plugin) => {
2865
+ return plugin.onEventsRouterInit(ctx);
2866
+ });
2867
+ await this.#initEvents();
2868
+ await this.#initCommands();
2869
+ }
2870
+ async #initCommands() {
2871
+ if (this.commandsRouter.isValidPath()) {
2872
+ const result = await this.commandsRouter.scan();
2873
+ if (require_constants.COMMANDKIT_IS_DEV) (0, node_fs.writeFileSync)("./.commandkit/commands.json", JSON.stringify(result, null, 2));
2874
+ }
2875
+ await this.commandHandler.loadCommands();
2876
+ this.commandHandler.printBanner();
2877
+ }
2878
+ async #initEvents() {
2879
+ if (this.eventsRouter.isValidPath()) await this.eventsRouter.scan();
2880
+ await this.eventHandler.loadEvents();
2881
+ }
2882
+ /**
2883
+ * Updates application commands with the latest from "commandsPath".
2884
+ */
2885
+ async reloadCommands() {
2886
+ await this.commandHandler.reloadCommands();
2887
+ }
2888
+ /**
2889
+ * Updates application events with the latest from "eventsPath".
2890
+ */
2891
+ async reloadEvents() {
2892
+ await this.eventHandler.reloadEvents();
2893
+ }
2894
+ /**
2895
+ * Increment the client listeners count.
2896
+ */
2897
+ incrementClientListenersCount() {
2898
+ this.options.client.setMaxListeners(this.options.client.getMaxListeners() + 1);
2899
+ }
2900
+ /**
2901
+ * Decrement the client listeners count.
2902
+ */
2903
+ decrementClientListenersCount() {
2904
+ this.options.client.setMaxListeners(this.options.client.getMaxListeners() - 1);
2905
+ }
2906
+ /**
2907
+ * Path to the app directory. Returns `null` if not found.
2908
+ * The lookup order is:
2909
+ * - `./app`
2910
+ * - `./src/app`
2911
+ */
2912
+ getAppDirectory() {
2913
+ return findAppDirectory();
2914
+ }
2915
+ getPath(to) {
2916
+ const appDir$1 = this.getAppDirectory();
2917
+ if (!appDir$1) return null;
2918
+ switch (to) {
2919
+ case "commands": return (0, node_path.join)(appDir$1, "commands");
2920
+ case "events": return (0, node_path.join)(appDir$1, "events");
2921
+ default: return to;
2922
+ }
2923
+ }
2924
+ };
2925
+
2926
+ //#endregion
2927
+ Object.defineProperty(exports, 'AppCommandHandler', {
2928
+ enumerable: true,
2929
+ get: function () {
2930
+ return AppCommandHandler;
2931
+ }
2932
+ });
2933
+ Object.defineProperty(exports, 'AppCommandRunner', {
2934
+ enumerable: true,
2935
+ get: function () {
2936
+ return AppCommandRunner;
2937
+ }
2938
+ });
2939
+ Object.defineProperty(exports, 'AppEventsHandler', {
2940
+ enumerable: true,
2941
+ get: function () {
2942
+ return AppEventsHandler;
2943
+ }
2944
+ });
2945
+ Object.defineProperty(exports, 'Button', {
2946
+ enumerable: true,
2947
+ get: function () {
2948
+ return Button;
2949
+ }
2950
+ });
2951
+ Object.defineProperty(exports, 'ButtonKit', {
2952
+ enumerable: true,
2953
+ get: function () {
2954
+ return ButtonKit;
2955
+ }
2956
+ });
2957
+ Object.defineProperty(exports, 'ChannelSelectMenu', {
2958
+ enumerable: true,
2959
+ get: function () {
2960
+ return ChannelSelectMenu;
2961
+ }
2962
+ });
2963
+ Object.defineProperty(exports, 'ChannelSelectMenuKit', {
2964
+ enumerable: true,
2965
+ get: function () {
2966
+ return ChannelSelectMenuKit;
2967
+ }
2968
+ });
2969
+ Object.defineProperty(exports, 'CommandExecutionMode', {
2970
+ enumerable: true,
2971
+ get: function () {
2972
+ return CommandExecutionMode;
2973
+ }
2974
+ });
2975
+ Object.defineProperty(exports, 'CommandKit', {
2976
+ enumerable: true,
2977
+ get: function () {
2978
+ return CommandKit;
2979
+ }
2980
+ });
2981
+ Object.defineProperty(exports, 'CommandKitEnvironment', {
2982
+ enumerable: true,
2983
+ get: function () {
2984
+ return CommandKitEnvironment;
2985
+ }
2986
+ });
2987
+ Object.defineProperty(exports, 'CommandKitEnvironmentType', {
2988
+ enumerable: true,
2989
+ get: function () {
2990
+ return CommandKitEnvironmentType;
2991
+ }
2992
+ });
2993
+ Object.defineProperty(exports, 'CommandKitPluginRuntime', {
2994
+ enumerable: true,
2995
+ get: function () {
2996
+ return CommandKitPluginRuntime;
2997
+ }
2998
+ });
2999
+ Object.defineProperty(exports, 'CommandRegistrar', {
3000
+ enumerable: true,
3001
+ get: function () {
3002
+ return CommandRegistrar;
3003
+ }
3004
+ });
3005
+ Object.defineProperty(exports, 'CommonDirectiveTransformer', {
3006
+ enumerable: true,
3007
+ get: function () {
3008
+ return CommonDirectiveTransformer;
3009
+ }
3010
+ });
3011
+ Object.defineProperty(exports, 'Context', {
3012
+ enumerable: true,
3013
+ get: function () {
3014
+ return Context;
3015
+ }
3016
+ });
3017
+ Object.defineProperty(exports, 'DefaultLogger', {
3018
+ enumerable: true,
3019
+ get: function () {
3020
+ return DefaultLogger;
3021
+ }
3022
+ });
3023
+ Object.defineProperty(exports, 'Logger', {
3024
+ enumerable: true,
3025
+ get: function () {
3026
+ return Logger;
3027
+ }
3028
+ });
3029
+ Object.defineProperty(exports, 'MacroPlugin', {
3030
+ enumerable: true,
3031
+ get: function () {
3032
+ return MacroPlugin;
3033
+ }
3034
+ });
3035
+ Object.defineProperty(exports, 'MentionableSelectMenu', {
3036
+ enumerable: true,
3037
+ get: function () {
3038
+ return MentionableSelectMenu;
3039
+ }
3040
+ });
3041
+ Object.defineProperty(exports, 'MentionableSelectMenuKit', {
3042
+ enumerable: true,
3043
+ get: function () {
3044
+ return MentionableSelectMenuKit;
3045
+ }
3046
+ });
3047
+ Object.defineProperty(exports, 'MiddlewareContext', {
3048
+ enumerable: true,
3049
+ get: function () {
3050
+ return MiddlewareContext;
3051
+ }
3052
+ });
3053
+ Object.defineProperty(exports, 'Modal', {
3054
+ enumerable: true,
3055
+ get: function () {
3056
+ return Modal;
3057
+ }
3058
+ });
3059
+ Object.defineProperty(exports, 'ModalKit', {
3060
+ enumerable: true,
3061
+ get: function () {
3062
+ return ModalKit;
3063
+ }
3064
+ });
3065
+ Object.defineProperty(exports, 'ParagraphInput', {
3066
+ enumerable: true,
3067
+ get: function () {
3068
+ return ParagraphInput;
3069
+ }
3070
+ });
3071
+ Object.defineProperty(exports, 'RoleSelectMenu', {
3072
+ enumerable: true,
3073
+ get: function () {
3074
+ return RoleSelectMenu;
3075
+ }
3076
+ });
3077
+ Object.defineProperty(exports, 'RoleSelectMenuKit', {
3078
+ enumerable: true,
3079
+ get: function () {
3080
+ return RoleSelectMenuKit;
3081
+ }
3082
+ });
3083
+ Object.defineProperty(exports, 'ShortInput', {
3084
+ enumerable: true,
3085
+ get: function () {
3086
+ return ShortInput;
3087
+ }
3088
+ });
3089
+ Object.defineProperty(exports, 'StopEventPropagationError', {
3090
+ enumerable: true,
3091
+ get: function () {
3092
+ return StopEventPropagationError;
3093
+ }
3094
+ });
3095
+ Object.defineProperty(exports, 'StringSelectMenu', {
3096
+ enumerable: true,
3097
+ get: function () {
3098
+ return StringSelectMenu;
3099
+ }
3100
+ });
3101
+ Object.defineProperty(exports, 'StringSelectMenuKit', {
3102
+ enumerable: true,
3103
+ get: function () {
3104
+ return StringSelectMenuKit;
3105
+ }
3106
+ });
3107
+ Object.defineProperty(exports, 'StringSelectMenuOption', {
3108
+ enumerable: true,
3109
+ get: function () {
3110
+ return StringSelectMenuOption;
3111
+ }
3112
+ });
3113
+ Object.defineProperty(exports, 'TextInput', {
3114
+ enumerable: true,
3115
+ get: function () {
3116
+ return TextInput;
3117
+ }
3118
+ });
3119
+ Object.defineProperty(exports, 'UserSelectMenu', {
3120
+ enumerable: true,
3121
+ get: function () {
3122
+ return UserSelectMenu;
3123
+ }
3124
+ });
3125
+ Object.defineProperty(exports, 'UserSelectMenuKit', {
3126
+ enumerable: true,
3127
+ get: function () {
3128
+ return UserSelectMenuKit;
3129
+ }
3130
+ });
3131
+ Object.defineProperty(exports, 'after', {
3132
+ enumerable: true,
3133
+ get: function () {
3134
+ return after;
3135
+ }
3136
+ });
3137
+ Object.defineProperty(exports, 'cancelAfter', {
3138
+ enumerable: true,
3139
+ get: function () {
3140
+ return cancelAfter;
3141
+ }
3142
+ });
3143
+ Object.defineProperty(exports, 'commandkit', {
3144
+ enumerable: true,
3145
+ get: function () {
3146
+ return commandkit;
3147
+ }
3148
+ });
3149
+ Object.defineProperty(exports, 'createLogger', {
3150
+ enumerable: true,
3151
+ get: function () {
3152
+ return createLogger;
3153
+ }
3154
+ });
3155
+ Object.defineProperty(exports, 'debounce', {
3156
+ enumerable: true,
3157
+ get: function () {
3158
+ return debounce;
3159
+ }
3160
+ });
3161
+ Object.defineProperty(exports, 'defaultConfig', {
3162
+ enumerable: true,
3163
+ get: function () {
3164
+ return defaultConfig;
3165
+ }
3166
+ });
3167
+ Object.defineProperty(exports, 'defineConfig', {
3168
+ enumerable: true,
3169
+ get: function () {
3170
+ return defineConfig;
3171
+ }
3172
+ });
3173
+ Object.defineProperty(exports, 'devOnly', {
3174
+ enumerable: true,
3175
+ get: function () {
3176
+ return devOnly;
3177
+ }
3178
+ });
3179
+ Object.defineProperty(exports, 'exitContext', {
3180
+ enumerable: true,
3181
+ get: function () {
3182
+ return exitContext;
3183
+ }
3184
+ });
3185
+ Object.defineProperty(exports, 'findAppDirectory', {
3186
+ enumerable: true,
3187
+ get: function () {
3188
+ return findAppDirectory;
3189
+ }
3190
+ });
3191
+ Object.defineProperty(exports, 'getCommandKit', {
3192
+ enumerable: true,
3193
+ get: function () {
3194
+ return getCommandKit;
3195
+ }
3196
+ });
3197
+ Object.defineProperty(exports, 'getConfig', {
3198
+ enumerable: true,
3199
+ get: function () {
3200
+ return getConfig;
3201
+ }
3202
+ });
3203
+ Object.defineProperty(exports, 'getContext', {
3204
+ enumerable: true,
3205
+ get: function () {
3206
+ return getContext;
3207
+ }
3208
+ });
3209
+ Object.defineProperty(exports, 'getCurrentDirectory', {
3210
+ enumerable: true,
3211
+ get: function () {
3212
+ return getCurrentDirectory;
3213
+ }
3214
+ });
3215
+ Object.defineProperty(exports, 'getPossibleConfigPaths', {
3216
+ enumerable: true,
3217
+ get: function () {
3218
+ return getPossibleConfigPaths;
3219
+ }
3220
+ });
3221
+ Object.defineProperty(exports, 'getSourceDirectories', {
3222
+ enumerable: true,
3223
+ get: function () {
3224
+ return getSourceDirectories;
3225
+ }
3226
+ });
3227
+ Object.defineProperty(exports, 'isCommandWorkerContext', {
3228
+ enumerable: true,
3229
+ get: function () {
3230
+ return isCommandWorkerContext;
3231
+ }
3232
+ });
3233
+ Object.defineProperty(exports, 'loadConfigFile', {
3234
+ enumerable: true,
3235
+ get: function () {
3236
+ return loadConfigFile;
3237
+ }
3238
+ });
3239
+ Object.defineProperty(exports, 'makeContextAwareFunction', {
3240
+ enumerable: true,
3241
+ get: function () {
3242
+ return makeContextAwareFunction;
3243
+ }
3244
+ });
3245
+ Object.defineProperty(exports, 'onApplicationBootstrap', {
3246
+ enumerable: true,
3247
+ get: function () {
3248
+ return onApplicationBootstrap;
3249
+ }
3250
+ });
3251
+ Object.defineProperty(exports, 'onBootstrap', {
3252
+ enumerable: true,
3253
+ get: function () {
3254
+ return onBootstrap;
3255
+ }
3256
+ });
3257
+ Object.defineProperty(exports, 'provideContext', {
3258
+ enumerable: true,
3259
+ get: function () {
3260
+ return provideContext;
3261
+ }
3262
+ });
3263
+ Object.defineProperty(exports, 'registerDevHooks', {
3264
+ enumerable: true,
3265
+ get: function () {
3266
+ return registerDevHooks;
3267
+ }
3268
+ });
3269
+ Object.defineProperty(exports, 'stopEvents', {
3270
+ enumerable: true,
3271
+ get: function () {
3272
+ return stopEvents;
3273
+ }
3274
+ });
3275
+ Object.defineProperty(exports, 'useEnvironment', {
3276
+ enumerable: true,
3277
+ get: function () {
3278
+ return useEnvironment;
3279
+ }
3280
+ });
3281
+ //# sourceMappingURL=CommandKit-DDrQtQns.js.map