foxwells.vinboard: .

This commit is contained in:
Cynthia Foxwell 2022-12-03 00:02:54 -07:00
parent 069e0f57b7
commit 84ddbce959

View file

@ -207,7 +207,7 @@ async function findSuitableImage(msg) {
return out;
}
async function createBoardMessage(msg, count) {
async function createBoardMessage(msg, count, fetchAttachment = true) {
const embed = {
title: `${count} \u2b50`,
color: getTopColor(msg, msg.author.id, pastelize(msg.author.id)),
@ -221,16 +221,19 @@ async function createBoardMessage(msg, count) {
timestamp: msg.timestamp,
};
const image = await findSuitableImage(msg);
if (image.url) {
if (image.video) {
embed.description += `\n(contains video ${
image.attachment ? "attachment" : "embed"
})`;
let image;
if (fetchAttachment) {
image = await findSuitableImage(msg);
if (image.url) {
if (image.video) {
embed.description += `\n(contains video ${
image.attachment ? "attachment" : "embed"
})`;
}
embed.image = {
url: image.url,
};
}
embed.image = {
url: image.url,
};
}
return {
@ -239,7 +242,7 @@ async function createBoardMessage(msg, count) {
username: msg.member?.displayName ?? msg.author.username,
threadID: VINBOARD_THREAD_ID,
embeds: [embed],
files: image.file ? [{contents: image.file, name: "thumb.jpg"}] : null,
files: image?.file ? [{contents: image.file, name: "thumb.jpg"}] : null,
wait: true,
};
}
@ -319,7 +322,7 @@ async function processReaction(_msg, user, reaction) {
} -> ${trueCount})`
);
const props = await createBoardMessage(msg, trueCount);
const props = await createBoardMessage(msg, trueCount, false);
props.attachments = [..._boardMessage.attachments.values()];
await vinboard_webhook.editMessage(_boardMessage.id, props);
await setBoardEntry(msg.id, trueCount, _boardMessage.id);
@ -330,6 +333,12 @@ async function processReaction(_msg, user, reaction) {
);
await setBoardEntry(msg.id, trueCount, boardMessage.id);
}
} else {
logger.verbose("vinboard", `Creating entry for "${msg.id}"`);
const boardMessage = await vinboard_webhook.execute(
await createBoardMessage(msg, trueCount)
);
await setBoardEntry(msg.id, trueCount, boardMessage.id);
}
} else {
logger.verbose("vinboard", `Creating entry for "${msg.id}"`);