Add new settings, fix a couple bugs, and add sample config.

Also updated gitignore
This commit is contained in:
eTronic
2018-07-05 10:16:49 -04:00
parent 7f42d67895
commit d8adeae427
6 changed files with 171 additions and 5 deletions

6
.gitignore vendored
View File

@@ -59,3 +59,9 @@ typings/
# next.js build output
.next
# Config file
config.js
# Player accounts
accounts.json

View File

@@ -73,8 +73,11 @@ export default class Player {
}
removePlayer() {
this.socket.terminate();
this.socket.close();
if (this.socket) {
this.socket.terminate();
this.socket.close();
}
this.handleClose();
}
async handleMessage(data) {
@@ -109,6 +112,7 @@ export default class Player {
this.logger.log(`Player ${this.username} sent answer ${answerNumber}) ${answer.text}`);
} catch (error) {
this.logger.log(`WebSocket error: ${this.username} can\'t send answer.`, LOG_TYPES.ERROR);
this.logger.logSilent(error);
this.lastAnswerId = null;
}
}

View File

@@ -9,6 +9,7 @@ import {
DISCORD_WEIGHTS,
PUSH_SUGGESTION_SECONDS,
SEND_SUGGESTION_SECONDS,
SUGGEST_USING_DELTAS,
TEST_MODE,
} from './config';

View File

@@ -79,8 +79,8 @@ export default class Searcher {
})
});
const textLower = text.toLowerCase().replace('\'', '');
if (textLower.includes('not') || textLower.includes('never') || textLower.includes('isnt') || textLower.includes('didnt')) {
const textLower = text.replace('\'', '');
if (textLower.includes('NOT') || textLower.includes('never') || textLower.includes('isnt') || textLower.includes('didnt')) {
const totalAnswers = answer1 + answer2 + answer3;
answer1 = totalAnswers - answer1;
answer2 = totalAnswers - answer2;

151
config.example.js Normal file
View File

@@ -0,0 +1,151 @@
// MASTER - Needed to do pretty much everything.
export const MASTER_BEARER_TOKEN = '';
// SERVER - Trivia server and default header settings.
export const SERVER_URL = 'api-quiz.hype.space';
export const HEADERS = {
'x-hq-client': 'Android/1.12.2',
'content-type': 'application/json; charset=UTF-8',
'user-agent': 'okhttp/3.8.0',
};
// TESTING - When true, uses the test server.
export const TEST_MODE = false;
export const TEST_SERVER = 'wss://hqecho.herokuapp.com/';
export const MAX_TEST_PLAYERS = 5;
export const MAX_TEST_QUESTIONS = 1;
// LOGGING - When enabled, writes each session to the specified directory.
export const ENABLE_LOGGING = true;
export const LOG_DIR = './logs/'
// Set AUTOPLAY to true if you wish to have the game wait and play automatically next game.
// Time buffer in ms to wait after end of previous game to check for new game.
// 1000 * 60 * 10 would be 10 minutes.
export const AUTOPLAY = true;
export const NEXT_GAME_TIME_BUFFER = 1000 * 60 * 5;
// Time buffer in ms before time is up when the game will choose for you.
// 1000 * 1 would be 1 second.
export const TIME_EXPIRE_BUFFER = 1000 * 1;
// Uses extra lives automatically if player has them if prize is > threshold set below.
export const USE_EXTRA_LIFE_MIN_PRIZE = 10000;
// If nothing is chosen before time expires, answers will send via the following choices.
export const SPLIT_MODES = {
// 33% of players will be allocated all 3 choices.
EVENLY: 'evenly',
// Players will split all 3 choices proportionally by weights.
// ** Requires Discord and/or Google Module enabled.
WEIGHTS: 'weights',
// Players will split all 3 choices proportionally by what Google recommends.
// ** Requires Google Module enabled.
GOOGLE: 'google',
// Players will either split or choose best answer based on suggestion algorithm.
// ** Requires Discord Module enabled.
SUGGESTION: 'suggestion',
};
export const SPLIT_MODE = SPLIT_MODES.SUGGESTION;
// If true, the SUGGESTION split modes will utilize the trend in answers over time to give
// suggestion instead of raw normalized weights. Useful for certain savage questions where
// people at the last second tend to have the correct answer but majority of the weights
// have already gone with a different answer.
export const SUGGEST_USING_DELTAS = false;
// If true, game will always split 1/2/3 before time expires if % of remaining players is
// greater than certain threshold of all remaining players below.
export const DISCRETE_MODE = true;
export const MAX_PERCENTAGE_OF_REMAINING = 5;
// If true, game will always split 1/2/3 before time expires if potential pot is > threshold.
export const SAFE_WINNINGS_MODE = true;
export const MIN_AMOUNT_THRESHOLD = 50;
// Start sending suggestions after this many seconds
// ** Requires Discord and/or Google Module enabled.
export const SEND_SUGGESTION_SECONDS = 4;
// Start sending suggestions after this many seconds
// ** Requires Discord and/or Google Module enabled with Pushover module enabled.
export const PUSH_SUGGESTION_SECONDS = 7;
// If true, game will call send answers on x amount of players evenly for each second after the
// interval set below.
export const STAGGER_ANSWERS = false;
export const STAGGER_AT_INTERVAL = 4;
// If true, game will try to predict savage questions and reserve a portion of your players
// to allow automatic win.
export const PREDICT_SAVAGE = true;
// If true, in autoplay last answer will always split evenly to ensure at least 1 win.
export const SPLIT_LAST_ROUND = true;
/***********************************/
/* EXTRA MODULES */
/***********************************/
// DISCORD
export const ENABLE_DISCORD = false;
export const DISCORD_SETTINGS = {
// This is the token that allows you to read community answers
SCRAPER_TOKEN: '',
// This is the token that allows you to post results if you wish. Leave null to disable.
PUBLISH_TOKEN: null,
// Ids of channels to push to (make sure your bot has permissions in each channel);
PUBLISH_CHANNELS: [''],
};
export const DISCORD_SOURCES = [
/*
{
name: 'Main Source',
id: '1234567890987654321',
channels: [
{
name: 'trivia-channel',
id: '12345123451234512345',
weightModifier: 30,
},
],
},
{
name: 'Testing Source',
id: '112233445566778899',
channels: [
{
name: 'testing-channel',
id: '998877665544332211',
weightModifier: 1,
},
],
isTestChannel: true,
},
*/
];
export const DISCORD_WEIGHTS = {
'standard': 10,
'apg': 30,
'not': -10,
'w': 1,
'?': 3,
'apb': 2,
'its': 30,
};
// PUSHOVER - Push notifications via pushover.net
export const ENABLE_PUSH = false;
export const PUSH_SETTINGS = {
PUSHOVER_USER: '',
PUSHOVER_TOKEN: '',
};
// GOOGLE
export const ENABLE_GOOGLE = false;
export const GOOGLE_SETTINGS = {
// The below two correspond exactly to what they're called in your Google Custom Search.
// See Google Custom Search API to get started.
// You'll want to make sure your site searches all www.google.com and not just a custom domain.
API_KEY: '',
CX: '',
};

View File

@@ -26,10 +26,14 @@ import {
MAX_TEST_QUESTIONS,
MIN_AMOUNT_THRESHOLD,
NEXT_GAME_TIME_BUFFER,
PREDICT_SAVAGE,
SAFE_WINNINGS_MODE,
SERVER_URL,
SPLIT_LAST_ROUND,
SPLIT_MODE,
SPLIT_MODES,
STAGGER_ANSWERS,
STAGGER_AT_INTERVAL,
TEST_MODE,
TEST_SERVER,
TIME_EXPIRE_BUFFER,
@@ -304,7 +308,7 @@ export default class Trivia {
const { answerCounts, advancingPlayersCount, id: questionId } = questionSummary;
const answerIndex = answerCounts.findIndex(answer => answer.correct);
const correctAnswer = answerCounts[answerIndex];
this.game.currentPlayersRemaining = this.advancingPlayersCount;
this.game.currentPlayersRemaining = advancingPlayersCount;
if (this.scraper) {
this.scraper.showSummary(questionSummary, answerIndex);