Skip to content

Commit 7a624e8

Browse files
committed
fix: use regex for suffix
1 parent 44ad734 commit 7a624e8

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/resolve.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ export const resolveEvent = (
3737
})
3838
const _evtPath = _jiti.resolve(evt)
3939
const event = _jiti(_evtPath) as HarmonixEvent
40+
const matchSuffix = filename(_evtPath).match(/\.(on|once)?$/)
41+
const type = event.options.type ?? (matchSuffix ? matchSuffix[1] : null)
4042
const options: EventOptions = {
41-
name: event.options.name || filename(_evtPath).split('.')[0],
42-
once: event.options.once || filename(_evtPath).endsWith('.once')
43+
name:
44+
event.options.name || filename(_evtPath).replace(/\.(on|once)?$/, ''),
45+
once: event.options.once || type === 'once'
4346
}
4447

4548
return { options, callback: event.callback }
@@ -59,7 +62,7 @@ export const resolveCommand = (
5962
const _cmdPath = _jiti.resolve(cmd)
6063
const command = _jiti(_cmdPath) as HarmonixCommand
6164
const config: CommandConfig = {
62-
name: command.config.name || filename(_cmdPath).split('.')[0],
65+
name: command.config.name || filename(_cmdPath),
6366
category: command.config.category || filename(dirname(_cmdPath)),
6467
...command.config
6568
}
@@ -80,9 +83,16 @@ export const resolveContextMenu = (
8083
})
8184
const _ctmPath = _jiti.resolve(ctm)
8285
const contextMenu = _jiti(_ctmPath) as HarmonixContextMenu
86+
const matchSuffix = filename(_ctmPath).match(/\.(user|message)?$/)
87+
const type =
88+
contextMenu.config.type ??
89+
(matchSuffix ? (matchSuffix[1] as 'message' | 'user') : null)
90+
const name =
91+
contextMenu.config.name ??
92+
filename(_ctmPath).replace(/\.(user|message)?$/, '')
8393
const config: ContextMenuConfig = {
84-
name: contextMenu.config.name || filename(_ctmPath).split('.')[0],
85-
type: contextMenu.config.type || 'message',
94+
name,
95+
type: type ?? 'message',
8696
...contextMenu.config
8797
}
8898

@@ -103,7 +113,7 @@ export const resolveButton = (
103113
const _btnPath = _jiti.resolve(btn)
104114
const button = _jiti(_btnPath) as HarmonixButton
105115
const config: ButtonConfig = {
106-
id: button.config.id || filename(_btnPath).split('.')[0],
116+
id: button.config.id || filename(_btnPath),
107117
...button.config
108118
}
109119

@@ -124,7 +134,7 @@ export const resolveModal = (
124134
const _mdlPath = _jiti.resolve(mdl)
125135
const modal = _jiti(_mdlPath) as HarmonixModal
126136
const config: ModalConfig = {
127-
id: modal.config.id || filename(_mdlPath).split('.')[0],
137+
id: modal.config.id || filename(_mdlPath),
128138
...modal.config
129139
}
130140

@@ -145,7 +155,7 @@ export const resolveSelectMenu = (
145155
const _slmPath = _jiti.resolve(slm)
146156
const selectMenu = _jiti(_slmPath) as HarmonixSelectMenu
147157
const config: SelectMenuConfig = {
148-
id: selectMenu.config.id || filename(_slmPath).split('.')[0],
158+
id: selectMenu.config.id || filename(_slmPath),
149159
...selectMenu.config
150160
}
151161

@@ -165,7 +175,7 @@ export const resolvePrecondition = (
165175
})
166176
const _prcPath = _jiti.resolve(prc)
167177
const precondition = _jiti(_prcPath) as HarmonixPrecondition
168-
const name = precondition.name || filename(_prcPath).split('.')[0]
178+
const name = precondition.name || filename(_prcPath)
169179

170180
return { name, callback: precondition.callback }
171181
} else {

0 commit comments

Comments
 (0)