Add opt-in for rawQuotes in SlashCommand registration

Closes #2739
Supersedes #2921
This commit is contained in:
Cohee
2025-03-27 23:22:38 +02:00
parent 0a85178846
commit 533aeffa36
3 changed files with 10 additions and 3 deletions

View File

@ -227,6 +227,7 @@ export function initDefaultSlashCommands() {
})); }));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'sendas', name: 'sendas',
rawQuotes: true,
callback: sendMessageAs, callback: sendMessageAs,
returns: 'Optionally the text of the sent message, if specified in the "return" argument', returns: 'Optionally the text of the sent message, if specified in the "return" argument',
namedArgumentList: [ namedArgumentList: [
@ -293,6 +294,7 @@ export function initDefaultSlashCommands() {
})); }));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'sys', name: 'sys',
rawQuotes: true,
callback: sendNarratorMessage, callback: sendNarratorMessage,
aliases: ['nar'], aliases: ['nar'],
returns: 'Optionally the text of the sent message, if specified in the "return" argument', returns: 'Optionally the text of the sent message, if specified in the "return" argument',
@ -357,6 +359,7 @@ export function initDefaultSlashCommands() {
})); }));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'comment', name: 'comment',
rawQuotes: true,
callback: sendCommentMessage, callback: sendCommentMessage,
returns: 'Optionally the text of the sent message, if specified in the "return" argument', returns: 'Optionally the text of the sent message, if specified in the "return" argument',
namedArgumentList: [ namedArgumentList: [
@ -574,6 +577,7 @@ export function initDefaultSlashCommands() {
})); }));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'send', name: 'send',
rawQuotes: true,
callback: sendUserMessageCallback, callback: sendUserMessageCallback,
returns: 'Optionally the text of the sent message, if specified in the "return" argument', returns: 'Optionally the text of the sent message, if specified in the "return" argument',
namedArgumentList: [ namedArgumentList: [
@ -936,6 +940,7 @@ export function initDefaultSlashCommands() {
})); }));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'echo', name: 'echo',
rawQuotes: true,
callback: echoCallback, callback: echoCallback,
returns: 'the text', returns: 'the text',
namedArgumentList: [ namedArgumentList: [

View File

@ -36,6 +36,7 @@ export class SlashCommand {
* @param {string} [props.helpString] * @param {string} [props.helpString]
* @param {boolean} [props.splitUnnamedArgument] * @param {boolean} [props.splitUnnamedArgument]
* @param {Number} [props.splitUnnamedArgumentCount] * @param {Number} [props.splitUnnamedArgumentCount]
* @param {boolean} [props.rawQuotes]
* @param {string[]} [props.aliases] * @param {string[]} [props.aliases]
* @param {string} [props.returns] * @param {string} [props.returns]
* @param {SlashCommandNamedArgument[]} [props.namedArgumentList] * @param {SlashCommandNamedArgument[]} [props.namedArgumentList]
@ -54,6 +55,7 @@ export class SlashCommand {
/**@type {string}*/ helpString; /**@type {string}*/ helpString;
/**@type {boolean}*/ splitUnnamedArgument = false; /**@type {boolean}*/ splitUnnamedArgument = false;
/**@type {Number}*/ splitUnnamedArgumentCount; /**@type {Number}*/ splitUnnamedArgumentCount;
/** @type {boolean} */ rawQuotes = false;
/**@type {string[]}*/ aliases = []; /**@type {string[]}*/ aliases = [];
/**@type {string}*/ returns; /**@type {string}*/ returns;
/**@type {SlashCommandNamedArgument[]}*/ namedArgumentList = []; /**@type {SlashCommandNamedArgument[]}*/ namedArgumentList = [];

View File

@ -975,7 +975,7 @@ export class SlashCommandParser {
cmd.startUnnamedArgs = this.index - (/\s(\s*)$/s.exec(this.behind)?.[1]?.length ?? 0); cmd.startUnnamedArgs = this.index - (/\s(\s*)$/s.exec(this.behind)?.[1]?.length ?? 0);
cmd.endUnnamedArgs = this.index; cmd.endUnnamedArgs = this.index;
if (this.testUnnamedArgument()) { if (this.testUnnamedArgument()) {
cmd.unnamedArgumentList = this.parseUnnamedArgument(cmd.command?.unnamedArgumentList?.length && cmd?.command?.splitUnnamedArgument, cmd?.command?.splitUnnamedArgumentCount); cmd.unnamedArgumentList = this.parseUnnamedArgument(cmd.command?.unnamedArgumentList?.length && cmd?.command?.splitUnnamedArgument, cmd?.command?.splitUnnamedArgumentCount, cmd?.command?.rawQuotes);
cmd.endUnnamedArgs = this.index; cmd.endUnnamedArgs = this.index;
if (cmd.name == 'let') { if (cmd.name == 'let') {
const keyArg = cmd.namedArgumentList.find(it=>it.name == 'key'); const keyArg = cmd.namedArgumentList.find(it=>it.name == 'key');
@ -1035,7 +1035,7 @@ export class SlashCommandParser {
testUnnamedArgumentEnd() { testUnnamedArgumentEnd() {
return this.testCommandEnd(); return this.testCommandEnd();
} }
parseUnnamedArgument(split, splitCount = null) { parseUnnamedArgument(split, splitCount = null, rawQuotes = false) {
const wasSplit = split; const wasSplit = split;
/**@type {SlashCommandClosure|String}*/ /**@type {SlashCommandClosure|String}*/
let value = this.jumpedEscapeSequence ? this.take() : ''; // take the first, already tested, char if it is an escaped one 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 {
/**@type {SlashCommandUnnamedArgumentAssignment}*/ /**@type {SlashCommandUnnamedArgumentAssignment}*/
let assignment = new SlashCommandUnnamedArgumentAssignment(); let assignment = new SlashCommandUnnamedArgumentAssignment();
assignment.start = this.index; assignment.start = this.index;
if (!split && this.testQuotedValue()) { if (!split && !rawQuotes && this.testQuotedValue()) {
// if the next bit is a quoted value, take the whole value and gather contents as a list // if the next bit is a quoted value, take the whole value and gather contents as a list
assignment.value = this.parseQuotedValue(); assignment.value = this.parseQuotedValue();
assignment.end = this.index; assignment.end = this.index;