fix alias list in help string

This commit is contained in:
LenAnderson
2024-04-07 16:50:04 -04:00
parent 16e8037e7f
commit d1682350e3
3 changed files with 20 additions and 19 deletions

View File

@ -1909,13 +1909,26 @@ export function setSlashCommandAutoComplete(textarea, isFloating = false) {
; ;
result = helpStrings result = helpStrings
.filter((it,idx)=>[idx, -1].includes(helpStrings.indexOf(parser.commands[it].name.toLowerCase()))) // remove duplicates .filter((it,idx)=>[idx, -1].includes(helpStrings.indexOf(parser.commands[it].name.toLowerCase()))) // remove duplicates
.map(it => ({ .map(name => {
name: it, const cmd = parser.commands[name];
label: `${buildHelpStringName(it)}${parser.commands[it].helpStringFormattedWithoutName}`, let aliases = '';
value: `/${it}`, if (cmd.aliases?.length > 0) {
score: matchType == 'fuzzy' ? fuzzyScore(it) : null, aliases = ' (alias: ';
li: null, aliases += [cmd.name, ...cmd.aliases]
})) // Map to the help string and score .filter(it=>it != name)
.map(it=>`<span class="monospace">/${it}</span>`)
.join(', ')
;
aliases += ')';
}
return {
name: name,
label: `${buildHelpStringName(name)}${cmd.helpString}${aliases}`,
value: `/${name}`,
score: matchType == 'fuzzy' ? fuzzyScore(name) : null,
li: null,
};
}) // Map to the help string and score
.toSorted(matchType == 'fuzzy' ? fuzzyScoreCompare : (a, b) => a.name.localeCompare(b.name)) // sort by score (if fuzzy) or name .toSorted(matchType == 'fuzzy' ? fuzzyScoreCompare : (a, b) => a.name.localeCompare(b.name)) // sort by score (if fuzzy) or name
; ;
} }

View File

@ -2,8 +2,6 @@ export class SlashCommand {
/**@type {String}*/ name; /**@type {String}*/ name;
/**@type {Function}*/ callback; /**@type {Function}*/ callback;
/**@type {String}*/ helpString; /**@type {String}*/ helpString;
/**@type {String}*/ helpStringFormatted;
/**@type {String}*/ helpStringFormattedWithoutName;
/**@type {Boolean}*/ interruptsGeneration; /**@type {Boolean}*/ interruptsGeneration;
/**@type {Boolean}*/ purgeFromMessage; /**@type {Boolean}*/ purgeFromMessage;
/**@type {String[]}*/ aliases; /**@type {String[]}*/ aliases;

View File

@ -150,16 +150,6 @@ export class SlashCommandParser {
this.commands[alias] = fnObj; this.commands[alias] = fnObj;
}); });
} }
let stringBuilder = `${helpString} `;
if (Array.isArray(aliases) && aliases.length) {
let aliasesString = `(alias: ${aliases.map(x => `<span class="monospace">/${x}</span>`).join(', ')})`;
stringBuilder += aliasesString;
}
fnObj.helpStringFormattedWithoutName = stringBuilder;
stringBuilder = `<span class="monospace">/${command}</span> ${stringBuilder}`;
this.helpStrings[command] = stringBuilder;
fnObj.helpStringFormatted = stringBuilder;
} }
getHelpString() { getHelpString() {