mirror of https://github.com/waku-org/js-waku.git
Make command handling more robust
This commit is contained in:
parent
f65d4a20ff
commit
462569583f
|
@ -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(' ');
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue