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' ) ,
2023-11-30 21:56:34 -06:00
WebSocket = require ( 'ws' ) ,
2023-11-30 22:17:27 -06:00
xml2json = require ( 'xml-js' )
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
2023-11-30 21:56:34 -06:00
var mastoData = {
"lastUpdate" : 0 ,
"HTML" : ""
}
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-17 08:43:11 -06:00
function pageUpdate ( ) {
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 ) {
addedHTML += ` <hr><p><em><span style="color: lightgray">" ${ lanyardData . activities [ 0 ] . state } "</span> - ${ lanyardData . discord _user . display _name } ${ new Date ( Date . now ( ) ) . getFullYear ( ) } </em></p> `
}
}
html = html . replace ( "{LANYARD_QUOTE}" , addedHTML )
addedHTML = ""
2023-11-16 19:29:22 -06:00
if ( lanyardData ) {
for ( let index = 0 ; index < lanyardData . activities . length ; index ++ ) {
const activity = lanyardData . activities [ index ] ;
2023-11-18 21:09:42 -06:00
if ( activity . type == 4 ) {
addedHTML += ` <p><em><span style="color: lightgray">" ${ lanyardData . activities [ 0 ] . state } "</span> - ${ lanyardData . discord _user . display _name } ${ new Date ( Date . now ( ) ) . getFullYear ( ) } </em></p> `
}
}
}
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 ) {
2023-11-30 22:49:14 -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
}
function get _img ( ) {
if ( "assets" in activity ) {
var image = undefined
if ( "large_image" in activity . assets ) {
image = activity . assets . large _image
} else if ( "small_image" in activity . assets ) {
image = activity . assets . small _image
}
if ( image ) {
if ( image . includes ( "https/" ) ) {
2023-11-30 20:18:56 -06:00
return decodeURIComponent ( 'https://' + image . substr ( image . indexOf ( 'https/' ) + 6 , image . length ) )
2023-11-18 21:09:42 -06:00
} else if ( image . includes ( "spotify" ) ) {
2023-11-30 20:18:56 -06:00
return decodeURIComponent ( 'https://i.scdn.co/image/' + image . substr ( image . indexOf ( 'spotify:' ) + 8 , image . length ) )
2023-11-20 18:50:02 -06:00
} else {
2023-11-30 20:18:56 -06:00
return decodeURIComponent ( ` https://cdn.discordapp.com/app-assets/ ${ activity . application _id } / ${ image } .png ` )
2023-11-18 21:09:42 -06:00
}
}
}
}
2023-11-16 19:29:22 -06:00
if ( activity . type == 2 ) {
2023-11-18 21:09:42 -06:00
if ( get _img ( ) ) {
addedHTML += `
2023-11-18 21:53:13 -06:00
< div class = "chip activity col-md-6 testing" >
2023-11-18 21:22:02 -06:00
< img src = "${get_img()}" title = "${activity.assets.large_text || activity.assets.small_text}" >
2023-11-18 21:09:42 -06:00
< p >
Listening to < span style = "color: limegreen;" > $ { activity . name } < / s p a n >
2023-11-30 21:56:34 -06:00
< br > Song : $ { activity . details }
< br > Album : $ { activity . assets . large _text }
< br > Artist : $ { activity . state }
2023-11-18 21:09:42 -06:00
< / p >
< / d i v >
`
} else {
addedHTML += `
2023-11-18 21:53:13 -06:00
< div class = "chip activity col-md-6 testing" >
2023-11-18 21:09:42 -06:00
< p style = "width: 100%;" >
Playing < span style = "color: rgb(255, 100, 150);" > $ { activity . name } < / s p a n >
< br > $ { activity . state }
< br > $ { activity . details }
< / p >
< / d i v >
`
}
} else if ( activity . type == 0 ) {
if ( get _img ( ) ) {
addedHTML += `
2023-11-18 21:53:13 -06:00
< div class = "chip activity col-md-6 testing" >
2023-11-18 21:22:02 -06:00
< img src = "${get_img()}" title = "${activity.assets.large_text || activity.assets.small_text}" >
2023-11-18 21:09:42 -06:00
< p >
Playing < span style = "color: rgb(255, 100, 150);" > $ { activity . name } < / s p a n >
2023-11-18 21:16:59 -06:00
< br > $ { activity . details || activity . assets . large _text }
2023-11-30 20:42:41 -06:00
< br > $ { activity . state || activity . assets . small _text }
2023-11-18 21:09:42 -06:00
< / p >
< / d i v >
`
} else {
addedHTML += `
2023-11-18 21:53:13 -06:00
< div class = "chip activity col-md-6 testing" >
2023-11-18 21:09:42 -06:00
< p >
Playing < span style = "color: rgb(255, 100, 150);" > $ { activity . name } < / s p a n >
< br > $ { activity . state }
< br > $ { activity . details }
< / p >
< / d i v >
`
}
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-11-30 21:56:34 -06:00
html = html . replace ( "{MASTODON_FEED}" , mastoData . HTML )
2023-12-17 21:23:39 -06:00
var now = new Date ( )
currentMonth = now . getMonth ( ) + 1
if ( [ 11 , 12 , 1 ] . includes ( currentMonth ) ) { // The Below HTML is copy and pasted from that one site :>
html = html . replace ( "{SEASONAL_EFFECT}" , `
< div class = "snowflakes" aria - hidden = "true" >
< div class = "snowflake" >
< div class = "inner" > ● < / d i v >
< / d i v >
< div class = "snowflake" >
< div class = "inner" > ● < / d i v >
< / d i v >
< div class = "snowflake" >
< div class = "inner" > ● < / d i v >
< / d i v >
< div class = "snowflake" >
< div class = "inner" > ● < / d i v >
< / d i v >
< div class = "snowflake" >
< div class = "inner" > ● < / d i v >
< / d i v >
< div class = "snowflake" >
< div class = "inner" > ● < / d i v >
< / d i v >
< div class = "snowflake" >
< div class = "inner" > ● < / d i v >
< / d i v >
< div class = "snowflake" >
< div class = "inner" > ● < / d i v >
< / d i v >
< div class = "snowflake" >
< div class = "inner" > ● < / d i v >
< / d i v >
< div class = "snowflake" >
< div class = "inner" > ● < / d i v >
< / d i v >
< div class = "snowflake" >
< div class = "inner" > ● < / d i v >
< / d i v >
< div class = "snowflake" >
< div class = "inner" > ● < / d i v >
< / d i v >
< / d i v >
< br >
< p > I love the winter : > < / p >
` )
} else {
html = html . replace ( "{SEASONAL_EFFECT}" , "" )
}
2023-11-17 08:43:11 -06:00
fs . writeFileSync ( path . join ( _ _dirname , 'static/index.html' ) , html )
}
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
2023-11-17 08:43:11 -06:00
pageUpdate ( )
2023-11-16 15:16:22 -06:00
}
2023-11-30 21:56:34 -06:00
} )
// Mastodon Updates
function mastoUpdate ( ) {
fetch ( "https://tech.lgbt/@bingus_violet.rss" )
. then ( ( data ) => {
return data . text ( )
} )
. then ( ( xml ) => {
2023-11-30 22:17:27 -06:00
var data = xml2json . xml2js ( xml , { compact : true } ) . rss . channel
2023-11-30 21:56:34 -06:00
var posts = data . item
2023-11-30 22:17:27 -06:00
var newHTML = ` <div> `
2023-11-30 21:56:34 -06:00
2023-11-30 22:41:34 -06:00
for ( let index = 0 ; index < Math . min ( posts . length , 7 ) ; index ++ ) {
2023-11-30 21:56:34 -06:00
const post = posts [ index ] ;
2023-11-30 22:17:27 -06:00
newHTML += ` <a href=" ${ post . link . _text } "><div class="post"> `
newHTML += ` <img class="minipfp" src=" ${ data . image . url . _text } "> `
newHTML += ` <h3 style="display: inline-block; vertical-align: -15%;"> ` + data . title . _text + ` </h3><br> `
newHTML += post . description . _text
2023-11-30 22:01:19 -06:00
newHTML += ` </a></div><br> `
2023-11-30 21:56:34 -06:00
}
2023-11-30 22:41:34 -06:00
mastoData . HTML = ` <h2><hr>Mastodon Posts: </h2> ` + newHTML + "</div>" + ` <br> <a class="chip" href="https://tech.lgbt/@bingus_violet">See more on Mastodon</a> `
2023-11-30 21:56:34 -06:00
pageUpdate ( )
} )
setTimeout ( ( ) => {
mastoUpdate ( )
} , 1000 * 60 * 60 )
}
2023-12-01 16:22:27 -06:00
// mastoUpdate()