const express = require('express'), path = require('path'), fs = require('fs'), WebSocket = require('ws'), xml2json = require('xml-js') 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 mastoData = { "lastUpdate": 0, "HTML": "" } app.use(express.static(staticpath)) app.listen(PORT, () => { console.log("Violet's Purgatory is now listening on port: " + PORT) }) 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) { addedHTML += `"${lanyardData.activities[0].state}" - ${lanyardData.discord_user.display_name} ${new Date(Date.now()).getFullYear()}
` } } html = html.replace("{LANYARD_QUOTE}", addedHTML) addedHTML = "" if (lanyardData) { for (let index = 0; index < lanyardData.activities.length; index++) { const activity = lanyardData.activities[index]; if (activity.type == 4) { addedHTML += `"${lanyardData.activities[0].state}" - ${lanyardData.discord_user.display_name} ${new Date(Date.now()).getFullYear()}
` } } } html = html.replace("{LANYARD_SPOTIFY}", 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]; if (!debounce && activity.type != 4) { addedHTML += `
Listening to ${activity.name}
Song: ${activity.details}
Album: ${activity.assets.large_text}
Artist: ${activity.state}
Playing ${activity.name}
${activity.state}
${activity.details}
Playing ${activity.name}
${activity.details || activity.assets.large_text}
${activity.state || activity.assets.small_text}
Playing ${activity.name}
${activity.state}
${activity.details}