From 4f5eae6dcbcdcf7fe88c9defe4dc1e581e4837b9 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Thu, 1 May 2025 21:55:23 -0600 Subject: [PATCH] presence: game icon large image fallback (client behavior) --- src/modules/utility/presence.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/modules/utility/presence.js b/src/modules/utility/presence.js index 3dffee5..1f5e72f 100644 --- a/src/modules/utility/presence.js +++ b/src/modules/utility/presence.js @@ -316,7 +316,35 @@ presence.callback = async function (msg, line) { smallUrl = CDNEndpoints.APP_ASSET(activity.application_id, activity.assets.small_image); } - thumbnail = fixMediaProxyURL(smallUrl); + const game = Games.find((game) => game.id == activity.application_id); + if (game?.icon) { + const gameIcon = `${CDNEndpoints.APP_ICON(game.id, game.icon)}?keep_aspect_ratio=false`; + image_links.push({label: "App Icon", url: gameIcon}); + + const largeImage = await fetch(gameIcon) + .then((res) => res.arrayBuffer()) + .then((b) => Buffer.from(b)); + const presenceImage = sharp(largeImage).resize(100, 100); + const smallImage = await fetch(smallUrl) + .then((res) => res.arrayBuffer()) + .then((b) => Buffer.from(b)); + const smallImageBuffer = await sharp(smallImage).resize(32, 32).toBuffer(); + + presenceImage.composite([ + { + input: smallImageBuffer, + gravity: "southeast", + }, + ]); + + files.push({ + contents: await presenceImage.toBuffer(), + name: `${index}.png`, + }); + thumbnail = `attachment://${index}.png`; + } else { + thumbnail = fixMediaProxyURL(smallUrl); + } image_links.push({label: "Small Image", url: thumbnail}); } }