Make command handling more robust

This commit is contained in:
Franck Royer 2021-04-27 16:26:32 +10:00
parent f65d4a20ff
commit 462569583f
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 6 additions and 1 deletions

View File

@ -84,7 +84,7 @@ export default function handleCommand(
setNick: (nick: string) => void setNick: (nick: string) => void
): { command: string; response: string[] } { ): { command: string; response: string[] } {
let response: string[] = []; let response: string[] = [];
const args = input.split(' '); const args = parseInput(input);
const command = args.shift()!; const command = args.shift()!;
switch (command) { switch (command) {
case '/help': case '/help':
@ -107,3 +107,8 @@ export default function handleCommand(
} }
return { command, response }; return { command, response };
} }
export function parseInput(input: string): string[] {
const clean = input.trim().replaceAll(/\s\s+/g, ' ');
return clean.split(' ');
}