mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add comments to STscript
This commit is contained in:
@@ -51,6 +51,11 @@ export {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class SlashCommandParser {
|
class SlashCommandParser {
|
||||||
|
static COMMENT_KEYWORDS = ['#', '/'];
|
||||||
|
static RESERVED_KEYWORDS = [
|
||||||
|
...this.COMMENT_KEYWORDS,
|
||||||
|
];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.commands = {};
|
this.commands = {};
|
||||||
this.helpStrings = {};
|
this.helpStrings = {};
|
||||||
@@ -59,6 +64,11 @@ class SlashCommandParser {
|
|||||||
addCommand(command, callback, aliases, helpString = '', interruptsGeneration = false, purgeFromMessage = true) {
|
addCommand(command, callback, aliases, helpString = '', interruptsGeneration = false, purgeFromMessage = true) {
|
||||||
const fnObj = { callback, helpString, interruptsGeneration, purgeFromMessage };
|
const fnObj = { callback, helpString, interruptsGeneration, purgeFromMessage };
|
||||||
|
|
||||||
|
if ([command, ...aliases].some(x => SlashCommandParser.RESERVED_KEYWORDS.includes(x))) {
|
||||||
|
console.error('ERROR: Reserved slash command keyword used!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ([command, ...aliases].some(x => Object.hasOwn(this.commands, x))) {
|
if ([command, ...aliases].some(x => Object.hasOwn(this.commands, x))) {
|
||||||
console.trace('WARN: Duplicate slash command registered!');
|
console.trace('WARN: Duplicate slash command registered!');
|
||||||
}
|
}
|
||||||
@@ -1735,6 +1745,11 @@ async function executeSlashCommands(text, unescape = false) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip comment commands. They don't run macros or interrupt pipes.
|
||||||
|
if (SlashCommandParser.COMMENT_KEYWORDS.includes(result.command)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (result.value && typeof result.value === 'string') {
|
if (result.value && typeof result.value === 'string') {
|
||||||
result.value = substituteParams(result.value.trim());
|
result.value = substituteParams(result.value.trim());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user