Add /imagine-source command

a4d02bd967132ae913524a4e73ff93c397b9302b

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

1 files changed, +32 -0Showing whitespace changes
public/scripts/extensions/stable-diffusion/index.js+32 -0
@@ -4029,6 +4029,38 @@ jQuery(async () => {
40294029 }));
40304030
40314031 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
4032+ name: 'imagine-source',
4033+ aliases: ['sd-source', 'img-source'],
4034+ returns: 'a name of the current generation source',
4035+ unnamedArgumentList: [
4036+ SlashCommandArgument.fromProps({
4037+ description: 'source name',
4038+ typeList: [ARGUMENT_TYPE.STRING],
4039+ isRequired: false,
4040+ forceEnum: true,
4041+ enumProvider: () => Array.from(document.querySelectorAll('#sd_source > [value]')).map(x => new SlashCommandEnumValue(x.getAttribute('value'), x.textContent)),
4042+ }),
4043+ ],
4044+ helpString: 'If an argument is provided, change the source of the image generation, e.g. <code>/imagine-source comfy</code>. Returns the current source.',
4045+ callback: async (_args, name) => {
4046+ if (!name) {
4047+ return extension_settings.sd.source;
4048+ }
4049+ const isKnownSource = Object.keys(sources).includes(String(name));
4050+ if (!isKnownSource) {
4051+ throw new Error('The value provided is not a valid image generation source.');
4052+ }
4053+ const option = document.querySelector(`#sd_source [value="${name}"]`);
4054+ if (!(option instanceof HTMLOptionElement)) {
4055+ throw new Error('Could not find the source option in the dropdown.');
4056+ }
4057+ option.selected = true;
4058+ await onSourceChange();
4059+ return extension_settings.sd.source;
4060+ },
4061+ }))
4062+
4063+ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
40324064 name: 'imagine-comfy-workflow',
40334065 callback: changeComfyWorkflow,
40344066 aliases: ['icw'],