Use api
This commit is contained in:
parent
30a2b53c4b
commit
980fdd5899
1 changed files with 63 additions and 56 deletions
35
index.js
35
index.js
|
@ -381,28 +381,32 @@ 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) {
|
||||
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()
|
||||
console.log("ping")
|
||||
} else if (data.op == 3) {
|
||||
lastPong = Date.now()
|
||||
console.log("pong")
|
||||
} else if (data.op == 0) {
|
||||
console.log(data.d)
|
||||
lanyardData = data.d
|
||||
lastLanyardUpdate = Date.now()
|
||||
|
||||
|
@ -439,7 +443,10 @@ lanyard.addEventListener("message", async (res) => {
|
|||
}
|
||||
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
socketeer()
|
||||
|
||||
app.get('/', async (req, res) => {
|
||||
var html = await (pageUpdate())
|
||||
|
|
Loading…
Reference in a new issue