@mostfeatured/dbi 0.0.89 → 0.0.90
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleMessageCommands.d.ts","sourceRoot":"","sources":["../../src/methods/handleMessageCommands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuD,OAAO,EAAgD,MAAM,YAAY,CAAC;AACxI,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAO7B,MAAM,MAAM,oCAAoC,GAAG,uBAAuB,GAAG,WAAW,GAAG,WAAW,GAAG,eAAe,GAAG,gBAAgB,GAAG,YAAY,GAAG,YAAY,GAAG,eAAe,GAAG,WAAW,GAAG,WAAW,GAAG,gBAAgB,GAAG,aAAa,GAAG,gBAAgB,GAAG,aAAa,GAAG,oBAAoB,GAAG,uBAAuB,CAAC;AAE/U,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,cAAc,CAAC,EAAE,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"handleMessageCommands.d.ts","sourceRoot":"","sources":["../../src/methods/handleMessageCommands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuD,OAAO,EAAgD,MAAM,YAAY,CAAC;AACxI,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAO7B,MAAM,MAAM,oCAAoC,GAAG,uBAAuB,GAAG,WAAW,GAAG,WAAW,GAAG,eAAe,GAAG,gBAAgB,GAAG,YAAY,GAAG,YAAY,GAAG,eAAe,GAAG,WAAW,GAAG,WAAW,GAAG,gBAAgB,GAAG,aAAa,GAAG,gBAAgB,GAAG,aAAa,GAAG,oBAAoB,GAAG,uBAAuB,CAAC;AAE/U,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,cAAc,CAAC,EAAE,OAAO,EAAE,OAAO,iBAqTrF"}
|
|
@@ -59,6 +59,8 @@ async function handleMessageCommands(dbi, message) {
|
|
|
59
59
|
lastValue = value;
|
|
60
60
|
switch (option.type) {
|
|
61
61
|
case discord_js_1.ApplicationCommandOptionType.String: {
|
|
62
|
+
if (!option.required && !value)
|
|
63
|
+
break;
|
|
62
64
|
if (option.autocomplete && option.onComplete) {
|
|
63
65
|
let choices = await option.onComplete({
|
|
64
66
|
interaction,
|
|
@@ -111,6 +113,8 @@ async function handleMessageCommands(dbi, message) {
|
|
|
111
113
|
break;
|
|
112
114
|
}
|
|
113
115
|
case discord_js_1.ApplicationCommandOptionType.Integer: {
|
|
116
|
+
if (!option.required && !value)
|
|
117
|
+
break;
|
|
114
118
|
let parsedInt = parseInt(value);
|
|
115
119
|
if (option.autocomplete && option.onComplete) {
|
|
116
120
|
let choices = await option.onComplete({
|
|
@@ -169,6 +173,8 @@ async function handleMessageCommands(dbi, message) {
|
|
|
169
173
|
break;
|
|
170
174
|
}
|
|
171
175
|
case discord_js_1.ApplicationCommandOptionType.Number: {
|
|
176
|
+
if (!option.required && !value)
|
|
177
|
+
break;
|
|
172
178
|
let parsedFloat = parseFloat(value);
|
|
173
179
|
if (option.autocomplete && option.onComplete) {
|
|
174
180
|
let choices = await option.onComplete({
|
|
@@ -228,35 +234,35 @@ async function handleMessageCommands(dbi, message) {
|
|
|
228
234
|
}
|
|
229
235
|
case discord_js_1.ApplicationCommandOptionType.Boolean: {
|
|
230
236
|
let boolKeys = Object.keys(dbi.config.messageCommands.typeAliases.booleans);
|
|
231
|
-
if (!boolKeys.includes(value.toLowerCase())) {
|
|
237
|
+
if (option.required && !boolKeys.includes(value.toLowerCase())) {
|
|
232
238
|
errorType = "InvalidBoolean";
|
|
233
239
|
break;
|
|
234
240
|
}
|
|
235
241
|
break;
|
|
236
242
|
}
|
|
237
243
|
case discord_js_1.ApplicationCommandOptionType.User: {
|
|
238
|
-
if (!interaction.options.getUser(option.name)) {
|
|
244
|
+
if (option.required && !interaction.options.getUser(option.name)) {
|
|
239
245
|
errorType = "InvalidUser";
|
|
240
246
|
break;
|
|
241
247
|
}
|
|
242
248
|
break;
|
|
243
249
|
}
|
|
244
250
|
case discord_js_1.ApplicationCommandOptionType.Channel: {
|
|
245
|
-
if (!interaction.options.getChannel(option.name, null, option.channelTypes)) {
|
|
251
|
+
if (option.required && !interaction.options.getChannel(option.name, null, option.channelTypes)) {
|
|
246
252
|
errorType = "InvalidChannel";
|
|
247
253
|
break;
|
|
248
254
|
}
|
|
249
255
|
break;
|
|
250
256
|
}
|
|
251
257
|
case discord_js_1.ApplicationCommandOptionType.Role: {
|
|
252
|
-
if (!interaction.options.getRole(option.name)) {
|
|
258
|
+
if (option.required && !interaction.options.getRole(option.name)) {
|
|
253
259
|
errorType = "InvalidRole";
|
|
254
260
|
break;
|
|
255
261
|
}
|
|
256
262
|
break;
|
|
257
263
|
}
|
|
258
264
|
case discord_js_1.ApplicationCommandOptionType.Mentionable: {
|
|
259
|
-
if (!interaction.options.getMentionable(option.name)) {
|
|
265
|
+
if (option.required && !interaction.options.getMentionable(option.name)) {
|
|
260
266
|
errorType = "InvalidMentionable";
|
|
261
267
|
break;
|
|
262
268
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleMessageCommands.js","sourceRoot":"","sources":["../../src/methods/handleMessageCommands.ts"],"names":[],"mappings":";;;AAAA,2CAAwI;AAGxI,kFAA+E;AAG/E,MAAM,aAAa,GAAG,SAAS,CAAC;AAChC,MAAM,YAAY,GAAG,mBAAmB,CAAC;AAIlC,KAAK,UAAU,qBAAqB,CAAC,GAAwB,EAAE,OAAgB;IACpF,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;IAC7E,MAAM,QAAQ,GAAG,G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AG,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;oBAClG,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;iBAC7K;gBACD,KAAK,EAAE;oBACL,IAAI,EAAE,SAAS;oBACf,MAAM,EAAE,UAAU;oBAClB,KAAK,EAAE,SAAS;oBAChB,KAAK,EAAE,SAAS;iBACjB;gBACD,KAAK,EAAE,SAAS;aACjB,CAAC,CAAC;YACH,IAAI,CAAC,GAAG;gBAAE,OAAO;SAClB;KACF;IAGD,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,EAAE,WAAkB,CAAC,CAAC;AAChF,CAAC;AA9SD,sDA8SC","sourcesContent":["import { ApplicationCommandType, ChatInputCommandInteraction, Message, MessagePayload, ApplicationCommandOptionType } from \"discord.js\";\r\nimport { NamespaceEnums } from \"../../generated/namespaceData\";\r\nimport { DBI } from \"../DBI\";\r\nimport { FakeMessageInteraction } from \"../types/other/FakeMessageInteraction\";\r\nimport { TDBILocaleString } from \"../types/other/Locale\";\r\n\r\nconst INTEGER_REGEX = /^-?\\d+$/;\r\nconst NUMBER_REGEX = /^-?\\d+(?:\\.\\d+)?$/;\r\n\r\nexport type TDBIMessageCommandArgumentErrorTypes = \"MissingRequiredOption\" | \"MinLength\" | \"MaxLength\" | \"InvalidChoice\" | \"InvalidInteger\" | \"MinInteger\" | \"MaxInteger\" | \"InvalidNumber\" | \"MinNumber\" | \"MaxNumber\" | \"InvalidBoolean\" | \"InvalidUser\" | \"InvalidChannel\" | \"InvalidRole\" | \"InvalidMentionable\" | \"InvalidCompleteChoice\";\r\n\r\nexport async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: Message) {\r\n const chatInputs = dbi.data.interactions.filter(i => i.type === \"ChatInput\");\r\n const prefixes = dbi.config.messageCommands.prefixes ?? [];\r\n if (!prefixes.length) return;\r\n const content = message.content;\r\n const usedPrefix = prefixes.find(p => content.startsWith(p));\r\n if (!usedPrefix) return;\r\n const contentWithoutPrefix = content.slice(usedPrefix?.length ?? 0);\r\n const contentLower = contentWithoutPrefix.toLowerCase();\r\n\r\n let locale: string = message.guild.preferredLocale?.split(\"-\")?.at(0) || dbi.config.defaults.locale as any;\r\n let usedAlias: string | undefined;\r\n let chatInput = chatInputs.find(i => {\r\n let found = contentLower.startsWith(i.name);\r\n if (found) return true;\r\n let alias = i.other?.messageCommand?.aliases?.find(a => contentLower.startsWith(a));\r\n if (alias) {\r\n usedAlias = alias;\r\n return true;\r\n }\r\n return false;\r\n });\r\n let commandName = usedAlias ?? chatInput?.name;\r\n\r\n if (!chatInput) {\r\n fLoop: for (const [localeInterName, localeData] of dbi.data.interactionLocales) {\r\n for (const [localeName, translation] of Object.entries(localeData.data || {})) {\r\n if (contentLower.startsWith(translation.name)) {\r\n commandName = translation.name;\r\n locale = localeName;\r\n chatInput = chatInputs.find(i => i.name === localeData.name);\r\n break fLoop;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (!chatInput) return;\r\n\r\n const interaction = new FakeMessageInteraction(dbi, message, chatInput, locale, commandName, usedPrefix);\r\n\r\n if (chatInput.options.length) {\r\n let errorType: TDBIMessageCommandArgumentErrorTypes;\r\n let lastOption: any;\r\n let lastValue: any;\r\n let lastExtra: any;\r\n let lastIndex: number;\r\n for (let i = 0; i < chatInput.options.length; i++) {\r\n lastIndex = i;\r\n const option: any = interaction.dbiChatInputOptions[i];\r\n const value = interaction.parsedArgs.get(option.name)?.value;\r\n\r\n lastOption = option;\r\n lastValue = value;\r\n\r\n switch (option.type) {\r\n case ApplicationCommandOptionType.String: {\r\n if (option.autocomplete && option.onComplete) {\r\n let choices = await option.onComplete({\r\n interaction,\r\n value\r\n });\r\n if (!choices.length) choices = await option.onComplete({\r\n interaction,\r\n value: \"\"\r\n });\r\n if (choices.length > 20) throw new Error(\"Autocomplete returned more than 20 choices.\");\r\n lastExtra = choices;\r\n if (!choices.find(c => c.name === value || c.value === value)) {\r\n if (value) {\r\n errorType = \"InvalidCompleteChoice\";\r\n break;\r\n } else if (option.required && !value) {\r\n errorType = \"MissingRequiredOption\";\r\n break;\r\n }\r\n }\r\n option._choices = choices;\r\n }\r\n\r\n if (option.choices) {\r\n const localeData = dbi.data.interactionLocales.get(chatInput.name)?.data;\r\n const choicesLocaleData = localeData?.[locale as TDBILocaleString]?.options?.[option.name]?.choices;\r\n if (!option.choices.find(c => c.name === value || c.value === value || (choicesLocaleData?.[c.value] && choicesLocaleData?.[c.value] === value))) {\r\n lastExtra = option.choices.map(c => ({ name: choicesLocaleData?.[c.value] ?? c.name, value: c.value }));\r\n if (value) {\r\n errorType = \"InvalidChoice\";\r\n break;\r\n } else if (option.required && !value) {\r\n errorType = \"MissingRequiredOption\";\r\n break;\r\n }\r\n }\r\n break;\r\n }\r\n\r\n if (option.minLength && value.length < option.minLength) {\r\n errorType = \"MinLength\";\r\n break;\r\n }\r\n if (option.maxLength && value.length > option.maxLength) {\r\n errorType = \"MaxLength\";\r\n break;\r\n }\r\n\r\n break;\r\n }\r\n case ApplicationCommandOptionType.Integer: {\r\n let parsedInt = parseInt(value);\r\n\r\n if (option.autocomplete && option.onComplete) {\r\n let choices = await option.onComplete({\r\n interaction,\r\n value\r\n });\r\n if (!choices.length) choices = await option.onComplete({\r\n interaction,\r\n value: \"\"\r\n });\r\n if (choices.length > 20) throw new Error(\"Autocomplete returned more than 20 choices.\");\r\n lastExtra = choices;\r\n if (!choices.find(c => c.value === parsedInt || c.name === value)) {\r\n if (value) {\r\n errorType = \"InvalidCompleteChoice\";\r\n break;\r\n } else if (option.required && !value) {\r\n errorType = \"MissingRequiredOption\";\r\n break;\r\n }\r\n }\r\n option._choices = choices;\r\n break;\r\n }\r\n\r\n if (option.choices) {\r\n const localeData = dbi.data.interactionLocales.get(chatInput.name)?.data;\r\n const choicesLocaleData = localeData?.[locale as TDBILocaleString]?.options?.[option.name]?.choices;\r\n if (!option.choices.find(c => c.value === parsedInt || c.name === value || (choicesLocaleData?.[c.value] && choicesLocaleData?.[c.value] === value))) {\r\n lastExtra = option.choices.map(c => ({ name: choicesLocaleData?.[c.value] ?? c.name, value: c.value }));\r\n if (value) {\r\n errorType = \"InvalidChoice\";\r\n break;\r\n } else if (option.required && !value) {\r\n errorType = \"MissingRequiredOption\";\r\n break;\r\n }\r\n }\r\n break;\r\n }\r\n\r\n if (!INTEGER_REGEX.test(value)) {\r\n errorType = \"InvalidInteger\";\r\n break;\r\n }\r\n \r\n if (option.minValue && parsedInt < option.minValue) {\r\n errorType = \"MinInteger\";\r\n break;\r\n }\r\n\r\n if (option.maxValue && parsedInt > option.maxValue) {\r\n errorType = \"MaxInteger\";\r\n break;\r\n }\r\n\r\n break;\r\n }\r\n case ApplicationCommandOptionType.Number: {\r\n let parsedFloat = parseFloat(value);\r\n\r\n if (option.autocomplete && option.onComplete) {\r\n let choices = await option.onComplete({\r\n interaction,\r\n value\r\n });\r\n if (!choices.length) choices = await option.onComplete({\r\n interaction,\r\n value: \"\"\r\n });\r\n if (choices.length > 20) throw new Error(\"Autocomplete returned more than 20 choices.\");\r\n lastExtra = choices;\r\n if (!choices.find(c => c.value === parsedFloat || c.name === value)) {\r\n if (value) {\r\n errorType = \"InvalidCompleteChoice\";\r\n break;\r\n } else if (option.required && !value) {\r\n errorType = \"MissingRequiredOption\";\r\n break;\r\n }\r\n }\r\n option._choices = choices;\r\n break;\r\n }\r\n\r\n if (option.choices) {\r\n const localeData = dbi.data.interactionLocales.get(chatInput.name)?.data;\r\n const choicesLocaleData = localeData?.[locale as TDBILocaleString]?.options?.[option.name]?.choices;\r\n if (!option.choices.find(c => c.value === parsedFloat || c.name === value || (choicesLocaleData?.[c.value] && choicesLocaleData?.[c.value] === value))) {\r\n lastExtra = option.choices.map(c => ({ name: choicesLocaleData?.[c.value] ?? c.name, value: c.value }));\r\n if (value) {\r\n errorType = \"InvalidChoice\";\r\n break;\r\n } else if (option.required && !value) {\r\n errorType = \"MissingRequiredOption\";\r\n break;\r\n }\r\n }\r\n break;\r\n }\r\n\r\n if (!NUMBER_REGEX.test(value)) {\r\n errorType = \"InvalidNumber\";\r\n break;\r\n }\r\n\r\n if (option.minValue && parsedFloat < option.minValue) {\r\n errorType = \"MinNumber\";\r\n break;\r\n }\r\n\r\n if (option.maxValue && parsedFloat > option.maxValue) {\r\n errorType = \"MaxNumber\";\r\n break;\r\n }\r\n break;\r\n }\r\n case ApplicationCommandOptionType.Boolean: {\r\n let boolKeys = Object.keys(dbi.config.messageCommands.typeAliases.booleans);\r\n if (!boolKeys.includes(value.toLowerCase())) {\r\n errorType = \"InvalidBoolean\";\r\n break;\r\n }\r\n break;\r\n }\r\n case ApplicationCommandOptionType.User: {\r\n if (!interaction.options.getUser(option.name)) {\r\n errorType = \"InvalidUser\";\r\n break;\r\n }\r\n break;\r\n }\r\n case ApplicationCommandOptionType.Channel: {\r\n if (!interaction.options.getChannel(option.name, null, option.channelTypes)) {\r\n errorType = \"InvalidChannel\";\r\n break;\r\n }\r\n break;\r\n }\r\n case ApplicationCommandOptionType.Role: {\r\n if (!interaction.options.getRole(option.name)) {\r\n errorType = \"InvalidRole\";\r\n break;\r\n }\r\n break;\r\n }\r\n case ApplicationCommandOptionType.Mentionable: {\r\n if (!interaction.options.getMentionable(option.name)) {\r\n errorType = \"InvalidMentionable\";\r\n break;\r\n }\r\n break;\r\n }\r\n case ApplicationCommandOptionType.Attachment: {\r\n if (option.required && !value) {\r\n errorType = \"MissingRequiredOption\";\r\n }\r\n break;\r\n }\r\n }\r\n\r\n if (errorType) {\r\n break;\r\n } else {\r\n lastExtra = null;\r\n lastIndex = null;\r\n lastOption = null;\r\n lastValue = null;\r\n }\r\n }\r\n\r\n if (errorType) {\r\n let res = await dbi.events.trigger(\"messageCommandArgumentError\", {\r\n interaction,\r\n message,\r\n locale: {\r\n user: dbi.data.locales.get(interaction.locale) || dbi.data.locales.get(dbi.config.defaults.locale),\r\n guild: message.guild?.preferredLocale ? (dbi.data.locales.get(message.guild?.preferredLocale?.split(\"-\")?.at(0)) || dbi.data.locales.get(dbi.config.defaults.locale)) : null\r\n },\r\n error: {\r\n type: errorType,\r\n option: lastOption,\r\n extra: lastExtra,\r\n index: lastIndex\r\n },\r\n value: lastValue\r\n });\r\n if (!res) return;\r\n }\r\n }\r\n\r\n\r\n dbi.data.clients.first().client.emit(\"interactionCreate\", interaction as any);\r\n}"]}
|
|
1
|
+
{"version":3,"file":"handleMessageCommands.js","sourceRoot":"","sources":["../../src/methods/handleMessageCommands.ts"],"names":[],"mappings":";;;AAAA,2CAAwI;AAGxI,kFAA+E;AAG/E,MAAM,aAAa,GAAG,SAAS,CAAC;AAChC,MAAM,YAAY,GAAG,mBAAmB,CAAC;AAIlC,KAAK,UAAU,qBAAqB,CAAC,GAAwB,EAAE,OAAgB;IACpF,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;IAC7E,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,QAAQ,IAAI,EAAE,CAAC;IAC3D,IAAI,CAAC,QAAQ,CAAC,MAAM;QAAE,OAAO;IAC7B,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAChC,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,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AAC,WAAW,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;oBAClG,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;iBAC7K;gBACD,KAAK,EAAE;oBACL,IAAI,EAAE,SAAS;oBACf,MAAM,EAAE,UAAU;oBAClB,KAAK,EAAE,SAAS;oBAChB,KAAK,EAAE,SAAS;iBACjB;gBACD,KAAK,EAAE,SAAS;aACjB,CAAC,CAAC;YACH,IAAI,CAAC,GAAG;gBAAE,OAAO;SAClB;KACF;IAGD,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,EAAE,WAAkB,CAAC,CAAC;AAChF,CAAC;AArTD,sDAqTC","sourcesContent":["import { ApplicationCommandType, ChatInputCommandInteraction, Message, MessagePayload, ApplicationCommandOptionType } from \"discord.js\";\r\nimport { NamespaceEnums } from \"../../generated/namespaceData\";\r\nimport { DBI } from \"../DBI\";\r\nimport { FakeMessageInteraction } from \"../types/other/FakeMessageInteraction\";\r\nimport { TDBILocaleString } from \"../types/other/Locale\";\r\n\r\nconst INTEGER_REGEX = /^-?\\d+$/;\r\nconst NUMBER_REGEX = /^-?\\d+(?:\\.\\d+)?$/;\r\n\r\nexport type TDBIMessageCommandArgumentErrorTypes = \"MissingRequiredOption\" | \"MinLength\" | \"MaxLength\" | \"InvalidChoice\" | \"InvalidInteger\" | \"MinInteger\" | \"MaxInteger\" | \"InvalidNumber\" | \"MinNumber\" | \"MaxNumber\" | \"InvalidBoolean\" | \"InvalidUser\" | \"InvalidChannel\" | \"InvalidRole\" | \"InvalidMentionable\" | \"InvalidCompleteChoice\";\r\n\r\nexport async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: Message) {\r\n const chatInputs = dbi.data.interactions.filter(i => i.type === \"ChatInput\");\r\n const prefixes = dbi.config.messageCommands.prefixes ?? [];\r\n if (!prefixes.length) return;\r\n const content = message.content;\r\n const usedPrefix = prefixes.find(p => content.startsWith(p));\r\n if (!usedPrefix) return;\r\n const contentWithoutPrefix = content.slice(usedPrefix?.length ?? 0);\r\n const contentLower = contentWithoutPrefix.toLowerCase();\r\n\r\n let locale: string = message.guild.preferredLocale?.split(\"-\")?.at(0) || dbi.config.defaults.locale as any;\r\n let usedAlias: string | undefined;\r\n let chatInput = chatInputs.find(i => {\r\n let found = contentLower.startsWith(i.name);\r\n if (found) return true;\r\n let alias = i.other?.messageCommand?.aliases?.find(a => contentLower.startsWith(a));\r\n if (alias) {\r\n usedAlias = alias;\r\n return true;\r\n }\r\n return false;\r\n });\r\n let commandName = usedAlias ?? chatInput?.name;\r\n\r\n if (!chatInput) {\r\n fLoop: for (const [localeInterName, localeData] of dbi.data.interactionLocales) {\r\n for (const [localeName, translation] of Object.entries(localeData.data || {})) {\r\n if (contentLower.startsWith(translation.name)) {\r\n commandName = translation.name;\r\n locale = localeName;\r\n chatInput = chatInputs.find(i => i.name === localeData.name);\r\n break fLoop;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (!chatInput) return;\r\n\r\n const interaction = new FakeMessageInteraction(dbi, message, chatInput, locale, commandName, usedPrefix);\r\n\r\n if (chatInput.options.length) {\r\n let errorType: TDBIMessageCommandArgumentErrorTypes;\r\n let lastOption: any;\r\n let lastValue: any;\r\n let lastExtra: any;\r\n let lastIndex: number;\r\n for (let i = 0; i < chatInput.options.length; i++) {\r\n lastIndex = i;\r\n const option: any = interaction.dbiChatInputOptions[i];\r\n const value = interaction.parsedArgs.get(option.name)?.value;\r\n\r\n lastOption = option;\r\n lastValue = value;\r\n\r\n switch (option.type) {\r\n case ApplicationCommandOptionType.String: {\r\n\r\n if (!option.required && !value) break;\r\n\r\n if (option.autocomplete && option.onComplete) {\r\n let choices = await option.onComplete({\r\n interaction,\r\n value\r\n });\r\n if (!choices.length) choices = await option.onComplete({\r\n interaction,\r\n value: \"\"\r\n });\r\n if (choices.length > 20) throw new Error(\"Autocomplete returned more than 20 choices.\");\r\n lastExtra = choices;\r\n if (!choices.find(c => c.name === value || c.value === value)) {\r\n if (value) {\r\n errorType = \"InvalidCompleteChoice\";\r\n break;\r\n } else if (option.required && !value) {\r\n errorType = \"MissingRequiredOption\";\r\n break;\r\n }\r\n }\r\n option._choices = choices;\r\n }\r\n\r\n if (option.choices) {\r\n const localeData = dbi.data.interactionLocales.get(chatInput.name)?.data;\r\n const choicesLocaleData = localeData?.[locale as TDBILocaleString]?.options?.[option.name]?.choices;\r\n if (!option.choices.find(c => c.name === value || c.value === value || (choicesLocaleData?.[c.value] && choicesLocaleData?.[c.value] === value))) {\r\n lastExtra = option.choices.map(c => ({ name: choicesLocaleData?.[c.value] ?? c.name, value: c.value }));\r\n if (value) {\r\n errorType = \"InvalidChoice\";\r\n break;\r\n } else if (option.required && !value) {\r\n errorType = \"MissingRequiredOption\";\r\n break;\r\n }\r\n }\r\n break;\r\n }\r\n\r\n if (option.minLength && value.length < option.minLength) {\r\n errorType = \"MinLength\";\r\n break;\r\n }\r\n if (option.maxLength && value.length > option.maxLength) {\r\n errorType = \"MaxLength\";\r\n break;\r\n }\r\n\r\n break;\r\n }\r\n case ApplicationCommandOptionType.Integer: {\r\n if (!option.required && !value) break;\r\n\r\n let parsedInt = parseInt(value);\r\n\r\n if (option.autocomplete && option.onComplete) {\r\n let choices = await option.onComplete({\r\n interaction,\r\n value\r\n });\r\n if (!choices.length) choices = await option.onComplete({\r\n interaction,\r\n value: \"\"\r\n });\r\n if (choices.length > 20) throw new Error(\"Autocomplete returned more than 20 choices.\");\r\n lastExtra = choices;\r\n if (!choices.find(c => c.value === parsedInt || c.name === value)) {\r\n if (value) {\r\n errorType = \"InvalidCompleteChoice\";\r\n break;\r\n } else if (option.required && !value) {\r\n errorType = \"MissingRequiredOption\";\r\n break;\r\n }\r\n }\r\n option._choices = choices;\r\n break;\r\n }\r\n\r\n if (option.choices) {\r\n const localeData = dbi.data.interactionLocales.get(chatInput.name)?.data;\r\n const choicesLocaleData = localeData?.[locale as TDBILocaleString]?.options?.[option.name]?.choices;\r\n if (!option.choices.find(c => c.value === parsedInt || c.name === value || (choicesLocaleData?.[c.value] && choicesLocaleData?.[c.value] === value))) {\r\n lastExtra = option.choices.map(c => ({ name: choicesLocaleData?.[c.value] ?? c.name, value: c.value }));\r\n if (value) {\r\n errorType = \"InvalidChoice\";\r\n break;\r\n } else if (option.required && !value) {\r\n errorType = \"MissingRequiredOption\";\r\n break;\r\n }\r\n }\r\n break;\r\n }\r\n\r\n if (!INTEGER_REGEX.test(value)) {\r\n errorType = \"InvalidInteger\";\r\n break;\r\n }\r\n\r\n if (option.minValue && parsedInt < option.minValue) {\r\n errorType = \"MinInteger\";\r\n break;\r\n }\r\n\r\n if (option.maxValue && parsedInt > option.maxValue) {\r\n errorType = \"MaxInteger\";\r\n break;\r\n }\r\n\r\n break;\r\n }\r\n case ApplicationCommandOptionType.Number: {\r\n if (!option.required && !value) break;\r\n\r\n let parsedFloat = parseFloat(value);\r\n\r\n if (option.autocomplete && option.onComplete) {\r\n let choices = await option.onComplete({\r\n interaction,\r\n value\r\n });\r\n if (!choices.length) choices = await option.onComplete({\r\n interaction,\r\n value: \"\"\r\n });\r\n if (choices.length > 20) throw new Error(\"Autocomplete returned more than 20 choices.\");\r\n lastExtra = choices;\r\n if (!choices.find(c => c.value === parsedFloat || c.name === value)) {\r\n if (value) {\r\n errorType = \"InvalidCompleteChoice\";\r\n break;\r\n } else if (option.required && !value) {\r\n errorType = \"MissingRequiredOption\";\r\n break;\r\n }\r\n }\r\n option._choices = choices;\r\n break;\r\n }\r\n\r\n if (option.choices) {\r\n const localeData = dbi.data.interactionLocales.get(chatInput.name)?.data;\r\n const choicesLocaleData = localeData?.[locale as TDBILocaleString]?.options?.[option.name]?.choices;\r\n if (!option.choices.find(c => c.value === parsedFloat || c.name === value || (choicesLocaleData?.[c.value] && choicesLocaleData?.[c.value] === value))) {\r\n lastExtra = option.choices.map(c => ({ name: choicesLocaleData?.[c.value] ?? c.name, value: c.value }));\r\n if (value) {\r\n errorType = \"InvalidChoice\";\r\n break;\r\n } else if (option.required && !value) {\r\n errorType = \"MissingRequiredOption\";\r\n break;\r\n }\r\n }\r\n break;\r\n }\r\n\r\n if (!NUMBER_REGEX.test(value)) {\r\n errorType = \"InvalidNumber\";\r\n break;\r\n }\r\n\r\n if (option.minValue && parsedFloat < option.minValue) {\r\n errorType = \"MinNumber\";\r\n break;\r\n }\r\n\r\n if (option.maxValue && parsedFloat > option.maxValue) {\r\n errorType = \"MaxNumber\";\r\n break;\r\n }\r\n break;\r\n }\r\n case ApplicationCommandOptionType.Boolean: {\r\n let boolKeys = Object.keys(dbi.config.messageCommands.typeAliases.booleans);\r\n if (option.required && !boolKeys.includes(value.toLowerCase())) {\r\n errorType = \"InvalidBoolean\";\r\n break;\r\n }\r\n break;\r\n }\r\n case ApplicationCommandOptionType.User: {\r\n if (option.required && !interaction.options.getUser(option.name)) {\r\n errorType = \"InvalidUser\";\r\n break;\r\n }\r\n break;\r\n }\r\n case ApplicationCommandOptionType.Channel: {\r\n if (option.required && !interaction.options.getChannel(option.name, null, option.channelTypes)) {\r\n errorType = \"InvalidChannel\";\r\n break;\r\n }\r\n break;\r\n }\r\n case ApplicationCommandOptionType.Role: {\r\n if (option.required && !interaction.options.getRole(option.name)) {\r\n errorType = \"InvalidRole\";\r\n break;\r\n }\r\n break;\r\n }\r\n case ApplicationCommandOptionType.Mentionable: {\r\n if (option.required && !interaction.options.getMentionable(option.name)) {\r\n errorType = \"InvalidMentionable\";\r\n break;\r\n }\r\n break;\r\n }\r\n case ApplicationCommandOptionType.Attachment: {\r\n if (option.required && !value) {\r\n errorType = \"MissingRequiredOption\";\r\n }\r\n break;\r\n }\r\n }\r\n\r\n if (errorType) {\r\n break;\r\n } else {\r\n lastExtra = null;\r\n lastIndex = null;\r\n lastOption = null;\r\n lastValue = null;\r\n }\r\n }\r\n\r\n if (errorType) {\r\n let res = await dbi.events.trigger(\"messageCommandArgumentError\", {\r\n interaction,\r\n message,\r\n locale: {\r\n user: dbi.data.locales.get(interaction.locale) || dbi.data.locales.get(dbi.config.defaults.locale),\r\n guild: message.guild?.preferredLocale ? (dbi.data.locales.get(message.guild?.preferredLocale?.split(\"-\")?.at(0)) || dbi.data.locales.get(dbi.config.defaults.locale)) : null\r\n },\r\n error: {\r\n type: errorType,\r\n option: lastOption,\r\n extra: lastExtra,\r\n index: lastIndex\r\n },\r\n value: lastValue\r\n });\r\n if (!res) return;\r\n }\r\n }\r\n\r\n\r\n dbi.data.clients.first().client.emit(\"interactionCreate\", interaction as any);\r\n}"]}
|
package/package.json
CHANGED
|
@@ -66,6 +66,9 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
66
66
|
|
|
67
67
|
switch (option.type) {
|
|
68
68
|
case ApplicationCommandOptionType.String: {
|
|
69
|
+
|
|
70
|
+
if (!option.required && !value) break;
|
|
71
|
+
|
|
69
72
|
if (option.autocomplete && option.onComplete) {
|
|
70
73
|
let choices = await option.onComplete({
|
|
71
74
|
interaction,
|
|
@@ -117,6 +120,8 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
117
120
|
break;
|
|
118
121
|
}
|
|
119
122
|
case ApplicationCommandOptionType.Integer: {
|
|
123
|
+
if (!option.required && !value) break;
|
|
124
|
+
|
|
120
125
|
let parsedInt = parseInt(value);
|
|
121
126
|
|
|
122
127
|
if (option.autocomplete && option.onComplete) {
|
|
@@ -163,7 +168,7 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
163
168
|
errorType = "InvalidInteger";
|
|
164
169
|
break;
|
|
165
170
|
}
|
|
166
|
-
|
|
171
|
+
|
|
167
172
|
if (option.minValue && parsedInt < option.minValue) {
|
|
168
173
|
errorType = "MinInteger";
|
|
169
174
|
break;
|
|
@@ -177,6 +182,8 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
177
182
|
break;
|
|
178
183
|
}
|
|
179
184
|
case ApplicationCommandOptionType.Number: {
|
|
185
|
+
if (!option.required && !value) break;
|
|
186
|
+
|
|
180
187
|
let parsedFloat = parseFloat(value);
|
|
181
188
|
|
|
182
189
|
if (option.autocomplete && option.onComplete) {
|
|
@@ -237,35 +244,35 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
237
244
|
}
|
|
238
245
|
case ApplicationCommandOptionType.Boolean: {
|
|
239
246
|
let boolKeys = Object.keys(dbi.config.messageCommands.typeAliases.booleans);
|
|
240
|
-
if (!boolKeys.includes(value.toLowerCase())) {
|
|
247
|
+
if (option.required && !boolKeys.includes(value.toLowerCase())) {
|
|
241
248
|
errorType = "InvalidBoolean";
|
|
242
249
|
break;
|
|
243
250
|
}
|
|
244
251
|
break;
|
|
245
252
|
}
|
|
246
253
|
case ApplicationCommandOptionType.User: {
|
|
247
|
-
if (!interaction.options.getUser(option.name)) {
|
|
254
|
+
if (option.required && !interaction.options.getUser(option.name)) {
|
|
248
255
|
errorType = "InvalidUser";
|
|
249
256
|
break;
|
|
250
257
|
}
|
|
251
258
|
break;
|
|
252
259
|
}
|
|
253
260
|
case ApplicationCommandOptionType.Channel: {
|
|
254
|
-
if (!interaction.options.getChannel(option.name, null, option.channelTypes)) {
|
|
261
|
+
if (option.required && !interaction.options.getChannel(option.name, null, option.channelTypes)) {
|
|
255
262
|
errorType = "InvalidChannel";
|
|
256
263
|
break;
|
|
257
264
|
}
|
|
258
265
|
break;
|
|
259
266
|
}
|
|
260
267
|
case ApplicationCommandOptionType.Role: {
|
|
261
|
-
if (!interaction.options.getRole(option.name)) {
|
|
268
|
+
if (option.required && !interaction.options.getRole(option.name)) {
|
|
262
269
|
errorType = "InvalidRole";
|
|
263
270
|
break;
|
|
264
271
|
}
|
|
265
272
|
break;
|
|
266
273
|
}
|
|
267
274
|
case ApplicationCommandOptionType.Mentionable: {
|
|
268
|
-
if (!interaction.options.getMentionable(option.name)) {
|
|
275
|
+
if (option.required && !interaction.options.getMentionable(option.name)) {
|
|
269
276
|
errorType = "InvalidMentionable";
|
|
270
277
|
break;
|
|
271
278
|
}
|