DDoSing myself? Don't mind if I do!

This commit is contained in:
bingus_violet 2024-04-13 00:08:16 -05:00
parent 5ef6b5525c
commit 94b24d614c
3 changed files with 58 additions and 6 deletions

View file

@ -31,6 +31,10 @@ if (!fs.existsSync(cachePath)) {
} }
} }
app.get("/discHTML", (req, res) => {
res.send(pageUpdater.getActivities())
})
app.use(pageUpdater.middleWare) app.use(pageUpdater.middleWare)
process.on('uncaughtException', (err, origin) => { process.on('uncaughtException', (err, origin) => {

View file

@ -55,7 +55,9 @@
</div> </div>
<p>Make sure to check out this project on <a href="https://codeberg.org/bingus_violet/violets-purgatory">Codeberg</a>!</p> <p>Make sure to check out this project on <a href="https://codeberg.org/bingus_violet/violets-purgatory">Codeberg</a>!</p>
<div id="activityHTML">
{ACTIVITIES} {ACTIVITIES}
</div>
<h2><hr>Services</h2> <h2><hr>Services</h2>
<p>List of services for public use hosted on Violet's Purgatory.</p> <p>List of services for public use hosted on Violet's Purgatory.</p>

View file

@ -1,7 +1,53 @@
window.onbeforeunload = function() { window.onbeforeunload = function () {
window.scrollTo(0, 0) window.scrollTo(0, 0);
} }
window.onload = function() { window.onload = function () {
window.scrollTo(0, 0) window.scrollTo(0, 0);
} }
function socketeer() {
var lanyard = new WebSocket('wss://api.violets-purgatory.dev')
lanyard.onerror = (error) => {
console.log(error)
}
lanyard.onclose = () => {
console.log("Connection Closed. Attempting Reconnect in 30 seconds.")
setTimeout(() => {
socketeer()
}, 3000);
}
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)
if (data.op == 1) {
console.log("Connected to Discord Websocket!")
ping(30000)
lastPong = Date.now()
} else if (data.op == 3) {
lastPong = Date.now()
}
var discStatusHTML = await (await fetch("/discHTML")).text();
var activityDiv = document.querySelector("#activityHTML")
activityDiv.innerHTML = discStatusHTML
})
}
socketeer()