mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-02 19:07:40 +01:00
Update /persona slash command with arguments
This commit is contained in:
parent
ea21de89c3
commit
9fb9253dcc
@ -84,15 +84,21 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
|||||||
helpString: 'Get help on macros, chat formatting and commands.',
|
helpString: 'Get help on macros, chat formatting and commands.',
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
name: 'name',
|
name: 'persona',
|
||||||
callback: setNameCallback,
|
callback: setNameCallback,
|
||||||
unnamedArgumentList: [
|
namedArgumentList: [
|
||||||
new SlashCommandArgument(
|
new SlashCommandNamedArgument(
|
||||||
'persona', [ARGUMENT_TYPE.STRING], true,
|
'mode', 'The mode for persona selection. ("lookup" = search for existing persona, "temp" = create a temporary name, set a temporary name, "all" = allow both in the same command)',
|
||||||
|
[ARGUMENT_TYPE.STRING], false, false, 'all', ['lookup', 'temp', 'all'],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
helpString: 'Sets user name and persona avatar (if set).',
|
unnamedArgumentList: [
|
||||||
aliases: ['persona'],
|
new SlashCommandArgument(
|
||||||
|
'persona name', [ARGUMENT_TYPE.STRING], true,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
helpString: 'Selects the given persona with its name and avatar (by name or avatar url). If no matching persona exists, applies a temporary name.',
|
||||||
|
aliases: ['name'],
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
name: 'sync',
|
name: 'sync',
|
||||||
@ -2372,27 +2378,45 @@ function setFlatModeCallback() {
|
|||||||
$('#chat_display').val(chat_styles.DEFAULT).trigger('change');
|
$('#chat_display').val(chat_styles.DEFAULT).trigger('change');
|
||||||
}
|
}
|
||||||
|
|
||||||
function setNameCallback(_, name) {
|
/**
|
||||||
|
*
|
||||||
|
* @param {{mode: 'lookup' | 'temp' | 'all'}} namedArgs
|
||||||
|
* @param {string} name
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
function setNameCallback({ mode = 'all' }, name) {
|
||||||
if (!name) {
|
if (!name) {
|
||||||
toastr.warning('you must specify a name to change to');
|
toastr.warning('you must specify a name to change to');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!['lookup', 'temp', 'all'].includes(mode)) {
|
||||||
|
toastr.warning('mode must be one of "lookup", "temp" or "all"');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
name = name.trim();
|
name = name.trim();
|
||||||
|
|
||||||
// If the name is a persona, auto-select it
|
// If the name matches a persona avatar, or a name, auto-select it
|
||||||
for (let persona of Object.values(power_user.personas)) {
|
if (['lookup', 'all'].includes(mode)) {
|
||||||
if (persona.toLowerCase() === name.toLowerCase()) {
|
let persona = Object.entries(power_user.personas).find(([avatar, _]) => avatar === name)?.[1];
|
||||||
autoSelectPersona(name);
|
if (!persona) persona = Object.entries(power_user.personas).find(([_, personaName]) => personaName.toLowerCase() === name.toLowerCase())?.[1];
|
||||||
|
if (persona) {
|
||||||
|
autoSelectPersona(persona);
|
||||||
retriggerFirstMessageOnEmptyChat();
|
retriggerFirstMessageOnEmptyChat();
|
||||||
return;
|
return;
|
||||||
|
} else if (mode === 'lookup') {
|
||||||
|
toastr.warning(`Persona ${name} not found`);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (['temp', 'all'].includes(mode)) {
|
||||||
// Otherwise, set just the name
|
// Otherwise, set just the name
|
||||||
setUserName(name); //this prevented quickReply usage
|
setUserName(name); //this prevented quickReply usage
|
||||||
retriggerFirstMessageOnEmptyChat();
|
retriggerFirstMessageOnEmptyChat();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function setNarratorName(_, text) {
|
async function setNarratorName(_, text) {
|
||||||
const name = text || NARRATOR_NAME_DEFAULT;
|
const name = text || NARRATOR_NAME_DEFAULT;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user