[HQ] Proxy socket connections
This commit is contained in:
14
config.json
14
config.json
@@ -83,10 +83,16 @@
|
||||
"dbName": "weights"
|
||||
},
|
||||
"proxy": {
|
||||
"user": "grbyzyjh",
|
||||
"pass": "fxaemf5dk3w1",
|
||||
"host": "p.webshare.io",
|
||||
"protocol": "http"
|
||||
"source": "https://api.proxyscrape.com/",
|
||||
"options": {
|
||||
"request": "getproxies",
|
||||
"proxytype": "http",
|
||||
"timeout": 500,
|
||||
"country": "US,CA",
|
||||
"ssl": "all",
|
||||
"anonymity": "all"
|
||||
},
|
||||
"enabled": true
|
||||
},
|
||||
"sms": {
|
||||
"apiKey": "c9836ccdd698f43dd3c62a58e42d49d3",
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'colors';
|
||||
import faker from 'faker';
|
||||
import delay from 'delay';
|
||||
import { decode } from 'jsonwebtoken';
|
||||
import Agent from 'https-proxy-agent';
|
||||
import { discord, hq } from '../../config';
|
||||
import { getTokens, updateTokens } from '../utils/tokens';
|
||||
import { getPhone, getCode } from '../utils/sms';
|
||||
@@ -13,7 +14,7 @@ import Logger from './Logger';
|
||||
request.promise = promisify(request);
|
||||
|
||||
export default class Client {
|
||||
constructor({ accessToken, loginToken, userId }, index, weights, show) {
|
||||
constructor({ accessToken, loginToken, userId }, index, weights, show, proxy) {
|
||||
this.index = index || 0;
|
||||
|
||||
if (index === 0 || !index) this.master = true;
|
||||
@@ -22,6 +23,7 @@ export default class Client {
|
||||
this.loginToken = loginToken;
|
||||
this.userId = userId;
|
||||
this.show = show;
|
||||
this.proxy = proxy;
|
||||
|
||||
this.headers = {
|
||||
'x-hq-client': 'Android/1.6.2',
|
||||
@@ -120,9 +122,11 @@ export default class Client {
|
||||
return this.connect();
|
||||
}
|
||||
|
||||
this.ws = new WebSocket(broadcast.socketUrl, {
|
||||
headers: this.headers,
|
||||
});
|
||||
const options = { headers: this.headers };
|
||||
|
||||
if (this.proxy) options.agent = new Agent(this.proxy);
|
||||
|
||||
this.ws = new WebSocket(broadcast.socketUrl, options);
|
||||
}
|
||||
|
||||
this.ws.sendAndLog = (data) => {
|
||||
|
||||
@@ -9,10 +9,12 @@ import search from '../utils/google';
|
||||
import googlev2 from '../utils/googlev2';
|
||||
import genResults from '../utils/img';
|
||||
import validate from '../utils/tokenvalidator';
|
||||
import { getProxyList } from '../utils/proxy';
|
||||
|
||||
request.promise = promisify(request);
|
||||
|
||||
export default async (client, prize, show) => {
|
||||
const proxies = await getProxyList();
|
||||
const channels = discord.channels['hq-trivia'].map(c => client.channels.cache.get(c));
|
||||
/* const validationResults = */ await validate();
|
||||
|
||||
@@ -23,7 +25,7 @@ export default async (client, prize, show) => {
|
||||
// if (!emuOnly) channels.forEach(c => c.send(validationEmbed));
|
||||
|
||||
const tokens = getTokens(discord.defaultTokenSet);
|
||||
const master = new Client(tokens.shift(), 0, client.weights.hq, show);
|
||||
const master = new Client(tokens.shift(), 0, client.weights.hq, show, ...proxies.splice(0, 1));
|
||||
|
||||
await master.login();
|
||||
|
||||
@@ -239,7 +241,7 @@ export default async (client, prize, show) => {
|
||||
client.hqClients = [];
|
||||
});
|
||||
|
||||
tokens.forEach((t, i) => client.hqClients.push(new Client(t, i + 1, client.weights.hq, show)));
|
||||
tokens.forEach((t, i) => client.hqClients.push(new Client(t, i + 1, client.weights.hq, show, ...proxies.splice(0, 1))));
|
||||
|
||||
client.hqClients.forEach(async (c) => {
|
||||
await c.login();
|
||||
|
||||
31
src/utils/proxy.js
Normal file
31
src/utils/proxy.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { stringify } from 'querystring';
|
||||
import request from 'request';
|
||||
import { promisify } from 'util';
|
||||
import { proxy } from '../../config.json';
|
||||
import 'colors';
|
||||
|
||||
request.promise = promisify(request);
|
||||
|
||||
export const verifyProxy = async (proxy) => {
|
||||
const { statusCode } = await request.promise('https://httpstat.us/200', { proxy }).catch(() => ({ statusCode: 0 }));
|
||||
|
||||
return statusCode === 200;
|
||||
};
|
||||
|
||||
export const getProxyList = async () => {
|
||||
if (!proxy.enabled) return [];
|
||||
|
||||
console.log('Initializing proxies...'.yellow);
|
||||
|
||||
const options = stringify(proxy.options);
|
||||
|
||||
const { body } = await request.promise(`${proxy.source}?${options}`);
|
||||
|
||||
const parsed = body.trim().split(/\r?\n/).map((proxy) => (proxy.includes('://') ? proxy : `http://${proxy}`));
|
||||
const proxies = await Promise.all(parsed.map(async (proxy) => await verifyProxy(proxy) && proxy));
|
||||
const usable = proxies.filter(Boolean);
|
||||
|
||||
console.log(`Loaded ${usable.length} of ${parsed.length} proxies!`.green);
|
||||
|
||||
return usable;
|
||||
};
|
||||
Reference in New Issue
Block a user