Disc Status
This commit is contained in:
parent
ca59f56a29
commit
0fb3204df1
4 changed files with 177 additions and 185 deletions
166
pageUpdater.js
166
pageUpdater.js
|
@ -1,5 +1,7 @@
|
|||
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')))
|
||||
|
||||
|
@ -9,51 +11,32 @@ var titles = config.titles
|
|||
|
||||
var commitCount = "300+"
|
||||
|
||||
function makeStars() {
|
||||
var html = ""
|
||||
var lanyardData = undefined
|
||||
|
||||
for (let index = 0; index < 35; index++) {
|
||||
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
|
||||
}
|
||||
var uptime = Date.now()
|
||||
|
||||
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)])
|
||||
|
||||
html = html.replaceAll("{QUOTE_COUNT}", quotes.length)
|
||||
|
||||
html = html.replaceAll("{RANDOM_TITLE}", titles[Math.floor(Math.random() * titles.length)])
|
||||
for (let index = 0; index < rpTable.length; index++) {
|
||||
const text = rpTable[index];
|
||||
html = html.replaceAll(`{${text}}`, replacers[text])
|
||||
}
|
||||
|
||||
var highTable = Object.keys(highlightedWords)
|
||||
for (let index = 0; index < highTable.length; index++) {
|
||||
|
@ -99,4 +82,103 @@ async function updateCommits() {
|
|||
commitCount = commits
|
||||
}
|
||||
|
||||
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()
|
Loading…
Add table
Add a link
Reference in a new issue