add /list-gallery command to gallery extension

This commit is contained in:
LenAnderson 2024-01-08 11:15:09 +00:00
parent 911428f545
commit 6d37519220
1 changed files with 20 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import {
characters, characters,
getRequestHeaders, getRequestHeaders,
} from '../../../script.js'; } from '../../../script.js';
import { selected_group } from '../../group-chats.js'; import { groups, selected_group } from '../../group-chats.js';
import { loadFileToDocument, delay } from '../../utils.js'; import { loadFileToDocument, delay } from '../../utils.js';
import { loadMovingUIState } from '../../power-user.js'; import { loadMovingUIState } from '../../power-user.js';
import { dragElement } from '../../RossAscends-mods.js'; import { dragElement } from '../../RossAscends-mods.js';
@ -416,7 +416,26 @@ function viewWithDragbox(items) {
// Registers a simple command for opening the char gallery. // Registers a simple command for opening the char gallery.
registerSlashCommand('show-gallery', showGalleryCommand, ['sg'], ' shows the gallery', true, true); registerSlashCommand('show-gallery', showGalleryCommand, ['sg'], ' shows the gallery', true, true);
registerSlashCommand('list-gallery', listGalleryCommand, ['lg'], '<span class="monospace">[optional char=charName] [optional group=groupName]</span> list images in the gallery of the current char / group or a specified char / group', true, true);
function showGalleryCommand(args) { function showGalleryCommand(args) {
showCharGallery(); showCharGallery();
} }
async function listGalleryCommand(args) {
try {
let url = args.char ?? (args.group ? groups.find(it=>it.name == args.group)?.id : null) ?? (selected_group || this_chid);
if (!args.char && !args.group && !selected_group && this_chid) {
const char = characters[this_chid];
url = char.avatar.replace('.png', '');
}
const items = await getGalleryItems(url);
return JSON.stringify(items.map(it=>it.src));
} catch (err) {
console.trace();
console.error(err);
}
return JSON.stringify([]);
}