const express = require('express'), path = require('path'), fs = require('fs'), WebSocket = require('ws') var app = express() const PORT = process.env.PORT || 8080 const staticpath = path.join(__dirname, 'static') const resourcePath = path.join(__dirname, 'resources') const mainpage = resourcePath + '/mainPage.html' var lanyardData = undefined var discData = null var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json'))) var thumborInstances = config.thumborInstances var thumbCount = 0 function getThumbor() { thumbCount += 1 return thumborInstances[thumbCount % thumborInstances.length] + "unsafe" } app.use(express.static(staticpath)) app.listen(PORT, () => { console.log("Violet's Purgatory is now listening on port: " + PORT) }) var randomQuotes = config.quotes function timeFormatter(seconds) { seconds = Math.ceil(seconds) var minutes = Math.floor(seconds / 60) if (seconds % 60 < 10) { return `${minutes}:0${seconds % 60}` } else { return `${minutes}:${seconds % 60}` } } function gameTimeFormatter(seconds) { seconds = Math.ceil(seconds) var minutes = Math.ceil(seconds / 60) var hours = Math.floor(minutes / 60) if (seconds < 60) { return 'Under a minute ago' } else if (minutes < 60) { return `${minutes} Minutes` } return `${hours} hours and ${minutes % 60} minutes` } function pageUpdate() { var statuses = { "online": { "text": "Online", "color": "rgb(100, 255, 100)" }, "dnd": { "text": "DND", "color": "rgb(255, 100, 100)" }, "idle": { "text": "Idle", "color": "rgb(255, 255, 75)" }, "offline": { "text": "Offline", "color": "rgb(125, 125, 125)" } } var html = fs.readFileSync(mainpage).toString() var addedHTML = "" if (lanyardData) { var statusData = statuses[lanyardData.discord_status] addedHTML += `
${statusData.text}
` addedHTML += `` } html = html.replace("{LANYARD_STATUS}", addedHTML) addedHTML = "" if (lanyardData && lanyardData.activities.length > 0) { if (lanyardData.activities[0].type == 4) { var status = lanyardData.activities[0] addedHTML += "" if (status.emoji) { if (status.emoji.id) { addedHTML += ` ` } else { addedHTML += status.emoji.name } } if (status.state) { addedHTML += `"` addedHTML += (status.state || "") addedHTML += `"` } addedHTML += ` - ${lanyardData.discord_user.display_name} ${new Date(Date.now()).getFullYear()}
` } } html = html.replace("{LANYARD_QUOTE}", addedHTML) addedHTML = "" var debounce = false if (lanyardData && lanyardData.activities.length > 0) { for (let index = 0; index < lanyardData.activities.length; index++) { const activity = lanyardData.activities[index]; var found = false for (let index = 0; index < lanyardData.activities.length; index++) { const act = lanyardData.activities[index] if (act.name == activity.name) { if (Object.keys(act).length > Object.keys(activity).length) { found = true } } } if (found) { continue } if (!debounce && activity.type != 4) { addedHTML += `
Listening to ${activity.name}
Song: ${activity.details || " "}
${songStats()}
${timeFormatter((activity.timestamps.end - activity.timestamps.start) / 1000)}
Playing ${activity.name}
${activity.details || activity.assets.large_text || " "}
${activity.state || activity.assets.small_text || " "}
${gameTimeFormatter((Date.now() - time) / 1000)}