Bind user names to avatars (create personas) and select personas for chats

This commit is contained in:
Cohee
2023-06-11 18:49:00 +03:00
parent 471bc6cb48
commit fc001b0b05
6 changed files with 250 additions and 23 deletions

View File

@@ -143,7 +143,9 @@ let power_user = {
output_sequence: '### Response:',
preset: 'Alpaca',
separator_sequence: '',
}
},
personas: {},
};
let themes = [];

View File

@@ -1,5 +1,6 @@
import {
addOneMessage,
autoSelectPersona,
characters,
chat,
chat_metadata,
@@ -11,11 +12,13 @@ import {
replaceBiasMarkup,
saveChatConditional,
sendSystemMessage,
setUserName,
substituteParams,
system_avatar,
system_message_types
} from "../script.js";
import { humanizedDateTime } from "./RossAscends-mods.js";
import { power_user } from "./power-user.js";
export {
executeSlashCommands,
registerSlashCommand,
@@ -93,6 +96,9 @@ const registerSlashCommand = parser.addCommand.bind(parser);
const getSlashCommandsHelp = parser.getHelpString.bind(parser);
parser.addCommand('help', helpCommandCallback, ['?'], ' displays this help message', true, true);
parser.addCommand('name', setNameCallback, ['persona'], '<span class="monospace">(name)</span> sets user name and persona avatar (if set)', true, true);
parser.addCommand('sync', syncCallback, [], ' syncs user name in user-attributed messages in the current chat', true, true);
parser.addCommand('bind', bindCallback, [], ' binds/unbinds a persona (name and avatar) to the current chat', true, true);
parser.addCommand('bg', setBackgroundCallback, ['background'], '<span class="monospace">(filename)</span> sets a background according to filename, partial names allowed, will set the first one alphabetically if multiple files begin with the provided argument string', false, true);
parser.addCommand('sendas', sendMessageAs, [], ` sends message as a specific character.<br>Example:<br><pre><code>/sendas Chloe\nHello, guys!</code></pre>will send "Hello, guys!" from "Chloe".<br>Uses character avatar if it exists in the characters list.`, true, true);
parser.addCommand('sys', sendNarratorMessage, [], '<span class="monospace">(text)</span> sends message as a system narrator', false, true);
@@ -101,6 +107,31 @@ parser.addCommand('sysname', setNarratorName, [], '<span class="monospace">(name
const NARRATOR_NAME_KEY = 'narrator_name';
const NARRATOR_NAME_DEFAULT = 'System';
function syncCallback() {
$('#sync_name_button').trigger('click');
}
function bindCallback() {
$('#lock_user_name').trigger('click');
}
function setNameCallback(_, name) {
if (!name) {
return;
}
name = name.trim();
// If the name is a persona, auto-select it
if (Object.values(power_user.personas).map(x => x.toLowerCase()).includes(name.toLowerCase())) {
autoSelectPersona(name);
}
// Otherwise, set just the name
else {
setUserName(name);
}
}
function setNarratorName(_, text) {
const name = text || NARRATOR_NAME_DEFAULT;
chat_metadata[NARRATOR_NAME_KEY] = name;