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'),
|
2024-01-27 12:45:39 -06:00
|
|
|
WebSocket = require('ws'),
|
2024-01-27 14:19:49 -06:00
|
|
|
minify = require('minify-html'),
|
|
|
|
sha256 = require('sha256')
|
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')
|
2024-01-25 23:29:28 -06:00
|
|
|
const resourcePath = path.join(__dirname, 'resources')
|
2023-11-16 15:16:22 -06:00
|
|
|
|
|
|
|
const mainpage = resourcePath + '/mainPage.html'
|
|
|
|
var lanyardData = undefined
|
|
|
|
|
2024-01-25 23:29:28 -06:00
|
|
|
var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json')))
|
|
|
|
|
|
|
|
var thumborInstances = config.thumborInstances
|
2024-01-19 11:18:50 -06:00
|
|
|
|
2024-01-25 23:50:09 -06:00
|
|
|
var activityImages = config.activityImages
|
|
|
|
|
2024-01-27 12:02:59 -06:00
|
|
|
var highlight = config.highlightedWords
|
|
|
|
|
2024-01-27 12:11:36 -06:00
|
|
|
var uptime = Date.now()
|
|
|
|
var lastLanyardUpdate = Date.now()
|
|
|
|
|
2024-01-19 11:18:50 -06:00
|
|
|
var thumbCount = 0
|
|
|
|
|
|
|
|
function getThumbor() {
|
|
|
|
thumbCount += 1
|
|
|
|
return thumborInstances[thumbCount % thumborInstances.length] + "unsafe"
|
|
|
|
}
|
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
|
|
|
})
|
|
|
|
|
2024-01-27 14:19:49 -06:00
|
|
|
if (!fs.existsSync(path.join(staticpath, 'cached'))) {
|
|
|
|
fs.mkdirSync(path.join(staticpath, 'cached'))
|
|
|
|
}
|
|
|
|
|
2024-01-25 23:29:28 -06:00
|
|
|
var randomQuotes = config.quotes
|
|
|
|
|
2024-01-29 18:48:42 -06:00
|
|
|
function get_img_url(activity, size="large_image") {
|
2024-01-27 14:19:49 -06:00
|
|
|
|
|
|
|
if ("assets" in activity) {
|
2024-01-29 18:48:42 -06:00
|
|
|
var image = activity.assets[size]
|
|
|
|
|
2024-01-27 14:19:49 -06:00
|
|
|
if (image) {
|
|
|
|
if (image.includes("https/")) {
|
|
|
|
return decodeURIComponent('https://' + image.substr(image.indexOf('https/') + 6, image.length))
|
|
|
|
} else if (image.includes("spotify")) {
|
|
|
|
return decodeURIComponent('https://i.scdn.co/image/' + image.substr(image.indexOf('spotify:') + 8, image.length))
|
|
|
|
} else {
|
|
|
|
return decodeURIComponent(`https://cdn.discordapp.com/app-assets/${activity.application_id}/${image}.png`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!image) {
|
|
|
|
if (activity.name in activityImages) {
|
|
|
|
return decodeURIComponent(activityImages[activity.name])
|
|
|
|
} else {
|
2024-01-27 15:41:08 -06:00
|
|
|
return null
|
2024-01-27 14:19:49 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-25 23:03:05 -06:00
|
|
|
function timeFormatter(seconds) {
|
|
|
|
seconds = Math.ceil(seconds)
|
2024-01-25 23:08:44 -06:00
|
|
|
var minutes = Math.floor(seconds / 60)
|
2024-01-25 23:03:05 -06:00
|
|
|
|
2024-01-25 23:11:53 -06:00
|
|
|
if (seconds % 60 < 10) {
|
2024-01-25 23:11:19 -06:00
|
|
|
return `${minutes}:0${seconds % 60}`
|
2024-01-25 23:11:53 -06:00
|
|
|
} else {
|
|
|
|
return `${minutes}:${seconds % 60}`
|
2024-01-25 23:11:19 -06:00
|
|
|
}
|
2024-01-27 14:19:49 -06:00
|
|
|
|
2024-01-25 23:03:05 -06:00
|
|
|
}
|
|
|
|
|
2024-01-25 23:07:26 -06:00
|
|
|
function gameTimeFormatter(seconds) {
|
|
|
|
seconds = Math.ceil(seconds)
|
|
|
|
var minutes = Math.ceil(seconds / 60)
|
2024-01-25 23:08:44 -06:00
|
|
|
var hours = Math.floor(minutes / 60)
|
2024-01-26 11:20:50 -06:00
|
|
|
if (seconds <= 60) {
|
|
|
|
return 'Under a minute'
|
2024-01-25 23:07:26 -06:00
|
|
|
} else if (minutes < 60) {
|
|
|
|
return `${minutes} Minutes`
|
|
|
|
}
|
2024-01-27 14:19:49 -06:00
|
|
|
|
2024-01-25 23:11:19 -06:00
|
|
|
return `${hours} hours and ${minutes % 60} minutes`
|
2024-01-27 14:19:49 -06:00
|
|
|
|
2024-01-25 23:07:26 -06:00
|
|
|
}
|
|
|
|
|
2024-01-27 14:19:49 -06:00
|
|
|
async function pageUpdate() {
|
2024-01-27 12:14:20 -06:00
|
|
|
|
|
|
|
var genStart = Date.now()
|
2024-01-27 14:19:49 -06:00
|
|
|
|
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-18 21:09:42 -06:00
|
|
|
|
2023-11-16 15:16:22 -06:00
|
|
|
var html = fs.readFileSync(mainpage).toString()
|
2023-11-16 22:00:16 -06:00
|
|
|
|
2023-11-17 08:43:11 -06:00
|
|
|
var addedHTML = ""
|
2023-11-16 22:00:16 -06:00
|
|
|
|
2023-11-18 21:09:42 -06:00
|
|
|
if (lanyardData) {
|
|
|
|
var statusData = statuses[lanyardData.discord_status]
|
2023-11-16 15:16:22 -06:00
|
|
|
|
2023-11-18 21:09:42 -06:00
|
|
|
addedHTML += `<p style="color: ${statusData.color}">${statusData.text}</p>`
|
|
|
|
addedHTML += `<style>.pfp { border-color: ${statusData.color} !important }</style>`
|
|
|
|
}
|
2023-11-16 22:00:16 -06:00
|
|
|
|
2023-11-17 08:43:11 -06:00
|
|
|
html = html.replace("{LANYARD_STATUS}", addedHTML)
|
|
|
|
|
|
|
|
addedHTML = ""
|
2023-11-16 19:29:22 -06:00
|
|
|
|
2023-11-18 21:09:42 -06:00
|
|
|
if (lanyardData && lanyardData.activities.length > 0) {
|
|
|
|
if (lanyardData.activities[0].type == 4) {
|
2024-01-04 16:29:47 -06:00
|
|
|
var status = lanyardData.activities[0]
|
|
|
|
addedHTML += "<hr><p>"
|
|
|
|
if (status.emoji) {
|
2024-01-11 12:43:30 -06:00
|
|
|
if (status.emoji.id) {
|
2024-01-19 11:18:50 -06:00
|
|
|
addedHTML += `<img class="emoji" src="${getThumbor()}/https://cdn.discordapp.com/emojis/${status.emoji.id}.webp?size=32&quality=lossless"/> `
|
2024-01-11 12:43:30 -06:00
|
|
|
} else {
|
|
|
|
addedHTML += status.emoji.name
|
|
|
|
}
|
2024-01-04 16:29:47 -06:00
|
|
|
}
|
2024-01-04 16:32:59 -06:00
|
|
|
if (status.state) {
|
2024-01-27 12:02:59 -06:00
|
|
|
addedHTML += `<em><span style="color: lightgray; white-space: pre-wrap">"`
|
|
|
|
// addedHTML += (status.state || "")
|
|
|
|
var splitStatus = status.state.split(' ')
|
2024-01-27 14:19:49 -06:00
|
|
|
|
2024-01-27 12:02:59 -06:00
|
|
|
for (let index = 0; index < splitStatus.length; index++) {
|
|
|
|
const text = splitStatus[index];
|
|
|
|
if (highlight[text]) {
|
|
|
|
addedHTML += `<span style="color: ${highlight[text]}">${text}</span>`
|
|
|
|
} else {
|
|
|
|
addedHTML += text
|
|
|
|
}
|
|
|
|
addedHTML += ' '
|
|
|
|
}
|
2024-01-27 13:16:49 -06:00
|
|
|
addedHTML = addedHTML.trim()
|
2024-01-04 16:32:59 -06:00
|
|
|
addedHTML += `"</span>`
|
|
|
|
}
|
|
|
|
addedHTML += ` - ${lanyardData.discord_user.display_name} ${new Date(Date.now()).getFullYear()}</em></p>`
|
2023-11-18 21:09:42 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
2024-01-03 17:40:05 -06:00
|
|
|
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
|
|
|
|
}
|
2024-01-27 14:19:49 -06:00
|
|
|
|
2023-11-18 21:09:42 -06:00
|
|
|
if (!debounce && activity.type != 4) {
|
2024-01-27 13:08:34 -06:00
|
|
|
addedHTML += `<h2><hr>What I'm up to:</h2><div class="container-fluid row" style="margin: 0; padding: 0; display: flex;">`
|
2023-11-18 21:09:42 -06:00
|
|
|
debounce = true
|
|
|
|
}
|
2024-01-03 17:40:05 -06:00
|
|
|
|
2024-01-03 17:53:06 -06:00
|
|
|
|
2024-01-29 18:48:42 -06:00
|
|
|
function get_img(activity, size="large_image") {
|
|
|
|
if (get_img_url(activity, size)) {
|
|
|
|
var fn = sha256(get_img_url(activity, size))
|
2024-01-27 15:41:08 -06:00
|
|
|
var fp = path.join(staticpath, 'cached', fn)
|
|
|
|
|
|
|
|
if (!fs.existsSync(fp)) {
|
|
|
|
return 'imgs/notFound.png'
|
|
|
|
} else if (fs.statSync(fp).size < 1000) {
|
|
|
|
fs.rmSync(fp)
|
|
|
|
}
|
|
|
|
} else {
|
2024-01-27 14:32:25 -06:00
|
|
|
return 'imgs/notFound.png'
|
|
|
|
}
|
2024-01-27 15:41:08 -06:00
|
|
|
|
2024-01-27 14:19:49 -06:00
|
|
|
return '/cached/' + fn
|
2023-11-18 21:09:42 -06:00
|
|
|
}
|
2024-01-27 14:19:49 -06:00
|
|
|
|
2024-01-01 21:51:51 -06:00
|
|
|
function songStats() {
|
|
|
|
var html = ``
|
|
|
|
|
|
|
|
if (activity.assets && activity.assets.large_text != activity.details) {
|
|
|
|
html += `
|
|
|
|
<br> Album: ${activity.assets.large_text || " "}
|
|
|
|
<br> Artist: ${activity.state || " "}
|
|
|
|
`
|
|
|
|
} else {
|
|
|
|
html += `<br> Artist: ${activity.state || " "}`
|
|
|
|
}
|
|
|
|
|
|
|
|
return html
|
|
|
|
}
|
2023-11-16 19:29:22 -06:00
|
|
|
if (activity.type == 2) {
|
2024-01-25 22:24:09 -06:00
|
|
|
var timeLeft = Math.round((activity.timestamps.end - Date.now()) / 1000)
|
|
|
|
var currentPercent = (Date.now() - activity.timestamps.start) / (activity.timestamps.end - activity.timestamps.start) * 100
|
|
|
|
addedHTML += `
|
|
|
|
<div class="chip activity col-md-6 testing">
|
2024-01-27 15:04:15 -06:00
|
|
|
<img src="${get_img(activity)}" title="${activity.assets.large_text || activity.assets.small_text}">
|
2024-01-25 22:24:09 -06:00
|
|
|
<p>
|
|
|
|
Listening to <span style="color: limegreen;">${activity.name}</span>
|
|
|
|
<br> Song: ${activity.details || " "}
|
|
|
|
${songStats()}
|
|
|
|
<br>
|
|
|
|
<span class="lengthBar lengthBar${index}"><span></span></span>
|
2024-01-25 23:03:05 -06:00
|
|
|
${timeFormatter((activity.timestamps.end - activity.timestamps.start) / 1000)}
|
2024-01-25 22:24:09 -06:00
|
|
|
</p>
|
2023-11-18 21:09:42 -06:00
|
|
|
</div>
|
2024-01-25 22:24:09 -06:00
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
|
|
.lengthBar${index} > span {
|
|
|
|
animation-name: songSlider${index};
|
|
|
|
animation-duration: ${timeLeft}s;
|
|
|
|
animation-timing-function: linear;
|
|
|
|
}
|
|
|
|
|
|
|
|
@keyframes songSlider${index} {
|
|
|
|
0% {
|
|
|
|
width: ${currentPercent}%;
|
|
|
|
}
|
|
|
|
100% {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
2023-11-18 21:09:42 -06:00
|
|
|
`
|
|
|
|
} else if (activity.type == 0) {
|
2024-01-27 14:19:49 -06:00
|
|
|
var time = activity.created_at
|
|
|
|
if (activity.timestamps) {
|
|
|
|
time = activity.timestamps.start
|
|
|
|
}
|
|
|
|
if (!activity.assets) {
|
|
|
|
activity.assets = { "large_text": " ", "small_text": " " }
|
|
|
|
}
|
|
|
|
|
2024-01-29 18:48:42 -06:00
|
|
|
function smch() {
|
|
|
|
if (get_img_url(activity, "small_image")) {
|
|
|
|
return `<img class="smallimg" src="${get_img(activity, "small_image")}" title="${activity.assets.small_text}">`
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2024-01-03 17:40:05 -06:00
|
|
|
|
2024-01-27 14:19:49 -06:00
|
|
|
addedHTML += `
|
2023-11-18 21:53:13 -06:00
|
|
|
<div class="chip activity col-md-6 testing">
|
2024-01-29 18:48:42 -06:00
|
|
|
<img src="${get_img(activity)}" title="${activity.assets.large_text}">
|
|
|
|
${smch()}
|
2023-11-18 21:09:42 -06:00
|
|
|
<p>
|
|
|
|
Playing <span style="color: rgb(255, 100, 150);">${activity.name}</span>
|
2024-01-27 14:59:58 -06:00
|
|
|
<br> ${(activity.details || activity.assets.large_text || " ")}
|
|
|
|
<br> ${(activity.state || activity.assets.small_text || " ")}
|
2024-01-26 20:55:47 -06:00
|
|
|
<br> ${gameTimeFormatter((Date.now() - time) / 1000)}
|
|
|
|
</p>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
} else if (activity.type != 4) {
|
|
|
|
var time = activity.created_at
|
2024-01-27 14:19:49 -06:00
|
|
|
if (activity.timestamps) {
|
|
|
|
time = activity.timestamps.start
|
|
|
|
}
|
|
|
|
if (!activity.assets) {
|
|
|
|
activity.assets = { "large_text": " ", "small_text": " " }
|
|
|
|
}
|
2024-01-26 20:55:47 -06:00
|
|
|
|
2024-01-27 14:19:49 -06:00
|
|
|
addedHTML += `
|
2024-01-26 20:55:47 -06:00
|
|
|
<div class="chip activity col-md-6 testing">
|
2024-01-27 15:04:15 -06:00
|
|
|
<img src="${get_img(activity)}" title="${activity.assets.large_text || activity.assets.small_text}">
|
2024-01-26 20:55:47 -06:00
|
|
|
<p>
|
|
|
|
<span style="color: rgb(225, 200, 255);">${activity.name}</span>
|
2024-01-27 14:59:58 -06:00
|
|
|
<br> ${(activity.details || activity.assets.large_text || " ")}
|
|
|
|
<br> ${(activity.state || activity.assets.small_text || " ")}
|
2024-01-25 23:07:26 -06:00
|
|
|
<br> ${gameTimeFormatter((Date.now() - time) / 1000)}
|
2023-11-18 21:09:42 -06:00
|
|
|
</p>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
`
|
2023-11-16 19:29:22 -06:00
|
|
|
}
|
2023-11-16 15:16:22 -06:00
|
|
|
}
|
2023-11-16 19:29:22 -06:00
|
|
|
}
|
2023-11-17 08:43:11 -06:00
|
|
|
|
2023-11-18 21:09:42 -06:00
|
|
|
if (addedHTML) {
|
|
|
|
addedHTML += "</div>"
|
|
|
|
}
|
|
|
|
|
|
|
|
html = html.replace("{LANYARD_FULL}", addedHTML)
|
2023-11-17 08:43:11 -06:00
|
|
|
|
2023-11-18 21:36:53 -06:00
|
|
|
addedHTML = ""
|
|
|
|
|
|
|
|
var socialsHTML = fs.readFileSync(path.join(__dirname, 'static/socials/index.html')).toString()
|
2023-11-19 10:27:01 -06:00
|
|
|
addedHTML += socialsHTML.substring(socialsHTML.indexOf("<h1>"), socialsHTML.indexOf("</body>"))
|
2023-11-18 21:36:53 -06:00
|
|
|
|
|
|
|
html = html.replace("{SOCIALS}", addedHTML)
|
|
|
|
|
2023-12-17 21:23:39 -06:00
|
|
|
var now = new Date()
|
2024-01-25 23:29:28 -06:00
|
|
|
|
2023-12-17 21:23:39 -06:00
|
|
|
currentMonth = now.getMonth() + 1
|
|
|
|
|
2024-01-03 16:57:00 -06:00
|
|
|
if ([11, 12].includes(currentMonth)) { // The Below HTML is copy and pasted from that one site :>
|
2024-01-11 12:09:32 -06:00
|
|
|
html = html.replace("{SEASONAL_EFFECT}", fs.readFileSync(path.join(__dirname, 'static/snow.html')))
|
2023-12-17 21:23:39 -06:00
|
|
|
} else {
|
|
|
|
html = html.replace("{SEASONAL_EFFECT}", "")
|
|
|
|
}
|
|
|
|
|
2024-01-26 10:53:59 -06:00
|
|
|
var quote = randomQuotes[Math.floor(Math.random() * randomQuotes.length)]
|
2024-01-27 14:19:49 -06:00
|
|
|
|
2024-01-27 12:02:59 -06:00
|
|
|
var splitQuote = quote.split(' ')
|
|
|
|
|
|
|
|
var finalQuote = ''
|
|
|
|
|
|
|
|
for (let index = 0; index < splitQuote.length; index++) {
|
|
|
|
const text = splitQuote[index];
|
|
|
|
if (highlight[text]) {
|
|
|
|
finalQuote += `<span style="color: ${highlight[text]}">${text}</span>`
|
|
|
|
} else {
|
|
|
|
finalQuote += text
|
|
|
|
}
|
|
|
|
finalQuote += ' '
|
|
|
|
}
|
|
|
|
|
|
|
|
quote = finalQuote.trim()
|
|
|
|
|
2024-01-26 10:53:59 -06:00
|
|
|
quote = quote.replace("{QUOTE_COUNT}", randomQuotes.length)
|
|
|
|
|
|
|
|
html = html.replace("{RANDOM_QUOTE}", quote)
|
2024-01-25 23:29:28 -06:00
|
|
|
|
2024-01-25 23:15:12 -06:00
|
|
|
if (process.env.BRANCH == "dev") {
|
|
|
|
html = html.replace("{OPPOSITE_URL}", "www")
|
|
|
|
html = html.replace("{OPPOSITE_BRANCH}", "Main")
|
|
|
|
} else {
|
|
|
|
html = html.replace("{OPPOSITE_URL}", "beta")
|
|
|
|
html = html.replace("{OPPOSITE_BRANCH}", "Beta")
|
|
|
|
}
|
|
|
|
|
2024-01-27 12:11:36 -06:00
|
|
|
html = html.replace("{UPTIME}", gameTimeFormatter((Date.now() - uptime) / 1000) + ' ago')
|
|
|
|
html = html.replace("{LAST_LANYARD}", gameTimeFormatter((Date.now() - lastLanyardUpdate) / 1000) + ' ago')
|
|
|
|
html = html.replace("{QUOTE_COUNT}", randomQuotes.length)
|
2024-01-27 14:26:20 -06:00
|
|
|
html = html.replace("{CACHED_IMAGES}", fs.readdirSync(path.join(staticpath, 'cached')).length)
|
2024-01-27 12:11:36 -06:00
|
|
|
|
2024-01-27 12:16:40 -06:00
|
|
|
html = html.replace("{GENERATION_TIME}", Math.ceil(Date.now() - genStart).toString() + 'ms')
|
2024-01-27 12:14:20 -06:00
|
|
|
|
2024-01-26 12:23:38 -06:00
|
|
|
//fs.writeFileSync(path.join(__dirname, 'static/index.html'), html)
|
|
|
|
return html
|
2023-11-17 08:43:11 -06:00
|
|
|
}
|
2023-11-16 15:16:22 -06:00
|
|
|
|
2024-01-27 14:19:49 -06:00
|
|
|
|
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
|
2024-01-27 12:11:36 -06:00
|
|
|
lastLanyardUpdate = Date.now()
|
2024-01-27 14:19:49 -06:00
|
|
|
|
|
|
|
for (let index = 0; index < lanyardData.activities.length; index++) {
|
|
|
|
const activity = lanyardData.activities[index];
|
|
|
|
|
2024-01-27 15:41:08 -06:00
|
|
|
if (get_img_url(activity)) {
|
|
|
|
var fn = sha256(get_img_url(activity))
|
|
|
|
var fp = path.join(__dirname, 'static/cached', fn)
|
|
|
|
if (!fs.existsSync(fp)) {
|
|
|
|
var wrst = fs.createWriteStream(fp)
|
|
|
|
|
2024-01-27 14:32:25 -06:00
|
|
|
fetch(`${get_img_url(activity)}`)
|
|
|
|
.then((response) => response.body)
|
|
|
|
.then((body) => {
|
|
|
|
const stream = new WritableStream({
|
|
|
|
write(chunk) {
|
|
|
|
wrst.write(chunk)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
body.pipeTo(stream)
|
2024-01-27 14:19:49 -06:00
|
|
|
})
|
2024-01-27 14:32:25 -06:00
|
|
|
}
|
2024-01-27 14:19:49 -06:00
|
|
|
}
|
2024-01-29 18:48:42 -06:00
|
|
|
if (get_img_url(activity, "small_image")) {
|
|
|
|
var fn = sha256(get_img_url(activity, "small_image"))
|
|
|
|
var fp = path.join(__dirname, 'static/cached', fn)
|
|
|
|
if (!fs.existsSync(fp)) {
|
|
|
|
var wrst = fs.createWriteStream(fp)
|
|
|
|
|
|
|
|
fetch(`${get_img_url(activity, "small_image")}`)
|
|
|
|
.then((response) => response.body)
|
|
|
|
.then((body) => {
|
|
|
|
const stream = new WritableStream({
|
|
|
|
write(chunk) {
|
|
|
|
wrst.write(chunk)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
body.pipeTo(stream)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2024-01-27 14:19:49 -06:00
|
|
|
}
|
2024-01-29 18:48:42 -06:00
|
|
|
|
2023-11-16 15:16:22 -06:00
|
|
|
}
|
2023-11-30 21:56:34 -06:00
|
|
|
})
|
|
|
|
|
2024-01-27 14:19:49 -06:00
|
|
|
app.get('/', async (req, res) => {
|
|
|
|
var html = await (pageUpdate())
|
|
|
|
res.send(minify.minify(html))
|
2024-01-26 12:23:38 -06:00
|
|
|
})
|
2024-01-25 22:50:31 -06:00
|
|
|
|
2024-01-27 14:19:49 -06:00
|
|
|
app.use((req, res, next) => {
|
2023-12-19 12:21:37 -06:00
|
|
|
res.status(404).send(`
|
|
|
|
<link rel="stylesheet" href="/style.css">
|
2024-01-12 13:05:34 -06:00
|
|
|
<h1>404</h1>
|
|
|
|
<p>Uh oh... I think your lost? There's nothing here :P</p>
|
2024-01-27 14:19:49 -06:00
|
|
|
`)
|
2024-01-25 22:24:09 -06:00
|
|
|
})
|