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