From 6d375192208ed136c8b12dde5d2b3f38e74a072b Mon Sep 17 00:00:00 2001 From: LenAnderson Date: Mon, 8 Jan 2024 11:15:09 +0000 Subject: [PATCH] add /list-gallery command to gallery extension --- public/scripts/extensions/gallery/index.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/public/scripts/extensions/gallery/index.js b/public/scripts/extensions/gallery/index.js index e297c2589..815170897 100644 --- a/public/scripts/extensions/gallery/index.js +++ b/public/scripts/extensions/gallery/index.js @@ -4,7 +4,7 @@ import { characters, getRequestHeaders, } 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 { loadMovingUIState } from '../../power-user.js'; import { dragElement } from '../../RossAscends-mods.js'; @@ -416,7 +416,26 @@ function viewWithDragbox(items) { // Registers a simple command for opening the char gallery. registerSlashCommand('show-gallery', showGalleryCommand, ['sg'], '– shows the gallery', true, true); +registerSlashCommand('list-gallery', listGalleryCommand, ['lg'], '[optional char=charName] [optional group=groupName] – list images in the gallery of the current char / group or a specified char / group', true, true); function showGalleryCommand(args) { 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([]); +}