This commit is contained in:
Louis Mazin 2026-04-16 17:53:07 +02:00
parent c3b8a5a563
commit d23d49d7c3
2 changed files with 29 additions and 10 deletions

View File

@ -56,9 +56,11 @@ client.once('clientReady', async () => {
});
client.on(Events.InteractionCreate, async interaction => {
if (interaction.isStringSelectMenu()) {
await handlePinboardSelection(interaction);
return;
if (interaction.isStringSelectMenu() || interaction.isButton()) {
const handled = await handlePinboardSelection(interaction);
if (handled) {
return;
}
}
if (!interaction.isChatInputCommand()) return;

View File

@ -13,6 +13,7 @@ const preloadedImagesByUrl = new Map();
const warmedMessageIds = new Set();
const warmingMessageIds = new Set();
let lastKnownStatus = null;
let imageRefreshKey = Date.now();
const getCacheBustValue = () => {
const bucketSeconds = Number.parseInt(process.env.PINBOARD_CACHE_BUST_SECONDS || '60', 10);
@ -29,6 +30,15 @@ const toCacheBustedUrl = (url) => {
return `${url}${separator}cb=${getCacheBustValue()}`;
};
const toRefreshKeyedUrl = (url, refreshKey) => {
if (!refreshKey) {
return url;
}
const separator = url.includes('?') ? '&' : '?';
return `${url}${separator}rk=${refreshKey}`;
};
const readPinboardRawFromEnvFile = () => {
try {
const envPath = path.join(process.cwd(), '.env');
@ -195,7 +205,8 @@ const runVisualWarmup = async (message, status, pinboardItems, initialIndex) =>
const payload = buildPanelPayload(status, message.id, pinboardItems, {
useAttachmentForSelected: false,
disableCacheBustForSelected: true,
includeFiles: false
includeFiles: false,
refreshKey: imageRefreshKey
});
await message.edit(payload);
await waitMs(delayMs);
@ -205,7 +216,8 @@ const runVisualWarmup = async (message, status, pinboardItems, initialIndex) =>
const restoredPayload = buildPanelPayload(status, message.id, pinboardItems, {
useAttachmentForSelected: false,
disableCacheBustForSelected: true,
includeFiles: false
includeFiles: false,
refreshKey: imageRefreshKey
});
await message.edit(restoredPayload);
@ -221,10 +233,11 @@ const runVisualWarmup = async (message, status, pinboardItems, initialIndex) =>
const buildSelectedImageEmbed = (item, imageReference, options = {}) => {
const useAttachment = options.useAttachment !== false;
const disableCacheBust = options.disableCacheBust === true;
const refreshKey = options.refreshKey || null;
const imageUrl = useAttachment && imageReference?.attachmentName
? `attachment://${imageReference.attachmentName}`
: (disableCacheBust ? item.url : toCacheBustedUrl(item.url));
: toRefreshKeyedUrl(disableCacheBust ? item.url : toCacheBustedUrl(item.url), refreshKey);
return new EmbedBuilder()
.setColor('#f59e0b')
@ -329,7 +342,8 @@ const buildPanelPayload = (status, messageId, pinboardItems = null, options = {}
const cachedImage = preloadedImagesByUrl.get(selectedItem.url);
const selectedImageEmbed = buildSelectedImageEmbed(selectedItem, cachedImage, {
useAttachment: options.useAttachmentForSelected,
disableCacheBust: options.disableCacheBustForSelected
disableCacheBust: options.disableCacheBustForSelected,
refreshKey: options.refreshKey
});
const selectorRow = buildImageSelectorRow(items, currentIndex);
const navigationRow = buildImageNavigationRow(items, currentIndex);
@ -383,6 +397,7 @@ const update = async (client) => {
}
const pinboardItems = parsePinboardImageItems().slice(0, 25);
imageRefreshKey = Date.now();
const [status] = await Promise.all([
getMinecraftStatus(),
preloadPinboardImages(pinboardItems)
@ -391,9 +406,10 @@ const update = async (client) => {
const { message } = await resolvePanelMessage(client, channelId, messageId);
const payload = buildPanelPayload(status, message.id, pinboardItems, {
useAttachmentForSelected: true,
useAttachmentForSelected: false,
disableCacheBustForSelected: false,
includeFiles: true
includeFiles: false,
refreshKey: imageRefreshKey
});
await message.edit(payload);
@ -443,7 +459,8 @@ const handlePinboardSelection = async (interaction) => {
const payload = buildPanelPayload(status, interaction.message.id, pinboardItems, {
useAttachmentForSelected: false,
disableCacheBustForSelected: true,
includeFiles: false
includeFiles: false,
refreshKey: imageRefreshKey
});
await interaction.update(payload);
return true;