Skip to content

Commit

Permalink
Rename to option (#318)
Browse files Browse the repository at this point in the history
* add documention about possible value "all" in allowed groups

* use "group" for the allowed group options, "option" for a set of args of an option
  • Loading branch information
wonderingabout authored Jun 13, 2020
1 parent f1918b0 commit 865b516
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 89 deletions.
68 changes: 34 additions & 34 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const fs = require('fs');

const { getArgNamesGRU } = require('./utils/getArgNamesGRU');
const { getFamilyName } = require('./utils/getFamilyName');
const { getOptionName } = require('./utils/getOptionName');
const { getRankedUnranked } = require('./utils/getRankedUnranked');
const { getRankedUnrankedUnderscored } = require('./utils/getRankedUnrankedUnderscored');

Expand Down Expand Up @@ -89,15 +89,15 @@ exports.updateFromArgv = function() {
.describe('unrankedonly', 'Only accept unranked matches')
.describe('fakerank', 'Fake bot ranking to calculate automatic handicap stones number in autohandicap (-1) based on rankDifference between fakerank and user ranking, to fix the bypass minhandicap maxhandicap issue if handicap is -automatic')
// 2) OPTIONS TO CHECK RANKED/UNRANKED CHALLENGES
// 2A) ALL/RANKED/UNRANKED FAMILIES
// 2A) ALL/RANKED/UNRANKED
.describe('bans', 'Comma separated list of usernames or IDs')
.string('bans')
.describe('bansranked', 'Comma separated list of usernames or IDs who are banned from ranked games')
.string('bansranked')
.describe('bansunranked', 'Comma separated list of usernames or IDs who are banned from unranked games')
.string('bansunranked')
// 2B) GENERAL/RANKED/UNRANKED FAMILIES
// 2B1) ALLOWED FAMILIES
// 2B) GENERAL/RANKED/UNRANKED
// 2B1) ALLOWED GROUP
.describe('boardsizes', 'Board size(s) to accept')
.string('boardsizes')
.describe('boardsizesranked', 'Board size(s) to accept for ranked games')
Expand All @@ -116,7 +116,7 @@ exports.updateFromArgv = function() {
.describe('timecontrols', 'Time control(s) to accept')
.describe('timecontrolsranked', 'Time control(s) to accept for ranked games')
.describe('timecontrolsunranked', 'Time control(s) to accept for unranked games')
// 2B2) GENERIC GENERAL/RANKED/UNRANKED OPTIONS
// 2B2) GENERIC GENERAL/RANKED/UNRANKED
.describe('proonly', 'For all games, only accept those from professionals')
.describe('proonlyranked', 'For ranked games, only accept those from professionals')
.describe('proonlyunranked', 'For unranked games, only accept those from professionals')
Expand Down Expand Up @@ -228,7 +228,7 @@ exports.updateFromArgv = function() {
throw `Please choose either --rankedonly or --unrankedonly, not both.`;
}

const rankedUnrankedFamilies = [{ name: "bans" },
const rankedUnrankedOptions = [{ name: "bans" },
{ name: "boardsizes", default: "9,13,19" },
{ name: "komis", default: "automatic" },
{ name: "speeds", default: "all" },
Expand Down Expand Up @@ -263,15 +263,15 @@ exports.updateFromArgv = function() {

testDroppedArgv(argv);
ensureSupportedOgspvAI(argv.ogspv, ogsPvAIs);
testRankedUnrankedFamilies(rankedUnrankedFamilies, argv);
testRankedUnrankedOptions(rankedUnrankedOptions, argv);

// C - set general/ranked/unranked families defaults
// C - set general/ranked/unranked options defaults

// For general/ranked/unranked families, do not add a default using .default of optimist, add it later in the
// For general/ranked/unranked options, do not add a default using .default of optimist, add it later in the
// code if no ranked arg nor unranked arg are used, else we would be force using the general arg regardless of
// botadmin using the ranked and/or unranked arg(s), triggering the no 3 args at the same time error.

setRankedUnrankedFamiliesDefaults(rankedUnrankedFamilies, argv);
setRankedUnrankedOptionsDefaults(rankedUnrankedOptions, argv);

// EXPORTS FROM ARGV
// 0) Export everything in argv first
Expand Down Expand Up @@ -338,7 +338,7 @@ exports.updateFromArgv = function() {
};
exports.bot_command = argv._;

// 2) specific ranked/unranked families exports
// 2) specific ranked/unranked options exports

processRankExport("minrank", argv);
processRankExport("minrankranked", argv);
Expand All @@ -360,13 +360,13 @@ exports.updateFromArgv = function() {
processKomisExport("komisranked", argv);
processKomisExport("komisunranked", argv);

processAllowedFamilyExport("speeds", argv);
processAllowedFamilyExport("speedsranked", argv);
processAllowedFamilyExport("speedsunranked", argv);
processAllowedGroupExport("speeds", argv);
processAllowedGroupExport("speedsranked", argv);
processAllowedGroupExport("speedsunranked", argv);

processAllowedFamilyExport("timecontrols", argv);
processAllowedFamilyExport("timecontrolsranked", argv);
processAllowedFamilyExport("timecontrolsunranked", argv);
processAllowedGroupExport("timecontrols", argv);
processAllowedGroupExport("timecontrolsranked", argv);
processAllowedGroupExport("timecontrolsunranked", argv);

// console messages
// C - test exports warnings
Expand All @@ -375,10 +375,10 @@ exports.updateFromArgv = function() {

}

function testRankedUnrankedFamilies(rankedUnrankedFamilies, argv) {
function testRankedUnrankedOptions(rankedUnrankedOptions, argv) {

for (const family of rankedUnrankedFamilies) {
const [general, ranked, unranked] = getArgNamesGRU(family.name);
for (const option of rankedUnrankedOptions) {
const [general, ranked, unranked] = getArgNamesGRU(option.name);

// check undefined specifically to handle valid values such as 0 or null which are tested false
if (argv[general] !== undefined) {
Expand All @@ -394,9 +394,9 @@ function testRankedUnrankedFamilies(rankedUnrankedFamilies, argv) {
}
}

function getBLCString(familyName, rankedUnranked) {
return `${familyName}blitz${rankedUnranked}, --${familyName}live${rankedUnranked} `
+ `and/or --${familyName}corr${rankedUnranked}`;
function getBLCString(optionName, rankedUnranked) {
return `${optionName}blitz${rankedUnranked}, --${optionName}live${rankedUnranked} `
+ `and/or --${optionName}corr${rankedUnranked}`;
}

// console messages
Expand Down Expand Up @@ -478,19 +478,19 @@ function ensureSupportedOgspvAI(ogspv, ogsPvAIs) {
}
}

function setRankedUnrankedFamiliesDefaults(rankedUnrankedFamilies, argv) {
for (const family of rankedUnrankedFamilies) {
if (!("default" in family)) continue;
function setRankedUnrankedOptionsDefaults(rankedUnrankedFamilies, argv) {
for (const option of rankedUnrankedFamilies) {
if (!("default" in option)) continue;

const [general, ranked, unranked] = getArgNamesGRU(family.name);
const [general, ranked, unranked] = getArgNamesGRU(option.name);

if ((argv[general] === undefined)) {
if ((argv[ranked] === undefined) && (argv[unranked] === undefined)) {
argv[general] = family.default;
argv[general] = option.default;
} else if (argv[unranked] === undefined) {
argv[ranked] = family.default;
argv[ranked] = option.default;
} else if (argv[ranked] === undefined) {
argv[unranked] = family.default;
argv[unranked] = option.default;
}
}
}
Expand Down Expand Up @@ -570,19 +570,19 @@ function processKomisExport(argName, argv) {
}
}

function processAllowedFamilyExport(argName, argv) {
function processAllowedGroupExport(argName, argv) {
const arg = argv[argName];

if (arg) {
const familyName = getFamilyName(argName);
const optionName = getOptionName(argName);
const rankedUnranked = getRankedUnranked(argName);
const rankedUnrankedUnderscored = getRankedUnrankedUnderscored(rankedUnranked);
const allowedValues = arg.split(',');
for (const allowedValue of allowedValues) {
if (allowedValue === "all") {
exports[`allow_all_${familyName}${rankedUnrankedUnderscored}`] = true;
exports[`allow_all_${optionName}${rankedUnrankedUnderscored}`] = true;
} else {
exports[`allowed_${familyName}${rankedUnrankedUnderscored}`][allowedValue] = true;
exports[`allowed_${optionName}${rankedUnrankedUnderscored}`][allowedValue] = true;
}
}
}
Expand Down
40 changes: 20 additions & 20 deletions connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ class Connection {
return { reject: false }; // OK !

}
// Check challenge allowed families settings are allowed
// Check challenge allowed group options are allowed
//
checkChallengeAllowedFamilies(notification) {
checkChallengeAllowedGroup(notification) {

// only square boardsizes, except if all is allowed
if (notification.width !== notification.height) {
Expand All @@ -443,16 +443,16 @@ class Connection {
}

// if square, check if square board size is allowed
const resultBoardsizes = getAllowedFamilyRejectResult("boardsizes", "Board size", notification.width, notification.ranked);
const resultBoardsizes = getAllowedGroupRejectResult("boardsizes", "Board size", notification.width, notification.ranked);
if (resultBoardsizes) return resultBoardsizes;

const resultKomis = getAllowedFamilyRejectResult("komis", "Komi", notification.komi, notification.ranked);
const resultKomis = getAllowedGroupRejectResult("komis", "Komi", notification.komi, notification.ranked);
if (resultKomis) return resultKomis;

const resultSpeeds = getAllowedFamilyRejectResult("speeds", "Speed", notification.time_control.speed, notification.ranked);
const resultSpeeds = getAllowedGroupRejectResult("speeds", "Speed", notification.time_control.speed, notification.ranked);
if (resultSpeeds) return resultSpeeds;

const resultTimecontrols = getAllowedFamilyRejectResult("timecontrols", "Time control", notification.time_control.time_control, notification.ranked);
const resultTimecontrols = getAllowedGroupRejectResult("timecontrols", "Time control", notification.time_control.time_control, notification.ranked);
if (resultTimecontrols) return resultTimecontrols;

return { reject: false }; // OK !
Expand Down Expand Up @@ -511,7 +511,7 @@ class Connection {
this.checkChallengeUser,
this.checkChallengeBot,
this.checkChallengeBooleans,
this.checkChallengeAllowedFamilies,
this.checkChallengeAllowedGroup,
this.checkChallengeHandicap,
this.checkChallengeTimeSettings]) {
const result = test.bind(this)(notification);
Expand Down Expand Up @@ -813,7 +813,7 @@ function boardsizeSquareToDisplayString(boardsizeSquare) {
.join(', ');
}

function getAllowedFamiliesNotifToString(argName, notif) {
function getAllowedGroupNotifToString(argName, notif) {
if (argName.includes("boardsizes")) {
return boardsizeSquareToDisplayString(notif);
}
Expand All @@ -824,37 +824,37 @@ function getAllowedFamiliesNotifToString(argName, notif) {
}
}

function getAllowedFamilyReject(argName, nameF, notif) {
function getAllowedGroupReject(argName, nameF, notif) {
const forRankedUnrankedGames = getForFromBLCRankedUnrankedGames("for ", "", argName, "");

const arg = config[argName];
const argToString = (argName.includes("boardsizes") ? boardsizeSquareToDisplayString(arg) : arg);
const notifToString = getAllowedFamiliesNotifToString(argName, notif);
const notifToString = getAllowedGroupNotifToString(argName, notif);

conn_log(`${nameF} ${forRankedUnrankedGames}is ${notifToString}, not in ${argToString} (${argName}).`);
const msg = `${nameF} ${notifToString} is not allowed on this bot${forRankedUnrankedGames}`
+ `, please choose one of these allowed ${nameF}s${forRankedUnrankedGames}:\n${argToString}.`;
return { reject: true, msg };
}

function getAllowedFamilyRejectResult(familyName, nameF, notif, notificationRanked) {
const argNames = getArgNamesGRU(familyName);
function getAllowedGroupRejectResult(optionName, nameF, notif, notificationRanked) {
const argNames = getArgNamesGRU(optionName);
const [general, ranked, unranked] = argNames;
const [general_underscored, ranked_underscored, unranked_underscored] = getArgNamesUnderscoredGRU(familyName);
const [general_underscored, ranked_underscored, unranked_underscored] = getArgNamesUnderscoredGRU(optionName);

if (config[general] && !config[ranked] && !config[unranked] && !config[`allow_all_${general_underscored}`] && !config[`allowed_${general_underscored}`][notif]) {
return getAllowedFamilyReject(general, nameF, notif);
return getAllowedGroupReject(general, nameF, notif);
}
if (config[ranked] && notificationRanked && !config[`allow_all_${ranked_underscored}`] && !config[`allowed_${ranked_underscored}`][notif]) {
return getAllowedFamilyReject(ranked, nameF, notif);
return getAllowedGroupReject(ranked, nameF, notif);
}
if (config[unranked] && !notificationRanked && !config[`allow_all_${unranked_underscored}`] && !config[`allowed_${unranked_underscored}`][notif]) {
return getAllowedFamilyReject(unranked, nameF, notif);
return getAllowedGroupReject(unranked, nameF, notif);
}
}

function getCheckedArgName(familyName, notificationRanked) {
const argNames = getArgNamesGRU(familyName);
function getCheckedArgName(optionName, notificationRanked) {
const argNames = getArgNamesGRU(optionName);
const [general, ranked, unranked] = argNames;

// for numbers, check for undefined: 0 is checked false but is a valid arg number to test against notif
Expand Down Expand Up @@ -919,8 +919,8 @@ function getMinMaxReject(argToString, notifToString, isMin,
conn_log(`${notifToString} is ${MIBL.belAbo} ${MIBL.miniMaxi} ${nameS}${forRankedUnranked}${timeControlSentence} ${argToString} (${argName}).`);

let msg = getMinMaxGenericMsg(MIBL, nameS, forRankedUnranked, timeControlSentence, argToString);
const familyNameIsRank = (argName.includes("minrank") || argName.includes("maxrank"));
if (familyNameIsRank) {
const optionNameIsRank = (argName.includes("minrank") || argName.includes("maxrank"));
if (optionNameIsRank) {
msg += ".";
} else {
msg += `, please ${MIBL.incDec} ${nameS}${middleSentence}${endingSentence}.`;
Expand Down
23 changes: 9 additions & 14 deletions docs/OPTIONS-LIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ connected games per user against this bot

### rankedonly unrankedonly

Below are the options of the "only" family.

`--rankedonly` Only accept ranked matches

`--unrankedonly` Only accept unranked matches
Expand All @@ -283,7 +281,7 @@ see [notes F](/docs/NOTES.md#f) for details
Options in this category allow us to accept or reject
a challenge based on the notification (challenge settings)

### 2A) ALL/RANKED/UNRANKED FAMILIES
### 2A) ALL/RANKED/UNRANKED

Here the general option (ex: bans) does not confict with
the ranked and unranked options for accepting/rejecting matches.
Expand All @@ -307,7 +305,7 @@ are banned from ranked games
`--bansunranked` Comma separated list of user names or IDs who
are banned from unranked games

### 2B) GENERAL/RANKED/UNRANKED FAMILIES
### 2B) GENERAL/RANKED/UNRANKED

Here you can either use:

Expand All @@ -320,20 +318,17 @@ and in that case, the general option will be ignored
and instead the ranked and unranked will be used depending
on whether the game is ranked or unranked.

### 2B1) ALLOWED FAMILIES
### 2B1) ALLOWED GROUP

For the allowed families arguments, you can either use the value:
For the allowed groups arguments, you can either use the value:

- `all`: will allow ALL possible values
- for text-only families ("blitz", "fischer", "white", etc.),
- for text-only groups (ex: speeds ("blitz", "fischer", "white", etc.)),
comma-separated values (without space) will allow every value inputted,
every other value will be rejected
- for numbers +/- text families (5.5,6.5,7.5 (komis), 9,13,19
(boardsizes)), it is possible to use as well the "range"
operator `:` to navigate one by one from min to max (ex:
`5.5:7.5` is `5.5,6.5,7.5` and `13:17` is `13,14,15,16,17`),
as well as the "increment" operator (ex: `13:19:2` is `13,15,17,19`,
see [notes A-](/docs/NOTES.md#a) for details.
- for numbers groups +/- text groups (ex: komis contain comma-separated numbers
(5.5,6.5,7.5) or text ("automatic"), (ex: boardsizes contain only comma-separated
numbers (9,13,19).

example: `--speeds blitz,live`
example 2: `--speedsranked live,correspondence --speedsunranked blitz,live`
Expand All @@ -349,7 +344,7 @@ example 3: `--komis 0.5,5.5,7.5,automatic`

Possible boardsize width value(s):

- `all` (allows all board size widths)
- `all` (allows all board sizes)
- comma separated and `:` separated values, for example
`25` (allows 25x25), or `9,13,15:17,19` (allows
9x9, 13x13, 15x15, 16x16, 17x17, 19x19)
Expand Down
Loading

0 comments on commit 865b516

Please sign in to comment.