From fcd3ebe051877fbd4ed79fa6cbe9706fc7252091 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 16 Jun 2020 00:41:21 +0100 Subject: [PATCH 1/3] Fix case-sensitivity of /me to match rest of slash commands also better error handling for attempted runs of unimplemented commands --- src/SlashCommands.tsx | 2 +- src/editor/serialize.ts | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx index 15798ae3b1..7ebdc4ee3b 100644 --- a/src/SlashCommands.tsx +++ b/src/SlashCommands.tsx @@ -118,7 +118,7 @@ export class Command { run(roomId: string, args: string, cmd: string) { // 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); } diff --git a/src/editor/serialize.ts b/src/editor/serialize.ts index 4d0b8cd03a..40038114d4 100644 --- a/src/editor/serialize.ts +++ b/src/editor/serialize.ts @@ -62,16 +62,20 @@ export function textSerialize(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]; // part type will be "plain" while editing, // and "command" while composing a message. - return firstPart && - (firstPart.type === "plain" || firstPart.type === "command") && - firstPart.text.startsWith(prefix); + let text = firstPart && firstPart.text; + if (caseInsensitive) { + prefix = prefix.toLowerCase(); + text = text.toLowerCase(); + } + + return firstPart && (firstPart.type === "plain" || firstPart.type === "command") && text.startsWith(prefix); } export function stripEmoteCommand(model: EditorModel) { From 3217becce8a930c9f8369c6dab0d64f021a69d49 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 16 Jun 2020 00:52:52 +0100 Subject: [PATCH 2/3] i18n --- src/i18n/strings/en_EN.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 396c3f9111..100d2938d8 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -148,6 +148,7 @@ "Actions": "Actions", "Advanced": "Advanced", "Other": "Other", + "Command error": "Command error", "Usage": "Usage", "Prepends ¯\\_(ツ)_/¯ to a plain-text message": "Prepends ¯\\_(ツ)_/¯ to a plain-text message", "Sends a message as plain text, without interpreting it as markdown": "Sends a message as plain text, without interpreting it as markdown", @@ -1170,7 +1171,6 @@ "All Rooms": "All Rooms", "Search…": "Search…", "Server error": "Server error", - "Command error": "Command error", "Server unavailable, overloaded, or something else went wrong.": "Server unavailable, overloaded, or something else went wrong.", "Unknown Command": "Unknown Command", "Unrecognised command: %(commandText)s": "Unrecognised command: %(commandText)s", From ef80a0b0b473a4d2a422e6a811c2149340a1e4ca Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 16 Jun 2020 14:06:42 +0100 Subject: [PATCH 3/3] avoid negatives --- src/editor/serialize.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/editor/serialize.ts b/src/editor/serialize.ts index 40038114d4..fc35f1e2ea 100644 --- a/src/editor/serialize.ts +++ b/src/editor/serialize.ts @@ -62,15 +62,15 @@ export function textSerialize(model: EditorModel) { } export function containsEmote(model: EditorModel) { - return startsWith(model, "/me ", true); + return startsWith(model, "/me ", false); } -export function startsWith(model: EditorModel, prefix: string, caseInsensitive = false) { +export function startsWith(model: EditorModel, prefix: string, caseSensitive = true) { const firstPart = model.parts[0]; // part type will be "plain" while editing, // and "command" while composing a message. let text = firstPart && firstPart.text; - if (caseInsensitive) { + if (!caseSensitive) { prefix = prefix.toLowerCase(); text = text.toLowerCase(); }