use API
This commit is contained in:
parent
30a2b53c4b
commit
9a7684c048
1 changed files with 62 additions and 56 deletions
34
index.js
34
index.js
|
@ -24,6 +24,7 @@ var highlight = config.highlightedWords
|
|||
|
||||
var uptime = Date.now()
|
||||
var lastLanyardUpdate = Date.now()
|
||||
var lastPong = Date.now()
|
||||
|
||||
var thumbCount = 0
|
||||
|
||||
|
@ -381,27 +382,29 @@ async function pageUpdate() {
|
|||
|
||||
// Lanyard Stuffs
|
||||
|
||||
var lanyard = new WebSocket('wss://api.lanyard.rest/socket')
|
||||
|
||||
function beat(dur) {
|
||||
function socketeer() {
|
||||
var lanyard = new WebSocket('https://api.violets-purgatory.dev')
|
||||
function ping(dur) {
|
||||
lanyard.send(JSON.stringify({
|
||||
op: 3
|
||||
}))
|
||||
setTimeout(() => {
|
||||
beat(dur)
|
||||
ping(dur)
|
||||
if (Date.now() - lastPong > 120000) {
|
||||
console.log("FUCK!")
|
||||
lanyard.close()
|
||||
socketeer()
|
||||
}
|
||||
}, dur);
|
||||
}
|
||||
}
|
||||
|
||||
lanyard.addEventListener("message", async (res) => {
|
||||
lanyard.addEventListener("message", async (res) => {
|
||||
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"
|
||||
}
|
||||
}))
|
||||
ping(30000)
|
||||
lastPong = Date.now()
|
||||
} else if (data.op == 3) {
|
||||
lastPong = Date.now()
|
||||
} else if (data.op == 0) {
|
||||
lanyardData = data.d
|
||||
lastLanyardUpdate = Date.now()
|
||||
|
@ -439,7 +442,10 @@ lanyard.addEventListener("message", async (res) => {
|
|||
}
|
||||
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
socketeer()
|
||||
|
||||
app.get('/', async (req, res) => {
|
||||
var html = await (pageUpdate())
|
||||
|
|
Loading…
Reference in a new issue