mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
add "/:name" as shorthand for "/run name" after all
This commit is contained in:
@ -225,7 +225,11 @@ export class SlashCommandParser {
|
|||||||
this.discardWhitespace();
|
this.discardWhitespace();
|
||||||
}
|
}
|
||||||
while (!this.testClosureEnd()) {
|
while (!this.testClosureEnd()) {
|
||||||
if (this.testCommand()) {
|
if (this.testRunShorthand()) {
|
||||||
|
const cmd = this.parseRunShorthand();
|
||||||
|
closure.executorList.push(cmd);
|
||||||
|
injectPipe = true;
|
||||||
|
} else if (this.testCommand()) {
|
||||||
const cmd = this.parseCommand();
|
const cmd = this.parseCommand();
|
||||||
cmd.injectPipe = injectPipe;
|
cmd.injectPipe = injectPipe;
|
||||||
closure.executorList.push(cmd);
|
closure.executorList.push(cmd);
|
||||||
@ -254,6 +258,39 @@ export class SlashCommandParser {
|
|||||||
return closure;
|
return closure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testRunShorthand() {
|
||||||
|
return this.char == '/' && this.behind.slice(-1) != '\\' && this.ahead[0] == ':';
|
||||||
|
}
|
||||||
|
testRunShorthandEnd() {
|
||||||
|
return this.testCommandEnd();
|
||||||
|
}
|
||||||
|
parseRunShorthand() {
|
||||||
|
const start = this.index;
|
||||||
|
const cmd = new SlashCommandExecutor(start);
|
||||||
|
cmd.name = 'run';
|
||||||
|
cmd.value = '';
|
||||||
|
cmd.command = this.commands[cmd.name];
|
||||||
|
this.commandIndex.push(cmd);
|
||||||
|
this.take(2); //discard "/:"
|
||||||
|
while (!/\s/.test(this.char) && !this.testCommandEnd()) cmd.value += this.take(); // take chars until whitespace or end
|
||||||
|
this.discardWhitespace();
|
||||||
|
while (this.testNamedArgument()) {
|
||||||
|
const arg = this.parseNamedArgument();
|
||||||
|
cmd.args[arg.key] = arg.value;
|
||||||
|
this.discardWhitespace();
|
||||||
|
}
|
||||||
|
this.discardWhitespace();
|
||||||
|
// /run shorthand does not take unnamed arguments (the command name practically *is* the unnamed argument)
|
||||||
|
if (this.testCommandEnd()) {
|
||||||
|
cmd.end = this.index;
|
||||||
|
if (!cmd.command?.purgeFromMessage) this.keptText += this.text.slice(cmd.start, cmd.end);
|
||||||
|
return cmd;
|
||||||
|
} else {
|
||||||
|
console.warn(this.behind, this.char, this.ahead);
|
||||||
|
throw new SlashCommandParserError(`Unexpected end of command at position ${this.index - 2}: "/${cmd.name}"`, this.text, this.index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
testCommand() {
|
testCommand() {
|
||||||
return this.char == '/' && this.behind.slice(-1) != '\\' && !['/', '#'].includes(this.ahead[0]);
|
return this.char == '/' && this.behind.slice(-1) != '\\' && !['/', '#'].includes(this.ahead[0]);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user