DDoSing myself? Don't mind if I do!
This commit is contained in:
parent
5ef6b5525c
commit
94b24d614c
3 changed files with 58 additions and 6 deletions
4
index.js
4
index.js
|
@ -31,6 +31,10 @@ if (!fs.existsSync(cachePath)) {
|
|||
}
|
||||
}
|
||||
|
||||
app.get("/discHTML", (req, res) => {
|
||||
res.send(pageUpdater.getActivities())
|
||||
})
|
||||
|
||||
app.use(pageUpdater.middleWare)
|
||||
|
||||
process.on('uncaughtException', (err, origin) => {
|
||||
|
|
|
@ -55,7 +55,9 @@
|
|||
</div>
|
||||
<p>Make sure to check out this project on <a href="https://codeberg.org/bingus_violet/violets-purgatory">Codeberg</a>!</p>
|
||||
|
||||
{ACTIVITIES}
|
||||
<div id="activityHTML">
|
||||
{ACTIVITIES}
|
||||
</div>
|
||||
|
||||
<h2><hr>Services</h2>
|
||||
<p>List of services for public use hosted on Violet's Purgatory.</p>
|
||||
|
|
|
@ -1,7 +1,53 @@
|
|||
window.onbeforeunload = function() {
|
||||
window.scrollTo(0, 0)
|
||||
window.onbeforeunload = function () {
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
window.scrollTo(0, 0)
|
||||
}
|
||||
window.onload = function () {
|
||||
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()
|
Loading…
Reference in a new issue