diff --git a/config.json b/config.json
index d5b46f1..59aa117 100644
--- a/config.json
+++ b/config.json
@@ -75,6 +75,8 @@
"Github": "gray",
"Steam": "lightgray",
"Univerter": "rgb(200, 175, 255)",
- "Ko-fi": "rgb(255, 150, 150)"
+ "Ko-fi": "rgb(255, 150, 150)",
+ "Revolt": "rgb(255, 50, 50)",
+ "Discord": "rgb(150, 150, 255)"
}
}
\ No newline at end of file
diff --git a/index.js b/index.js
index 2361b03..5f38520 100644
--- a/index.js
+++ b/index.js
@@ -11,7 +11,6 @@ const PORT = process.env.PORT || 8080
const staticpath = path.join(__dirname, 'static')
var mostRecentVideo = undefined
-var lanyardData = undefined
var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json')))
@@ -39,38 +38,17 @@ app.listen(PORT, () => {
console.log("Violet's Purgatory is now listening on port: " + PORT)
})
-if (!fs.existsSync(path.join(staticpath, 'cached'))) {
- fs.mkdirSync(path.join(staticpath, 'cached'))
-}
+var cachePath = path.join(staticpath, 'cached')
+var imgPath = path.join(staticpath, 'imgs')
-var randomQuotes = config.quotes
-
-var commitCount = "300+"
-
-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}`
+if (!fs.existsSync(cachePath)) {
+ fs.mkdirSync(cachePath)
+} else {
+ var files = fs.readdirSync(cachePath)
+ for (let index = 0; index < files.length; index++) {
+ const file = files[index];
+ fs.rmSync(path.join(cachePath, file))
}
-
-}
-
-function gameTimeFormatter(seconds) {
- seconds = Math.ceil(seconds)
- var minutes = Math.ceil(seconds / 60)
- var hours = Math.floor(minutes / 60)
- if (seconds <= 60) {
- return 'about ' + seconds + ' seconds'
- } else if (minutes < 60) {
- return `${minutes} Minutes`
- }
-
- return `${hours} hours and ${minutes % 60} minutes`
-
}
app.use(pageUpdater.middleWare)
\ No newline at end of file
diff --git a/overcomplicatedStatuses.js b/overcomplicatedStatuses.js
new file mode 100644
index 0000000..b9a57d1
--- /dev/null
+++ b/overcomplicatedStatuses.js
@@ -0,0 +1,195 @@
+const path = require("path")
+
+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) {
+ 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 'about ' + seconds + ' seconds'
+ } else if (minutes < 60) {
+ return `${minutes} Minutes`
+ }
+
+ return `${hours} hours and ${minutes % 60} minutes`
+
+}
+
+module.exports = {
+ activitiesToHTML: (lanyardData, cachedImages) => {
+ var debounce = false
+ var addedHTML = ""
+
+ 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 += `
What I'm up to:
`
+ debounce = true
+ }
+
+
+ function get_img(activity, size = "large_image") {
+ if (cachedImages[get_img_url(activity, size)]) {
+ var fn = cachedImages[get_img_url(activity, size)]
+ var fp = path.join(__dirname, 'static/cached', fn)
+ } else {
+ return 'imgs/notFound.png'
+ }
+
+ return '/cached/' + fn
+ }
+
+ function songStats() {
+ var html = ``
+
+ if (activity.assets && activity.assets.large_text != activity.details) {
+ html += `
+
Album: ${activity.assets.large_text || " "}
+
Artist: ${activity.state || " "}
+ `
+ } else {
+ html += `
Artist: ${activity.state || " "}`
+ }
+
+ return html
+ }
+ if (activity.type == 2) {
+ 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 += `
+
+
+
+ Listening to ${activity.name}
+
Song: ${activity.details || " "}
+ ${songStats()}
+
+
+ ${timeFormatter((activity.timestamps.end - activity.timestamps.start) / 1000)}
+
+
+
+ `
+ } else if (activity.type == 0) {
+ var time = activity.created_at
+ if (activity.timestamps) {
+ time = activity.timestamps.start
+ }
+ if (!activity.assets) {
+ activity.assets = { "large_text": " ", "small_text": " " }
+ }
+
+ function smch() {
+ if (get_img_url(activity, "small_image")) {
+ return `
`
+ }
+ return ""
+ }
+
+
+ addedHTML += `
+
+
+ ${smch()}
+
+ Playing ${activity.name}
+
${(activity.details || activity.assets.large_text || " ")}
+
${(activity.state || activity.assets.small_text || " ")}
+
${gameTimeFormatter((Date.now() - time) / 1000)}
+
+
+ `
+ } else if (activity.type != 4) {
+ var time = activity.created_at
+ if (activity.timestamps) {
+ time = activity.timestamps.start
+ }
+ if (!activity.assets) {
+ activity.assets = { "large_text": " ", "small_text": " " }
+ }
+
+ addedHTML += `
+
+
+
+ ${activity.name}
+
${(activity.details || activity.assets.large_text || " ")}
+
${(activity.state || activity.assets.small_text || " ")}
+
${gameTimeFormatter((Date.now() - time) / 1000)}
+
+
+ `
+ }
+ }
+ }
+ return addedHTML + "
"
+ }
+}
\ No newline at end of file
diff --git a/pageUpdater.js b/pageUpdater.js
index 3ec5451..2f91687 100644
--- a/pageUpdater.js
+++ b/pageUpdater.js
@@ -1,7 +1,8 @@
const path = require('path'),
fs = require('fs'),
WebSocket = require('ws'),
- minify = require('minify-html')
+ minify = require('minify-html'),
+ activityToHTML = require("./overcomplicatedStatuses.js")
var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json')))
@@ -16,30 +17,6 @@ var lanyardData = undefined
var uptime = Date.now()
function converter(html) {
- 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":
- `${statusData.text}` +
- ``,
- "UPTIME": uptime,
- "TOPBAR": ``
- }
-
- var rpTable = Object.keys(replacers)
-
- for (let index = 0; index < rpTable.length; index++) {
- const text = rpTable[index];
- html = html.replaceAll(`{${text}}`, replacers[text])
- }
-
while (html.includes("{PATH_")) {
var pagePath = html.substring(html.indexOf("{PATH_"))
pagePath = pagePath.substring(6, pagePath.indexOf('}'))
@@ -52,6 +29,42 @@ function converter(html) {
html = html.replace(stringIndex, pageHTML)
}
+ var statusText = ""
+
+ if (lanyardData) {
+ var statusData = config.discStatuses[lanyardData.discord_status]
+ var username = lanyardData.discord_user.username
+
+ if (lanyardData.activities[0] && lanyardData.activities[0].type == 4) {
+ var statusText = `
${lanyardData.activities[0].state}
`
+ }
+ } else {
+ var statusData = config.discStatuses.offline
+ var username = "bingus_violet"
+ }
+
+ 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":
+ `${statusData.text}` +
+ ``,
+ "UPTIME": uptime,
+ "TOPBAR": ``,
+ "DISCORD_USER": username,
+ "CUSTOM_STATUS": statusText,
+ "ACTIVITIES": activityToHTML.activitiesToHTML(lanyardData, cachedImages)
+ }
+
+ var rpTable = Object.keys(replacers)
+
+ for (let index = 0; index < rpTable.length; index++) {
+ const text = rpTable[index];
+ html = html.replaceAll(`{${text}}`, replacers[text])
+ }
+
var bodyHTML = html.substring(html.indexOf("") + 6, html.lastIndexOf(""))
var highTable = Object.keys(highlightedWords)
for (let index = 0; index < highTable.length; index++) {
@@ -73,6 +86,14 @@ module.exports = {
var filePath = (req.baseUrl + req.path).trim()
+ if (filePath.includes("cached") || filePath.includes("imgs")) {
+ filePath = path.join(__dirname, 'static', filePath)
+ console.log(filePath)
+ res.send(fs.readFileSync(filePath))
+
+ return
+ }
+
if (filePath.includes(".")) {
} else {
diff --git a/static/imgs/notFound.png b/static/imgs/notFound.png
new file mode 100644
index 0000000..a750080
Binary files /dev/null and b/static/imgs/notFound.png differ
diff --git a/static/index.html b/static/index.html
index a4bba37..7002f55 100644
--- a/static/index.html
+++ b/static/index.html
@@ -25,7 +25,7 @@
{RANDOM_QUOTE}
-
Violet
+
{Violet}
@@ -34,23 +34,19 @@
{DISCORD_STATUS}
-
Donate (Ko-fi)
-
-
Hi! I'm Violet, a 15 year old web and game developer.
I aspire to make fast and Javascript free websites! I'm currently learning the Godot Engine, and have been becoming quite fluent in NodeJS.
+
+
+
Hi! I'm Violet, a 15 year old web and game developer.
I aspire to make fast and Javascript free websites! I'm currently learning the Godot Engine, but most of my time recently has been spent learning NodeJS.
Beta site
Blog
Clipdump
+ {CUSTOM_STATUS}
+ {ACTIVITIES}
-
-
-
Socials
+
+
Socials
{PATH_SOCIALS}
Socials
+ Here's most of the sites you can find me on- if you needed that for some reason?
+
+ Please note I am extremely unhinged and gay on Fedi, I don't use Github, and I barely understand Docker.