I would call it random daily video but its not at all daily...
`
}
return ``
},
"WEATHER_MODIFIER": randomThemer.returnTheme(),
"WEATHER_TEXT": "",
"ANNOUNCEMENT": fs.readFileSync(path.join(__dirname, "config/announcement.html")),
"SOCIALS": () => {
if (lanyardData && lanyardData.socials) {
var socials = lanyardData.socials
var html = ""
var socialsTable = Object.keys(socials)
for (var i = 0; i < socialsTable.length; i++) {
var category = socialsTable[i]
var sites = socials[category]
var sitesTable = Object.keys(sites)
html += `
${category}
`
for (var x = 0; x < sitesTable.length; x++) {
var siteName = sitesTable[x]
var siteData = sites[siteName]
if (siteData.url) {
html += `${siteName}: ${siteData.name}`
}
}
html += "
"
}
}
return html
},
}
var realtimeReplacers = {
"ACTIVITIES": activityToHTML.activitiesToHTML(lanyardData),
"SPINCOUNT": globalSpins,
"UPTIME": timeFormatter((Date.now() - uptime) / 1000),
"LAST_LANYARD": timeFormatter((Date.now() - lastLanyardUpdate) / 1000),
"RANDOM_TITLE": titles[Math.floor(Math.random() * titles.length)],
"RANDOM_QUOTE": quotes[Math.floor(Math.random() * quotes.length)],
}
if (dynamic) {
var replacers = realtimeReplacers
} else {
var replacers = staticReplacers
}
html = pathReplacer(html)
var rpTable = Object.keys(replacers)
for (let index = 0; index < rpTable.length; index++) {
const text = rpTable[index];
if (dynamic) {
replacers[text] = himalaya.stringify(highlighter(himalaya.parse(replacers[text])))
}
html = html.replaceAll(`{${text}}`, replacers[text])
}
if (!dynamic) {
if (html.includes("")) {
var bodyHTML = htmlMinifier.minify(html.substring(html.indexOf("") + 6, html.lastIndexOf("")))
var parsedHTML = himalaya.parse(bodyHTML)
} else {
var parsedHTML = himalaya.parse(html)
}
parsedHTML = highlighter(parsedHTML)
parsedHTML = himalaya.stringify(parsedHTML)
if (html.includes("")) {
parsedHTML = "" + parsedHTML + ""
html = html.substring(0, html.indexOf("")) + parsedHTML + html.substring(html.indexOf("") + 7)
} else {
html = parsedHTML
}
}
if (dynamic) {
html = html.replaceAll("{LOAD_TIME}", (Date.now() - startTime).toString() + "ms")
}
return html
}
module.exports = {
getActivities: function () {
return htmlMinifier.minify(converter(activityToHTML.activitiesToHTML(lanyardData)))
},
middleWare: async function (req, res, next) {
var filePath = (req.baseUrl + req.path).trim()
if (!filePath.includes(".")) {
if (filePath.charAt(filePath.length - 1) != '/') {
res.redirect(filePath + '/')
return
}
filePath = path.join(filePath, '/index.html')
}
filePath = path.join(__dirname, 'static', filePath || 'index.html')
if (fs.existsSync(filePath)) {
var data = fs.readFileSync(filePath).toString()
res.contentType(path.basename(filePath))
if (filePath.includes(".html")) {
for (var i = 0; i < pregenFiles.length; i++) {
if (pregenFiles[i].html && pregenFiles[i].absolutePath == filePath) {
data = pregenFiles[i].html
}
}
data = converter(data, true)
// console.log(data)
}
if (!filePath.includes(".js")) {
data = htmlMinifier.minify(data)
} else {
data = await minify({
compressor: uglifyJs,
content: data
})
}
res.send(data)
} else {
res.status(404).send(`
404
Uh oh... I think your lost? There's nothing here :P
`)
}
}
}
async function updateCommits() {
var siteResponse = await (await fetch(`https://git.violets-purgatory.dev/bingus_violet/violets-purgatory/src/branch/${process.env.BRANCH || "origin"}`)).text()
var commits = siteResponse.substring(0, siteResponse.indexOf("Commits"))
commits = commits.substring(commits.lastIndexOf("") + 3, commits.lastIndexOf(""))
// ^ this works for Forgejo (basically everything i use that isnt Github, E.G. Codeberg)
// commits = commits.substring(commits.lastIndexOf(">") + 1)
// ^ This works for Github (fuck you Github)
commitCount = commits.toString()
if (process.env.BRANCH == "dev") {
commitCount += " | Beta site"
}
}
updateCommits()
// Lanyard Stuffs
var lastLanyardUpdate = Date.now()
var lastPong = 0
function pregenerate() {
for (var i = 0; i < pregenFiles.length; i++) {
var startTime = Date.now()
pregenFiles[i].html = converter(fs.readFileSync(pregenFiles[i].absolutePath).toString(), false)
pregenFiles[i].html = pregenFiles[i].html.replaceAll("{PREGEN_TIME}", Date.now() - startTime)
}
}
pregenerate()
function socketeer() {
var lanyard = new WebSocket('https://api.violets-purgatory.dev')
lanyard.on("error", (error) => {
console.log(error)
})
lanyard.on("close", () => {
console.log("Connection Closed. Attempting Reconnect in 30 seconds.")
setTimeout(() => {
socketeer()
}, 30000);
})
function ping(dur) {
lanyard.send(JSON.stringify({
op: 3
}))
setTimeout(() => {
ping(dur)
if (Date.now() - lastPong > 120000) {
lanyard.close()
console.log("Max duration since last pong exceeded- Closing socket.")
}
}, dur);
}
lanyard.addEventListener("message", async (res) => {
var data = JSON.parse(res.data)
// console.log(data.op)
if (data.op == 1) {
console.log("Connected to Discord Websocket!")
ping(30000)
lastPong = Date.now()
} else if (data.op == 3) {
lastPong = Date.now()
} else if (data.op == 0) {
lanyardData = data.d
lastLanyardUpdate = Date.now()
pregenerate()
for (var i = 0; i < lanyardData.activities.length; i++) {
var activity = lanyardData.activities[i]
if (activity.type == 4 && activity.emoji) {
if (activity.emoji.id) {
if (activity.emoji.animated) {
var emoji = Buffer.from(await (await fetch(`https://cdn.discordapp.com/emojis/${activity.emoji.id}.gif?quality=lossless`)).arrayBuffer())
} else {
var emoji = Buffer.from(await (await fetch(`https://cdn.discordapp.com/emojis/${activity.emoji.id}.png?quality=lossless`)).arrayBuffer())
}
fs.writeFileSync(path.join(__dirname, "cached/emojis", activity.emoji.id), emoji)
}
}
}
} else if (data.op == 4) {
globalSpins = data.spins
}
})
}
socketeer()