{{charPrefix}} is real.

7a6c930adccf7f2853c52c05c6b9fed5e13cd113

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +27 -0Ignore whitespace
public/scripts/extensions/stable-diffusion/index.js+27 -0
@@ -56,6 +56,8 @@ import { SlashCommandEnumValue } from '../../slash-commands/SlashCommandEnumValu
5656import { callGenericPopup, Popup, POPUP_RESULT, POPUP_TYPE } from '../../popup.js';
5757import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
5858import { ToolManager } from '../../tool-calling.js';
59+import { MacrosParser } from '../../macros.js';
60+import { t } from '../../i18n.js';
5961
6062export { MODULE_NAME };
6163
@@ -4548,4 +4550,29 @@ jQuery(async () => {
45484550
45494551 await loadSettings();
45504552 $('body').addClass('sd');
4553+
4554+ const getMacroValue = ({ isNegative }) => {
4555+ if (selected_group || this_chid === undefined) {
4556+ return '';
4557+ }
4558+
4559+ const key = getCharaFilename(this_chid);
4560+ let characterPrompt = key ? (extension_settings.sd.character_prompts[key] || '') : '';
4561+ let negativePrompt = key ? (extension_settings.sd.character_negative_prompts[key] || '') : '';
4562+
4563+ const context = getContext();
4564+ const sharedPromptData = context?.characters[this_chid]?.data?.extensions?.sd_character_prompt;
4565+
4566+ if (typeof sharedPromptData?.positive === 'string' && !characterPrompt && sharedPromptData.positive) {
4567+ characterPrompt = sharedPromptData.positive || '';
4568+ }
4569+ if (typeof sharedPromptData?.negative === 'string' && !negativePrompt && sharedPromptData.negative) {
4570+ negativePrompt = sharedPromptData.negative || '';
4571+ }
4572+
4573+ return isNegative ? negativePrompt : characterPrompt;
4574+ };
4575+
4576+ MacrosParser.registerMacro('charPrefix', () => getMacroValue({ isNegative: false }), t`Character's positive positive Image Generation prompt prefix`);
4577+ MacrosParser.registerMacro('charNegativePrefix', () => getMacroValue({ isNegative: true }), t`Character's negative Image Generation prompt prefix`);
45514578});