Add opt-in for rawQuotes in SlashCommand registration Closes #2739 Supersedes #2921

533aeffa369ef4f61b961323c7578a13c6440d38

Cohee <18619528+Cohee1207@users.noreply.github.com>

3 files changed, +10 -3Ignore whitespace
public/scripts/slash-commands.js+5 -0
@@ -227,6 +227,7 @@ export function initDefaultSlashCommands() {
227 }));227 }));
228 SlashCommandParser.addCommandObject(SlashCommand.fromProps({228 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
229 name: 'sendas',229 name: 'sendas',
230 rawQuotes: true,
230 callback: sendMessageAs,231 callback: sendMessageAs,
231 returns: 'Optionally the text of the sent message, if specified in the "return" argument',232 returns: 'Optionally the text of the sent message, if specified in the "return" argument',
232 namedArgumentList: [233 namedArgumentList: [
@@ -293,6 +294,7 @@ export function initDefaultSlashCommands() {
293 }));294 }));
294 SlashCommandParser.addCommandObject(SlashCommand.fromProps({295 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
295 name: 'sys',296 name: 'sys',
297 rawQuotes: true,
296 callback: sendNarratorMessage,298 callback: sendNarratorMessage,
297 aliases: ['nar'],299 aliases: ['nar'],
298 returns: 'Optionally the text of the sent message, if specified in the "return" argument',300 returns: 'Optionally the text of the sent message, if specified in the "return" argument',
@@ -357,6 +359,7 @@ export function initDefaultSlashCommands() {
357 }));359 }));
358 SlashCommandParser.addCommandObject(SlashCommand.fromProps({360 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
359 name: 'comment',361 name: 'comment',
362 rawQuotes: true,
360 callback: sendCommentMessage,363 callback: sendCommentMessage,
361 returns: 'Optionally the text of the sent message, if specified in the "return" argument',364 returns: 'Optionally the text of the sent message, if specified in the "return" argument',
362 namedArgumentList: [365 namedArgumentList: [
@@ -574,6 +577,7 @@ export function initDefaultSlashCommands() {
574 }));577 }));
575 SlashCommandParser.addCommandObject(SlashCommand.fromProps({578 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
576 name: 'send',579 name: 'send',
580 rawQuotes: true,
577 callback: sendUserMessageCallback,581 callback: sendUserMessageCallback,
578 returns: 'Optionally the text of the sent message, if specified in the "return" argument',582 returns: 'Optionally the text of the sent message, if specified in the "return" argument',
579 namedArgumentList: [583 namedArgumentList: [
@@ -936,6 +940,7 @@ export function initDefaultSlashCommands() {
936 }));940 }));
937 SlashCommandParser.addCommandObject(SlashCommand.fromProps({941 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
938 name: 'echo',942 name: 'echo',
943 rawQuotes: true,
939 callback: echoCallback,944 callback: echoCallback,
940 returns: 'the text',945 returns: 'the text',
941 namedArgumentList: [946 namedArgumentList: [
public/scripts/slash-commands/SlashCommand.js+2 -0
@@ -36,6 +36,7 @@ export class SlashCommand {
36 * @param {string} [props.helpString]36 * @param {string} [props.helpString]
37 * @param {boolean} [props.splitUnnamedArgument]37 * @param {boolean} [props.splitUnnamedArgument]
38 * @param {Number} [props.splitUnnamedArgumentCount]38 * @param {Number} [props.splitUnnamedArgumentCount]
39 * @param {boolean} [props.rawQuotes]
39 * @param {string[]} [props.aliases]40 * @param {string[]} [props.aliases]
40 * @param {string} [props.returns]41 * @param {string} [props.returns]
41 * @param {SlashCommandNamedArgument[]} [props.namedArgumentList]42 * @param {SlashCommandNamedArgument[]} [props.namedArgumentList]
@@ -54,6 +55,7 @@ export class SlashCommand {
54 /**@type {string}*/ helpString;55 /**@type {string}*/ helpString;
55 /**@type {boolean}*/ splitUnnamedArgument = false;56 /**@type {boolean}*/ splitUnnamedArgument = false;
56 /**@type {Number}*/ splitUnnamedArgumentCount;57 /**@type {Number}*/ splitUnnamedArgumentCount;
58 /** @type {boolean} */ rawQuotes = false;
57 /**@type {string[]}*/ aliases = [];59 /**@type {string[]}*/ aliases = [];
58 /**@type {string}*/ returns;60 /**@type {string}*/ returns;
59 /**@type {SlashCommandNamedArgument[]}*/ namedArgumentList = [];61 /**@type {SlashCommandNamedArgument[]}*/ namedArgumentList = [];
public/scripts/slash-commands/SlashCommandParser.js+3 -3
@@ -975,7 +975,7 @@ export class SlashCommandParser {
975 cmd.startUnnamedArgs = this.index - (/\s(\s*)$/s.exec(this.behind)?.[1]?.length ?? 0);975 cmd.startUnnamedArgs = this.index - (/\s(\s*)$/s.exec(this.behind)?.[1]?.length ?? 0);
976 cmd.endUnnamedArgs = this.index;976 cmd.endUnnamedArgs = this.index;
977 if (this.testUnnamedArgument()) {977 if (this.testUnnamedArgument()) {
978 cmd.unnamedArgumentList = this.parseUnnamedArgument(cmd.command?.unnamedArgumentList?.length && cmd?.command?.splitUnnamedArgument, cmd?.command?.splitUnnamedArgumentCount);978 cmd.unnamedArgumentList = this.parseUnnamedArgument(cmd.command?.unnamedArgumentList?.length && cmd?.command?.splitUnnamedArgument, cmd?.command?.splitUnnamedArgumentCount, cmd?.command?.rawQuotes);
979 cmd.endUnnamedArgs = this.index;979 cmd.endUnnamedArgs = this.index;
980 if (cmd.name == 'let') {980 if (cmd.name == 'let') {
981 const keyArg = cmd.namedArgumentList.find(it=>it.name == 'key');981 const keyArg = cmd.namedArgumentList.find(it=>it.name == 'key');
@@ -1035,7 +1035,7 @@ export class SlashCommandParser {
1035 testUnnamedArgumentEnd() {1035 testUnnamedArgumentEnd() {
1036 return this.testCommandEnd();1036 return this.testCommandEnd();
1037 }1037 }
1038 parseUnnamedArgument(split, splitCount = null) {1038 parseUnnamedArgument(split, splitCount = null, rawQuotes = false) {
1039 const wasSplit = split;1039 const wasSplit = split;
1040 /**@type {SlashCommandClosure|String}*/1040 /**@type {SlashCommandClosure|String}*/
1041 let value = this.jumpedEscapeSequence ? this.take() : ''; // take the first, already tested, char if it is an escaped one1041 let value = this.jumpedEscapeSequence ? this.take() : ''; // take the first, already tested, char if it is an escaped one
@@ -1045,7 +1045,7 @@ export class SlashCommandParser {
1045 /**@type {SlashCommandUnnamedArgumentAssignment}*/1045 /**@type {SlashCommandUnnamedArgumentAssignment}*/
1046 let assignment = new SlashCommandUnnamedArgumentAssignment();1046 let assignment = new SlashCommandUnnamedArgumentAssignment();
1047 assignment.start = this.index;1047 assignment.start = this.index;
1048 if (!split && this.testQuotedValue()) {1048 if (!split && !rawQuotes && this.testQuotedValue()) {
1049 // if the next bit is a quoted value, take the whole value and gather contents as a list1049 // if the next bit is a quoted value, take the whole value and gather contents as a list
1050 assignment.value = this.parseQuotedValue();1050 assignment.value = this.parseQuotedValue();
1051 assignment.end = this.index;1051 assignment.end = this.index;