140 lines
4.4 KiB
JavaScript
140 lines
4.4 KiB
JavaScript
'use strict';
|
|
|
|
import fs from 'fs';
|
|
import WebSocket from 'ws';
|
|
import request from 'request';
|
|
import HttpsProxyAgent from 'https-proxy-agent';
|
|
|
|
import {
|
|
accounts
|
|
} from './accounts.json';
|
|
let masterPingTimeout = null;
|
|
let masterPingInterval = null;
|
|
let susmsg = {};
|
|
let socket = null;
|
|
let connected = false;
|
|
let acc = 0;
|
|
let spamloop = null;
|
|
|
|
let ks = 1;
|
|
const agent = new HttpsProxyAgent('http://ckjownvo-rotate:ke4p9155j0mk@p.webshare.io', {
|
|
secureProxy: true
|
|
});
|
|
const smessage = 'Matt can you satisfy me?';
|
|
|
|
const headers = {
|
|
'x-hq-client': 'Android/1.20.0',
|
|
'content-type': 'application/json; charset=UTF-8',
|
|
'user-agent': 'okhttp/3.8.0',
|
|
};
|
|
|
|
const S4 = () => {
|
|
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1).toUpperCase();
|
|
};
|
|
|
|
const uuid = () => {
|
|
return (S4() + S4() + "-" + S4() + "-4" + S4().substr(0, 3) + "-" + S4() + "-" + S4() + S4() + S4());
|
|
};
|
|
|
|
const run = () => {
|
|
request({
|
|
uri: 'https://api-quiz.hype.space/shows/now',
|
|
agent: agent,
|
|
headers: { ...headers,
|
|
'Authorization': `Bearer ${accounts[acc].accessToken}`
|
|
}
|
|
}, (err, res, body) => {
|
|
|
|
let response = JSON.parse(body);
|
|
if (response.active) {
|
|
|
|
susmsg = {
|
|
"type": "subscribe",
|
|
"broadcastId": response.broadcastId
|
|
};
|
|
socket = new WebSocket(response.broadcast.socketUrl, {
|
|
headers: { ...headers,
|
|
'Authorization': `Bearer ${accounts[acc].accessToken}`
|
|
},
|
|
agent: agent
|
|
});
|
|
socket.on('error', (eer) => {
|
|
console.error(eer);
|
|
console.error('WS error');
|
|
});
|
|
socket.on('pong', function () {
|
|
clearTimeout(masterPingTimeout);
|
|
});
|
|
socket.on('open', function () {
|
|
console.log('Connected!');
|
|
connected = true;
|
|
socket.send(JSON.stringify(susmsg));
|
|
spamloop = setInterval(() => {
|
|
if (ks > 50) {
|
|
socket.close();
|
|
} else {
|
|
let spammy = {
|
|
"type": "interaction",
|
|
"metadata": {
|
|
"username": accounts[acc].username,
|
|
"message": smessage,
|
|
"messageId": uuid,
|
|
"userId": accounts[acc].userId,
|
|
"interaction": "chat",
|
|
"avatarUrl": accounts[acc].avatarUrl
|
|
},
|
|
"itemId": "chat"
|
|
};
|
|
socket.send(JSON.stringify(spammy));
|
|
}
|
|
}, 8000);
|
|
masterPingInterval = setInterval(function () {
|
|
if (!connected) return;
|
|
if (!socket) return;
|
|
try {
|
|
socket.ping();
|
|
masterPingTimeout = setTimeout(function () {
|
|
socket.terminate();
|
|
try {
|
|
console.log('connection closed.');
|
|
connected = false;
|
|
} catch (e) {}
|
|
}, 2000);
|
|
} catch (error) {
|
|
socket.close();
|
|
connected = false;
|
|
}
|
|
}, 10000);
|
|
|
|
});
|
|
socket.on('message', function (message) {
|
|
console.log(message);
|
|
let msg = JSON.parse(message);
|
|
if (msg.type === "broadcastEnded") {
|
|
connected = false;
|
|
socket.close();
|
|
}
|
|
fs.appendFile('logs/messages.txt', message + '\n', function (err) {
|
|
if (err) console.error(err);
|
|
});
|
|
});
|
|
socket.on('close', function () {
|
|
connected = false;
|
|
clearInterval(spamloop);
|
|
console.log("Master closed");
|
|
});
|
|
} else {
|
|
console.warn(`HQ isn't active`);
|
|
}
|
|
});
|
|
};
|
|
|
|
|
|
setInterval(() => {
|
|
if (!connected) {
|
|
run();
|
|
acc += 1;
|
|
} else if (socket.readyState === socket.CLOSED) {
|
|
connected = false;
|
|
}
|
|
}, 5000); |