const path = require('path'), fs = require('fs'), WebSocket = require('ws'), minify = require('@node-minify/core'), uglifyJs = require("@node-minify/uglify-js"), htmlMinifier = require("minify-html"), activityToHTML = require("./overcomplicatedStatuses.js"), randomThemer = require("./randomThemer.js"), himalaya = require("himalaya") var constants = JSON.parse(fs.readFileSync(path.join(__dirname, 'constants.json'))) var highlightedWords = constants.highlightedWords var quotes = constants.quotes var titles = constants.titles var globalSpins = 0 var commitCount = "500+" var lanyardData = undefined var uptime = Date.now() function firstToUpper(str) { return str.charAt(0).toUpperCase() + str.slice(1) } function timeFormatter(seconds) { seconds = Math.ceil(seconds) var minutes = Math.ceil(seconds / 60) var hours = Math.floor(minutes / 60) if (seconds <= 60) { return 'about ' + seconds + ' seconds' } else if (minutes < 60) { return `${minutes} Minutes` } return `${hours} hours and ${minutes % 60} minutes` } function converter(html) { var startTime = Date.now() html = html var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config/config.json'))) var statusText = "" var bnchName = "Beta" var bnchSub = "beta." if (process.env.BRANCH == "dev") { bnchName = "Stable" bnchSub = "" } var replacers = { "ALL_KEYWORDS": undefined, "ALL_HIGHLIGHTS": Object.keys(highlightedWords).join(", "), "BRANCH_NAME": bnchName, "BRANCH_SUB": bnchSub, "RANDOM_QUOTE": quotes[Math.floor(Math.random() * quotes.length)], "COMMIT_COUNT": commitCount, "QUOTE_COUNT": quotes.length, "RANDOM_TITLE": titles[Math.floor(Math.random() * titles.length)], "DISCORD_STATUS": `${constants.discStatuses[lanyardData.discord_status].text}` + ``, "UPTIME": uptime, "TOPBAR": `
`, "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 `I would call it random daily video but its not at all daily...
Uh oh... I think your lost? There's nothing here :P
`) } } } async function updateCommits() { var siteResponse = await (await fetch(`https://git.violets-purgatory.dev/bingus_violet/violets-purgatory/src/branch/${process.env.BRANCH || "origin"}`)).text() var commits = siteResponse.substring(0, siteResponse.indexOf("Commits")) commits = commits.substring(commits.lastIndexOf("") + 3, commits.lastIndexOf("")) // ^ this works for Forgejo (basically everything i use that isnt Github, E.G. Codeberg) // commits = commits.substring(commits.lastIndexOf(">") + 1) // ^ This works for Github (fuck you Github) commitCount = commits.toString() if (process.env.BRANCH == "dev") { commitCount += " | Beta site" } } updateCommits() // Lanyard Stuffs var lastLanyardUpdate = Date.now() var lastPong = 0 function socketeer() { var lanyard = new WebSocket('https://api.violets-purgatory.dev') lanyard.on("error", (error) => { console.log(error) }) lanyard.on("close", () => { console.log("Connection Closed. Attempting Reconnect in 30 seconds.") setTimeout(() => { socketeer() }, 30000); }) function ping(dur) { lanyard.send(JSON.stringify({ op: 3 })) setTimeout(() => { ping(dur) if (Date.now() - lastPong > 120000) { lanyard.close() console.log("Max duration since last pong exceeded- Closing socket.") } }, dur); } lanyard.addEventListener("message", async (res) => { var data = JSON.parse(res.data) // console.log(data.op) if (data.op == 1) { console.log("Connected to Discord Websocket!") ping(30000) lastPong = Date.now() } else if (data.op == 3) { lastPong = Date.now() } 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 } }) } socketeer()