@buape/carbon 0.1.3 → 0.2.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 (65) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-dev.log +3 -170
  3. package/CHANGELOG.md +10 -0
  4. package/dist/package.json +1 -1
  5. package/dist/src/abstracts/BaseCommand.d.ts +1 -6
  6. package/dist/src/abstracts/BaseCommand.d.ts.map +1 -1
  7. package/dist/src/abstracts/BaseCommand.js +0 -5
  8. package/dist/src/abstracts/BaseCommand.js.map +1 -1
  9. package/dist/src/abstracts/BaseInteraction.d.ts +10 -7
  10. package/dist/src/abstracts/BaseInteraction.d.ts.map +1 -1
  11. package/dist/src/abstracts/BaseInteraction.js +25 -8
  12. package/dist/src/abstracts/BaseInteraction.js.map +1 -1
  13. package/dist/src/classes/Client.d.ts +11 -0
  14. package/dist/src/classes/Client.d.ts.map +1 -1
  15. package/dist/src/classes/Client.js +22 -0
  16. package/dist/src/classes/Client.js.map +1 -1
  17. package/dist/src/classes/Modal.d.ts +21 -0
  18. package/dist/src/classes/Modal.d.ts.map +1 -0
  19. package/dist/src/classes/Modal.js +14 -0
  20. package/dist/src/classes/Modal.js.map +1 -0
  21. package/dist/src/classes/Row.d.ts +7 -9
  22. package/dist/src/classes/Row.d.ts.map +1 -1
  23. package/dist/src/classes/Row.js +5 -4
  24. package/dist/src/classes/Row.js.map +1 -1
  25. package/dist/src/classes/TextInput.d.ts +40 -0
  26. package/dist/src/classes/TextInput.d.ts.map +1 -0
  27. package/dist/src/classes/TextInput.js +44 -0
  28. package/dist/src/classes/TextInput.js.map +1 -0
  29. package/dist/src/index.d.ts +3 -0
  30. package/dist/src/index.d.ts.map +1 -1
  31. package/dist/src/index.js +3 -0
  32. package/dist/src/index.js.map +1 -1
  33. package/dist/src/internals/CommandHandler.d.ts +4 -0
  34. package/dist/src/internals/CommandHandler.d.ts.map +1 -1
  35. package/dist/src/internals/CommandHandler.js +4 -0
  36. package/dist/src/internals/CommandHandler.js.map +1 -1
  37. package/dist/src/internals/ComponentHandler copy.d.ts +17 -0
  38. package/dist/src/internals/ComponentHandler copy.d.ts.map +1 -0
  39. package/dist/src/internals/ComponentHandler copy.js +75 -0
  40. package/dist/src/internals/ComponentHandler copy.js.map +1 -0
  41. package/dist/src/internals/ComponentHandler.d.ts +11 -0
  42. package/dist/src/internals/ComponentHandler.d.ts.map +1 -1
  43. package/dist/src/internals/ComponentHandler.js +15 -4
  44. package/dist/src/internals/ComponentHandler.js.map +1 -1
  45. package/dist/src/internals/ModalHandler.d.ts +17 -0
  46. package/dist/src/internals/ModalHandler.d.ts.map +1 -0
  47. package/dist/src/internals/ModalHandler.js +25 -0
  48. package/dist/src/internals/ModalHandler.js.map +1 -0
  49. package/dist/src/internals/ModalInteraction.d.ts +11 -0
  50. package/dist/src/internals/ModalInteraction.d.ts.map +1 -0
  51. package/dist/src/internals/ModalInteraction.js +19 -0
  52. package/dist/src/internals/ModalInteraction.js.map +1 -0
  53. package/dist/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +1 -1
  55. package/src/abstracts/BaseCommand.ts +1 -11
  56. package/src/abstracts/BaseInteraction.ts +42 -10
  57. package/src/classes/Client.ts +23 -0
  58. package/src/classes/Modal.ts +38 -0
  59. package/src/classes/Row.ts +14 -8
  60. package/src/classes/TextInput.ts +65 -0
  61. package/src/index.ts +3 -0
  62. package/src/internals/CommandHandler.ts +4 -0
  63. package/src/internals/ComponentHandler.ts +15 -4
  64. package/src/internals/ModalHandler.ts +27 -0
  65. package/src/internals/ModalInteraction.ts +25 -0
@@ -0,0 +1,65 @@
1
+ import {
2
+ type APITextInputComponent,
3
+ ComponentType,
4
+ TextInputStyle
5
+ } from "discord-api-types/v10"
6
+ import { BaseComponent } from "../abstracts/BaseComponent.js"
7
+
8
+ export abstract class TextInput extends BaseComponent {
9
+ type = ComponentType.TextInput
10
+
11
+ /**
12
+ * The custom ID of the text input
13
+ */
14
+ abstract customId: string
15
+
16
+ /**
17
+ * The label of the text input
18
+ */
19
+ abstract label: string
20
+
21
+ /**
22
+ * The style of the text input
23
+ * @default TextInputStyle.Short
24
+ */
25
+ style: TextInputStyle = TextInputStyle.Short
26
+
27
+ /**
28
+ * The minimum length of the text input
29
+ */
30
+ minLength?: number
31
+
32
+ /**
33
+ * The maximum length of the text input
34
+ */
35
+ maxLength?: number
36
+
37
+ /**
38
+ * Whether the text input is required
39
+ */
40
+ required?: boolean
41
+
42
+ /**
43
+ * The value of the text input
44
+ */
45
+ value?: string
46
+
47
+ /**
48
+ * The placeholder of the text input
49
+ */
50
+ placeholder?: string
51
+
52
+ serialize = (): APITextInputComponent => {
53
+ return {
54
+ type: ComponentType.TextInput,
55
+ custom_id: this.customId,
56
+ style: this.style,
57
+ label: this.label,
58
+ min_length: this.minLength,
59
+ max_length: this.maxLength,
60
+ required: this.required,
61
+ value: this.value,
62
+ placeholder: this.placeholder
63
+ }
64
+ }
65
+ }
package/src/index.ts CHANGED
@@ -19,8 +19,10 @@ export * from "./classes/Command.js"
19
19
  export * from "./classes/CommandWithSubcommandGroups.js"
20
20
  export * from "./classes/CommandWithSubcommands.js"
21
21
  export * from "./classes/MentionableSelectMenu.js"
22
+ export * from "./classes/Modal.js"
22
23
  export * from "./classes/RoleSelectMenu.js"
23
24
  export * from "./classes/Row.js"
25
+ export * from "./classes/TextInput.js"
24
26
  export * from "./classes/StringSelectMenu.js"
25
27
  export * from "./classes/UserSelectMenu.js"
26
28
 
@@ -35,6 +37,7 @@ export * from "./internals/CommandHandler.js"
35
37
  export * from "./internals/CommandInteraction.js"
36
38
  export * from "./internals/ComponentHandler.js"
37
39
  export * from "./internals/MentionableSelectMenuInteraction.js"
40
+ export * from "./internals/ModalInteraction.js"
38
41
  export * from "./internals/OptionsHandler.js"
39
42
  export * from "./internals/RoleSelectMenuInteraction.js"
40
43
  export * from "./internals/StringSelectMenuInteraction.js"
@@ -76,6 +76,10 @@ export class CommandHandler extends Base {
76
76
 
77
77
  throw new Error("Command is not a valid command type")
78
78
  }
79
+ /**
80
+ * Handle a command interaction
81
+ * @internal
82
+ */
79
83
  async handleCommandInteraction(
80
84
  rawInteraction: APIApplicationCommandInteraction
81
85
  ) {
@@ -19,11 +19,22 @@ import { StringSelectMenuInteraction } from "./StringSelectMenuInteraction.js"
19
19
  import { UserSelectMenuInteraction } from "./UserSelectMenuInteraction.js"
20
20
 
21
21
  export class ComponentHandler extends Base {
22
+ components: BaseComponent[] = []
23
+ /**
24
+ * Register a component with the handler
25
+ * @internal
26
+ */
27
+ registerComponent(component: BaseComponent) {
28
+ if (!this.components.find((x) => x.customId === component.customId)) {
29
+ this.components.push(component)
30
+ }
31
+ }
32
+ /**
33
+ * Handle an interaction
34
+ * @internal
35
+ */
22
36
  async handleInteraction(data: APIMessageComponentInteraction) {
23
- const allComponents = this.client.commands
24
- .filter((x) => x.components && x.components.length > 0)
25
- .flatMap((x) => x.components) as BaseComponent[]
26
- const component = allComponents.find(
37
+ const component = this.components.find(
27
38
  (x) =>
28
39
  x.customId === data.data.custom_id &&
29
40
  x.type === data.data.component_type
@@ -0,0 +1,27 @@
1
+ import type { APIModalSubmitInteraction } from "discord-api-types/v10"
2
+ import { Base } from "../abstracts/Base.js"
3
+ import type { Modal } from "../classes/Modal.js"
4
+ import { ModalInteraction } from "./ModalInteraction.js"
5
+
6
+ export class ModalHandler extends Base {
7
+ modals: Modal[] = []
8
+ /**
9
+ * Register a modal with the handler
10
+ * @internal
11
+ */
12
+ registerModal(modal: Modal) {
13
+ if (!this.modals.find((x) => x.customId === modal.customId)) {
14
+ this.modals.push(modal)
15
+ }
16
+ }
17
+ /**
18
+ * Handle an interaction
19
+ * @internal
20
+ */
21
+ async handleInteraction(data: APIModalSubmitInteraction) {
22
+ const modal = this.modals.find((x) => x.customId === data.data.custom_id)
23
+ if (!modal) return false
24
+
25
+ modal.run(new ModalInteraction(this.client, data))
26
+ }
27
+ }
@@ -0,0 +1,25 @@
1
+ import {
2
+ type APIModalSubmitInteraction,
3
+ ComponentType
4
+ } from "discord-api-types/v10"
5
+ import { BaseInteraction } from "../abstracts/BaseInteraction.js"
6
+ import type { Client } from "../index.js"
7
+
8
+ export class ModalInteraction extends BaseInteraction<APIModalSubmitInteraction> {
9
+ customId: string
10
+ values: { [key: string]: string }
11
+
12
+ constructor(client: Client, data: APIModalSubmitInteraction) {
13
+ super(client, data)
14
+
15
+ this.customId = data.data.custom_id
16
+ this.values = {}
17
+ data.data.components.map((row) => {
18
+ row.components.map((component) => {
19
+ if (component.type === ComponentType.TextInput) {
20
+ this.values[component.custom_id] = component.value
21
+ }
22
+ })
23
+ })
24
+ }
25
+ }