mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
add command source indicator
This commit is contained in:
@ -63,6 +63,10 @@ export class SlashCommand {
|
||||
/**@type {Object.<string, HTMLElement>}*/ helpCache = {};
|
||||
/**@type {Object.<string, DocumentFragment>}*/ helpDetailsCache = {};
|
||||
|
||||
/**@type {boolean}*/ isExtension = false;
|
||||
/**@type {boolean}*/ isThirdParty = false;
|
||||
/**@type {string}*/ source;
|
||||
|
||||
renderHelpItem(key = null) {
|
||||
key = key ?? this.name;
|
||||
if (!this.helpCache[key]) {
|
||||
@ -227,12 +231,35 @@ export class SlashCommand {
|
||||
const aliasList = [cmd.name, ...(cmd.aliases ?? [])].filter(it=>it != key);
|
||||
const specs = document.createElement('div'); {
|
||||
specs.classList.add('specs');
|
||||
const name = document.createElement('div'); {
|
||||
name.classList.add('name');
|
||||
name.classList.add('monospace');
|
||||
name.title = 'command name';
|
||||
name.textContent = `/${key}`;
|
||||
specs.append(name);
|
||||
const head = document.createElement('div'); {
|
||||
head.classList.add('head');
|
||||
const name = document.createElement('div'); {
|
||||
name.classList.add('name');
|
||||
name.classList.add('monospace');
|
||||
name.title = 'command name';
|
||||
name.textContent = `/${key}`;
|
||||
head.append(name);
|
||||
}
|
||||
const src = document.createElement('div'); {
|
||||
src.classList.add('source');
|
||||
src.classList.add('fa-solid');
|
||||
if (this.isExtension) {
|
||||
src.classList.add('isExtension');
|
||||
src.classList.add('fa-cubes');
|
||||
if (this.isThirdParty) src.classList.add('isThirdParty');
|
||||
else src.classList.add('isCore');
|
||||
} else {
|
||||
src.classList.add('isCore');
|
||||
src.classList.add('fa-star-of-life');
|
||||
}
|
||||
src.title = [
|
||||
this.isExtension ? 'Extension' : 'Core',
|
||||
this.isThirdParty ? 'Third Party' : (this.isExtension ? 'Core' : null),
|
||||
this.source,
|
||||
].filter(it=>it).join('\n');
|
||||
head.append(src);
|
||||
}
|
||||
specs.append(head);
|
||||
}
|
||||
const body = document.createElement('div'); {
|
||||
body.classList.add('body');
|
||||
|
@ -73,6 +73,18 @@ export class SlashCommandParser {
|
||||
console.trace('WARN: Duplicate slash command registered!', [command.name, ...command.aliases]);
|
||||
}
|
||||
|
||||
const stack = new Error().stack.split('\n').map(it=>it.trim());
|
||||
command.isExtension = stack.find(it=>it.includes('/scripts/extensions/')) != null;
|
||||
command.isThirdParty = stack.find(it=>it.includes('/scripts/extensions/third-party/')) != null;
|
||||
if (command.isThirdParty) {
|
||||
command.source = stack.find(it=>it.includes('/scripts/extensions/third-party/')).replace(/^.*?\/scripts\/extensions\/third-party\/([^/]+)\/.*$/, '$1');
|
||||
} else if (command.isExtension) {
|
||||
command.source = stack.find(it=>it.includes('/scripts/extensions/')).replace(/^.*?\/scripts\/extensions\/([^/]+)\/.*$/, '$1');
|
||||
} else {
|
||||
const idx = stack.findLastIndex(it=>it.includes('at SlashCommandParser\.')) + 1;
|
||||
command.source = stack[idx].replace(/^.*?\/((?:scripts\/)?(?:[^/]+)\.js).*$/, '$1');
|
||||
}
|
||||
|
||||
this.commands[command.name] = command;
|
||||
|
||||
if (Array.isArray(command.aliases)) {
|
||||
|
Reference in New Issue
Block a user