utility.presence: image links

This commit is contained in:
Cynthia Foxwell 2024-07-07 13:03:50 -06:00
parent 1957d026b4
commit 95b24f8e7f

View file

@ -1890,6 +1890,8 @@ presence.callback = async function (msg, line) {
if (activity.assets) {
if (activity.assets.large_image != null) {
const image_links = [];
let largeUrl;
if (activity.assets.large_image.startsWith("mp:")) {
largeUrl = activity.assets.large_image.replace(
@ -1905,6 +1907,8 @@ presence.callback = async function (msg, line) {
largeUrl = `https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.large_image}.png`;
}
image_links.push(`[Large Image](${largeUrl})`);
let smallUrl;
if (activity.assets.small_image != null) {
if (activity.assets.small_image.startsWith("mp:")) {
@ -1912,9 +1916,16 @@ presence.callback = async function (msg, line) {
"mp:",
"https://media.discordapp.net/"
);
} else if (activity.assets.small_image.startsWith("spotify:")) {
smallUrl = activity.assets.small_image.replace(
"spotify:",
"https://i.scdn.co/image/"
);
} else {
smallUrl = `https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.small_image}.png`;
}
image_links.push(`[Small Image](${smallUrl})`);
}
const largeImage = await fetch(largeUrl)
@ -1944,6 +1955,10 @@ presence.callback = async function (msg, line) {
embed.thumbnail = {
url: `attachment://${index}.png`,
};
embed.fields.push({
name: "\u200b",
value: image_links.join("\u3000\u3000"),
});
} else if (
!activity.assets.large_image &&
activity.assets.small_image != null
@ -1962,7 +1977,7 @@ presence.callback = async function (msg, line) {
.then((res) => res.arrayBuffer())
.then((b) => Buffer.from(b));
const presenceImage = await sharp(smallImage)
.resize(60, 60)
.resize(40, 40)
.toBuffer();
files.push({
@ -1972,6 +1987,10 @@ presence.callback = async function (msg, line) {
embed.thumbnail = {
url: `attachment://${index}.png`,
};
embed.fields.push({
name: "\u200b",
value: `[Small Image](${smallUrl})`,
});
}
}
@ -1987,6 +2006,13 @@ presence.callback = async function (msg, line) {
embed.thumbnail = {
url: `https://cdn.discordapp.com/app-icons/${game.id}/${game.icon}.png?size=40&keep_aspect_ratio=false`,
};
embed.fields.push({
name: "\u200b",
value: `[App Icon](${embed.thumbnail.url.replace(
"size=40&",
""
)})`,
});
}
}