Disc Status

This commit is contained in:
Bingus_Violet 2024-02-12 08:46:49 -06:00
parent ca59f56a29
commit 0fb3204df1
4 changed files with 177 additions and 185 deletions

View file

@ -2,7 +2,24 @@
"activityImages": { "activityImages": {
"ULTRAKILL": "https://fs.violets-purgatory.dev/ULTRAKILL/etc/DiscordIcon.webp" "ULTRAKILL": "https://fs.violets-purgatory.dev/ULTRAKILL/etc/DiscordIcon.webp"
}, },
"discStatuses": {
"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": "",
"color": "rgb(175, 175, 200)"
}
},
"quotes": [ "quotes": [
"Remember the 14th commandment: Thou shalt always clean thy plate and not waste anything, whether thy stomach is full, or not.", "Remember the 14th commandment: Thou shalt always clean thy plate and not waste anything, whether thy stomach is full, or not.",
"Remember son, dying is gay!", "Remember son, dying is gay!",

106
index.js
View file

@ -1,8 +1,6 @@
const express = require('express'), const express = require('express'),
path = require('path'), path = require('path'),
fs = require('fs'), fs = require('fs'),
WebSocket = require('ws'),
minify = require('minify-html'),
pageUpdater = require('./pageUpdater.js') pageUpdater = require('./pageUpdater.js')
var app = express() var app = express()
@ -10,23 +8,13 @@ var app = express()
const PORT = process.env.PORT || 8080 const PORT = process.env.PORT || 8080
const staticpath = path.join(__dirname, 'static') const staticpath = path.join(__dirname, 'static')
const resourcePath = path.join(__dirname, 'resources')
const mainpage = resourcePath + '/mainPage.html'
var lanyardData = undefined var lanyardData = undefined
var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json'))) var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json')))
var thumborInstances = config.thumborInstances var thumborInstances = config.thumborInstances
var activityImages = config.activityImages
var highlight = config.highlightedWords
var uptime = Date.now()
var lastLanyardUpdate = Date.now()
var lastPong = Date.now()
var thumbCount = 0 var thumbCount = 0
function getThumbor() { function getThumbor() {
@ -38,8 +26,6 @@ app.listen(PORT, () => {
console.log("Violet's Purgatory is now listening on port: " + PORT) console.log("Violet's Purgatory is now listening on port: " + PORT)
}) })
var cachedImages = {}
if (!fs.existsSync(path.join(staticpath, 'cached'))) { if (!fs.existsSync(path.join(staticpath, 'cached'))) {
fs.mkdirSync(path.join(staticpath, 'cached')) fs.mkdirSync(path.join(staticpath, 'cached'))
} }
@ -48,31 +34,6 @@ var randomQuotes = config.quotes
var commitCount = "300+" var commitCount = "300+"
function get_img_url(activity, size = "large_image") {
if ("assets" in activity) {
var image = activity.assets[size]
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 {
return null
}
}
}
function timeFormatter(seconds) { function timeFormatter(seconds) {
seconds = Math.ceil(seconds) seconds = Math.ceil(seconds)
var minutes = Math.floor(seconds / 60) var minutes = Math.floor(seconds / 60)
@ -100,70 +61,3 @@ function gameTimeFormatter(seconds) {
} }
app.use(pageUpdater.middleWare) app.use(pageUpdater.middleWare)
// Lanyard Stuffs
function socketeer() {
var lanyard = new WebSocket('https://api.violets-purgatory.dev')
function ping(dur) {
lanyard.send(JSON.stringify({
op: 3
}))
setTimeout(() => {
ping(dur)
if (Date.now() - lastPong > 120000) {
console.log("FUCK!")
lanyard.close()
socketeer()
}
}, dur);
}
lanyard.addEventListener("message", async (res) => {
var data = JSON.parse(res.data)
if (data.op == 1) {
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 (let index = 0; index < lanyardData.activities.length; index++) {
const activity = lanyardData.activities[index];
if (get_img_url(activity)) {
var url = get_img_url(activity)
var fn = Math.ceil(Math.random() * 100_000_000_000).toString()
var fp = path.join(__dirname, 'static/cached', fn)
if (!cachedImages[url]) {
const response = await (await fetch(url)).arrayBuffer()
fs.writeFileSync(fp, Buffer.from(response))
cachedImages[url] = fn
}
}
if (get_img_url(activity, "small_image")) {
var url = get_img_url(activity, "small_image")
var fn = Math.ceil(Math.random() * 100_000_000_000).toString()
var fp = path.join(__dirname, 'static/cached', fn)
if (!cachedImages[url]) {
const response = await (await fetch(url)).arrayBuffer()
fs.writeFileSync(fp, Buffer.from(response))
cachedImages[url] = fn
}
}
}
}
})
}
socketeer()

View file

@ -1,5 +1,7 @@
const path = require('path'), const path = require('path'),
fs = require('fs') fs = require('fs'),
WebSocket = require('ws'),
minify = require('minify-html')
var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json'))) var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json')))
@ -9,51 +11,32 @@ var titles = config.titles
var commitCount = "300+" var commitCount = "300+"
function makeStars() { var lanyardData = undefined
var html = ""
for (let index = 0; index < 35; index++) { var uptime = Date.now()
html += `<div class="rainDrop"></div>`
}
html += "<style>"
for (let index = 0; index < 35; index++) {
html += `
.rainDrop:nth-of-type(${index + 1}) {
animation: rainAnim${index} 1s linear;
animation-iteration-count: infinite;
animation-delay: ${Math.random() * 15}s;
}
`
var rando = Math.random() * 100
html += `@keyframes rainAnim${index} {
0% {
top: -10vh;
right: ${rando}vw;
visibility: visible;
}
100% {
top: 110vh;
right: calc(${rando}vw);
}
}`
}
html += "</style>"
return html
}
function converter(html) { function converter(html) {
html = html.replaceAll("{BG_EFFECT}", makeStars()) if (lanyardData) {
var statusData = config.discStatuses[lanyardData.discord_status]
} else {
var statusData = config.discStatuses.offline
}
var replacers = {
"COMMIT_COUNT": commitCount,
"RANDOM_QUOTE": quotes[Math.floor(Math.random() * quotes.length)],
"QUOTE_COUNT": quotes.length,
"RANDOM_TITLE": titles[Math.floor(Math.random() * titles.length)],
"DISCORD_STATUS":
`<span style="color: ${statusData.color};">${statusData.text}</span>` +
`<style>.pfp { border-color: ${statusData.color} }</style>`
}
html = html.replaceAll("{COMMIT_COUNT}", commitCount) var rpTable = Object.keys(replacers)
html = html.replaceAll("{RANDOM_QUOTE}", quotes[Math.floor(Math.random() * quotes.length)]) for (let index = 0; index < rpTable.length; index++) {
const text = rpTable[index];
html = html.replaceAll("{QUOTE_COUNT}", quotes.length) html = html.replaceAll(`{${text}}`, replacers[text])
}
html = html.replaceAll("{RANDOM_TITLE}", titles[Math.floor(Math.random() * titles.length)])
var highTable = Object.keys(highlightedWords) var highTable = Object.keys(highlightedWords)
for (let index = 0; index < highTable.length; index++) { for (let index = 0; index < highTable.length; index++) {
@ -100,3 +83,102 @@ async function updateCommits() {
} }
updateCommits() updateCommits()
// Lanyard Stuffs
var lastLanyardUpdate = Date.now()
var lastPong = Date.now()
var activityImages = config.activityImages
var cachedImages = {}
function get_img_url(activity, size = "large_image") {
if ("assets" in activity) {
var image = activity.assets[size]
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 {
return null
}
}
}
function socketeer() {
var lanyard = new WebSocket('https://api.violets-purgatory.dev')
function ping(dur) {
lanyard.send(JSON.stringify({
op: 3
}))
setTimeout(() => {
ping(dur)
if (Date.now() - lastPong > 120000) {
console.log("FUCK!")
lanyard.close()
socketeer()
}
}, dur);
}
lanyard.addEventListener("message", async (res) => {
var data = JSON.parse(res.data)
if (data.op == 1) {
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 (let index = 0; index < lanyardData.activities.length; index++) {
const activity = lanyardData.activities[index];
if (get_img_url(activity)) {
var url = get_img_url(activity)
var fn = Math.ceil(Math.random() * 100_000_000_000).toString()
var fp = path.join(__dirname, 'static/cached', fn)
if (!cachedImages[url]) {
const response = await (await fetch(url)).arrayBuffer()
fs.writeFileSync(fp, Buffer.from(response))
cachedImages[url] = fn
}
}
if (get_img_url(activity, "small_image")) {
var url = get_img_url(activity, "small_image")
var fn = Math.ceil(Math.random() * 100_000_000_000).toString()
var fp = path.join(__dirname, 'static/cached', fn)
if (!cachedImages[url]) {
const response = await (await fetch(url)).arrayBuffer()
fs.writeFileSync(fp, Buffer.from(response))
cachedImages[url] = fn
}
}
}
}
})
}
socketeer()

View file

@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<link rel="stylesheet" type="text/css" href="/style.css"> <link rel="stylesheet" type="text/css" href="./style.css">
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
@ -26,45 +26,44 @@
{COMMIT_COUNT}</span><br></h1> {COMMIT_COUNT}</span><br></h1>
<main> <main>
<p>{RANDOM_QUOTE}</p> <p>{RANDOM_QUOTE}</p>
<div class="container-fluid row" id="card"> <div class="container-fluid row" id="card">
<h2>Violet</h2> <h2>Violet</h2>
<div style="display: flex; justify-content: center; align-items: center;"> <div style="display: flex; justify-content: center; align-items: center;">
<img src="https://api.violets-purgatory.dev/v1/pfp" class="pfp"> <img src="https://api.violets-purgatory.dev/v1/pfp" class="pfp">
<div>
<p><a href="pronouns">They/Them</a></p>
<p>Developer</p>
<p>{DISCORD_STATUS}</p>
</div>
</div>
<div> <div>
<br> <p><a href="pronouns">They/Them</a></p>
<!-- <span style="white-space: nowrap;"> --> <p>Developer</p>
<!-- <p class="chip"><a href="https://status.violets-purgatory.dev">Status</a></p> --> <p>{DISCORD_STATUS}</p>
<p class="chip"><a href="https://fs.violets-purgatory.dev">FileShare</a></p>
<p class="chip"><a href="./socials">Socials</a></p>
<p class="chip"><a href="./projects">Projects</a></p>
<p class="chip"><a href="https://ko-fi.com/bingus_violet" style="color: rgb(255, 100, 100);">Donate</a>
</p>
<!-- </span> -->
<!-- <p class="chip"><a href="./extras">Extras</a></p> -->
<br>
<!-- <span style="white-space: nowrap;"> -->
<p class="chip"><a href="https://blog.violets-purgatory.dev">Blog</a></p>
<p class="chip"><a href="./faq">FAQ</a></p>
<p class="chip"><a href="https://beta.violets-purgatory.dev">Dev Branch</a></p>
<!-- </span> -->
<br>
<p style="padding: 10px;">Hi! I'm Violet, a 15 year old web and game developer. <br>
I aspire to make fast and javascript free websites! I'm currently learning the Godot Engine, and have been
becoming quite fluent in NodeJS.</p>
</div> </div>
</div> </div>
<p>Although my site is pretty barebones at the moment due to a recent rewrite, I hope to continue with this <div>
<br>
<!-- <span style="white-space: nowrap;"> -->
<!-- <p class="chip"><a href="https://status.violets-purgatory.dev">Status</a></p> -->
<p class="chip"><a href="https://ko-fi.com/bingus_violet" style="color: rgb(255, 100, 100);">Donate</a></p>
<p class="chip"><a href="https://fs.violets-purgatory.dev">FileShare</a></p>
<!-- <p class="chip"><a href="./socials">Socials</a></p> -->
<!-- <p class="chip"><a href="./projects">Projects</a></p> -->
<!-- </span> -->
<!-- <p class="chip"><a href="./extras">Extras</a></p> -->
<!-- <br> -->
<!-- <span style="white-space: nowrap;"> -->
<p class="chip"><a href="https://blog.violets-purgatory.dev">Blog</a></p>
<!-- <p class="chip"><a href="./faq">FAQ</a></p> -->
<p class="chip"><a href="https://beta.violets-purgatory.dev">Dev Branch</a></p>
<!-- </span> -->
<br>
<p style="padding: 10px;">Hi! I'm Violet, a 15 year old web and game developer. <br>
I aspire to make fast and javascript free websites! I'm currently learning the Godot Engine, and
have been
becoming quite fluent in NodeJS.</p>
</div>
</div>
<p>Although my site is pretty barebones at the moment due to a recent rewrite, I hope to continue with this
passion and update this website along with it. passion and update this website along with it.
</p> </p>
<p>As is probably very obvious, I'm not great at graphic design at the moment, but I hope to improve upon that
as time goes on.<br><span class="note">I'm sure you can tell I have a pretty low self esteem too...</span>
</p>
</main> </main>
</body> </body>