fixup vinboard a bit as testing before separating it out
This commit is contained in:
parent
db03d2d489
commit
b63e2dadb3
1 changed files with 56 additions and 22 deletions
|
@ -177,20 +177,34 @@ async function findSuitableImage(msg) {
|
||||||
|
|
||||||
if (attachment) {
|
if (attachment) {
|
||||||
const url = attachment.url;
|
const url = attachment.url;
|
||||||
if (/(jpe?g|png|gif|webp)$/.test(url)) {
|
const parsed = new URL(url);
|
||||||
|
if (/(jpe?g|png|gif|webp)$/.test(parsed.pathname)) {
|
||||||
out.url = url;
|
out.url = url;
|
||||||
} else if (/(mp4|webm|mov)$/.test(url)) {
|
} else if (/(mp4|webm|mov)$/.test(parsed.pathname)) {
|
||||||
out.video = true;
|
out.video = true;
|
||||||
out.attachment = true;
|
out.attachment = true;
|
||||||
out.url = "attachment://thumb.jpg";
|
out.url = "attachment://thumb.jpg";
|
||||||
out.file = await fetch(attachment.proxyURL + "?format=jpeg")
|
|
||||||
|
let thumbUrl = attachment.proxyURL;
|
||||||
|
if (thumbUrl.includes("media.discordapp.net") && thumbUrl.includes("?")) {
|
||||||
|
if (thumbUrl.endsWith("&")) {
|
||||||
|
thumbUrl = thumbUrl += "format=jpeg";
|
||||||
|
} else {
|
||||||
|
thumbUrl = thumbUrl += "&format=jpeg";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
thumbUrl = thumbUrl += "?format=jpeg";
|
||||||
|
}
|
||||||
|
|
||||||
|
out.file = await fetch(thumbUrl)
|
||||||
.then((res) => res.arrayBuffer())
|
.then((res) => res.arrayBuffer())
|
||||||
.then((buf) => Buffer.from(buf));
|
.then((buf) => Buffer.from(buf));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (const embed of msg.embeds) {
|
for (const embed of msg.embeds) {
|
||||||
if (!embed.url) continue;
|
if (!embed.url) continue;
|
||||||
if (embed.url && /(jpe?g|png|gif|webp)$/.test(embed.url)) {
|
const parsed = new URL(embed.url);
|
||||||
|
if (embed.url && /(jpe?g|png|gif|webp)$/.test(parsed.pathname)) {
|
||||||
out.url = embed.url;
|
out.url = embed.url;
|
||||||
} else if (embed.image) {
|
} else if (embed.image) {
|
||||||
out.url = embed.image.url;
|
out.url = embed.image.url;
|
||||||
|
@ -198,13 +212,38 @@ async function findSuitableImage(msg) {
|
||||||
} else if (embed.video) {
|
} else if (embed.video) {
|
||||||
out.video = true;
|
out.video = true;
|
||||||
out.url = "attachment://thumb.jpg";
|
out.url = "attachment://thumb.jpg";
|
||||||
out.file = await fetch(
|
|
||||||
(embed.video.proxyURL ??
|
let thumbUrl =
|
||||||
embed.video.url.replace(
|
embed.video.proxyURL ??
|
||||||
"cdn.discordapp.com",
|
embed.video.url.replace("cdn.discordapp.com", "media.discordapp.net");
|
||||||
"media.discordapp.net"
|
if (
|
||||||
)) + "?format=jpeg"
|
thumbUrl.includes("media.discordapp.net") &&
|
||||||
)
|
thumbUrl.includes("?")
|
||||||
|
) {
|
||||||
|
if (thumbUrl.endsWith("&")) {
|
||||||
|
thumbUrl = thumbUrl += "format=jpeg";
|
||||||
|
} else {
|
||||||
|
thumbUrl = thumbUrl += "&format=jpeg";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
thumbUrl = thumbUrl += "?format=jpeg";
|
||||||
|
}
|
||||||
|
if (embed.thumbnail?.url) thumbUrl = embed.thumbnail.url;
|
||||||
|
|
||||||
|
let valid = await fetch(thumbUrl, {method: "HEAD"}).then(
|
||||||
|
(res) => res.ok
|
||||||
|
);
|
||||||
|
if (!valid && thumbUrl.includes("media.discordapp.net")) {
|
||||||
|
thumbUrl = await hf.bot.requestHandler
|
||||||
|
.request("POST", "/attachments/refresh-urls", true, {
|
||||||
|
attachment_urls: [thumbUrl],
|
||||||
|
})
|
||||||
|
.then((res) => res.refreshed_urls[0].refreshed);
|
||||||
|
valid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valid)
|
||||||
|
out.file = await fetch(thumbUrl)
|
||||||
.then((res) => res.arrayBuffer())
|
.then((res) => res.arrayBuffer())
|
||||||
.then((buf) => Buffer.from(buf));
|
.then((buf) => Buffer.from(buf));
|
||||||
break;
|
break;
|
||||||
|
@ -216,16 +255,11 @@ async function findSuitableImage(msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createBoardMessage(msg, count, fetchAttachment = true) {
|
async function createBoardMessage(msg, count, fetchAttachment = true) {
|
||||||
|
const name = msg.member?.nick ?? msg.author.globalName ?? msg.author.username;
|
||||||
const embed = {
|
const embed = {
|
||||||
title: `${count} \u2b50`,
|
title: `${count} \u2b50 - ${msg.jumpLink}`,
|
||||||
color: pastelize(msg.author.username),
|
color: pastelize(name),
|
||||||
description: msg.content,
|
description: msg.content,
|
||||||
fields: [
|
|
||||||
{
|
|
||||||
name: "Jump Link",
|
|
||||||
value: `[Jump](${msg.jumpLink})`,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
timestamp: new Date(msg.timestamp).toISOString(),
|
timestamp: new Date(msg.timestamp).toISOString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -246,7 +280,7 @@ async function createBoardMessage(msg, count, fetchAttachment = true) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
avatarURL: msg.member?.avatarURL ?? msg.author.avatarURL,
|
avatarURL: msg.member?.avatarURL ?? msg.author.avatarURL,
|
||||||
username: msg.member?.displayName ?? msg.author.username,
|
username: name,
|
||||||
threadID: VINBOARD_THREAD_ID,
|
threadID: VINBOARD_THREAD_ID,
|
||||||
embeds: [embed],
|
embeds: [embed],
|
||||||
attachments: image?.file
|
attachments: image?.file
|
||||||
|
|
Loading…
Reference in a new issue