Fix case-sensitivity of /me to match rest of slash commands

also better error handling for attempted runs of unimplemented commands
pull/21833/head
Michael Telatynski 2020-06-16 00:41:21 +01:00
parent 94f52c4ee2
commit fcd3ebe051
2 changed files with 10 additions and 6 deletions

View File

@ -118,7 +118,7 @@ export class Command {
run(roomId: string, args: string, cmd: string) { run(roomId: string, args: string, cmd: string) {
// if it has no runFn then its an ignored/nop command (autocomplete only) e.g `/me` // if it has no runFn then its an ignored/nop command (autocomplete only) e.g `/me`
if (!this.runFn) return; if (!this.runFn) return reject(_t("Command error"));
return this.runFn.bind(this)(roomId, args, cmd); return this.runFn.bind(this)(roomId, args, cmd);
} }

View File

@ -62,16 +62,20 @@ export function textSerialize(model: EditorModel) {
} }
export function containsEmote(model: EditorModel) { export function containsEmote(model: EditorModel) {
return startsWith(model, "/me "); return startsWith(model, "/me ", true);
} }
export function startsWith(model: EditorModel, prefix: string) { export function startsWith(model: EditorModel, prefix: string, caseInsensitive = false) {
const firstPart = model.parts[0]; const firstPart = model.parts[0];
// part type will be "plain" while editing, // part type will be "plain" while editing,
// and "command" while composing a message. // and "command" while composing a message.
return firstPart && let text = firstPart && firstPart.text;
(firstPart.type === "plain" || firstPart.type === "command") && if (caseInsensitive) {
firstPart.text.startsWith(prefix); prefix = prefix.toLowerCase();
text = text.toLowerCase();
}
return firstPart && (firstPart.type === "plain" || firstPart.type === "command") && text.startsWith(prefix);
} }
export function stripEmoteCommand(model: EditorModel) { export function stripEmoteCommand(model: EditorModel) {