From 5a967de4cd6218c085427fdecad1659ca7e415fa Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Thu, 4 Jul 2024 15:24:35 -0600 Subject: [PATCH] utility.presence: hang status --- src/modules/utility.js | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/modules/utility.js b/src/modules/utility.js index 7a42541..eaffd92 100644 --- a/src/modules/utility.js +++ b/src/modules/utility.js @@ -97,6 +97,37 @@ const PRESENCE_TYPES = [ "Competing in", ]; +const HANG_STATUS_TEXT = { + chilling: "Chilling", + gaming: "GAMING", + focusing: "In the zone", + brb: "Gonna BRB", + eating: "Grubbin", + "in-transit": "Wandering IRL", + watching: "Watchin' stuff", +}; + +const HANG_STATUS_ICONS = { + chilling: "/assets/d5df7edf0b2f38954140.svg", + gaming: "/assets/0c7aa94c8471f12c1583.svg", + focusing: "/assets/5ba60eea3fdfa7b63f2e.svg", + brb: "/assets/194dda5f6443bc84d703.svg", + eating: "/assets/5f41131fa82e3a74fbf7.svg", + "in-transit": "/assets/0cb37cec5b33d664373a.svg", + watching: "/assets/b7832fa2d0b75e26e279.svg", +}; + +(async () => { + for (const key of Object.keys(HANG_STATUS_ICONS)) { + const svg = await fetch(`https://discord.com${HANG_STATUS_ICONS[key]}`) + .then((res) => res.arrayBuffer()) + .then((b) => Buffer.from(b)); + HANG_STATUS_ICONS[key] = await sharp(svg, {density: 2400}) + .resize(128) + .toBuffer(); + } +})(); + const USER_FLAGS = [ "STAFF", "PARTNER", @@ -1692,6 +1723,33 @@ presence.callback = async function (msg, line) { embed.title = activity.state ?? ""; } + embeds.push(embed); + } else if (activity.type == 6) { + const embed = {}; + + embed.title = "Hang Status"; + embed.description = `Right now I'm \u2013\n**${ + activity.state == "custom" + ? activity.details + : HANG_STATUS_TEXT[activity.state] + }**`; + + if (activity.emoji) { + embed.thumbnail = { + url: `${EMOTE_BASE}${activity.emoji.id}${ + activity.emoji.animated ? ".gif" : ".png" + }`, + }; + } else { + files.push({ + contents: HANG_STATUS_ICONS[activity.state], + name: `${activity.state}.png`, + }); + embed.thumbnail = { + url: `attachment://${activity.state}.png`, + }; + } + embeds.push(embed); } else { const embed = {