-
-
Notifications
You must be signed in to change notification settings - Fork 10
feat(structs): Modal #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tristancamejo
merged 51 commits into
Disploy:feat/message-components
from
TenDRILLL:main
Nov 15, 2022
Merged
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
3220d4d
feat(structs): Interaction#showModal
TenDRILLL f1ac427
feat(structs): ActionRow
TenDRILLL 4c15766
feat(structs): ActionRowComponent
TenDRILLL a7642e0
feat(structs): Modal
TenDRILLL 625242d
feat(structs): ModalActionRowComponent
TenDRILLL 0b6ba73
Merge branch 'Disploy:main' into main
TenDRILLL 839a0b6
feat(structs): ModalSubmitInteraction
TenDRILLL 57669b5
Merge remote-tracking branch 'origin/main'
TenDRILLL ff7f086
refactor(structs): Array<T> -> T[]
TenDRILLL 10ea2ba
refactor(structs): Modal pseudo-optional properties
TenDRILLL 8ec53c9
Merge remote-tracking branch 'origin/main'
TenDRILLL 82cb0fa
fix(structs): make ActionRow#type public
TenDRILLL 7acef49
feat(structs): ModalSubmitComponent
TenDRILLL db9c170
feat(structs): TextInputComponent
TenDRILLL 42af16c
refactor(structs): ActionRow return itself on methods
TenDRILLL 3b7fbbb
refactor(structs): ActionRowComponent return itself on methods
TenDRILLL 432920c
refactor(structs): Modal return itself on methods
TenDRILLL e38dfd1
refactor(structs): move TextInputComponent methods and properties out
TenDRILLL f6de0c9
fix(structs): ModalSubmitInteraction components use constructors
TenDRILLL a4735dc
feat(structs): Modal#toJSON
TenDRILLL 1ab04b6
fix(structs): CommandInteraction#showModal uses modal
TenDRILLL eff7008
style(structs): Modal Array<T> -> T[]
TenDRILLL 34327c7
style(structs): Modal Array<T> -> T[]
TenDRILLL 85a2baf
refactor(structs): remove redundant app extending
TenDRILLL 76f7339
Merge remote-tracking branch 'origin/main'
TenDRILLL 15932d8
refactor(structs): TextInputComponent remove redundant app extending
TenDRILLL 05ed571
fix(structs): CommandInteraction import Modal
TenDRILLL fa85fe7
chore(structs): index exports new classes
TenDRILLL 6b7c5be
feat(structs): ActionRow takes an array of components
TenDRILLL 63043b3
feat(structs): Modal can be built on constructor.
TenDRILLL a3ff7c9
feat(structs): ModalActionRowComponent can be built on constructor.
TenDRILLL f03340d
fix(structs): make ActionRow constructor argument optional
TenDRILLL 64fb416
feat(structs): TextInputComponent can be built on constructor
TenDRILLL 55983e0
chore(structs): Define functions and constructors public
TenDRILLL cba70fc
feat(structs): ActionRow#get
TenDRILLL 695d969
feat(structs): ModalSubmitComponent#getValue()
TenDRILLL 9d7b03a
feat(example): Modal command
TenDRILLL 0de1b86
feat(commands): implement modalSubmit
TenDRILLL 25c5087
chore(*): run yarn format
TenDRILLL 4621b26
feat(structs): CommandInteraction#showModal takes a union as a parameter
TenDRILLL d62c5a7
Merge branch 'Disploy:main' into main
TenDRILLL 3f4e684
refactor(structs): make Command#modalSubmit optional
TenDRILLL 916fbaf
chore(*): undo yarn format on README
TenDRILLL bd22c3a
Merge remote-tracking branch 'origin/main'
TenDRILLL dbb196c
fix(example): fix type-errors on modal
TenDRILLL ef5d2dc
feat(structs): ModalSubmitInteraction#reply
TenDRILLL fd715b6
fix(example): type-errors on modal
TenDRILLL 885b183
fix(example): type-errors on modal
TenDRILLL 08749da
fix(example): type-errors on modal
TenDRILLL 60e6dca
fix(example): type-errors on modal
TenDRILLL 86d2036
fix(example): type-errors on modal
TenDRILLL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { Command, Modal, ActionRow, ModalSubmitInteraction, TextInputComponent, ModalSubmitComponent } from 'disploy'; | ||
| import { TextInputStyle } from 'discord-api-types/v10'; | ||
|
|
||
| export default { | ||
| name: 'modal', | ||
| description: 'show a cool modal', | ||
|
|
||
| async run(interaction) { | ||
| const modal = new Modal() | ||
| .setCustomId("cool-modal") | ||
| .setComponents([ | ||
| new ActionRow() | ||
| .setComponents([ | ||
| new TextInputComponent() | ||
| .setCustomId("favNum") | ||
| .setLabel("What is your favorite number?") | ||
| .setStyle(TextInputStyle.Short) | ||
| .setMinLength(1) | ||
| .setRequired(true) | ||
| .setPlaceholder("10") | ||
| ]) | ||
| ]); | ||
| interaction.showModal(modal); | ||
| }, | ||
|
|
||
| async modalSubmit(interaction: ModalSubmitInteraction) { | ||
| const favNumComp: ModalSubmitComponent = interaction.components[0]?.get("favNum") as ModalSubmitComponent; | ||
| const favNum: string = favNumComp?.getValue(); | ||
| interaction.reply({ | ||
| content: `Nice favorite number: ${favNum ?? "10"}.` | ||
| }); | ||
| } | ||
| } satisfies Command; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { ComponentType } from 'discord-api-types/v10'; | ||
| import type { ActionRowComponent } from './ActionRowComponent'; | ||
|
|
||
| export class ActionRow { | ||
| public type: ComponentType; | ||
| public components: ActionRowComponent[]; | ||
|
|
||
| public addComponents(components: ActionRowComponent[]) { | ||
| this.components.push(...components); | ||
| return this; | ||
| } | ||
|
|
||
| public setComponents(components: ActionRowComponent[]) { | ||
| this.components = components; | ||
| return this; | ||
| } | ||
|
|
||
| public get(customId: string) { | ||
| return this.components.filter((component) => component.customId === customId)[0]; | ||
| } | ||
|
|
||
| public constructor(components?: ActionRowComponent[]) { | ||
| this.type = ComponentType.ActionRow; | ||
| this.components = components ?? []; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import type { ComponentType } from 'discord-api-types/v10'; | ||
|
|
||
| export class ActionRowComponent { | ||
| public customId?: string; | ||
| public type?: ComponentType; | ||
|
|
||
| public setCustomId(id: string) { | ||
| this.customId = id; | ||
| return this; | ||
| } | ||
|
|
||
| public constructor() {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import type { ActionRow } from './ActionRow'; | ||
|
|
||
| export class Modal { | ||
| public customId?: string; | ||
| public title?: string; | ||
| public components: ActionRow[] = []; | ||
|
|
||
| public setCustomId(id: string) { | ||
| this.customId = id; | ||
| return this; | ||
| } | ||
|
|
||
| public setTitle(title: string) { | ||
| this.title = title; | ||
| return this; | ||
| } | ||
|
|
||
| public setComponents(components: ActionRow[]) { | ||
| this.components = components; | ||
| return this; | ||
| } | ||
|
|
||
| public addComponents(components: ActionRow[]) { | ||
| this.components.push(...components); | ||
| return this; | ||
| } | ||
|
|
||
| public toJSON() { | ||
| return JSON.stringify(this); | ||
| } | ||
|
|
||
| public constructor(raw?: RawModalBuilder) { | ||
| this.title = raw?.title ?? undefined; | ||
| this.customId = raw?.customId ?? undefined; | ||
| this.components = raw?.components ?? []; | ||
| } | ||
| } | ||
|
|
||
| class RawModalBuilder { | ||
| title?: string; | ||
| customId?: string; | ||
| components?: ActionRow[]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { ActionRowComponent } from './ActionRowComponent'; | ||
|
|
||
| export class ModalActionRowComponent extends ActionRowComponent { | ||
TenDRILLL marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public required?: boolean; | ||
| public value?: string; | ||
| public placeholder?: string; | ||
|
|
||
| public setRequired(required: boolean) { | ||
| this.required = required; | ||
| return this; | ||
| } | ||
|
|
||
| public setValue(value: string) { | ||
| this.value = value; | ||
| return this; | ||
| } | ||
|
|
||
| public setPlaceholder(placeholder: string) { | ||
| this.placeholder = placeholder; | ||
| return this; | ||
| } | ||
|
|
||
| public constructor(raw?: RawModalActionComponent) { | ||
| super(); | ||
| this.required = raw?.required ?? undefined; | ||
| this.value = raw?.value ?? undefined; | ||
| this.placeholder = raw?.placeholder ?? undefined; | ||
| } | ||
| } | ||
|
|
||
| class RawModalActionComponent { | ||
| required?: boolean; | ||
| value?: string; | ||
| placeholder?: string; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { ActionRowComponent } from './ActionRowComponent'; | ||
| import type { ModalSubmitComponent as APIModalSubmitComponent } from 'discord-api-types/v10'; | ||
|
|
||
| export class ModalSubmitComponent extends ActionRowComponent { | ||
| public value: string; | ||
|
|
||
| public getValue() { | ||
| return this.value; | ||
| } | ||
|
|
||
| public constructor(raw: APIModalSubmitComponent) { | ||
| super(); | ||
| this.type = raw.type; | ||
| this.customId = raw.custom_id; | ||
| this.value = raw.value; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { BaseInteraction } from './BaseInteraction'; | ||
| import type { APIModalSubmitInteraction } from 'discord-api-types/v10'; | ||
| import type { App } from '../client'; | ||
| import { ActionRow } from './ActionRow'; | ||
| import { ModalSubmitComponent } from './ModalSubmitComponent'; | ||
| import { APIInteractionResponseCallbackData, InteractionResponseType } from 'discord-api-types/v10'; | ||
| import { RouterEvents } from '../router'; | ||
|
|
||
| export class ModalSubmitInteraction extends BaseInteraction { | ||
| public customId: string; | ||
| public components: ActionRow[]; | ||
|
|
||
| public reply(payload: APIInteractionResponseCallbackData) { | ||
| return void this.app.router.emit(RouterEvents.Respond(this.id), { | ||
| type: InteractionResponseType.ChannelMessageWithSource, | ||
| data: payload, | ||
| }); | ||
| } | ||
|
|
||
| public constructor(app: App, raw: APIModalSubmitInteraction) { | ||
| super(app, raw); | ||
| this.customId = raw.data.custom_id; | ||
| this.components = raw.data.components.map((rawActionRow) => { | ||
| return new ActionRow().setComponents( | ||
| rawActionRow.components.map((rawModalSubmitComponent) => { | ||
| return new ModalSubmitComponent(rawModalSubmitComponent); | ||
| }), | ||
| ); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { ModalActionRowComponent } from './ModalActionRowComponent'; | ||
| import { ComponentType, TextInputStyle } from 'discord-api-types/v10'; | ||
|
|
||
| export class TextInputComponent extends ModalActionRowComponent { | ||
| public style?: TextInputStyle; | ||
| public label?: string; | ||
| public minLength?: number; | ||
| public maxLength?: number; | ||
|
|
||
| public setStyle(style: TextInputStyle) { | ||
| this.style = style; | ||
| return this; | ||
| } | ||
|
|
||
| public setLabel(label: string) { | ||
| this.label = label; | ||
| return this; | ||
| } | ||
|
|
||
| public setMinLength(length: number) { | ||
| this.minLength = length; | ||
| return this; | ||
| } | ||
|
|
||
| public setMaxLength(length: number) { | ||
| this.maxLength = length; | ||
| return this; | ||
| } | ||
|
|
||
| public constructor(raw?: RawTextInputComponent) { | ||
| super(); | ||
| this.type = ComponentType.TextInput; | ||
| this.style = raw?.style ?? undefined; | ||
| this.label = raw?.label ?? undefined; | ||
| this.minLength = raw?.minLength ?? undefined; | ||
| this.maxLength = raw?.maxLength ?? undefined; | ||
| } | ||
| } | ||
|
|
||
| class RawTextInputComponent { | ||
| public style?: TextInputStyle; | ||
| public label?: string; | ||
| public minLength?: number; | ||
| public maxLength?: number; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,14 @@ | ||
| export * from './ActionRow'; | ||
| export * from './ActionRowComponent'; | ||
| export * from './BaseInteraction'; | ||
| export * from './ChatInputInteraction'; | ||
| export * from './ChatInputInteractionOptions'; | ||
| export * from './Guild'; | ||
| export * from './GuildMember'; | ||
| export * from './managers'; | ||
| export * from './Modal'; | ||
| export * from './ModalActionRowComponent'; | ||
| export * from './ModalSubmitComponent'; | ||
| export * from './ModalSubmitInteraction'; | ||
| export * from './TextInputComponent'; | ||
| export * from './User'; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.