From 5c0b892e2237c222cf97495dc5d872e071e32bee Mon Sep 17 00:00:00 2001 From: bingus_violet Date: Sat, 8 Jun 2024 18:31:34 -0500 Subject: [PATCH] Emojis! --- .gitignore | 3 ++- index.js | 8 ++------ pageUpdater.js | 50 ++++++++++++++++++++++++++++++++++---------------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 17398b6..8a9acf7 100644 --- a/.gitignore +++ b/.gitignore @@ -133,4 +133,5 @@ dist # Violet's Purgatory static/cached cached -config \ No newline at end of file +config +emojis \ No newline at end of file diff --git a/index.js b/index.js index 25eb585..d60fdbb 100644 --- a/index.js +++ b/index.js @@ -39,14 +39,10 @@ app.use("/cached", express.static(cachePath)) app.use("/imgs", express.static(path.join(assetPath, "Images"))) app.use("/snds", express.static(path.join(assetPath, "Sounds"))) +app.use("/emojis", express.static(path.join(cachePath, "emojis"))) + if (!fs.existsSync(cachePath)) { fs.mkdirSync(cachePath) -} else { - var files = fs.readdirSync(cachePath) - for (let index = 0; index < files.length; index++) { - const file = files[index]; - fs.rmSync(path.join(cachePath, file)) - } } app.get("/discHTML", (req, res) => { diff --git a/pageUpdater.js b/pageUpdater.js index fbdf822..455b968 100644 --- a/pageUpdater.js +++ b/pageUpdater.js @@ -49,18 +49,6 @@ function converter(html) { var statusText = "" - if (lanyardData) { - var statusData = constants.discStatuses[lanyardData.discord_status] - var username = lanyardData.discord_user.username - - if (lanyardData.activities[0] && lanyardData.activities[0].type == 4) { - var statusText = `

${lanyardData.activities[0].state}

` - } - } else { - var statusData = constants.discStatuses.offline - var username = "bingus_violet" - } - var bnchName = "Beta" var bnchSub = "beta." @@ -79,12 +67,27 @@ function converter(html) { "QUOTE_COUNT": quotes.length, "RANDOM_TITLE": titles[Math.floor(Math.random() * titles.length)], "DISCORD_STATUS": - `${statusData.text}` + - ``, + `${constants.discStatuses[lanyardData.discord_status].text}` + + ``, "UPTIME": uptime, "TOPBAR": `

Socials

`, - "DISCORD_USER": username, - "CUSTOM_STATUS": statusText, + "CUSTOM_STATUS": () => { + if (lanyardData && lanyardData.activities[0] && lanyardData.activities[0].type == 4) { + var status = lanyardData.activities[0] + var addedHTML = "

" + if (status.emoji) { + if (status.emoji.id) { + addedHTML += `` + } else { + addedHTML += status.emoji.name + } + } + addedHTML += status.state + addedHTML += "

" + return addedHTML + } + return "" + }, "SELECTED_VIDEO": () => { if (config.dailyVideoURL) { return `


Random video!

I would call it random daily video but its not at all daily...

@@ -309,6 +312,21 @@ function socketeer() { } else if (data.op == 0) { lanyardData = data.d lastLanyardUpdate = Date.now() + + for (var i = 0; i < lanyardData.activities.length; i++) { + var activity = lanyardData.activities[i] + if (activity.type == 4 && activity.emoji) { + + if (activity.emoji.id) { + if (activity.emoji.animated) { + var emoji = Buffer.from(await (await fetch(`https://cdn.discordapp.com/emojis/${activity.emoji.id}.gif?quality=lossless`)).arrayBuffer()) + } else { + var emoji = Buffer.from(await (await fetch(`https://cdn.discordapp.com/emojis/${activity.emoji.id}.png?quality=lossless`)).arrayBuffer()) + } + fs.writeFileSync(path.join(__dirname, "cached/emojis", activity.emoji.id), emoji) + } + } + } } else if (data.op == 4) { globalSpins = data.spins }