test
This commit is contained in:
parent
c3b8a5a563
commit
d23d49d7c3
6
index.js
6
index.js
@ -56,10 +56,12 @@ client.once('clientReady', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.on(Events.InteractionCreate, async interaction => {
|
client.on(Events.InteractionCreate, async interaction => {
|
||||||
if (interaction.isStringSelectMenu()) {
|
if (interaction.isStringSelectMenu() || interaction.isButton()) {
|
||||||
await handlePinboardSelection(interaction);
|
const handled = await handlePinboardSelection(interaction);
|
||||||
|
if (handled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!interaction.isChatInputCommand()) return;
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ const preloadedImagesByUrl = new Map();
|
|||||||
const warmedMessageIds = new Set();
|
const warmedMessageIds = new Set();
|
||||||
const warmingMessageIds = new Set();
|
const warmingMessageIds = new Set();
|
||||||
let lastKnownStatus = null;
|
let lastKnownStatus = null;
|
||||||
|
let imageRefreshKey = Date.now();
|
||||||
|
|
||||||
const getCacheBustValue = () => {
|
const getCacheBustValue = () => {
|
||||||
const bucketSeconds = Number.parseInt(process.env.PINBOARD_CACHE_BUST_SECONDS || '60', 10);
|
const bucketSeconds = Number.parseInt(process.env.PINBOARD_CACHE_BUST_SECONDS || '60', 10);
|
||||||
@ -29,6 +30,15 @@ const toCacheBustedUrl = (url) => {
|
|||||||
return `${url}${separator}cb=${getCacheBustValue()}`;
|
return `${url}${separator}cb=${getCacheBustValue()}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toRefreshKeyedUrl = (url, refreshKey) => {
|
||||||
|
if (!refreshKey) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
const separator = url.includes('?') ? '&' : '?';
|
||||||
|
return `${url}${separator}rk=${refreshKey}`;
|
||||||
|
};
|
||||||
|
|
||||||
const readPinboardRawFromEnvFile = () => {
|
const readPinboardRawFromEnvFile = () => {
|
||||||
try {
|
try {
|
||||||
const envPath = path.join(process.cwd(), '.env');
|
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, {
|
const payload = buildPanelPayload(status, message.id, pinboardItems, {
|
||||||
useAttachmentForSelected: false,
|
useAttachmentForSelected: false,
|
||||||
disableCacheBustForSelected: true,
|
disableCacheBustForSelected: true,
|
||||||
includeFiles: false
|
includeFiles: false,
|
||||||
|
refreshKey: imageRefreshKey
|
||||||
});
|
});
|
||||||
await message.edit(payload);
|
await message.edit(payload);
|
||||||
await waitMs(delayMs);
|
await waitMs(delayMs);
|
||||||
@ -205,7 +216,8 @@ const runVisualWarmup = async (message, status, pinboardItems, initialIndex) =>
|
|||||||
const restoredPayload = buildPanelPayload(status, message.id, pinboardItems, {
|
const restoredPayload = buildPanelPayload(status, message.id, pinboardItems, {
|
||||||
useAttachmentForSelected: false,
|
useAttachmentForSelected: false,
|
||||||
disableCacheBustForSelected: true,
|
disableCacheBustForSelected: true,
|
||||||
includeFiles: false
|
includeFiles: false,
|
||||||
|
refreshKey: imageRefreshKey
|
||||||
});
|
});
|
||||||
await message.edit(restoredPayload);
|
await message.edit(restoredPayload);
|
||||||
|
|
||||||
@ -221,10 +233,11 @@ const runVisualWarmup = async (message, status, pinboardItems, initialIndex) =>
|
|||||||
const buildSelectedImageEmbed = (item, imageReference, options = {}) => {
|
const buildSelectedImageEmbed = (item, imageReference, options = {}) => {
|
||||||
const useAttachment = options.useAttachment !== false;
|
const useAttachment = options.useAttachment !== false;
|
||||||
const disableCacheBust = options.disableCacheBust === true;
|
const disableCacheBust = options.disableCacheBust === true;
|
||||||
|
const refreshKey = options.refreshKey || null;
|
||||||
|
|
||||||
const imageUrl = useAttachment && imageReference?.attachmentName
|
const imageUrl = useAttachment && imageReference?.attachmentName
|
||||||
? `attachment://${imageReference.attachmentName}`
|
? `attachment://${imageReference.attachmentName}`
|
||||||
: (disableCacheBust ? item.url : toCacheBustedUrl(item.url));
|
: toRefreshKeyedUrl(disableCacheBust ? item.url : toCacheBustedUrl(item.url), refreshKey);
|
||||||
|
|
||||||
return new EmbedBuilder()
|
return new EmbedBuilder()
|
||||||
.setColor('#f59e0b')
|
.setColor('#f59e0b')
|
||||||
@ -329,7 +342,8 @@ const buildPanelPayload = (status, messageId, pinboardItems = null, options = {}
|
|||||||
const cachedImage = preloadedImagesByUrl.get(selectedItem.url);
|
const cachedImage = preloadedImagesByUrl.get(selectedItem.url);
|
||||||
const selectedImageEmbed = buildSelectedImageEmbed(selectedItem, cachedImage, {
|
const selectedImageEmbed = buildSelectedImageEmbed(selectedItem, cachedImage, {
|
||||||
useAttachment: options.useAttachmentForSelected,
|
useAttachment: options.useAttachmentForSelected,
|
||||||
disableCacheBust: options.disableCacheBustForSelected
|
disableCacheBust: options.disableCacheBustForSelected,
|
||||||
|
refreshKey: options.refreshKey
|
||||||
});
|
});
|
||||||
const selectorRow = buildImageSelectorRow(items, currentIndex);
|
const selectorRow = buildImageSelectorRow(items, currentIndex);
|
||||||
const navigationRow = buildImageNavigationRow(items, currentIndex);
|
const navigationRow = buildImageNavigationRow(items, currentIndex);
|
||||||
@ -383,6 +397,7 @@ const update = async (client) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pinboardItems = parsePinboardImageItems().slice(0, 25);
|
const pinboardItems = parsePinboardImageItems().slice(0, 25);
|
||||||
|
imageRefreshKey = Date.now();
|
||||||
const [status] = await Promise.all([
|
const [status] = await Promise.all([
|
||||||
getMinecraftStatus(),
|
getMinecraftStatus(),
|
||||||
preloadPinboardImages(pinboardItems)
|
preloadPinboardImages(pinboardItems)
|
||||||
@ -391,9 +406,10 @@ const update = async (client) => {
|
|||||||
|
|
||||||
const { message } = await resolvePanelMessage(client, channelId, messageId);
|
const { message } = await resolvePanelMessage(client, channelId, messageId);
|
||||||
const payload = buildPanelPayload(status, message.id, pinboardItems, {
|
const payload = buildPanelPayload(status, message.id, pinboardItems, {
|
||||||
useAttachmentForSelected: true,
|
useAttachmentForSelected: false,
|
||||||
disableCacheBustForSelected: false,
|
disableCacheBustForSelected: false,
|
||||||
includeFiles: true
|
includeFiles: false,
|
||||||
|
refreshKey: imageRefreshKey
|
||||||
});
|
});
|
||||||
|
|
||||||
await message.edit(payload);
|
await message.edit(payload);
|
||||||
@ -443,7 +459,8 @@ const handlePinboardSelection = async (interaction) => {
|
|||||||
const payload = buildPanelPayload(status, interaction.message.id, pinboardItems, {
|
const payload = buildPanelPayload(status, interaction.message.id, pinboardItems, {
|
||||||
useAttachmentForSelected: false,
|
useAttachmentForSelected: false,
|
||||||
disableCacheBustForSelected: true,
|
disableCacheBustForSelected: true,
|
||||||
includeFiles: false
|
includeFiles: false,
|
||||||
|
refreshKey: imageRefreshKey
|
||||||
});
|
});
|
||||||
await interaction.update(payload);
|
await interaction.update(payload);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user