Skip to content

Commit b438645

Browse files
committed
fix: select menu interaction type according to select menu type
1 parent abf4b5b commit b438645

File tree

5 files changed

+49
-252
lines changed

5 files changed

+49
-252
lines changed

playground/harmonix.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { defineHarmonixConfig } from '../src'
22

33
export default defineHarmonixConfig({
4-
ownerIds: ['556083802628161546']
4+
ownerIds: ['556083802628161546'],
5+
client: {
6+
intents: []
7+
}
58
})

playground/modals/form.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@ import { defineModal } from '../../src'
33
export default defineModal(
44
{
55
title: 'Form',
6-
textInputs: [
7-
{
8-
id: 'color',
6+
inputs: {
7+
color: {
98
label: 'Favorite color',
10-
placeholder: 'Enter your favorite color',
11-
style: 'Short'
9+
style: 'Short',
10+
placeholder: 'Enter your favorite color'
1211
},
13-
{
14-
id: 'hobbies',
12+
hobbies: {
1513
label: 'Hobbies',
16-
placeholder: 'Enter your hobbies',
17-
style: 'Paragraph'
14+
style: 'Paragraph',
15+
placeholder: 'Enter your hobbies'
1816
}
19-
]
17+
}
2018
},
21-
(interaction) => {
22-
const color = interaction.fields.getTextInputValue('color')
19+
(interaction, context) => {
20+
const { color } = context.inputs
2321

2422
interaction.reply(`Submitted color: ${color}`)
2523
}

src/define.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,22 @@ import type {
1111
DefineEventWithOptions,
1212
DefinePrecondition,
1313
DefinePreconditionWithName,
14-
DefineSelectMenu,
1514
EventCallback,
1615
EventOptions,
1716
HarmonixCommand,
1817
HarmonixConfig,
1918
HarmonixContextMenu,
2019
HarmonixEvent,
2120
HarmonixModal,
21+
HarmonixSelectMenu,
2222
ModalCallback,
2323
ModalConfig,
2424
ModalInputs,
2525
OptionsDef,
26-
PreconditionCallback
26+
PreconditionCallback,
27+
SelectMenuCallback,
28+
SelectMenuConfig,
29+
SelectMenuType
2730
} from './types'
2831

2932
export const defineHarmonixConfig = (config: HarmonixConfig) => {
@@ -106,7 +109,10 @@ export const defineModal = <T extends ModalInputs = ModalInputs>(
106109
return { config, callback }
107110
}
108111

109-
export const defineSelectMenu: DefineSelectMenu = (config, callback) => {
112+
export const defineSelectMenu = <T extends SelectMenuType = SelectMenuType>(
113+
config: SelectMenuConfig & { type?: T },
114+
callback: SelectMenuCallback<T>
115+
): HarmonixSelectMenu<T> => {
110116
return { config, callback }
111117
}
112118

src/gets.ts

Lines changed: 0 additions & 226 deletions
This file was deleted.

src/types/select-menus.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
11
import type {
22
APISelectMenuDefaultValue,
3-
AnySelectMenuInteraction,
3+
ChannelSelectMenuInteraction,
44
ChannelType,
55
ComponentEmojiResolvable,
6-
SelectMenuDefaultValueType
6+
MentionableSelectMenuInteraction,
7+
RoleSelectMenuInteraction,
8+
SelectMenuDefaultValueType,
9+
StringSelectMenuInteraction,
10+
UserSelectMenuInteraction
711
} from 'discord.js'
812

9-
type SelectMenuCallback = (interaction: AnySelectMenuInteraction) => void
13+
export type SelectMenuType =
14+
| 'String'
15+
| 'User'
16+
| 'Channel'
17+
| 'Role'
18+
| 'Mentionable'
19+
20+
export type SelectMenuCallback<T extends SelectMenuType = SelectMenuType> = (
21+
interaction: T extends 'String'
22+
? StringSelectMenuInteraction
23+
: T extends 'User'
24+
? UserSelectMenuInteraction
25+
: T extends 'Channel'
26+
? ChannelSelectMenuInteraction
27+
: T extends 'Role'
28+
? RoleSelectMenuInteraction
29+
: MentionableSelectMenuInteraction
30+
) => void
1031

1132
export interface StringSelectMenuConfig {
1233
type: 'String'
@@ -59,14 +80,9 @@ export type SelectMenuConfig = BaseSelectMenuConfig &
5980
| MentionableSelectMenuConfig
6081
)
6182

62-
export type DefineSelectMenu = (
63-
config: SelectMenuConfig,
64-
callback: SelectMenuCallback
65-
) => HarmonixSelectMenu
66-
6783
export type HarmonixSelectMenuInput = string | HarmonixSelectMenu
6884

69-
export interface HarmonixSelectMenu {
85+
export interface HarmonixSelectMenu<T extends SelectMenuType = SelectMenuType> {
7086
config: SelectMenuConfig
71-
callback: SelectMenuCallback
87+
callback: SelectMenuCallback<T>
7288
}

0 commit comments

Comments
 (0)