Clean the parsing

This commit is contained in:
Barrca 2025-01-29 13:31:13 -08:00
parent f446e63b96
commit 108eb0c251
2 changed files with 6 additions and 8 deletions

View file

@ -2,11 +2,11 @@ import { SlashCommand } from "./source";
export function parseCommand(userInput: string, prefix: string, customCommands: SlashCommand[]): string {
for (const command of customCommands) {
const commandPattern = `${prefix}${command.keyword}`;
if (userInput.startsWith(commandPattern)) {
return userInput.replace(commandPattern, command.prompt).trim();
for (const command of customCommands) {
const commandPattern = `${prefix}${command.keyword}`;
if (userInput.includes(commandPattern)) {
return userInput.replace(commandPattern, command.prompt);
}
}
}
return userInput; // Return original text if no command matches
return userInput; // Return original text if no command matches
}

View file

@ -20,8 +20,6 @@ function createSlashCommandSource(options: {
customCommands: []
}) {
const { prefix, customCommands } = options;
console.log(prefix, customCommands)
return (context: CompletionContext) => {
let word = context.matchBefore(new RegExp(`^\\${prefix}\\w*`))
if (!word || (word.from == word.to && !context.explicit))