Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
|
83595482b7 | |
|
cdc710385f | |
|
59d4435c32 | |
|
2cfa923093 | |
|
c58ebcc9f9 | |
|
e01097b1e3 | |
|
4efbed7424 | |
|
4a5e33c9a0 | |
|
6bf671f82d | |
|
587d5aa19d | |
|
1bb8c1a308 | |
|
e06abac9cf |
|
@ -1,4 +1,4 @@
|
||||||
# The Artificer - A Dice Rolling Discord Bot | V4.1.1 - 2025/08/05
|
# The Artificer - A Dice Rolling Discord Bot | V4.1.2 - 2025/08/06
|
||||||
[](https://sonarcloud.io/summary/new_code?id=TheArtificer)
|
[](https://sonarcloud.io/summary/new_code?id=TheArtificer)
|
||||||
[](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer)
|
[](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
export const config = {
|
export const config = {
|
||||||
name: 'The Artificer', // Name of the bot
|
name: 'The Artificer', // Name of the bot
|
||||||
maxFileSize: 8_388_290, // Max file size bot can send
|
maxFileSize: 8_388_290, // Max file size bot can send
|
||||||
version: '4.1.1', // Version of the bot
|
version: '4.1.2', // Version of the bot
|
||||||
token: 'the_bot_token', // Discord API Token for this bot
|
token: 'the_bot_token', // Discord API Token for this bot
|
||||||
localtoken: 'local_testing_token', // Discord API Token for a secondary OPTIONAL testing bot, THIS MUST BE DIFFERENT FROM "token"
|
localtoken: 'local_testing_token', // Discord API Token for a secondary OPTIONAL testing bot, THIS MUST BE DIFFERENT FROM "token"
|
||||||
prefix: '[[', // Prefix for all commands
|
prefix: '[[', // Prefix for all commands
|
||||||
|
@ -16,7 +16,7 @@ export const config = {
|
||||||
guild: 1_000, // Allows guilds to have 1000 aliased rolls for free
|
guild: 1_000, // Allows guilds to have 1000 aliased rolls for free
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
maxLoops: 1_000_000, // Determines how long the bot will attempt a roll, number of loops before it kills a roll. Increase this at your own risk.
|
maxLoops: 2_000_000, // Determines how long the bot will attempt a roll, number of loops before it kills a roll. Increase this at your own risk.
|
||||||
maxWorkers: 16, // Maximum number of worker threads to spawn at once (Set this to less than the number of threads your CPU has, Artificer will eat it all if too many rolls happen at once)
|
maxWorkers: 16, // Maximum number of worker threads to spawn at once (Set this to less than the number of threads your CPU has, Artificer will eat it all if too many rolls happen at once)
|
||||||
workerTimeout: 300_000, // Maximum time before the bot kills a worker thread in ms
|
workerTimeout: 300_000, // Maximum time before the bot kills a worker thread in ms
|
||||||
defaultSimulatedNominal: 10_000, // Default number of loops to run for simulating a nominal
|
defaultSimulatedNominal: 10_000, // Default number of loops to run for simulating a nominal
|
||||||
|
|
|
@ -23,6 +23,7 @@ export interface SolvedRoll {
|
||||||
line1: string;
|
line1: string;
|
||||||
line2: string;
|
line2: string;
|
||||||
line3: string;
|
line3: string;
|
||||||
|
footer: string;
|
||||||
counts: CountDetails;
|
counts: CountDetails;
|
||||||
rollDistributions: RollDistributionMap;
|
rollDistributions: RollDistributionMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,12 @@ import { tokenizeCmd } from 'artigen/cmdTokenizer.ts';
|
||||||
|
|
||||||
import { Modifiers } from 'artigen/dice/getModifiers.ts';
|
import { Modifiers } from 'artigen/dice/getModifiers.ts';
|
||||||
|
|
||||||
import { loopCountCheck } from 'artigen/managers/loopManager.ts';
|
import { getLoopCount, loopCountCheck } from 'artigen/managers/loopManager.ts';
|
||||||
import { QueuedRoll } from 'artigen/managers/manager.d.ts';
|
import { QueuedRoll } from 'artigen/managers/manager.d.ts';
|
||||||
|
|
||||||
import { reduceCountDetails } from 'artigen/utils/counter.ts';
|
import { reduceCountDetails } from 'artigen/utils/counter.ts';
|
||||||
import { cmdSplitRegex, escapeCharacters, withYVarsDash } from 'artigen/utils/escape.ts';
|
import { cmdSplitRegex, escapeCharacters, withYVarsDash } from 'artigen/utils/escape.ts';
|
||||||
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
import { loggingEnabled, showLoopCountDebug } from 'artigen/utils/logFlag.ts';
|
||||||
import { assertPrePostBalance } from 'artigen/utils/parenBalance.ts';
|
import { assertPrePostBalance } from 'artigen/utils/parenBalance.ts';
|
||||||
import { reduceRollDistMaps } from 'artigen/utils/rollDist.ts';
|
import { reduceRollDistMaps } from 'artigen/utils/rollDist.ts';
|
||||||
import { compareTotalRolls, compareTotalRollsReverse, sortYVars } from 'artigen/utils/sortFuncs.ts';
|
import { compareTotalRolls, compareTotalRollsReverse, sortYVars } from 'artigen/utils/sortFuncs.ts';
|
||||||
|
@ -26,6 +26,7 @@ export const runCmd = (rollRequest: QueuedRoll): SolvedRoll => {
|
||||||
line1: '',
|
line1: '',
|
||||||
line2: '',
|
line2: '',
|
||||||
line3: '',
|
line3: '',
|
||||||
|
footer: '',
|
||||||
counts: {
|
counts: {
|
||||||
total: 0,
|
total: 0,
|
||||||
successful: 0,
|
successful: 0,
|
||||||
|
@ -109,7 +110,7 @@ export const runCmd = (rollRequest: QueuedRoll): SolvedRoll => {
|
||||||
if (rollRequest.modifiers.simulatedNominal) line2 += `Iterations performed per roll: \`${rollRequest.modifiers.simulatedNominal.toLocaleString()}\`\n`;
|
if (rollRequest.modifiers.simulatedNominal) line2 += `Iterations performed per roll: \`${rollRequest.modifiers.simulatedNominal.toLocaleString()}\`\n`;
|
||||||
|
|
||||||
// Reduce counts to a single object
|
// Reduce counts to a single object
|
||||||
returnMsg.counts = reduceCountDetails(tempCountDetails);
|
if (rollRequest.modifiers.count) returnMsg.counts = reduceCountDetails(tempCountDetails);
|
||||||
|
|
||||||
// If a regular nominal and roll looks somewhat complex, alert user simulatedNominal exists
|
// If a regular nominal and roll looks somewhat complex, alert user simulatedNominal exists
|
||||||
if (rollRequest.modifiers.nominalRoll && tempReturnData.filter((data) => data.isComplex).length) {
|
if (rollRequest.modifiers.nominalRoll && tempReturnData.filter((data) => data.isComplex).length) {
|
||||||
|
@ -120,7 +121,7 @@ export const runCmd = (rollRequest: QueuedRoll): SolvedRoll => {
|
||||||
const line2Space = rollRequest.modifiers.noSpaces ? '' : ' ';
|
const line2Space = rollRequest.modifiers.noSpaces ? '' : ' ';
|
||||||
// Fill out all of the details and results now
|
// Fill out all of the details and results now
|
||||||
tempReturnData.forEach((e, i) => {
|
tempReturnData.forEach((e, i) => {
|
||||||
loopCountCheck();
|
loopCountCheck('artigen.ts - tempReturnData');
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `Parsing roll ${rollRequest.rollCmd} | Making return text ${JSON.stringify(e)}`);
|
loggingEnabled && log(LT.LOG, `Parsing roll ${rollRequest.rollCmd} | Making return text ${JSON.stringify(e)}`);
|
||||||
let preFormat = '';
|
let preFormat = '';
|
||||||
|
@ -169,7 +170,7 @@ export const runCmd = (rollRequest: QueuedRoll): SolvedRoll => {
|
||||||
returnMsg.line3 = line3;
|
returnMsg.line3 = line3;
|
||||||
|
|
||||||
// Reduce rollDist maps into a single map
|
// Reduce rollDist maps into a single map
|
||||||
returnMsg.rollDistributions = reduceRollDistMaps(tempRollDists);
|
if (rollRequest.modifiers.rollDist) returnMsg.rollDistributions = reduceRollDistMaps(tempRollDists);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Fill in the return block
|
// Fill in the return block
|
||||||
const solverError = e as Error;
|
const solverError = e as Error;
|
||||||
|
@ -178,5 +179,7 @@ export const runCmd = (rollRequest: QueuedRoll): SolvedRoll => {
|
||||||
[returnMsg.errorCode, returnMsg.errorMsg] = translateError(solverError);
|
[returnMsg.errorCode, returnMsg.errorMsg] = translateError(solverError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (showLoopCountDebug) returnMsg.footer = `Loop Count: ${getLoopCount()}`;
|
||||||
|
|
||||||
return returnMsg;
|
return returnMsg;
|
||||||
};
|
};
|
||||||
|
|
|
@ -32,7 +32,7 @@ export const tokenizeCmd = (
|
||||||
|
|
||||||
// Wrapped commands still exist, unwrap them
|
// Wrapped commands still exist, unwrap them
|
||||||
while (cmd.includes(config.prefix)) {
|
while (cmd.includes(config.prefix)) {
|
||||||
loopCountCheck();
|
loopCountCheck('cmdTokenizer.ts - while cmd includes prefix');
|
||||||
|
|
||||||
const openIdx = cmd.indexOf(config.prefix);
|
const openIdx = cmd.indexOf(config.prefix);
|
||||||
const closeIdx = getMatchingPostfixIdx(cmd, openIdx);
|
const closeIdx = getMatchingPostfixIdx(cmd, openIdx);
|
||||||
|
@ -49,7 +49,7 @@ export const tokenizeCmd = (
|
||||||
|
|
||||||
const simulatedData: ReturnData[] = [];
|
const simulatedData: ReturnData[] = [];
|
||||||
for (let i = 0; i < simulatedLoopCount; i++) {
|
for (let i = 0; i < simulatedLoopCount; i++) {
|
||||||
loopCountCheck();
|
loopCountCheck(`cmdTokenizer.ts - simulate nominal loop #${i}`);
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `In simLoop:${i} "${currentCmd}" of ${JSON.stringify(cmd)}`);
|
loggingEnabled && log(LT.LOG, `In simLoop:${i} "${currentCmd}" of ${JSON.stringify(cmd)}`);
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ export const tokenizeCmd = (
|
||||||
loggingEnabled && log(LT.LOG, `ConfirmCrit on ${JSON.stringify(currentCmd)}`);
|
loggingEnabled && log(LT.LOG, `ConfirmCrit on ${JSON.stringify(currentCmd)}`);
|
||||||
let done = false;
|
let done = false;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
loopCountCheck();
|
loopCountCheck('cmdTokenizer.ts - confirming crit');
|
||||||
|
|
||||||
// Keep running the same roll again until its not successful
|
// Keep running the same roll again until its not successful
|
||||||
const [ccTempData, ccTempCounts, ccTempDists] = tokenizeCmd(
|
const [ccTempData, ccTempCounts, ccTempDists] = tokenizeCmd(
|
||||||
|
@ -194,7 +194,7 @@ export const tokenizeCmd = (
|
||||||
const tempInitConf = data.initConfig.split(internalGrpWrapRegex).filter((x) => x);
|
const tempInitConf = data.initConfig.split(internalGrpWrapRegex).filter((x) => x);
|
||||||
loggingEnabled && log(LT.LOG, `Split solved math into tempInitConf ${JSON.stringify(tempInitConf)}`);
|
loggingEnabled && log(LT.LOG, `Split solved math into tempInitConf ${JSON.stringify(tempInitConf)}`);
|
||||||
while (tempInitConf.includes(openInternalGrp)) {
|
while (tempInitConf.includes(openInternalGrp)) {
|
||||||
loopCountCheck();
|
loopCountCheck('cmdTokenizer.ts - handling internal group result merging');
|
||||||
|
|
||||||
const openIdx = tempInitConf.indexOf(openInternalGrp);
|
const openIdx = tempInitConf.indexOf(openInternalGrp);
|
||||||
const closeIdx = getMatchingInternalGrpIdx(tempInitConf, openIdx);
|
const closeIdx = getMatchingInternalGrpIdx(tempInitConf, openIdx);
|
||||||
|
@ -214,7 +214,7 @@ export const tokenizeCmd = (
|
||||||
.filter((x) => x);
|
.filter((x) => x);
|
||||||
loggingEnabled && log(LT.LOG, `Split tempInitConfig into initConf ${JSON.stringify(initConf)}`);
|
loggingEnabled && log(LT.LOG, `Split tempInitConfig into initConf ${JSON.stringify(initConf)}`);
|
||||||
while (initConf.includes(openInternal)) {
|
while (initConf.includes(openInternal)) {
|
||||||
loopCountCheck();
|
loopCountCheck('cmdTokenizer.ts - handling internal nested roll result merging');
|
||||||
|
|
||||||
const openIdx = initConf.indexOf(openInternal);
|
const openIdx = initConf.indexOf(openInternal);
|
||||||
const closeIdx = getMatchingInternalIdx(initConf, openIdx);
|
const closeIdx = getMatchingInternalIdx(initConf, openIdx);
|
||||||
|
|
|
@ -80,7 +80,7 @@ export const executeRoll = (rollStr: string, modifiers: RollModifiers): Executed
|
||||||
for (let i = 0; i < rollConf.dieCount; i++) {
|
for (let i = 0; i < rollConf.dieCount; i++) {
|
||||||
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | Initial rolling ${i} of ${JSON.stringify(rollConf)}`);
|
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | Initial rolling ${i} of ${JSON.stringify(rollConf)}`);
|
||||||
// If loopCount gets too high, stop trying to calculate infinity
|
// If loopCount gets too high, stop trying to calculate infinity
|
||||||
loopCountCheck();
|
loopCountCheck('executeRoll.ts - handling initial rolling');
|
||||||
|
|
||||||
// Copy the template to fill out for this iteration
|
// Copy the template to fill out for this iteration
|
||||||
const rolling = getTemplateRoll();
|
const rolling = getTemplateRoll();
|
||||||
|
@ -104,7 +104,7 @@ export const executeRoll = (rollStr: string, modifiers: RollModifiers): Executed
|
||||||
for (let i = 0; i < rollSet.length; i++) {
|
for (let i = 0; i < rollSet.length; i++) {
|
||||||
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | Handling rerolling and exploding ${JSON.stringify(rollSet[i])}`);
|
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | Handling rerolling and exploding ${JSON.stringify(rollSet[i])}`);
|
||||||
// If loopCount gets too high, stop trying to calculate infinity
|
// If loopCount gets too high, stop trying to calculate infinity
|
||||||
loopCountCheck();
|
loopCountCheck('executeRoll.ts - handling rerolling and exploding');
|
||||||
|
|
||||||
// This big boolean statement first checks if reroll is on, if the roll is within the reroll range, and finally if ro is ON, make sure we haven't already rerolled the roll
|
// This big boolean statement first checks if reroll is on, if the roll is within the reroll range, and finally if ro is ON, make sure we haven't already rerolled the roll
|
||||||
if (rollConf.reroll.on && rollConf.reroll.nums.includes(rollSet[i].roll) && (!rollConf.reroll.once || !rollSet[i ? i - 1 : i].rerolled)) {
|
if (rollConf.reroll.on && rollConf.reroll.nums.includes(rollSet[i].roll) && (!rollConf.reroll.once || !rollSet[i ? i - 1 : i].rerolled)) {
|
||||||
|
@ -117,7 +117,7 @@ export const executeRoll = (rollStr: string, modifiers: RollModifiers): Executed
|
||||||
if (modifiers.maxRoll && !minMaxOverride) {
|
if (modifiers.maxRoll && !minMaxOverride) {
|
||||||
// If maximizeRoll is on and we've entered the reroll code, dieSize is not allowed, determine the next best option and always return that
|
// If maximizeRoll is on and we've entered the reroll code, dieSize is not allowed, determine the next best option and always return that
|
||||||
mmMaxLoop: for (let m = rollConf.dieSize - 1; m > 0; m--) {
|
mmMaxLoop: for (let m = rollConf.dieSize - 1; m > 0; m--) {
|
||||||
loopCountCheck();
|
loopCountCheck('executeRoll.ts - maximizeRoll');
|
||||||
|
|
||||||
if (!rollConf.reroll.nums.includes(m)) {
|
if (!rollConf.reroll.nums.includes(m)) {
|
||||||
minMaxOverride = m;
|
minMaxOverride = m;
|
||||||
|
@ -127,7 +127,7 @@ export const executeRoll = (rollStr: string, modifiers: RollModifiers): Executed
|
||||||
} else if (modifiers.minRoll && !minMaxOverride) {
|
} else if (modifiers.minRoll && !minMaxOverride) {
|
||||||
// If minimizeRoll is on and we've entered the reroll code, 1 is not allowed, determine the next best option and always return that
|
// If minimizeRoll is on and we've entered the reroll code, 1 is not allowed, determine the next best option and always return that
|
||||||
mmMinLoop: for (let m = rollConf.dPercent.on ? 1 : 2; m <= rollConf.dieSize; m++) {
|
mmMinLoop: for (let m = rollConf.dPercent.on ? 1 : 2; m <= rollConf.dieSize; m++) {
|
||||||
loopCountCheck();
|
loopCountCheck('executeRoll.ts - minimizeRoll');
|
||||||
|
|
||||||
if (!rollConf.reroll.nums.includes(m)) {
|
if (!rollConf.reroll.nums.includes(m)) {
|
||||||
minMaxOverride = m;
|
minMaxOverride = m;
|
||||||
|
@ -181,7 +181,7 @@ export const executeRoll = (rollStr: string, modifiers: RollModifiers): Executed
|
||||||
for (const penRoll of rollSet) {
|
for (const penRoll of rollSet) {
|
||||||
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | Handling penetrating explosions ${JSON.stringify(penRoll)}`);
|
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | Handling penetrating explosions ${JSON.stringify(penRoll)}`);
|
||||||
// If loopCount gets too high, stop trying to calculate infinity
|
// If loopCount gets too high, stop trying to calculate infinity
|
||||||
loopCountCheck();
|
loopCountCheck('executeRoll.ts - penetrating explosion');
|
||||||
|
|
||||||
// If the die was from an explosion, decrement it by one
|
// If the die was from an explosion, decrement it by one
|
||||||
if (penRoll.exploding) {
|
if (penRoll.exploding) {
|
||||||
|
@ -195,7 +195,7 @@ export const executeRoll = (rollStr: string, modifiers: RollModifiers): Executed
|
||||||
for (let i = 0; i < rollSet.length; i++) {
|
for (let i = 0; i < rollSet.length; i++) {
|
||||||
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | Handling compounding explosions ${JSON.stringify(rollSet[i])}`);
|
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | Handling compounding explosions ${JSON.stringify(rollSet[i])}`);
|
||||||
// If loopCount gets too high, stop trying to calculate infinity
|
// If loopCount gets too high, stop trying to calculate infinity
|
||||||
loopCountCheck();
|
loopCountCheck('executeRoll.ts - compounding explosion');
|
||||||
|
|
||||||
// Compound the exploding rolls, including the exploding flag and
|
// Compound the exploding rolls, including the exploding flag and
|
||||||
if (rollSet[i].exploding) {
|
if (rollSet[i].exploding) {
|
||||||
|
@ -215,8 +215,7 @@ export const executeRoll = (rollStr: string, modifiers: RollModifiers): Executed
|
||||||
let rerollCount = 0;
|
let rerollCount = 0;
|
||||||
if (rollConf.reroll.on) {
|
if (rollConf.reroll.on) {
|
||||||
for (let j = 0; j < rollSet.length; j++) {
|
for (let j = 0; j < rollSet.length; j++) {
|
||||||
// If loopCount gets too high, stop trying to calculate infinity
|
loopCountCheck('executeRoll.ts - count rerolls');
|
||||||
loopCountCheck();
|
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | Setting originalIdx on ${JSON.stringify(rollSet[j])}`);
|
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | Setting originalIdx on ${JSON.stringify(rollSet[j])}`);
|
||||||
rollSet[j].origIdx = j;
|
rollSet[j].origIdx = j;
|
||||||
|
@ -265,8 +264,7 @@ export const executeRoll = (rollStr: string, modifiers: RollModifiers): Executed
|
||||||
// Now its time to drop all dice needed
|
// Now its time to drop all dice needed
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while (dropCount > 0 && i < rollSet.length) {
|
while (dropCount > 0 && i < rollSet.length) {
|
||||||
// If loopCount gets too high, stop trying to calculate infinity
|
loopCountCheck('executeRoll.ts - dropping/keeping');
|
||||||
loopCountCheck();
|
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | Dropping dice ${dropCount} ${JSON.stringify(rollSet[i])}`);
|
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | Dropping dice ${dropCount} ${JSON.stringify(rollSet[i])}`);
|
||||||
// Skip all rolls that were rerolled
|
// Skip all rolls that were rerolled
|
||||||
|
@ -290,7 +288,7 @@ export const executeRoll = (rollStr: string, modifiers: RollModifiers): Executed
|
||||||
|
|
||||||
// Drop all dice that are not a part of the max
|
// Drop all dice that are not a part of the max
|
||||||
for (const ovaRoll of rollSet) {
|
for (const ovaRoll of rollSet) {
|
||||||
loopCountCheck();
|
loopCountCheck('executeRoll.ts - OVA');
|
||||||
|
|
||||||
loggingEnabled &&
|
loggingEnabled &&
|
||||||
log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | checking if this roll should be dropped ${ovaRoll.roll} | to keep: ${maxRoll}`);
|
log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | checking if this roll should be dropped ${ovaRoll.roll} | to keep: ${maxRoll}`);
|
||||||
|
@ -311,7 +309,7 @@ export const executeRoll = (rollStr: string, modifiers: RollModifiers): Executed
|
||||||
const labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
const labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||||
let labelIdx = 0;
|
let labelIdx = 0;
|
||||||
const rollLabels: Array<string> = rollVals.map((count) => {
|
const rollLabels: Array<string> = rollVals.map((count) => {
|
||||||
loopCountCheck();
|
loopCountCheck('executeRoll.ts - matching');
|
||||||
|
|
||||||
if (labelIdx >= labels.length) {
|
if (labelIdx >= labels.length) {
|
||||||
throw new Error(`TooManyLabels_${labels.length}`);
|
throw new Error(`TooManyLabels_${labels.length}`);
|
||||||
|
@ -327,7 +325,7 @@ export const executeRoll = (rollStr: string, modifiers: RollModifiers): Executed
|
||||||
|
|
||||||
// Apply labels
|
// Apply labels
|
||||||
for (const roll of rollSet) {
|
for (const roll of rollSet) {
|
||||||
loopCountCheck();
|
loopCountCheck('executeRoll.ts - labeling matches');
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | trying to add a label to ${JSON.stringify(roll)}`);
|
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | trying to add a label to ${JSON.stringify(roll)}`);
|
||||||
if (rollLabels[roll.roll - 1]) {
|
if (rollLabels[roll.roll - 1]) {
|
||||||
|
|
|
@ -20,7 +20,7 @@ export const formatRoll = (executedRoll: ExecutedRoll, modifiers: RollModifiers)
|
||||||
// Loop thru all parts of the roll to document everything that was done to create the total roll
|
// Loop thru all parts of the roll to document everything that was done to create the total roll
|
||||||
loggingEnabled && log(LT.LOG, `Formatting roll ${JSON.stringify(executedRoll)}`);
|
loggingEnabled && log(LT.LOG, `Formatting roll ${JSON.stringify(executedRoll)}`);
|
||||||
executedRoll.rollSet.forEach((e) => {
|
executedRoll.rollSet.forEach((e) => {
|
||||||
loopCountCheck();
|
loopCountCheck('generateFormattedRoll.ts - formatting executed roll');
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `At ${JSON.stringify(e)}`);
|
loggingEnabled && log(LT.LOG, `At ${JSON.stringify(e)}`);
|
||||||
let preFormat = '';
|
let preFormat = '';
|
||||||
|
|
|
@ -14,7 +14,7 @@ export const getGroupConf = (groupStr: string, rawStr: string): GroupConf => {
|
||||||
|
|
||||||
let biggest = parseInt(numberMatches.length ? numberMatches[0] : '1');
|
let biggest = parseInt(numberMatches.length ? numberMatches[0] : '1');
|
||||||
for (const num of numberMatches) {
|
for (const num of numberMatches) {
|
||||||
loopCountCheck();
|
loopCountCheck('getGroupConf.ts - finding biggest number for die size');
|
||||||
|
|
||||||
const curNum = parseInt(num);
|
const curNum = parseInt(num);
|
||||||
loggingEnabled && log(LT.LOG, `Finding biggest number to use as die size, ${curNum} ${biggest}`);
|
loggingEnabled && log(LT.LOG, `Finding biggest number to use as die size, ${curNum} ${biggest}`);
|
||||||
|
@ -37,7 +37,7 @@ export const getGroupConf = (groupStr: string, rawStr: string): GroupConf => {
|
||||||
let maxFail: number | null = null;
|
let maxFail: number | null = null;
|
||||||
|
|
||||||
while (groupSplit.length) {
|
while (groupSplit.length) {
|
||||||
loopCountCheck();
|
loopCountCheck('getGroupConf.ts - parsing groupConf');
|
||||||
|
|
||||||
const option = groupSplit.shift() ?? '';
|
const option = groupSplit.shift() ?? '';
|
||||||
const value = parseInt(groupSplit.shift() ?? '');
|
const value = parseInt(groupSplit.shift() ?? '');
|
||||||
|
|
|
@ -126,7 +126,7 @@ export const getRollConf = (rollStr: string, customTypes: CustomDiceShapes = new
|
||||||
const difficulty = parseInt(tempDifficulty.slice(0, afterDifficultyIdx) || '10');
|
const difficulty = parseInt(tempDifficulty.slice(0, afterDifficultyIdx) || '10');
|
||||||
|
|
||||||
for (let i = difficulty; i <= rollConf.dieSize; i++) {
|
for (let i = difficulty; i <= rollConf.dieSize; i++) {
|
||||||
loopCountCheck();
|
loopCountCheck('getRollConf.ts - setting cwod difficulty');
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling cwod ${rollStr} | Parsing difficulty ${i}`);
|
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling cwod ${rollStr} | Parsing difficulty ${i}`);
|
||||||
rollConf.success.range.push(i);
|
rollConf.success.range.push(i);
|
||||||
|
@ -216,7 +216,7 @@ export const getRollConf = (rollStr: string, customTypes: CustomDiceShapes = new
|
||||||
|
|
||||||
// Loop until all remaining args are parsed
|
// Loop until all remaining args are parsed
|
||||||
while (remains.length > 0) {
|
while (remains.length > 0) {
|
||||||
loopCountCheck();
|
loopCountCheck('getRollConf.ts - parsing rollConf');
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | Parsing remains ${remains}`);
|
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | Parsing remains ${remains}`);
|
||||||
// Find the next number in the remains to be able to cut out the rule name
|
// Find the next number in the remains to be able to cut out the rule name
|
||||||
|
@ -232,7 +232,7 @@ export const getRollConf = (rollStr: string, customTypes: CustomDiceShapes = new
|
||||||
let noNumberAfter = false;
|
let noNumberAfter = false;
|
||||||
if (!(Object.values(DiceOptions) as string[]).includes(tempSep)) {
|
if (!(Object.values(DiceOptions) as string[]).includes(tempSep)) {
|
||||||
NumberlessDiceOptions.some((opt) => {
|
NumberlessDiceOptions.some((opt) => {
|
||||||
loopCountCheck();
|
loopCountCheck('getRollConf.ts - parsing numberlessDiceOptions');
|
||||||
loggingEnabled && log(LT.LOG, `In NumberlessDiceOptions ${opt} ${tempSep.startsWith(opt) && tempSep !== opt}`);
|
loggingEnabled && log(LT.LOG, `In NumberlessDiceOptions ${opt} ${tempSep.startsWith(opt) && tempSep !== opt}`);
|
||||||
if (tempSep.startsWith(opt) && tempSep !== opt) {
|
if (tempSep.startsWith(opt) && tempSep !== opt) {
|
||||||
afterSepIdx = opt.length;
|
afterSepIdx = opt.length;
|
||||||
|
|
|
@ -30,7 +30,7 @@ export const handleGroup = (
|
||||||
|
|
||||||
// Nested groups still exist, unwrap them
|
// Nested groups still exist, unwrap them
|
||||||
while (groupParts.includes('{')) {
|
while (groupParts.includes('{')) {
|
||||||
loopCountCheck();
|
loopCountCheck('groupHandler.ts - handling nested groups');
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `Handling Nested Groups | Current cmd: ${JSON.stringify(groupParts)}`);
|
loggingEnabled && log(LT.LOG, `Handling Nested Groups | Current cmd: ${JSON.stringify(groupParts)}`);
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ export const handleGroup = (
|
||||||
const groupResults: ReturnData[] = [];
|
const groupResults: ReturnData[] = [];
|
||||||
|
|
||||||
for (const part of commaParts) {
|
for (const part of commaParts) {
|
||||||
loopCountCheck();
|
loopCountCheck('groupHandler.ts - solving commaParts');
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `Solving commaPart: ${part}`);
|
loggingEnabled && log(LT.LOG, `Solving commaPart: ${part}`);
|
||||||
const [tempData, tempCounts, tempDists] = tokenizeMath(part, modifiers, previousResults, prevGrpReturnData);
|
const [tempData, tempCounts, tempDists] = tokenizeMath(part, modifiers, previousResults, prevGrpReturnData);
|
||||||
|
@ -131,7 +131,7 @@ export const handleGroup = (
|
||||||
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while (dropCount > 0 && i < groupResults.length) {
|
while (dropCount > 0 && i < groupResults.length) {
|
||||||
loopCountCheck();
|
loopCountCheck('groupHandler.ts - handling group drop/keep');
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `Handling group dropping | Dropping ${dropCount}`);
|
loggingEnabled && log(LT.LOG, `Handling group dropping | Dropping ${dropCount}`);
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ export const handleGroup = (
|
||||||
let failCnt = 0;
|
let failCnt = 0;
|
||||||
if (groupConf.success.on || groupConf.fail.on) {
|
if (groupConf.success.on || groupConf.fail.on) {
|
||||||
groupResults.forEach((rd, idx) => {
|
groupResults.forEach((rd, idx) => {
|
||||||
loopCountCheck();
|
loopCountCheck('groupHandler.ts - handling group success/fail');
|
||||||
|
|
||||||
if (!resultFlags[idx].dropped) {
|
if (!resultFlags[idx].dropped) {
|
||||||
if (
|
if (
|
||||||
|
@ -265,7 +265,7 @@ export const handleGroup = (
|
||||||
const initConf = retData.initConfig.split(internalGrpWrapRegex).filter((x) => x);
|
const initConf = retData.initConfig.split(internalGrpWrapRegex).filter((x) => x);
|
||||||
loggingEnabled && log(LT.LOG, `Split retData into initConf ${JSON.stringify(initConf)}`);
|
loggingEnabled && log(LT.LOG, `Split retData into initConf ${JSON.stringify(initConf)}`);
|
||||||
while (initConf.includes(openInternalGrp)) {
|
while (initConf.includes(openInternalGrp)) {
|
||||||
loopCountCheck();
|
loopCountCheck('groupHandler.ts - handling merging nested groups up');
|
||||||
|
|
||||||
const openIdx = initConf.indexOf(openInternalGrp);
|
const openIdx = initConf.indexOf(openInternalGrp);
|
||||||
const closeIdx = getMatchingInternalGrpIdx(initConf, openIdx);
|
const closeIdx = getMatchingInternalGrpIdx(initConf, openIdx);
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
import { closeLog, initLog } from '@Log4Deno';
|
import { closeLog, initLog } from '@Log4Deno';
|
||||||
|
|
||||||
import { runCmd } from 'artigen/artigen.ts';
|
import { runCmd } from 'artigen/artigen.ts';
|
||||||
|
import { SolvedRoll } from 'artigen/artigen.d.ts';
|
||||||
|
|
||||||
import { QueuedRoll } from 'artigen/managers/manager.d.ts';
|
import { QueuedRoll } from 'artigen/managers/manager.d.ts';
|
||||||
|
|
||||||
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
import { loggingEnabled, loopLoggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||||
|
|
||||||
loggingEnabled && initLog('logs/worker', loggingEnabled);
|
if (loggingEnabled || loopLoggingEnabled) initLog('logs/worker', loggingEnabled || loopLoggingEnabled);
|
||||||
|
|
||||||
// Extend the BigInt prototype to support JSON.stringify
|
// Extend the BigInt prototype to support JSON.stringify
|
||||||
interface BigIntX extends BigInt {
|
interface BigIntX extends BigInt {
|
||||||
|
@ -23,13 +24,14 @@ self.postMessage('ready');
|
||||||
// Handle the roll
|
// Handle the roll
|
||||||
self.onmessage = async (e: MessageEvent<QueuedRoll>) => {
|
self.onmessage = async (e: MessageEvent<QueuedRoll>) => {
|
||||||
const payload = e.data;
|
const payload = e.data;
|
||||||
const returnMsg = runCmd(payload) || {
|
const returnMsg: SolvedRoll = runCmd(payload) || {
|
||||||
error: true,
|
error: true,
|
||||||
errorCode: 'EmptyMessage',
|
errorCode: 'EmptyMessage',
|
||||||
errorMsg: 'Error: Empty message',
|
errorMsg: 'Error: Empty message',
|
||||||
line1: '',
|
line1: '',
|
||||||
line2: '',
|
line2: '',
|
||||||
line3: '',
|
line3: '',
|
||||||
|
footer: '',
|
||||||
counts: {
|
counts: {
|
||||||
total: 0,
|
total: 0,
|
||||||
successful: 0,
|
successful: 0,
|
||||||
|
@ -37,9 +39,12 @@ self.onmessage = async (e: MessageEvent<QueuedRoll>) => {
|
||||||
rerolled: 0,
|
rerolled: 0,
|
||||||
dropped: 0,
|
dropped: 0,
|
||||||
exploded: 0,
|
exploded: 0,
|
||||||
|
success: 0,
|
||||||
|
fail: 0,
|
||||||
|
matches: new Map<string, number>(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
self.postMessage(returnMsg);
|
self.postMessage(returnMsg);
|
||||||
loggingEnabled && (await closeLog());
|
if (loggingEnabled || loopLoggingEnabled) await closeLog();
|
||||||
self.close();
|
self.close();
|
||||||
};
|
};
|
||||||
|
|
|
@ -278,7 +278,7 @@ Please click on "<@${botId}> *Click to see attachment*" above this message to se
|
||||||
details: returnMsg.line3,
|
details: returnMsg.line3,
|
||||||
},
|
},
|
||||||
counts: rollRequest.modifiers.count ? returnMsg.counts : null,
|
counts: rollRequest.modifiers.count ? returnMsg.counts : null,
|
||||||
rollDistributions: returnMsg.rollDistributions.entries().toArray(),
|
rollDistributions: rollRequest.modifiers.rollDist ? returnMsg.rollDistributions.entries().toArray() : null,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
|
import { log, LogTypes as LT } from '@Log4Deno';
|
||||||
|
|
||||||
import config from '~config';
|
import config from '~config';
|
||||||
|
|
||||||
|
import { loopLoggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||||
|
|
||||||
let loopCount = 0;
|
let loopCount = 0;
|
||||||
|
|
||||||
// Will ensure if maxLoops is 10, 10 loops will be allowed, 11 will not.
|
// Will ensure if maxLoops is 10, 10 loops will be allowed, 11 will not.
|
||||||
export const loopCountCheck = (): void => {
|
export const loopCountCheck = (location = 'unset'): void => {
|
||||||
loopCount++;
|
loopCount++;
|
||||||
|
loopLoggingEnabled && log(LT.LOG, `Loop #${loopCount} at "${location}"`);
|
||||||
if (loopCount > config.limits.maxLoops) {
|
if (loopCount > config.limits.maxLoops) {
|
||||||
throw new Error('MaxLoopsExceeded');
|
throw new Error('MaxLoopsExceeded');
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ export const mathSolver = (conf: MathConf[], wrapDetails = false): SolvedStep =>
|
||||||
|
|
||||||
// Evaluate all parenthesis
|
// Evaluate all parenthesis
|
||||||
while (conf.includes('(')) {
|
while (conf.includes('(')) {
|
||||||
loopCountCheck();
|
loopCountCheck('mathSolver.ts - evaluating parens');
|
||||||
|
|
||||||
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
|
||||||
|
@ -75,7 +75,7 @@ export const mathSolver = (conf: MathConf[], wrapDetails = false): SolvedStep =>
|
||||||
// Start at index 1 as there will never be implicit multiplication before the first element
|
// Start at index 1 as there will never be implicit multiplication before the first element
|
||||||
loggingEnabled && log(LT.LOG, `Checking for missing implicit multiplication ${JSON.stringify(conf)}`);
|
loggingEnabled && log(LT.LOG, `Checking for missing implicit multiplication ${JSON.stringify(conf)}`);
|
||||||
for (let i = 1; i < conf.length; i++) {
|
for (let i = 1; i < conf.length; i++) {
|
||||||
loopCountCheck();
|
loopCountCheck('mathSolver.ts - checking for implicit multiplication');
|
||||||
|
|
||||||
const prevConfAsStr = <string> conf[i - 1];
|
const prevConfAsStr = <string> conf[i - 1];
|
||||||
const curConfAsStr = <string> conf[i];
|
const curConfAsStr = <string> conf[i];
|
||||||
|
@ -94,14 +94,15 @@ export const mathSolver = (conf: MathConf[], wrapDetails = false): SolvedStep =>
|
||||||
['+', '-'],
|
['+', '-'],
|
||||||
];
|
];
|
||||||
allCurOps.forEach((curOps) => {
|
allCurOps.forEach((curOps) => {
|
||||||
loggingEnabled && log(LT.LOG, `Evaluating roll ${JSON.stringify(conf)} | Evaluating ${JSON.stringify(curOps)}`);
|
// No loopCountCheck here since its finite/will always be 3 loops
|
||||||
|
loggingEnabled && log(LT.LOG, `Cur Ops ${JSON.stringify(curOps)}`);
|
||||||
// Iterate thru all operators/operands in the conf
|
// Iterate thru all operators/operands in the conf
|
||||||
for (let i = 0; i < conf.length; i++) {
|
for (let i = 0; i < conf.length; i++) {
|
||||||
loopCountCheck();
|
loggingEnabled && log(LT.LOG, `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.includes(conf[i].toString())) {
|
if (curOps.includes(conf[i].toString())) {
|
||||||
|
loggingEnabled && log(LT.LOG, `Evaluating roll ${JSON.stringify(conf)} as ${JSON.stringify(conf[i])} is in curOps`);
|
||||||
|
loopCountCheck('mathSolver.ts - evaluating roll');
|
||||||
// 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];
|
||||||
|
|
|
@ -45,11 +45,11 @@ export const tokenizeMath = (
|
||||||
loggingEnabled && log(LT.LOG, `Split roll into mathConf ${JSON.stringify(mathConf)}`);
|
loggingEnabled && log(LT.LOG, `Split roll into mathConf ${JSON.stringify(mathConf)}`);
|
||||||
|
|
||||||
// Verify balanced parens before doing anything
|
// Verify balanced parens before doing anything
|
||||||
assertParenBalance(mathConf);
|
if (mathConf.includes('(') || mathConf.includes(')')) assertParenBalance(mathConf);
|
||||||
|
|
||||||
// Evaluate all rolls into stepSolve format and all numbers into floats
|
// Evaluate all rolls into stepSolve format and all numbers into floats
|
||||||
for (let i = 0; i < mathConf.length; i++) {
|
for (let i = 0; i < mathConf.length; i++) {
|
||||||
loopCountCheck();
|
loopCountCheck('mathTokenizer.ts - parsing all tokens into MathConf');
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `Parsing roll ${JSON.stringify(cmd)} | Evaluating rolls into math-able items ${JSON.stringify(mathConf[i])}`);
|
loggingEnabled && log(LT.LOG, `Parsing roll ${JSON.stringify(cmd)} | Evaluating rolls into math-able items ${JSON.stringify(mathConf[i])}`);
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ export const tokenizeMath = (
|
||||||
const formattedRoll = formatRoll(executedRoll, modifiers);
|
const formattedRoll = formatRoll(executedRoll, modifiers);
|
||||||
mathConf[i] = formattedRoll.solvedStep;
|
mathConf[i] = formattedRoll.solvedStep;
|
||||||
countDetails.push(formattedRoll.countDetails);
|
countDetails.push(formattedRoll.countDetails);
|
||||||
rollDists.push(formattedRoll.rollDistributions);
|
if (modifiers.rollDist) rollDists.push(formattedRoll.rollDistributions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ export const tokenizeMath = (
|
||||||
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while (dropCount > 0 && i < allRollSets.length) {
|
while (dropCount > 0 && i < allRollSets.length) {
|
||||||
loopCountCheck();
|
loopCountCheck('mathTokenizer.ts - handling group dropping');
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `Handling group dropping | Dropping ${dropCount}, looking at ${JSON.stringify(allRollSets[i])}`);
|
loggingEnabled && log(LT.LOG, `Handling group dropping | Dropping ${dropCount}, looking at ${JSON.stringify(allRollSets[i])}`);
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ export const tokenizeMath = (
|
||||||
// Handle marking new successes/fails
|
// Handle marking new successes/fails
|
||||||
if (groupConf.success.on || groupConf.fail.on) {
|
if (groupConf.success.on || groupConf.fail.on) {
|
||||||
allRollSets.forEach((rs) => {
|
allRollSets.forEach((rs) => {
|
||||||
loopCountCheck();
|
loopCountCheck('mathTokenizer.ts - handling group success/fails');
|
||||||
|
|
||||||
if (!rs.dropped && !rs.rerolled) {
|
if (!rs.dropped && !rs.rerolled) {
|
||||||
if (groupConf.success.on && groupConf.success.range.includes(rs.roll)) {
|
if (groupConf.success.on && groupConf.success.range.includes(rs.roll)) {
|
||||||
|
@ -318,7 +318,7 @@ export const tokenizeMath = (
|
||||||
const formattedRoll = formatRoll(executedRoll, modifiers);
|
const formattedRoll = formatRoll(executedRoll, modifiers);
|
||||||
mathConf[rollGroupIdx] = formattedRoll.solvedStep;
|
mathConf[rollGroupIdx] = formattedRoll.solvedStep;
|
||||||
countDetails.push(formattedRoll.countDetails);
|
countDetails.push(formattedRoll.countDetails);
|
||||||
rollDists.push(formattedRoll.rollDistributions);
|
if (modifiers.rollDist) rollDists.push(formattedRoll.rollDistributions);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ export const rollCounter = (rollSet: RollSet[]): CountDetails => {
|
||||||
};
|
};
|
||||||
|
|
||||||
rollSet.forEach((roll) => {
|
rollSet.forEach((roll) => {
|
||||||
loopCountCheck();
|
loopCountCheck('counter.ts - summing RollSet into CountDetails');
|
||||||
countDetails.total++;
|
countDetails.total++;
|
||||||
if (roll.critHit) countDetails.successful++;
|
if (roll.critHit) countDetails.successful++;
|
||||||
if (roll.critFail) countDetails.failed++;
|
if (roll.critFail) countDetails.failed++;
|
||||||
|
@ -34,9 +34,9 @@ export const rollCounter = (rollSet: RollSet[]): CountDetails => {
|
||||||
export const reduceCountDetails = (counts: CountDetails[]): CountDetails =>
|
export const reduceCountDetails = (counts: CountDetails[]): CountDetails =>
|
||||||
counts.reduce(
|
counts.reduce(
|
||||||
(acc, cur) => {
|
(acc, cur) => {
|
||||||
loopCountCheck();
|
loopCountCheck('counter.ts - merging array of CountDetails down to single CountDetail');
|
||||||
cur.matches.forEach((cnt, label) => {
|
cur.matches.forEach((cnt, label) => {
|
||||||
loopCountCheck();
|
loopCountCheck('counter.ts - merging matches');
|
||||||
acc.matches.set(label, (acc.matches.get(label) ?? 0) + cnt);
|
acc.matches.set(label, (acc.matches.get(label) ?? 0) + cnt);
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -259,13 +259,17 @@ export const generateRollEmbed = (
|
||||||
|
|
||||||
// Embed desc limit is 4096
|
// Embed desc limit is 4096
|
||||||
// Discord only formats 200 items per message
|
// Discord only formats 200 items per message
|
||||||
if (fullDesc.length < 4_000 && formattingCount <= 200) {
|
const fullSize = fullDesc.length + returnDetails.footer.length;
|
||||||
|
if (fullSize < 4_000 && formattingCount <= 200) {
|
||||||
// Response is valid size
|
// Response is valid size
|
||||||
return {
|
return {
|
||||||
charCount: fullDesc.length,
|
charCount: fullSize,
|
||||||
embed: {
|
embed: {
|
||||||
color: infoColor2,
|
color: infoColor2,
|
||||||
description: fullDesc,
|
description: fullDesc,
|
||||||
|
footer: {
|
||||||
|
text: returnDetails.footer,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
hasAttachment: false,
|
hasAttachment: false,
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,12 +11,14 @@ import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||||
export const escapeCharacters = (str: string, esc: string): string => {
|
export const escapeCharacters = (str: string, esc: string): string => {
|
||||||
// Loop thru each esc char one at a time
|
// Loop thru each esc char one at a time
|
||||||
for (const e of esc) {
|
for (const e of esc) {
|
||||||
loopCountCheck();
|
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `Escaping character ${e} | ${str}, ${esc}`);
|
loggingEnabled && log(LT.LOG, `Escaping character ${e} | ${str}, ${esc}`);
|
||||||
// Create a new regex to look for that char that needs replaced and escape it
|
if (str.includes(e)) {
|
||||||
const tempRgx = new RegExp(`[${e}]`, 'g');
|
loopCountCheck(`escape.ts - escaping character ${e}`);
|
||||||
str = str.replace(tempRgx, `\\${e}`);
|
|
||||||
|
// Create a new regex to look for that char that needs replaced and escape it
|
||||||
|
const tempRgx = new RegExp(`[${e}]`, 'g');
|
||||||
|
str = str.replace(tempRgx, `\\${e}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
export const loggingEnabled = false;
|
export const loggingEnabled = false;
|
||||||
|
export const loopLoggingEnabled = false;
|
||||||
|
export const showLoopCountDebug = false;
|
||||||
|
|
|
@ -22,7 +22,8 @@ const checkBalance = (
|
||||||
|
|
||||||
// Verify there are equal numbers of opening and closing parenthesis by adding 1 for opening parens and subtracting 1 for closing parens
|
// Verify there are equal numbers of opening and closing parenthesis by adding 1 for opening parens and subtracting 1 for closing parens
|
||||||
for (let i = openIdx; i < conf.length; i++) {
|
for (let i = openIdx; i < conf.length; i++) {
|
||||||
countLoops && loopCountCheck();
|
countLoops &&
|
||||||
|
loopCountCheck(`parenBalance.ts - ${getMatching ? 'Looking for matching' : 'Checking'} ${openStr}/${closeStr}${getMatching ? '' : ' balance'}`);
|
||||||
loggingEnabled &&
|
loggingEnabled &&
|
||||||
log(
|
log(
|
||||||
LT.LOG,
|
LT.LOG,
|
||||||
|
|
|
@ -14,7 +14,7 @@ export const addToRange = (tSep: string, range: Array<number>, tNum: number) =>
|
||||||
|
|
||||||
const internalAddMultipleToRange = (tSep: string, range: Array<number>, start: number, end: number) => {
|
const internalAddMultipleToRange = (tSep: string, range: Array<number>, start: number, end: number) => {
|
||||||
for (let i = start; i <= end; i++) {
|
for (let i = start; i <= end; i++) {
|
||||||
loopCountCheck();
|
loopCountCheck(`rangeAdder.ts - ${tSep} range adder`);
|
||||||
addToRange(tSep, range, i);
|
addToRange(tSep, range, i);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,7 @@ export const createRollDistMap = (rollSet: RollSet[]): RollDistributionMap => {
|
||||||
const rollDistMap = new Map<string, number[]>();
|
const rollDistMap = new Map<string, number[]>();
|
||||||
|
|
||||||
rollSet.forEach((roll) => {
|
rollSet.forEach((roll) => {
|
||||||
loopCountCheck();
|
loopCountCheck('rollDist.ts - convert RollSet into RollDist');
|
||||||
const tempArr: number[] = rollDistMap.get(rollDistKey(roll.type, roll.size)) ?? new Array<number>(roll.type === 'fate' ? roll.size + 2 : roll.size).fill(0);
|
const tempArr: number[] = rollDistMap.get(rollDistKey(roll.type, roll.size)) ?? new Array<number>(roll.type === 'fate' ? roll.size + 2 : roll.size).fill(0);
|
||||||
tempArr[roll.type === 'fate' ? roll.roll + 1 : roll.roll - 1]++;
|
tempArr[roll.type === 'fate' ? roll.roll + 1 : roll.roll - 1]++;
|
||||||
rollDistMap.set(rollDistKey(roll.type, roll.size), tempArr);
|
rollDistMap.set(rollDistKey(roll.type, roll.size), tempArr);
|
||||||
|
@ -22,17 +22,17 @@ export const createRollDistMap = (rollSet: RollSet[]): RollDistributionMap => {
|
||||||
// Collapses an array of RollDistMaps into a single RollDistMap
|
// Collapses an array of RollDistMaps into a single RollDistMap
|
||||||
export const reduceRollDistMaps = (rollDistArr: RollDistributionMap[]): RollDistributionMap =>
|
export const reduceRollDistMaps = (rollDistArr: RollDistributionMap[]): RollDistributionMap =>
|
||||||
rollDistArr.reduce((acc, cur) => {
|
rollDistArr.reduce((acc, cur) => {
|
||||||
loopCountCheck();
|
loopCountCheck('rollDist.ts - merge array of RollDists into single RollDist');
|
||||||
|
|
||||||
cur
|
cur
|
||||||
.entries()
|
.entries()
|
||||||
.toArray()
|
.toArray()
|
||||||
.forEach(([key, value]) => {
|
.forEach(([key, value]) => {
|
||||||
loopCountCheck();
|
loopCountCheck('rollDist.ts - doing the merge on each item of current');
|
||||||
|
|
||||||
const tempArr = acc.get(key) ?? new Array<number>(value.length).fill(0);
|
const tempArr = acc.get(key) ?? new Array<number>(value.length).fill(0);
|
||||||
for (let i = 0; i < tempArr.length; i++) {
|
for (let i = 0; i < tempArr.length; i++) {
|
||||||
loopCountCheck();
|
loopCountCheck('rollDist.ts - doing the merge');
|
||||||
tempArr[i] += value[i];
|
tempArr[i] += value[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ export const generateRollVals = (rollConf: RollConf, rollSet: RollSet[], rollStr
|
||||||
|
|
||||||
// Count up all rolls
|
// Count up all rolls
|
||||||
for (const ovaRoll of rollSet) {
|
for (const ovaRoll of rollSet) {
|
||||||
loopCountCheck();
|
loopCountCheck('rollValCounter.ts - counting roll vals');
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | incrementing rollVals for ${JSON.stringify(ovaRoll)}`);
|
loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | incrementing rollVals for ${JSON.stringify(ovaRoll)}`);
|
||||||
if (!ovaRoll.dropped && !ovaRoll.rerolled) {
|
if (!ovaRoll.dropped && !ovaRoll.rerolled) {
|
||||||
|
|
Loading…
Reference in New Issue