From 95b24f8e7f2df91225e8a8aaf46c17b19a28a26c Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Sun, 7 Jul 2024 13:03:50 -0600 Subject: [PATCH] utility.presence: image links --- src/modules/utility.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/modules/utility.js b/src/modules/utility.js index a7b0091..9e89520 100644 --- a/src/modules/utility.js +++ b/src/modules/utility.js @@ -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&", + "" + )})`, + }); } }