2023-10-20 21:53:49 -05:00
|
|
|
const express = require('express'),
|
2023-11-16 19:29:22 -06:00
|
|
|
path = require('path'),
|
|
|
|
fs = require('fs'),
|
|
|
|
WebSocket = require('ws')
|
2023-10-20 21:53:49 -05:00
|
|
|
|
|
|
|
var app = express()
|
|
|
|
|
|
|
|
const PORT = process.env.PORT || 8080
|
|
|
|
|
2023-11-16 15:16:22 -06:00
|
|
|
const staticpath = path.join(__dirname, 'static')
|
|
|
|
const resourcePath = path.join(__dirname, "resources")
|
|
|
|
|
|
|
|
const mainpage = resourcePath + '/mainPage.html'
|
|
|
|
var lanyardData = undefined
|
|
|
|
|
|
|
|
var discData = null
|
2023-10-20 21:53:49 -05:00
|
|
|
|
|
|
|
app.use(express.static(staticpath))
|
|
|
|
|
2023-11-16 15:16:22 -06:00
|
|
|
app.listen(PORT, () => {
|
|
|
|
console.log("Violet's Purgatory is now listening on port: " + PORT)
|
2023-11-03 13:01:13 -05:00
|
|
|
})
|
|
|
|
|
2023-11-16 15:16:22 -06:00
|
|
|
app.get("/", (req, res) => {
|
2023-11-16 22:08:34 -06:00
|
|
|
|
|
|
|
res.setHeader("X-Content-Type-Options", "none")
|
|
|
|
|
2023-11-16 22:00:16 -06:00
|
|
|
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)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-16 15:16:22 -06:00
|
|
|
var html = fs.readFileSync(mainpage).toString()
|
2023-11-16 22:00:16 -06:00
|
|
|
|
|
|
|
var checkpoint = ["{LANYARD_STATUS}", "{LANYARD}"]
|
|
|
|
|
|
|
|
function io(numb, end=false) {
|
|
|
|
if (end) {
|
|
|
|
return html.indexOf(checkpoint[numb]) + checkpoint[numb].length
|
|
|
|
}
|
|
|
|
return html.indexOf(checkpoint[numb])
|
|
|
|
}
|
|
|
|
|
|
|
|
res.write(html.substring(0, io(0)))
|
|
|
|
|
|
|
|
var statusData = statuses[lanyardData.discord_status]
|
2023-11-16 15:16:22 -06:00
|
|
|
|
2023-11-16 22:00:16 -06:00
|
|
|
res.write(`<p style="color: ${statusData.color}">${statusData.text}</p>`)
|
|
|
|
res.write(`<style>.pfp { border-color: ${statusData.color} !important }</style>`)
|
|
|
|
|
|
|
|
res.write(html.substring(io(0, true), io(1)))
|
2023-11-16 19:29:22 -06:00
|
|
|
|
|
|
|
if (lanyardData) {
|
|
|
|
for (let index = 0; index < lanyardData.activities.length; index++) {
|
|
|
|
const activity = lanyardData.activities[index];
|
|
|
|
console.log(activity)
|
|
|
|
if (activity.type == 2) {
|
2023-11-16 22:00:16 -06:00
|
|
|
res.write(`<p class="chip">Listening on <a style="color: limegreen">${activity.name}</a>: ${activity.details} (by ${activity.state})</p>`)
|
2023-11-16 19:29:22 -06:00
|
|
|
} else if (activity.type == 4) {
|
2023-11-16 22:00:16 -06:00
|
|
|
res.write(`<p><em><span style="color: lightgray">"${lanyardData.activities[0].state}"</span> - ${lanyardData.discord_user.display_name} ${new Date(Date.now()).getFullYear()}</em></p>`)
|
2023-11-16 19:29:22 -06:00
|
|
|
}
|
2023-11-16 15:16:22 -06:00
|
|
|
}
|
|
|
|
|
2023-11-16 19:29:22 -06:00
|
|
|
console.log(lanyardData.activities)
|
|
|
|
}
|
2023-11-16 22:00:16 -06:00
|
|
|
console.log(io(checkpoint.length - 1, true))
|
|
|
|
res.write(html.substring(io(checkpoint.length - 1, true), html.length) + "<p>Thank you for checking out my website <3</p>", () => {
|
|
|
|
res.end()
|
|
|
|
})
|
2023-11-16 15:16:22 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
// Lanyard Stuffs
|
|
|
|
|
|
|
|
var lanyard = new WebSocket('wss://api.lanyard.rest/socket')
|
|
|
|
|
|
|
|
function beat(dur) {
|
|
|
|
lanyard.send(JSON.stringify({
|
|
|
|
op: 3
|
|
|
|
}))
|
|
|
|
setTimeout(() => {
|
|
|
|
beat(dur)
|
|
|
|
}, dur);
|
|
|
|
}
|
|
|
|
|
2023-11-16 19:29:22 -06:00
|
|
|
lanyard.addEventListener("message", (res) => {
|
2023-11-16 15:16:22 -06:00
|
|
|
var data = JSON.parse(res.data)
|
|
|
|
if (data.op == 1) {
|
|
|
|
beat(data.d.heartbeat_interval)
|
|
|
|
lanyard.send(JSON.stringify({
|
|
|
|
op: 2,
|
|
|
|
d: {
|
|
|
|
subscribe_to_id: "534132311781015564"
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
} else if (data.op == 0) {
|
|
|
|
lanyardData = data.d
|
|
|
|
} else {
|
|
|
|
console.log(data.d)
|
|
|
|
}
|
2023-11-07 13:07:11 -06:00
|
|
|
})
|