@buape/carbon 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/dist/package.json +7 -2
  2. package/dist/src/abstracts/BaseComponentInteraction.d.ts +6 -1
  3. package/dist/src/abstracts/BaseComponentInteraction.d.ts.map +1 -1
  4. package/dist/src/abstracts/BaseComponentInteraction.js +12 -0
  5. package/dist/src/abstracts/BaseComponentInteraction.js.map +1 -1
  6. package/dist/src/abstracts/BaseInteraction.d.ts +4 -0
  7. package/dist/src/abstracts/BaseInteraction.d.ts.map +1 -1
  8. package/dist/src/abstracts/BaseInteraction.js +4 -0
  9. package/dist/src/abstracts/BaseInteraction.js.map +1 -1
  10. package/dist/src/classes/Client.d.ts.map +1 -1
  11. package/dist/src/classes/Client.js +21 -11
  12. package/dist/src/classes/Client.js.map +1 -1
  13. package/dist/src/internals/AutocompleteInteraction.d.ts +1 -1
  14. package/dist/src/internals/FieldsHandler.d.ts +27 -0
  15. package/dist/src/internals/FieldsHandler.d.ts.map +1 -0
  16. package/dist/src/internals/FieldsHandler.js +37 -0
  17. package/dist/src/internals/FieldsHandler.js.map +1 -0
  18. package/dist/src/internals/ModalInteraction.d.ts +3 -4
  19. package/dist/src/internals/ModalInteraction.d.ts.map +1 -1
  20. package/dist/src/internals/ModalInteraction.js +3 -10
  21. package/dist/src/internals/ModalInteraction.js.map +1 -1
  22. package/dist/src/internals/OptionsHandler.d.ts +33 -17
  23. package/dist/src/internals/OptionsHandler.d.ts.map +1 -1
  24. package/dist/src/internals/OptionsHandler.js +52 -58
  25. package/dist/src/internals/OptionsHandler.js.map +1 -1
  26. package/dist/src/utils.d.ts +3 -0
  27. package/dist/src/utils.d.ts.map +1 -1
  28. package/dist/src/utils.js +54 -0
  29. package/dist/src/utils.js.map +1 -1
  30. package/dist/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +6 -1
  32. package/.turbo/turbo-build.log +0 -5
  33. package/.turbo/turbo-dev.log +0 -8
  34. package/.turbo/turbo-docs.log +0 -12
  35. package/CHANGELOG.md +0 -44
  36. package/dist/src/abstracts/ButtonInteraction.d.ts +0 -8
  37. package/dist/src/abstracts/ButtonInteraction.d.ts.map +0 -1
  38. package/dist/src/abstracts/ButtonInteraction.js +0 -18
  39. package/dist/src/abstracts/ButtonInteraction.js.map +0 -1
  40. package/dist/src/abstracts/ChannelSelectMenuInteraction.d.ts +0 -7
  41. package/dist/src/abstracts/ChannelSelectMenuInteraction.d.ts.map +0 -1
  42. package/dist/src/abstracts/ChannelSelectMenuInteraction.js +0 -11
  43. package/dist/src/abstracts/ChannelSelectMenuInteraction.js.map +0 -1
  44. package/dist/src/abstracts/CommandHandler.d.ts +0 -6
  45. package/dist/src/abstracts/CommandHandler.d.ts.map +0 -1
  46. package/dist/src/abstracts/CommandHandler.js +0 -65
  47. package/dist/src/abstracts/CommandHandler.js.map +0 -1
  48. package/dist/src/abstracts/CommandInteraction.d.ts +0 -15
  49. package/dist/src/abstracts/CommandInteraction.d.ts.map +0 -1
  50. package/dist/src/abstracts/CommandInteraction.js +0 -60
  51. package/dist/src/abstracts/CommandInteraction.js.map +0 -1
  52. package/dist/src/abstracts/ComponentHandler.d.ts +0 -6
  53. package/dist/src/abstracts/ComponentHandler.d.ts.map +0 -1
  54. package/dist/src/abstracts/ComponentHandler.js +0 -64
  55. package/dist/src/abstracts/ComponentHandler.js.map +0 -1
  56. package/dist/src/abstracts/MentionableSelectMenuInteraction.d.ts +0 -8
  57. package/dist/src/abstracts/MentionableSelectMenuInteraction.d.ts.map +0 -1
  58. package/dist/src/abstracts/MentionableSelectMenuInteraction.js +0 -15
  59. package/dist/src/abstracts/MentionableSelectMenuInteraction.js.map +0 -1
  60. package/dist/src/abstracts/RoleSelectMenuInteraction.d.ts +0 -8
  61. package/dist/src/abstracts/RoleSelectMenuInteraction.d.ts.map +0 -1
  62. package/dist/src/abstracts/RoleSelectMenuInteraction.js +0 -14
  63. package/dist/src/abstracts/RoleSelectMenuInteraction.js.map +0 -1
  64. package/dist/src/abstracts/StringSelectMenuInteraction.d.ts +0 -8
  65. package/dist/src/abstracts/StringSelectMenuInteraction.d.ts.map +0 -1
  66. package/dist/src/abstracts/StringSelectMenuInteraction.js +0 -14
  67. package/dist/src/abstracts/StringSelectMenuInteraction.js.map +0 -1
  68. package/dist/src/abstracts/UserSelectMenuInteraction.d.ts +0 -8
  69. package/dist/src/abstracts/UserSelectMenuInteraction.d.ts.map +0 -1
  70. package/dist/src/abstracts/UserSelectMenuInteraction.js +0 -14
  71. package/dist/src/abstracts/UserSelectMenuInteraction.js.map +0 -1
  72. package/dist/src/classes/Paginator.d.ts +0 -3
  73. package/dist/src/classes/Paginator.d.ts.map +0 -1
  74. package/dist/src/classes/Paginator.js +0 -3
  75. package/dist/src/classes/Paginator.js.map +0 -1
  76. package/dist/src/internals/ComponentHandler copy.d.ts +0 -17
  77. package/dist/src/internals/ComponentHandler copy.d.ts.map +0 -1
  78. package/dist/src/internals/ComponentHandler copy.js +0 -75
  79. package/dist/src/internals/ComponentHandler copy.js.map +0 -1
  80. package/dist/src/structures/AnySelectMenu.d.ts +0 -31
  81. package/dist/src/structures/AnySelectMenu.d.ts.map +0 -1
  82. package/dist/src/structures/AnySelectMenu.js +0 -19
  83. package/dist/src/structures/AnySelectMenu.js.map +0 -1
  84. package/dist/src/structures/AnySelectMenuInteraction.d.ts +0 -12
  85. package/dist/src/structures/AnySelectMenuInteraction.d.ts.map +0 -1
  86. package/dist/src/structures/AnySelectMenuInteraction.js +0 -21
  87. package/dist/src/structures/AnySelectMenuInteraction.js.map +0 -1
  88. package/dist/src/structures/Base.d.ts +0 -10
  89. package/dist/src/structures/Base.d.ts.map +0 -1
  90. package/dist/src/structures/Base.js +0 -11
  91. package/dist/src/structures/Base.js.map +0 -1
  92. package/dist/src/structures/BaseCommand.d.ts +0 -64
  93. package/dist/src/structures/BaseCommand.d.ts.map +0 -1
  94. package/dist/src/structures/BaseCommand.js +0 -58
  95. package/dist/src/structures/BaseCommand.js.map +0 -1
  96. package/dist/src/structures/BaseComponent.d.ts +0 -34
  97. package/dist/src/structures/BaseComponent.d.ts.map +0 -1
  98. package/dist/src/structures/BaseComponent.js +0 -30
  99. package/dist/src/structures/BaseComponent.js.map +0 -1
  100. package/dist/src/structures/BaseComponentInteraction.d.ts +0 -9
  101. package/dist/src/structures/BaseComponentInteraction.d.ts.map +0 -1
  102. package/dist/src/structures/BaseComponentInteraction.js +0 -14
  103. package/dist/src/structures/BaseComponentInteraction.js.map +0 -1
  104. package/dist/src/structures/BaseInteraction.d.ts +0 -81
  105. package/dist/src/structures/BaseInteraction.d.ts.map +0 -1
  106. package/dist/src/structures/BaseInteraction.js +0 -99
  107. package/dist/src/structures/BaseInteraction.js.map +0 -1
  108. package/dist/src/structures/ButtonInteraction.d.ts +0 -8
  109. package/dist/src/structures/ButtonInteraction.d.ts.map +0 -1
  110. package/dist/src/structures/ButtonInteraction.js +0 -18
  111. package/dist/src/structures/ButtonInteraction.js.map +0 -1
  112. package/dist/src/structures/ChannelSelectMenuInteraction.d.ts +0 -7
  113. package/dist/src/structures/ChannelSelectMenuInteraction.d.ts.map +0 -1
  114. package/dist/src/structures/ChannelSelectMenuInteraction.js +0 -11
  115. package/dist/src/structures/ChannelSelectMenuInteraction.js.map +0 -1
  116. package/dist/src/structures/CommandHandler.d.ts +0 -6
  117. package/dist/src/structures/CommandHandler.d.ts.map +0 -1
  118. package/dist/src/structures/CommandHandler.js +0 -70
  119. package/dist/src/structures/CommandHandler.js.map +0 -1
  120. package/dist/src/structures/CommandInteraction.d.ts +0 -15
  121. package/dist/src/structures/CommandInteraction.d.ts.map +0 -1
  122. package/dist/src/structures/CommandInteraction.js +0 -60
  123. package/dist/src/structures/CommandInteraction.js.map +0 -1
  124. package/dist/src/structures/ComponentHandler.d.ts +0 -6
  125. package/dist/src/structures/ComponentHandler.d.ts.map +0 -1
  126. package/dist/src/structures/ComponentHandler.js +0 -64
  127. package/dist/src/structures/ComponentHandler.js.map +0 -1
  128. package/dist/src/structures/MentionableSelectMenuInteraction.d.ts +0 -8
  129. package/dist/src/structures/MentionableSelectMenuInteraction.d.ts.map +0 -1
  130. package/dist/src/structures/MentionableSelectMenuInteraction.js +0 -15
  131. package/dist/src/structures/MentionableSelectMenuInteraction.js.map +0 -1
  132. package/dist/src/structures/RoleSelectMenuInteraction.d.ts +0 -8
  133. package/dist/src/structures/RoleSelectMenuInteraction.d.ts.map +0 -1
  134. package/dist/src/structures/RoleSelectMenuInteraction.js +0 -14
  135. package/dist/src/structures/RoleSelectMenuInteraction.js.map +0 -1
  136. package/dist/src/structures/StringSelectMenuInteraction.d.ts +0 -8
  137. package/dist/src/structures/StringSelectMenuInteraction.d.ts.map +0 -1
  138. package/dist/src/structures/StringSelectMenuInteraction.js +0 -14
  139. package/dist/src/structures/StringSelectMenuInteraction.js.map +0 -1
  140. package/dist/src/structures/UserSelectMenuInteraction.d.ts +0 -8
  141. package/dist/src/structures/UserSelectMenuInteraction.d.ts.map +0 -1
  142. package/dist/src/structures/UserSelectMenuInteraction.js +0 -14
  143. package/dist/src/structures/UserSelectMenuInteraction.js.map +0 -1
  144. package/dist/src/types.d.ts +0 -31
  145. package/dist/src/types.d.ts.map +0 -1
  146. package/dist/src/types.js +0 -33
  147. package/dist/src/types.js.map +0 -1
  148. package/docs/classes/AnySelectMenu.mdx +0 -114
  149. package/docs/classes/AnySelectMenuInteraction.mdx +0 -175
  150. package/docs/classes/AutocompleteInteraction.mdx +0 -166
  151. package/docs/classes/AutocompleteOptionsHandler.mdx +0 -243
  152. package/docs/classes/BaseChannel.mdx +0 -97
  153. package/docs/classes/BaseCommand.mdx +0 -61
  154. package/docs/classes/BaseComponent.mdx +0 -55
  155. package/docs/classes/BaseComponentInteraction.mdx +0 -160
  156. package/docs/classes/BaseGuildChannel.mdx +0 -262
  157. package/docs/classes/BaseGuildTextChannel.mdx +0 -360
  158. package/docs/classes/BaseInteraction.mdx +0 -137
  159. package/docs/classes/Button.mdx +0 -99
  160. package/docs/classes/ButtonInteraction.mdx +0 -155
  161. package/docs/classes/ChannelSelectMenu.mdx +0 -122
  162. package/docs/classes/ChannelSelectMenuInteraction.mdx +0 -171
  163. package/docs/classes/Client.mdx +0 -48
  164. package/docs/classes/Command.mdx +0 -111
  165. package/docs/classes/CommandHandler.mdx +0 -65
  166. package/docs/classes/CommandInteraction.mdx +0 -155
  167. package/docs/classes/CommandWithSubcommandGroups.mdx +0 -73
  168. package/docs/classes/CommandWithSubcommands.mdx +0 -76
  169. package/docs/classes/ComponentHandler.mdx +0 -49
  170. package/docs/classes/DmChannel.mdx +0 -118
  171. package/docs/classes/GroupDmChannel.mdx +0 -197
  172. package/docs/classes/Guild.mdx +0 -157
  173. package/docs/classes/GuildAnnouncementChannel.mdx +0 -377
  174. package/docs/classes/GuildCategoryChannel.mdx +0 -272
  175. package/docs/classes/GuildForumChannel.mdx +0 -333
  176. package/docs/classes/GuildMediaChannel.mdx +0 -327
  177. package/docs/classes/GuildStageChannel.mdx +0 -276
  178. package/docs/classes/GuildStageOrVoiceChannel.mdx +0 -292
  179. package/docs/classes/GuildTextChannel.mdx +0 -367
  180. package/docs/classes/GuildThreadChannel.mdx +0 -425
  181. package/docs/classes/GuildThreadOnlyChannel.mdx +0 -333
  182. package/docs/classes/GuildVoiceChannel.mdx +0 -276
  183. package/docs/classes/LinkButton.mdx +0 -84
  184. package/docs/classes/MentionableSelectMenu.mdx +0 -120
  185. package/docs/classes/MentionableSelectMenuInteraction.mdx +0 -171
  186. package/docs/classes/Message.mdx +0 -126
  187. package/docs/classes/OptionsHandler.mdx +0 -203
  188. package/docs/classes/PremiumButton.mdx +0 -84
  189. package/docs/classes/Role.mdx +0 -228
  190. package/docs/classes/RoleSelectMenu.mdx +0 -120
  191. package/docs/classes/RoleSelectMenuInteraction.mdx +0 -171
  192. package/docs/classes/Row.mdx +0 -88
  193. package/docs/classes/StringSelectMenu.mdx +0 -120
  194. package/docs/classes/StringSelectMenuInteraction.mdx +0 -171
  195. package/docs/classes/User.mdx +0 -119
  196. package/docs/classes/UserSelectMenu.mdx +0 -120
  197. package/docs/classes/UserSelectMenuInteraction.mdx +0 -171
  198. package/docs/enumerations/ClientMode.mdx +0 -16
  199. package/docs/functions/channelFactory.mdx +0 -16
  200. package/docs/index.mdx +0 -83
  201. package/docs/type-aliases/AnySelectMenuComponentType.mdx +0 -5
  202. package/docs/type-aliases/ClientOptions.mdx +0 -20
  203. package/docs/type-aliases/CommandOptions.mdx +0 -5
  204. package/docs/type-aliases/ComponentAdditionalData.mdx +0 -9
  205. package/docs/type-aliases/InteractionFileData.mdx +0 -15
  206. package/docs/type-aliases/InteractionReplyData.mdx +0 -14
  207. package/docs/type-aliases/InteractionReplyOptions.mdx +0 -13
  208. package/docs/type-aliases/RawOptions.mdx +0 -9
  209. package/docs/type-aliases/meta.json +0 -3
  210. package/src/README.md +0 -7
  211. package/src/abstracts/AnySelectMenu.ts +0 -63
  212. package/src/abstracts/AnySelectMenuInteraction.ts +0 -29
  213. package/src/abstracts/Base.ts +0 -12
  214. package/src/abstracts/BaseChannel.ts +0 -73
  215. package/src/abstracts/BaseCommand.ts +0 -89
  216. package/src/abstracts/BaseComponent.ts +0 -49
  217. package/src/abstracts/BaseComponentInteraction.ts +0 -19
  218. package/src/abstracts/BaseGuildChannel.ts +0 -152
  219. package/src/abstracts/BaseGuildTextChannel.ts +0 -77
  220. package/src/abstracts/BaseInteraction.ts +0 -209
  221. package/src/abstracts/GuildThreadOnlyChannel.ts +0 -71
  222. package/src/classes/Button.ts +0 -95
  223. package/src/classes/ChannelSelectMenu.ts +0 -21
  224. package/src/classes/Client.ts +0 -277
  225. package/src/classes/Command.ts +0 -53
  226. package/src/classes/CommandWithSubcommandGroups.ts +0 -47
  227. package/src/classes/CommandWithSubcommands.ts +0 -35
  228. package/src/classes/MentionableSelectMenu.ts +0 -19
  229. package/src/classes/Modal.ts +0 -38
  230. package/src/classes/RoleSelectMenu.ts +0 -19
  231. package/src/classes/Row.ts +0 -50
  232. package/src/classes/StringSelectMenu.ts +0 -19
  233. package/src/classes/TextInput.ts +0 -65
  234. package/src/classes/UserSelectMenu.ts +0 -19
  235. package/src/factories/channelFactory.ts +0 -43
  236. package/src/index.ts +0 -62
  237. package/src/internals/AutocompleteInteraction.ts +0 -107
  238. package/src/internals/ButtonInteraction.ts +0 -26
  239. package/src/internals/ChannelSelectMenuInteraction.ts +0 -15
  240. package/src/internals/CommandHandler.ts +0 -127
  241. package/src/internals/CommandInteraction.ts +0 -49
  242. package/src/internals/ComponentHandler.ts +0 -92
  243. package/src/internals/MentionableSelectMenuInteraction.ts +0 -21
  244. package/src/internals/ModalHandler.ts +0 -27
  245. package/src/internals/ModalInteraction.ts +0 -25
  246. package/src/internals/OptionsHandler.ts +0 -148
  247. package/src/internals/RoleSelectMenuInteraction.ts +0 -20
  248. package/src/internals/StringSelectMenuInteraction.ts +0 -20
  249. package/src/internals/UserSelectMenuInteraction.ts +0 -20
  250. package/src/structures/DmChannel.ts +0 -31
  251. package/src/structures/GroupDmChannel.ts +0 -132
  252. package/src/structures/Guild.ts +0 -154
  253. package/src/structures/GuildAnnouncementChannel.ts +0 -20
  254. package/src/structures/GuildCategoryChannel.ts +0 -16
  255. package/src/structures/GuildForumChannel.ts +0 -20
  256. package/src/structures/GuildMediaChannel.ts +0 -13
  257. package/src/structures/GuildMember.ts +0 -231
  258. package/src/structures/GuildStageOrVoiceChannel.ts +0 -46
  259. package/src/structures/GuildTextChannel.ts +0 -21
  260. package/src/structures/GuildThreadChannel.ts +0 -150
  261. package/src/structures/Message.ts +0 -124
  262. package/src/structures/Role.ts +0 -201
  263. package/src/structures/User.ts +0 -153
  264. package/src/utils.ts +0 -13
  265. package/tests/index.test.ts +0 -4
  266. package/tsconfig.json +0 -12
  267. package/typedoc.json +0 -9
@@ -1,95 +0,0 @@
1
- import {
2
- type APIButtonComponent,
3
- type APIButtonComponentWithSKUId,
4
- type APIButtonComponentWithURL,
5
- ButtonStyle,
6
- ComponentType
7
- } from "discord-api-types/v10"
8
- import { BaseComponent } from "../abstracts/BaseComponent.js"
9
- import type { ButtonInteraction } from "../internals/ButtonInteraction.js"
10
-
11
- abstract class BaseButton extends BaseComponent {
12
- type = ComponentType.Button
13
-
14
- /**
15
- * The label of the button
16
- */
17
- abstract label: string
18
-
19
- /**
20
- * The emoji of the button
21
- */
22
- emoji?: {
23
- name: string
24
- id?: string
25
- animated?: boolean
26
- }
27
-
28
- /**
29
- * The style of the button
30
- */
31
- style: ButtonStyle = ButtonStyle.Primary
32
-
33
- /**
34
- * The disabled state of the button
35
- */
36
- disabled = false
37
- }
38
-
39
- export abstract class Button extends BaseButton {
40
- /**
41
- * The style of the button
42
- */
43
- abstract style: Exclude<ButtonStyle, ButtonStyle.Link | ButtonStyle.Premium>
44
-
45
- abstract run(interaction: ButtonInteraction): Promise<void>
46
-
47
- serialize = (): APIButtonComponent => {
48
- return {
49
- type: ComponentType.Button,
50
- style: this.style,
51
- label: this.label,
52
- custom_id: this.customId,
53
- disabled: this.disabled,
54
- emoji: this.emoji
55
- }
56
- }
57
- }
58
-
59
- export abstract class LinkButton extends BaseButton {
60
- customId = ""
61
- /**
62
- * The URL that the button links to
63
- */
64
- abstract url: string
65
- style: ButtonStyle.Link = ButtonStyle.Link
66
-
67
- serialize = (): APIButtonComponentWithURL => {
68
- return {
69
- type: ComponentType.Button,
70
- url: this.url,
71
- style: this.style,
72
- label: this.label,
73
- disabled: this.disabled,
74
- emoji: this.emoji
75
- }
76
- }
77
- }
78
-
79
- export abstract class PremiumButton extends BaseButton {
80
- style: ButtonStyle.Premium = ButtonStyle.Premium
81
-
82
- /**
83
- * The SKU ID of the button
84
- */
85
- abstract sku_id: string
86
-
87
- serialize = (): APIButtonComponentWithSKUId => {
88
- return {
89
- style: this.style,
90
- type: ComponentType.Button,
91
- disabled: this.disabled,
92
- sku_id: this.sku_id
93
- }
94
- }
95
- }
@@ -1,21 +0,0 @@
1
- import {
2
- type APIChannelSelectComponent,
3
- ComponentType
4
- } from "discord-api-types/v10"
5
- import { AnySelectMenu } from "../abstracts/AnySelectMenu.js"
6
- import type { ChannelSelectMenuInteraction } from "../internals/ChannelSelectMenuInteraction.js"
7
-
8
- export abstract class ChannelSelectMenu extends AnySelectMenu {
9
- type: ComponentType.ChannelSelect = ComponentType.ChannelSelect
10
- channelTypes?: APIChannelSelectComponent["channel_types"]
11
- defaultValues?: APIChannelSelectComponent["default_values"]
12
- abstract run(interaction: ChannelSelectMenuInteraction): Promise<void>
13
-
14
- serializeOptions() {
15
- return {
16
- type: this.type,
17
- default_values: this.defaultValues,
18
- channel_types: this.channelTypes
19
- }
20
- }
21
- }
@@ -1,277 +0,0 @@
1
- import { RequestClient, type RequestClientOptions } from "@buape/carbon-request"
2
- import {
3
- type APIInteraction,
4
- InteractionResponseType,
5
- InteractionType,
6
- Routes
7
- } from "discord-api-types/v10"
8
- import { PlatformAlgorithm, isValidRequest } from "discord-verify"
9
- import { AutoRouter, type IRequestStrict, StatusError, json } from "itty-router"
10
- import type { BaseCommand } from "../abstracts/BaseCommand.js"
11
- import { CommandHandler } from "../internals/CommandHandler.js"
12
- import { ComponentHandler } from "../internals/ComponentHandler.js"
13
- import { ModalHandler } from "../internals/ModalHandler.js"
14
-
15
- /**
16
- * The mode that the client is running in.
17
- * Different platforms have different requirements for how processes are handled.
18
- */
19
- export enum ClientMode {
20
- NodeJS = "node",
21
- CloudflareWorkers = "cloudflare",
22
- Bun = "bun",
23
- Vercel = "vercel",
24
- Web = "web"
25
- }
26
-
27
- /**
28
- * The options used for initializing the client
29
- */
30
- export type ClientOptions = {
31
- /**
32
- * If you want to have the root route for the interaction handler redirect to a different URL, you can set this.
33
- */
34
- redirectUrl?: string
35
- /**
36
- * The client ID of the bot
37
- */
38
- clientId: string
39
- /**
40
- * The public key of the bot, used for interaction verification
41
- */
42
- publicKey: string
43
- /**
44
- * The token of the bot
45
- */
46
- token: string
47
- /**
48
- * The mode of the client, generally where you are hosting the bot. If you have a different mode for your local development, make sure to set it to the local one.
49
- * @example
50
- * ```ts
51
- * import { Client, ClientMode } from "@buape/carbon"
52
- *
53
- * const client = new Client({
54
- * clientId: "12345678901234567890",
55
- * publicKey: "c1a2f941ae8ce6d776f7704d0bb3d46b863e21fda491cdb2bdba6b8bc5fe7269",
56
- * token: "MTA4NjEwNTYxMDUxMDE1NTg1Nw.GNt-U8.OSHy-g-5FlfESnu3Z9MEEMJLHiRthXajiXNwiE",
57
- * mode: process.env.NODE_ENV === "development" ? ClientMode.NodeJS : ClientMode.CloudflareWorkers
58
- * })
59
- * ```
60
- */
61
- mode: ClientMode
62
- /**
63
- * The route to use for interactions on your server.
64
- * @default "/interaction"
65
- */
66
- interactionRoute?: string
67
- /**
68
- * The options used to initialize the request client, if you want to customize it.
69
- */
70
- requestOptions?: RequestClientOptions
71
- /**
72
- * The port to run the server on, if you are using {@link ClientMode.Bun} mode.
73
- */
74
- port?: number
75
- /**
76
- * Whether the commands should be deployed to Discord automatically.
77
- */
78
- autoDeploy?: boolean
79
- }
80
-
81
- /**
82
- * The main client used to interact with Discord
83
- */
84
- export class Client {
85
- /**
86
- * The options used to initialize the client
87
- */
88
- options: ClientOptions
89
- /**
90
- * The commands that the client has registered
91
- */
92
- commands: BaseCommand[]
93
- /**
94
- * The router used to handle requests
95
- */
96
- router: ReturnType<typeof AutoRouter<IRequestStrict>>
97
- /**
98
- * The rest client used to interact with the Discord API
99
- */
100
- rest: RequestClient
101
- /**
102
- * The handler for the component interactions sent from Discord
103
- * @internal
104
- */
105
- componentHandler: ComponentHandler
106
- /**
107
- * The handler for the modal interactions sent from Discord
108
- * @internal
109
- */
110
- commandHandler: CommandHandler
111
- /**
112
- * The handler for the modal interactions sent from Discord
113
- * @internal
114
- */
115
- modalHandler: ModalHandler
116
-
117
- /**
118
- * Creates a new client
119
- * @param options The options used to initialize the client
120
- * @param commands The commands that the client has registered
121
- */
122
- constructor(options: ClientOptions, commands: BaseCommand[]) {
123
- if (!options.clientId) throw new Error("Missing client ID")
124
- if (!options.publicKey) throw new Error("Missing public key")
125
- if (!options.token) throw new Error("Missing token")
126
- this.options = options
127
- this.commands = commands
128
- const routerData =
129
- this.options.mode === ClientMode.Bun && this.options.port
130
- ? { port: this.options.port }
131
- : {}
132
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
133
- this.router = AutoRouter<IRequestStrict, any[], Response>(routerData)
134
- this.rest = new RequestClient(options.token, options.requestOptions)
135
- this.componentHandler = new ComponentHandler(this)
136
- this.commandHandler = new CommandHandler(this)
137
- this.modalHandler = new ModalHandler(this)
138
- this.setupRoutes()
139
- if (this.options.autoDeploy) this.deployCommands()
140
- }
141
-
142
- /**
143
- * Deploy the commands registered to Discord.
144
- * This is automatically called when running in NodeJS mode.
145
- */
146
- async deployCommands() {
147
- try {
148
- const commands = this.commands.map((command) => {
149
- return command.serialize()
150
- })
151
- await this.rest.put(Routes.applicationCommands(this.options.clientId), {
152
- body: commands
153
- })
154
- console.log(`Deployed ${commands.length} commands to Discord`)
155
- } catch (err) {
156
- console.error("Failed to deploy commands")
157
- console.error(err)
158
- }
159
- }
160
-
161
- /**
162
- * Setup the routes for the client
163
- */
164
- private setupRoutes() {
165
- this.router.get("/", () => {
166
- if (this.options.redirectUrl)
167
- return Response.redirect(this.options.redirectUrl, 302)
168
- throw new StatusError(404)
169
- })
170
- this.router.post(
171
- this.options.interactionRoute || "/interaction",
172
- async (req, ctx?: ExecutionContext) => {
173
- return await this.handle(req, ctx)
174
- }
175
- )
176
- }
177
-
178
- /**
179
- * If you want use a custom handler for HTTP requests instead of Carbon's router, you can use this method.
180
- * @param req The request to handle
181
- * @param ctx Cloudflare Workers only. The execution context of the request, provided in the fetch handler from CF.
182
- * @returns A response to send back to the client.
183
- */
184
- public async handle(req: Request, ctx?: ExecutionContext) {
185
- const isValid = await this.validateInteraction(req)
186
- if (!isValid) {
187
- return new Response("Invalid request signature", { status: 401 })
188
- }
189
-
190
- const rawInteraction = (await req.json()) as unknown as APIInteraction
191
- if (rawInteraction.type === InteractionType.Ping) {
192
- return json({
193
- type: InteractionResponseType.Pong
194
- })
195
- }
196
-
197
- if (rawInteraction.type === InteractionType.ApplicationCommand) {
198
- if (ctx?.waitUntil) {
199
- ctx.waitUntil(
200
- (async () => {
201
- await this.commandHandler.handleCommandInteraction(rawInteraction)
202
- })()
203
- )
204
- } else {
205
- await this.commandHandler.handleCommandInteraction(rawInteraction)
206
- }
207
- }
208
- if (
209
- rawInteraction.type === InteractionType.ApplicationCommandAutocomplete
210
- ) {
211
- if (ctx?.waitUntil) {
212
- ctx.waitUntil(
213
- (async () => {
214
- await this.commandHandler.handleAutocompleteInteraction(
215
- rawInteraction
216
- )
217
- })()
218
- )
219
- } else {
220
- await this.commandHandler.handleAutocompleteInteraction(rawInteraction)
221
- }
222
- }
223
- if (rawInteraction.type === InteractionType.MessageComponent) {
224
- if (ctx?.waitUntil) {
225
- ctx.waitUntil(
226
- (async () => {
227
- await this.componentHandler.handleInteraction(rawInteraction)
228
- })()
229
- )
230
- } else {
231
- await this.componentHandler.handleInteraction(rawInteraction)
232
- }
233
- }
234
- if (rawInteraction.type === InteractionType.ModalSubmit) {
235
- if (ctx?.waitUntil) {
236
- ctx.waitUntil(
237
- (async () => {
238
- await this.modalHandler.handleInteraction(rawInteraction)
239
- })()
240
- )
241
- } else {
242
- await this.modalHandler.handleInteraction(rawInteraction)
243
- }
244
- }
245
- return new Response(null, { status: 202 })
246
- }
247
-
248
- /**
249
- * Validate the interaction request
250
- * @param req The request to validate
251
- */
252
- private async validateInteraction(req: Request) {
253
- if (req.method !== "POST") {
254
- throw new StatusError(405)
255
- }
256
- const isValid = await isValidRequest(
257
- req,
258
- this.options.publicKey,
259
- this.options.mode === ClientMode.CloudflareWorkers
260
- ? PlatformAlgorithm.Cloudflare
261
- : this.options.mode === ClientMode.Vercel
262
- ? PlatformAlgorithm.VercelProd
263
- : this.options.mode === ClientMode.Web
264
- ? PlatformAlgorithm.Web
265
- : PlatformAlgorithm.NewNode
266
- )
267
- return isValid
268
- }
269
- }
270
-
271
- /**
272
- * @hidden
273
- */
274
- export interface ExecutionContext {
275
- // biome-ignore lint/suspicious/noExplicitAny: true any
276
- waitUntil(promise: Promise<any>): void
277
- }
@@ -1,53 +0,0 @@
1
- import {
2
- type APIApplicationCommandBasicOption,
3
- ApplicationCommandType
4
- } from "discord-api-types/v10"
5
- import {
6
- type AutocompleteInteraction,
7
- BaseCommand,
8
- type CommandInteraction
9
- } from "../index.js"
10
-
11
- export type CommandOptions = APIApplicationCommandBasicOption[]
12
-
13
- /**
14
- * Represents a standard command that the user creates
15
- */
16
- export abstract class Command extends BaseCommand {
17
- /**
18
- * The options that the user passes along with the command in Discord
19
- */
20
- options?: CommandOptions
21
-
22
- /**
23
- * The type of command, either ChatInput, User, or Message. User and Message are context menu commands.
24
- * @default ChatInput
25
- */
26
- type: ApplicationCommandType = ApplicationCommandType.ChatInput
27
-
28
- /**
29
- * The function that is called when the command is ran
30
- * @param interaction The interaction that triggered the command
31
- */
32
- abstract run(interaction: CommandInteraction): Promise<void>
33
-
34
- /**
35
- * The function that is called when the command's autocomplete is triggered.
36
- * @param interaction The interaction that triggered the autocomplete
37
- * @remarks You are expected to `override` this function to provide your own autocomplete functionality.
38
- */
39
- public async autocomplete(
40
- interaction: AutocompleteInteraction
41
- ): Promise<void> {
42
- throw new Error(
43
- `The ${interaction.rawData.data.name} command does not support autocomplete`
44
- )
45
- }
46
-
47
- /**
48
- * @internal
49
- */
50
- serializeOptions() {
51
- return this.options
52
- }
53
- }
@@ -1,47 +0,0 @@
1
- import {
2
- type APIApplicationCommandBasicOption,
3
- type APIApplicationCommandSubcommandGroupOption,
4
- type APIApplicationCommandSubcommandOption,
5
- ApplicationCommandOptionType
6
- } from "discord-api-types/v10"
7
- import type { Command } from "./Command.js"
8
- import { CommandWithSubcommands } from "./CommandWithSubcommands.js"
9
-
10
- /**
11
- * Represents a subcommand group command that the user creates.
12
- * You make this instead of a {@link Command} class when you want to have subcommand groups in your options.
13
- */
14
- export abstract class CommandWithSubcommandGroups extends CommandWithSubcommands {
15
- /**
16
- * The subcommands that the user can use
17
- */
18
- subcommands: Command[] = []
19
-
20
- /**
21
- * The subcommands that the user can use
22
- */
23
- abstract subcommandGroups: CommandWithSubcommands[]
24
-
25
- /**
26
- * @internal
27
- */
28
- serializeOptions() {
29
- const subcommands = this.subcommands.map((subcommand) => ({
30
- name: subcommand.name,
31
- description: subcommand.description,
32
- type: ApplicationCommandOptionType.Subcommand,
33
- options:
34
- subcommand.serializeOptions() as APIApplicationCommandBasicOption[]
35
- })) as APIApplicationCommandSubcommandOption[]
36
-
37
- const subcommandGroups = this.subcommandGroups.map((subcommandGroup) => ({
38
- name: subcommandGroup.name,
39
- description: subcommandGroup.description,
40
- type: ApplicationCommandOptionType.SubcommandGroup,
41
- options:
42
- subcommandGroup.serializeOptions() as APIApplicationCommandSubcommandOption[]
43
- })) as APIApplicationCommandSubcommandGroupOption[]
44
-
45
- return [...subcommands, ...subcommandGroups]
46
- }
47
- }
@@ -1,35 +0,0 @@
1
- import {
2
- type APIApplicationCommandBasicOption,
3
- type APIApplicationCommandSubcommandOption,
4
- ApplicationCommandOptionType,
5
- ApplicationCommandType,
6
- type RESTPostAPIApplicationCommandsJSONBody
7
- } from "discord-api-types/v10"
8
- import { BaseCommand } from "../abstracts/BaseCommand.js"
9
- import type { Command } from "./Command.js"
10
-
11
- /**
12
- * Represents a subcommand command that the user creates.
13
- * You make this instead of a {@link Command} class when you want to have subcommands in your options.
14
- */
15
- export abstract class CommandWithSubcommands extends BaseCommand {
16
- type = ApplicationCommandType.ChatInput
17
-
18
- /**
19
- * The subcommands that the user can use
20
- */
21
- abstract subcommands: Command[]
22
-
23
- /**
24
- * @internal
25
- */
26
- serializeOptions(): RESTPostAPIApplicationCommandsJSONBody["options"] {
27
- return this.subcommands.map((subcommand) => ({
28
- name: subcommand.name,
29
- description: subcommand.description,
30
- type: ApplicationCommandOptionType.Subcommand,
31
- options:
32
- subcommand.serializeOptions() as APIApplicationCommandBasicOption[]
33
- })) as APIApplicationCommandSubcommandOption[]
34
- }
35
- }
@@ -1,19 +0,0 @@
1
- import {
2
- type APIMentionableSelectComponent,
3
- ComponentType
4
- } from "discord-api-types/v10"
5
- import { AnySelectMenu } from "../abstracts/AnySelectMenu.js"
6
- import type { MentionableSelectMenuInteraction } from "../internals/MentionableSelectMenuInteraction.js"
7
-
8
- export abstract class MentionableSelectMenu extends AnySelectMenu {
9
- type: ComponentType.MentionableSelect = ComponentType.MentionableSelect
10
- defaultValues?: APIMentionableSelectComponent["default_values"]
11
- abstract run(interaction: MentionableSelectMenuInteraction): Promise<void>
12
-
13
- serializeOptions() {
14
- return {
15
- type: this.type,
16
- default_values: this.defaultValues
17
- }
18
- }
19
- }
@@ -1,38 +0,0 @@
1
- import type {
2
- APIActionRowComponent,
3
- APIModalInteractionResponseCallbackData,
4
- APITextInputComponent
5
- } from "discord-api-types/v10"
6
- import type { ModalInteraction } from "../internals/ModalInteraction.js"
7
- import type { Row } from "./Row.js"
8
- import type { TextInput } from "./TextInput.js"
9
-
10
- export abstract class Modal {
11
- /**
12
- * The title of the modal
13
- */
14
- abstract title: string
15
-
16
- /**
17
- * The components of the modal
18
- */
19
- components: Row<TextInput>[] = []
20
-
21
- /**
22
- * The custom ID of the modal
23
- */
24
- abstract customId: string
25
-
26
- abstract run(interaction: ModalInteraction): Promise<void>
27
-
28
- serialize = (): APIModalInteractionResponseCallbackData => {
29
- return {
30
- title: this.title,
31
- custom_id: this.customId,
32
- components: this.components.map(
33
- (row) =>
34
- row.serialize() as unknown as APIActionRowComponent<APITextInputComponent>
35
- )
36
- }
37
- }
38
- }
@@ -1,19 +0,0 @@
1
- import {
2
- type APIRoleSelectComponent,
3
- ComponentType
4
- } from "discord-api-types/v10"
5
- import { AnySelectMenu } from "../abstracts/AnySelectMenu.js"
6
- import type { RoleSelectMenuInteraction } from "../internals/RoleSelectMenuInteraction.js"
7
-
8
- export abstract class RoleSelectMenu extends AnySelectMenu {
9
- type: ComponentType.RoleSelect = ComponentType.RoleSelect
10
- defaultValues?: APIRoleSelectComponent["default_values"]
11
- abstract run(interaction: RoleSelectMenuInteraction): Promise<void>
12
-
13
- serializeOptions() {
14
- return {
15
- type: this.type,
16
- default_values: this.defaultValues
17
- }
18
- }
19
- }
@@ -1,50 +0,0 @@
1
- import type {
2
- APIActionRowComponent,
3
- APIActionRowComponentTypes
4
- } from "discord-api-types/v10"
5
- import type { BaseComponent } from "../abstracts/BaseComponent.js"
6
-
7
- export class Row<T extends BaseComponent = BaseComponent> {
8
- /**
9
- * The components in the action row
10
- */
11
- components: T[] = []
12
-
13
- constructor(components?: T[]) {
14
- if (components) this.components = components
15
- }
16
-
17
- /**
18
- * Add a component to the action row
19
- * @param component The component to add
20
- */
21
- addComponent(component: T) {
22
- this.components.push(component)
23
- }
24
-
25
- /**
26
- * Remove a component from the action row
27
- * @param component The component to remove
28
- */
29
- removeComponent(component: T) {
30
- const index = this.components.indexOf(component)
31
- if (index === -1) return
32
- this.components.splice(index, 1)
33
- }
34
-
35
- /**
36
- * Remove all components from the action row
37
- */
38
- removeAllComponents() {
39
- this.components = []
40
- }
41
-
42
- serialize = (): APIActionRowComponent<APIActionRowComponentTypes> => {
43
- return {
44
- type: 1,
45
- components: this.components.map((component) =>
46
- component.serialize()
47
- ) as APIActionRowComponentTypes[]
48
- }
49
- }
50
- }
@@ -1,19 +0,0 @@
1
- import {
2
- type APIStringSelectComponent,
3
- ComponentType
4
- } from "discord-api-types/v10"
5
- import { AnySelectMenu } from "../abstracts/AnySelectMenu.js"
6
- import type { StringSelectMenuInteraction } from "../internals/StringSelectMenuInteraction.js"
7
-
8
- export abstract class StringSelectMenu extends AnySelectMenu {
9
- type: ComponentType.StringSelect = ComponentType.StringSelect
10
- abstract options: APIStringSelectComponent["options"]
11
- abstract run(interaction: StringSelectMenuInteraction): Promise<void>
12
-
13
- serializeOptions() {
14
- return {
15
- type: this.type,
16
- options: this.options
17
- }
18
- }
19
- }