Swap indexOf to includes when indexOf was just being used to check if an item was in an array
This commit is contained in:
parent
2e2e08f48a
commit
73e4ca94b7
2
mod.ts
2
mod.ts
|
@ -303,7 +303,7 @@ startBot({
|
||||||
// [[xdydz (aka someone copy pasted the template as a roll)
|
// [[xdydz (aka someone copy pasted the template as a roll)
|
||||||
// Help command specifically for the roll command
|
// Help command specifically for the roll command
|
||||||
commands.rollHelp(message);
|
commands.rollHelp(message);
|
||||||
} else if (command && `${command}${args.join('')}`.indexOf(config.postfix) > -1) {
|
} else if (command && `${command}${args.join('')}`.includes(config.postfix)) {
|
||||||
// [[roll]]
|
// [[roll]]
|
||||||
// Dice rolling commence!
|
// Dice rolling commence!
|
||||||
commands.roll(message, args, command);
|
commands.roll(message, args, command);
|
||||||
|
|
|
@ -23,7 +23,7 @@ export const emoji = (message: DiscordenoMessage, command: string) => {
|
||||||
config.emojis.some((curEmoji: EmojiConf) => {
|
config.emojis.some((curEmoji: EmojiConf) => {
|
||||||
log(LT.LOG, `Checking if command was emoji ${JSON.stringify(curEmoji)}`);
|
log(LT.LOG, `Checking if command was emoji ${JSON.stringify(curEmoji)}`);
|
||||||
// If a match gets found
|
// If a match gets found
|
||||||
if (curEmoji.aliases.indexOf(command || '') > -1) {
|
if (curEmoji.aliases.includes(command || '')) {
|
||||||
// Light telemetry to see how many times a command is being run
|
// Light telemetry to see how many times a command is being run
|
||||||
dbClient.execute(queries.callIncCnt('emojis')).catch((e) => utils.commonLoggers.dbError('emojis.ts:28', 'call sproc INC_CNT on', e));
|
dbClient.execute(queries.callIncCnt('emojis')).catch((e) => utils.commonLoggers.dbError('emojis.ts:28', 'call sproc INC_CNT on', e));
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ export const apiChannelManageActive = async (query: Map<string, string>, apiUser
|
||||||
erroredOut = false;
|
erroredOut = false;
|
||||||
|
|
||||||
// Determine value to set
|
// Determine value to set
|
||||||
if (path.toLowerCase().indexOf('de') > 0) {
|
if (path.toLowerCase().includes('de')) {
|
||||||
value = 0;
|
value = 0;
|
||||||
} else {
|
} else {
|
||||||
value = 1;
|
value = 1;
|
||||||
|
|
|
@ -12,7 +12,7 @@ export const apiChannelManageBan = async (query: Map<string, string>, apiUserid:
|
||||||
erroredOut = false;
|
erroredOut = false;
|
||||||
|
|
||||||
// Determine value to set
|
// Determine value to set
|
||||||
if (path.toLowerCase().indexOf('un') > 0) {
|
if (path.toLowerCase().includes('un')) {
|
||||||
value = 0;
|
value = 0;
|
||||||
} else {
|
} else {
|
||||||
value = 1;
|
value = 1;
|
||||||
|
|
|
@ -13,14 +13,14 @@ export const apiKeyManage = async (query: Map<string, string>, apiUserid: bigint
|
||||||
erroredOut = false;
|
erroredOut = false;
|
||||||
|
|
||||||
// Determine key to edit
|
// Determine key to edit
|
||||||
if (path.toLowerCase().indexOf('ban') > 0) {
|
if (path.toLowerCase().includes('ban')) {
|
||||||
key = 'banned';
|
key = 'banned';
|
||||||
} else {
|
} else {
|
||||||
key = 'active';
|
key = 'active';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine value to set
|
// Determine value to set
|
||||||
if (path.toLowerCase().indexOf('de') > 0 || path.toLowerCase().indexOf('un') > 0) {
|
if (path.toLowerCase().includes('de') || path.toLowerCase().includes('un')) {
|
||||||
value = 0;
|
value = 0;
|
||||||
} else {
|
} else {
|
||||||
value = 1;
|
value = 1;
|
||||||
|
|
|
@ -411,7 +411,7 @@ export const roll = (rollStr: string, maximizeRoll: boolean, nominalRoll: boolea
|
||||||
if (rollConf.keepLow.on && rollConf.keepLow.count === 0) {
|
if (rollConf.keepLow.on && rollConf.keepLow.count === 0) {
|
||||||
throw new Error('NoZerosAllowed_keepLow');
|
throw new Error('NoZerosAllowed_keepLow');
|
||||||
}
|
}
|
||||||
if (rollConf.reroll.on && rollConf.reroll.nums.indexOf(0) >= 0) {
|
if (rollConf.reroll.on && rollConf.reroll.nums.includes(0)) {
|
||||||
throw new Error('NoZerosAllowed_reroll');
|
throw new Error('NoZerosAllowed_reroll');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,13 +466,13 @@ export const roll = (rollStr: string, maximizeRoll: boolean, nominalRoll: boolea
|
||||||
rolling.origIdx = i;
|
rolling.origIdx = i;
|
||||||
|
|
||||||
// If critScore arg is on, check if the roll should be a crit, if its off, check if the roll matches the die size
|
// If critScore arg is on, check if the roll should be a crit, if its off, check if the roll matches the die size
|
||||||
if (rollConf.critScore.on && rollConf.critScore.range.indexOf(rolling.roll) >= 0) {
|
if (rollConf.critScore.on && rollConf.critScore.range.includes(rolling.roll)) {
|
||||||
rolling.critHit = true;
|
rolling.critHit = true;
|
||||||
} else if (!rollConf.critScore.on) {
|
} else if (!rollConf.critScore.on) {
|
||||||
rolling.critHit = rolling.roll === rollConf.dieSize;
|
rolling.critHit = rolling.roll === rollConf.dieSize;
|
||||||
}
|
}
|
||||||
// If critFail arg is on, check if the roll should be a fail, if its off, check if the roll matches 1
|
// If critFail arg is on, check if the roll should be a fail, if its off, check if the roll matches 1
|
||||||
if (rollConf.critFail.on && rollConf.critFail.range.indexOf(rolling.roll) >= 0) {
|
if (rollConf.critFail.on && rollConf.critFail.range.includes(rolling.roll)) {
|
||||||
rolling.critFail = true;
|
rolling.critFail = true;
|
||||||
} else if (!rollConf.critFail.on) {
|
} else if (!rollConf.critFail.on) {
|
||||||
if (rollType === 'fate') {
|
if (rollType === 'fate') {
|
||||||
|
@ -535,7 +535,7 @@ export const roll = (rollStr: string, maximizeRoll: boolean, nominalRoll: boolea
|
||||||
} else if (
|
} else if (
|
||||||
rollConf.exploding.on &&
|
rollConf.exploding.on &&
|
||||||
!rollSet[i].rerolled &&
|
!rollSet[i].rerolled &&
|
||||||
(rollConf.exploding.nums.length ? rollConf.exploding.nums.indexOf(rollSet[i].roll) >= 0 : rollSet[i].critHit) &&
|
(rollConf.exploding.nums.length ? rollConf.exploding.nums.includes(rollSet[i].roll) : rollSet[i].critHit) &&
|
||||||
(!rollConf.exploding.once || !rollSet[i].exploding)
|
(!rollConf.exploding.once || !rollSet[i].exploding)
|
||||||
) {
|
) {
|
||||||
// If we have exploding.nums set, use those to determine the exploding range, and make sure if !o is on, make sure we don't repeatedly explode
|
// If we have exploding.nums set, use those to determine the exploding range, and make sure if !o is on, make sure we don't repeatedly explode
|
||||||
|
@ -549,13 +549,13 @@ export const roll = (rollStr: string, maximizeRoll: boolean, nominalRoll: boolea
|
||||||
newExplodingRoll.exploding = true;
|
newExplodingRoll.exploding = true;
|
||||||
|
|
||||||
// If critScore arg is on, check if the roll should be a crit, if its off, check if the roll matches the die size
|
// If critScore arg is on, check if the roll should be a crit, if its off, check if the roll matches the die size
|
||||||
if (rollConf.critScore.on && rollConf.critScore.range.indexOf(newExplodingRoll.roll) >= 0) {
|
if (rollConf.critScore.on && rollConf.critScore.range.includes(newExplodingRoll.roll)) {
|
||||||
newExplodingRoll.critHit = true;
|
newExplodingRoll.critHit = true;
|
||||||
} else if (!rollConf.critScore.on) {
|
} else if (!rollConf.critScore.on) {
|
||||||
newExplodingRoll.critHit = newExplodingRoll.roll === rollConf.dieSize;
|
newExplodingRoll.critHit = newExplodingRoll.roll === rollConf.dieSize;
|
||||||
}
|
}
|
||||||
// If critFail arg is on, check if the roll should be a fail, if its off, check if the roll matches 1
|
// If critFail arg is on, check if the roll should be a fail, if its off, check if the roll matches 1
|
||||||
if (rollConf.critFail.on && rollConf.critFail.range.indexOf(newExplodingRoll.roll) >= 0) {
|
if (rollConf.critFail.on && rollConf.critFail.range.includes(newExplodingRoll.roll)) {
|
||||||
newExplodingRoll.critFail = true;
|
newExplodingRoll.critFail = true;
|
||||||
} else if (!rollConf.critFail.on) {
|
} else if (!rollConf.critFail.on) {
|
||||||
newExplodingRoll.critFail = newExplodingRoll.roll === 1;
|
newExplodingRoll.critFail = newExplodingRoll.roll === 1;
|
||||||
|
|
|
@ -32,7 +32,7 @@ export const fullSolver = (conf: (string | number | SolvedStep)[], wrapDetails:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate all parenthesis
|
// Evaluate all parenthesis
|
||||||
while (conf.indexOf('(') > -1) {
|
while (conf.includes('(')) {
|
||||||
loggingEnabled && log(LT.LOG, `Evaluating roll ${JSON.stringify(conf)} | Looking for (`);
|
loggingEnabled && log(LT.LOG, `Evaluating roll ${JSON.stringify(conf)} | Looking for (`);
|
||||||
// Get first open parenthesis
|
// Get first open parenthesis
|
||||||
const openParen = conf.indexOf('(');
|
const openParen = conf.indexOf('(');
|
||||||
|
@ -91,7 +91,7 @@ export const fullSolver = (conf: (string | number | SolvedStep)[], wrapDetails:
|
||||||
for (let i = 0; i < conf.length; i++) {
|
for (let i = 0; i < conf.length; i++) {
|
||||||
loggingEnabled && log(LT.LOG, `Evaluating roll ${JSON.stringify(conf)} | Evaluating ${JSON.stringify(curOps)} | Checking ${JSON.stringify(conf[i])}`);
|
loggingEnabled && log(LT.LOG, `Evaluating roll ${JSON.stringify(conf)} | Evaluating ${JSON.stringify(curOps)} | Checking ${JSON.stringify(conf[i])}`);
|
||||||
// Check if the current index is in the active tier of operators
|
// Check if the current index is in the active tier of operators
|
||||||
if (curOps.indexOf(conf[i].toString()) > -1) {
|
if (curOps.includes(conf[i].toString())) {
|
||||||
// Grab the operands from before and after the operator
|
// Grab the operands from before and after the operator
|
||||||
const operand1 = conf[i - 1];
|
const operand1 = conf[i - 1];
|
||||||
const operand2 = conf[i + 1];
|
const operand2 = conf[i + 1];
|
||||||
|
|
Loading…
Reference in New Issue