[Config] Modify auto split threshold
This commit is contained in:
@@ -98,7 +98,7 @@
|
|||||||
},
|
},
|
||||||
"hq": {
|
"hq": {
|
||||||
"autoSplit": true,
|
"autoSplit": true,
|
||||||
"splitThreshold": 65,
|
"splitThreshold": 0.65,
|
||||||
"autoCheckpoints": false,
|
"autoCheckpoints": false,
|
||||||
"checkpointThreshold": 2
|
"checkpointThreshold": 2
|
||||||
}
|
}
|
||||||
|
|||||||
63
src/classes/SwagClient.js
Normal file
63
src/classes/SwagClient.js
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import request from 'request';
|
||||||
|
|
||||||
|
export default class SwagClient {
|
||||||
|
constructor() {
|
||||||
|
this.apiUrl = 'api.playswagiq.com';
|
||||||
|
this.appUrl = 'app.swagbucks.com';
|
||||||
|
this.socketUrl = 'wss://api.playswagiq.com/sock/1';
|
||||||
|
this.decryptionKey = '24fcc0515bffdcb56e3dfa48884dad7e020d985ae7450d605376b3547197b8b6';
|
||||||
|
this.secret = 'f7Q3QGSUOYuH9wO9m8kVRGdS1ij0hWrb';
|
||||||
|
this.headers = {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
Connection: 'keep-alive',
|
||||||
|
Accept: '*/*',
|
||||||
|
'User-Agent': 'SwagIQ-iOS/116',
|
||||||
|
'Accept-Language': 'en-US;q=1',
|
||||||
|
'Accept-Encoding': 'br, gzip, deflate',
|
||||||
|
};
|
||||||
|
this.socketHeaders = {
|
||||||
|
'Accept-Encoding': 'gzip',
|
||||||
|
'User-Agent': 'SwagIQ-iOS/116',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async requestWithEncoding(url, headers, body) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const bodyQueryString = queryString.stringify(body).replace('%2F', '/');
|
||||||
|
const options = {
|
||||||
|
url,
|
||||||
|
headers: {
|
||||||
|
...this.headers,
|
||||||
|
'Content-Length': bodyQueryString.length,
|
||||||
|
},
|
||||||
|
body: bodyQueryString,
|
||||||
|
};
|
||||||
|
|
||||||
|
const req = request.post(options);
|
||||||
|
|
||||||
|
req.on('response', (res) => {
|
||||||
|
const chunks = [];
|
||||||
|
res.on('data', (chunk) => {
|
||||||
|
chunks.push(chunk);
|
||||||
|
});
|
||||||
|
|
||||||
|
res.on('end', () => {
|
||||||
|
const buffer = Buffer.concat(chunks);
|
||||||
|
const encoding = res.headers['content-encoding'];
|
||||||
|
|
||||||
|
if (encoding === 'gzip') {
|
||||||
|
zlib.gunzip(buffer, (err, decoded) => {
|
||||||
|
resolve(parseResult(err, decoded && decoded.toString()));
|
||||||
|
});
|
||||||
|
} else if (encoding === 'deflate') {
|
||||||
|
zlib.inflate(buffer, (err, decoded) => {
|
||||||
|
resolve(parseResult(err, decoded && decoded.toString()));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve(parseResult(null, buffer.toString()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -2,7 +2,9 @@
|
|||||||
import { MessageEmbed, MessageAttachment } from 'discord.js';
|
import { MessageEmbed, MessageAttachment } from 'discord.js';
|
||||||
import Client from '../classes/Client';
|
import Client from '../classes/Client';
|
||||||
import {
|
import {
|
||||||
discord, emuOnly, logs, logChannel,
|
discord,
|
||||||
|
emuOnly,
|
||||||
|
hq,
|
||||||
} from '../../config';
|
} from '../../config';
|
||||||
import { getTokens } from '../utils/tokens';
|
import { getTokens } from '../utils/tokens';
|
||||||
import search from '../utils/google';
|
import search from '../utils/google';
|
||||||
@@ -68,9 +70,23 @@ export default async (client, prize) => {
|
|||||||
m.edit(embed);
|
m.edit(embed);
|
||||||
}, 2000);
|
}, 2000);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
const total = client.weights.hq.reduce((a, b) => a + b);
|
||||||
const bestAnswer = client.weights.hq.indexOf(Math.max(...client.weights.hq));
|
const bestAnswer = client.weights.hq.indexOf(Math.max(...client.weights.hq));
|
||||||
client.hqClients.forEach(c => c.submitAnswer(bestAnswer));
|
const bestAnswerPercentage = client.weights.hq[bestAnswer] / total;
|
||||||
}, 10000);
|
const canAnswer = client.hqClients.filter(c => c.inTheGame);
|
||||||
|
const splitArr = [...canAnswer];
|
||||||
|
if ((bestAnswerPercentage < hq.splitThreshold) && hq.autoSplit) {
|
||||||
|
const arr = [...client.weights.hq].splice(bestAnswer, 1);
|
||||||
|
const secondBestAnswer = arr.indexOf(Math.max(...arr));
|
||||||
|
const secondBestAnswerPercentage = secondBestAnswer / total;
|
||||||
|
const answers = [bestAnswerPercentage, secondBestAnswerPercentage];
|
||||||
|
answers.forEach((a, i) => {
|
||||||
|
const num = Math.round(canAnswer.length * a);
|
||||||
|
const clients = splitArr.slice(0, num <= splitArr.length ? num : splitArr.length);
|
||||||
|
clients.forEach(c => c.submitAnswer(i === 0 ? bestAnswer : secondBestAnswer));
|
||||||
|
});
|
||||||
|
} else client.hqClients.forEach(c => c.submitAnswer(bestAnswer));
|
||||||
|
}, 11000);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
clearInterval(i);
|
clearInterval(i);
|
||||||
}, 12000);
|
}, 12000);
|
||||||
@@ -114,9 +130,14 @@ export default async (client, prize) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
incorrectUsers.forEach((u) => {
|
incorrectUsers.forEach((u) => {
|
||||||
if (u.weight < 0) return;
|
if (u.weight < 0) {
|
||||||
|
client.db.updateWeight(u.id, modifier);
|
||||||
|
client.db.questionCorrect(u.id, true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
client.db.updateWeight(u.id, -modifier);
|
client.db.updateWeight(u.id, -modifier);
|
||||||
client.db.questionCorrect(u.id, false);
|
client.db.questionCorrect(u.id, false);
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (json.type === 'checkpoint') {
|
if (json.type === 'checkpoint') {
|
||||||
@@ -141,7 +162,7 @@ export default async (client, prize) => {
|
|||||||
const image = genResults('HQ Trivia', winners, winnings, `${correctCount}/${questionCount}`);
|
const image = genResults('HQ Trivia', winners, winnings, `${correctCount}/${questionCount}`);
|
||||||
const attachment = new MessageAttachment(image);
|
const attachment = new MessageAttachment(image);
|
||||||
if (!emuOnly) channels.forEach(c => c.send(attachment));
|
if (!emuOnly) channels.forEach(c => c.send(attachment));
|
||||||
if (logs) client.channels.get(logChannel).send(attachment);
|
if (discord.logs) client.channels.get(discord.logChannel).send(attachment);
|
||||||
client.activeGames.splice(client.activeGames.indexOf('hq-trivia'), 1);
|
client.activeGames.splice(client.activeGames.indexOf('hq-trivia'), 1);
|
||||||
client.hqClients = [];
|
client.hqClients = [];
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user