Add comments to STscript

This commit is contained in:
Cohee 2024-03-25 14:22:39 +02:00
parent 101693ba99
commit 5e8999cc43

View File

@ -51,6 +51,11 @@ export {
};
class SlashCommandParser {
static COMMENT_KEYWORDS = ['#', '/'];
static RESERVED_KEYWORDS = [
...this.COMMENT_KEYWORDS,
];
constructor() {
this.commands = {};
this.helpStrings = {};
@ -59,6 +64,11 @@ class SlashCommandParser {
addCommand(command, callback, aliases, helpString = '', interruptsGeneration = false, purgeFromMessage = true) {
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))) {
console.trace('WARN: Duplicate slash command registered!');
}
@ -1735,6 +1745,11 @@ async function executeSlashCommands(text, unescape = false) {
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') {
result.value = substituteParams(result.value.trim());
}