Move RollModifiers to live in artigen
This commit is contained in:
parent
1b2851353e
commit
c9aff85452
|
@ -4,14 +4,14 @@ import config from '~config';
|
||||||
|
|
||||||
import { CountDetails, ReturnData } from 'artigen/solver.d.ts';
|
import { CountDetails, ReturnData } from 'artigen/solver.d.ts';
|
||||||
|
|
||||||
|
import { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||||
|
|
||||||
import { tokenizeMath } from 'artigen/math/mathTokenizer.ts';
|
import { tokenizeMath } from 'artigen/math/mathTokenizer.ts';
|
||||||
|
|
||||||
import { closeInternal, internalWrapRegex, openInternal } from 'artigen/utils/escape.ts';
|
import { closeInternal, internalWrapRegex, openInternal } from 'artigen/utils/escape.ts';
|
||||||
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||||
import { getMatchingInternalIdx, getMatchingPostfixIdx } from 'artigen/utils/parenBalance.ts';
|
import { getMatchingInternalIdx, getMatchingPostfixIdx } from 'artigen/utils/parenBalance.ts';
|
||||||
|
|
||||||
import { RollModifiers } from 'src/mod.d.ts';
|
|
||||||
|
|
||||||
// tokenizeCmd expects a string[] of items that are either config.prefix/config.postfix or some text that contains math and/or dice rolls
|
// tokenizeCmd expects a string[] of items that are either config.prefix/config.postfix or some text that contains math and/or dice rolls
|
||||||
export const tokenizeCmd = (cmd: string[], modifiers: RollModifiers, topLevel: boolean): [ReturnData[], CountDetails[]] => {
|
export const tokenizeCmd = (cmd: string[], modifiers: RollModifiers, topLevel: boolean): [ReturnData[], CountDetails[]] => {
|
||||||
loggingEnabled && log(LT.LOG, `Tokenizing command ${JSON.stringify(cmd)}`);
|
loggingEnabled && log(LT.LOG, `Tokenizing command ${JSON.stringify(cmd)}`);
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
// RollModifiers is the structure to keep track of the decorators applied to a roll command
|
||||||
|
export type RollModifiers = {
|
||||||
|
noDetails: boolean;
|
||||||
|
superNoDetails: boolean;
|
||||||
|
spoiler: string;
|
||||||
|
maxRoll: boolean;
|
||||||
|
minRoll: boolean;
|
||||||
|
nominalRoll: boolean;
|
||||||
|
gmRoll: boolean;
|
||||||
|
gms: string[];
|
||||||
|
order: string;
|
||||||
|
count: boolean;
|
||||||
|
commaTotals: boolean;
|
||||||
|
valid: boolean;
|
||||||
|
apiWarn: string;
|
||||||
|
};
|
|
@ -4,12 +4,12 @@ import config from '~config';
|
||||||
|
|
||||||
import { RollConf, RollSet, RollType } from 'artigen/solver.d.ts';
|
import { RollConf, RollSet, RollType } from 'artigen/solver.d.ts';
|
||||||
|
|
||||||
|
import { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||||
|
|
||||||
import { genFateRoll, genRoll } from 'artigen/utils/generateRoll.ts';
|
import { genFateRoll, genRoll } from 'artigen/utils/generateRoll.ts';
|
||||||
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||||
import { compareOrigIdx, compareRolls } from 'artigen/utils/sortFuncs.ts';
|
import { compareOrigIdx, compareRolls } from 'artigen/utils/sortFuncs.ts';
|
||||||
|
|
||||||
import { RollModifiers } from 'src/mod.d.ts';
|
|
||||||
|
|
||||||
// Call with loopCountCheck(++loopCount);
|
// Call with loopCountCheck(++loopCount);
|
||||||
// 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.
|
||||||
const loopCountCheck = (loopCount: number): void => {
|
const loopCountCheck = (loopCount: number): void => {
|
||||||
|
|
|
@ -2,16 +2,15 @@ import { log, LogTypes as LT } from '@Log4Deno';
|
||||||
|
|
||||||
import { RollFormat } from 'artigen/solver.d.ts';
|
import { RollFormat } from 'artigen/solver.d.ts';
|
||||||
|
|
||||||
|
import { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||||
import { executeRoll } from 'artigen/dice/executeRoll.ts';
|
import { executeRoll } from 'artigen/dice/executeRoll.ts';
|
||||||
|
|
||||||
import { rollCounter } from 'artigen/utils/counter.ts';
|
import { rollCounter } from 'artigen/utils/counter.ts';
|
||||||
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||||
|
|
||||||
import { RollModifiers } from 'src/mod.d.ts';
|
// generateFormattedRoll(rollConf, modifiers) returns one SolvedStep
|
||||||
|
// generateFormattedRoll handles creating and formatting the completed rolls into the SolvedStep format
|
||||||
// generateSolvedRoll(rollConf, modifiers) returns one SolvedStep
|
export const generateFormattedRoll = (rollConf: string, modifiers: RollModifiers): RollFormat => {
|
||||||
// generateSolvedRoll handles creating and formatting the completed rolls into the SolvedStep format
|
|
||||||
export const generateSolvedRoll = (rollConf: string, modifiers: RollModifiers): RollFormat => {
|
|
||||||
let tempTotal = 0;
|
let tempTotal = 0;
|
||||||
let tempDetails = '[';
|
let tempDetails = '[';
|
||||||
let tempCrit = false;
|
let tempCrit = false;
|
|
@ -1,5 +1,7 @@
|
||||||
import { SolvedRoll } from 'artigen/solver.d.ts';
|
import { SolvedRoll } from 'artigen/solver.d.ts';
|
||||||
|
|
||||||
|
import { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||||
|
|
||||||
import { removeWorker } from 'artigen/managers/countManager.ts';
|
import { removeWorker } from 'artigen/managers/countManager.ts';
|
||||||
import { QueuedRoll } from 'artigen/managers/manager.d.ts';
|
import { QueuedRoll } from 'artigen/managers/manager.d.ts';
|
||||||
|
|
||||||
|
@ -7,7 +9,6 @@ import stdResp from 'endpoints/stdResponses.ts';
|
||||||
|
|
||||||
import { generateRollEmbed } from 'src/commandUtils.ts';
|
import { generateRollEmbed } from 'src/commandUtils.ts';
|
||||||
import utils from 'src/utils.ts';
|
import utils from 'src/utils.ts';
|
||||||
import { RollModifiers } from 'src/mod.d.ts';
|
|
||||||
|
|
||||||
export const terminateWorker = async (rollWorker: Worker, rollRequest: QueuedRoll) => {
|
export const terminateWorker = async (rollWorker: Worker, rollRequest: QueuedRoll) => {
|
||||||
rollWorker.terminate();
|
rollWorker.terminate();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { DiscordenoMessage } from '@discordeno';
|
import { DiscordenoMessage } from '@discordeno';
|
||||||
|
|
||||||
import { RollModifiers } from 'src/mod.d.ts';
|
import { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||||
|
|
||||||
// QueuedRoll is the structure to track rolls we could not immediately handle
|
// QueuedRoll is the structure to track rolls we could not immediately handle
|
||||||
interface BaseQueuedRoll {
|
interface BaseQueuedRoll {
|
||||||
|
|
|
@ -2,7 +2,8 @@ import { log, LogTypes as LT } from '@Log4Deno';
|
||||||
|
|
||||||
import { CountDetails, MathConf, ReturnData, SolvedStep } from 'artigen/solver.d.ts';
|
import { CountDetails, MathConf, ReturnData, SolvedStep } from 'artigen/solver.d.ts';
|
||||||
|
|
||||||
import { generateSolvedRoll } from 'artigen/dice/generateSolvedRoll.ts';
|
import { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||||
|
import { generateFormattedRoll } from 'artigen/dice/generateFormattedRoll.ts';
|
||||||
|
|
||||||
import { mathSolver } from 'artigen/math/mathSolver.ts';
|
import { mathSolver } from 'artigen/math/mathSolver.ts';
|
||||||
|
|
||||||
|
@ -11,8 +12,6 @@ import { legalMathOperators } from 'artigen/utils/legalMath.ts';
|
||||||
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||||
import { assertParenBalance } from 'artigen/utils/parenBalance.ts';
|
import { assertParenBalance } from 'artigen/utils/parenBalance.ts';
|
||||||
|
|
||||||
import { RollModifiers } from 'src/mod.d.ts';
|
|
||||||
|
|
||||||
const operators = ['(', ')', '^', '*', '/', '%', '+', '-'];
|
const operators = ['(', ')', '^', '*', '/', '%', '+', '-'];
|
||||||
|
|
||||||
export const tokenizeMath = (cmd: string, modifiers: RollModifiers): [ReturnData[], CountDetails[]] => {
|
export const tokenizeMath = (cmd: string, modifiers: RollModifiers): [ReturnData[], CountDetails[]] => {
|
||||||
|
@ -102,7 +101,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers): [ReturnData
|
||||||
containsCrit: false,
|
containsCrit: false,
|
||||||
containsFail: false,
|
containsFail: false,
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
);
|
);
|
||||||
i += 2;
|
i += 2;
|
||||||
} else if (!legalMathOperators.includes(strMathConfI) && legalMathOperators.some((mathOp) => strMathConfI.endsWith(mathOp))) {
|
} else if (!legalMathOperators.includes(strMathConfI) && legalMathOperators.some((mathOp) => strMathConfI.endsWith(mathOp))) {
|
||||||
|
@ -114,7 +113,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers): [ReturnData
|
||||||
i += 2;
|
i += 2;
|
||||||
} else if (![...operators, ...legalMathOperators].includes(strMathConfI)) {
|
} else if (![...operators, ...legalMathOperators].includes(strMathConfI)) {
|
||||||
// If nothing else has handled it by now, try it as a roll
|
// If nothing else has handled it by now, try it as a roll
|
||||||
const formattedRoll = generateSolvedRoll(strMathConfI, modifiers);
|
const formattedRoll = generateFormattedRoll(strMathConfI, modifiers);
|
||||||
mathConf[i] = formattedRoll.solvedStep;
|
mathConf[i] = formattedRoll.solvedStep;
|
||||||
countDetails.push(formattedRoll.countDetails);
|
countDetails.push(formattedRoll.countDetails);
|
||||||
}
|
}
|
||||||
|
@ -128,10 +127,10 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers): [ReturnData
|
||||||
} else {
|
} else {
|
||||||
// Handle normally, just set current item to negative
|
// Handle normally, just set current item to negative
|
||||||
if (typeof mathConf[i] === 'number') {
|
if (typeof mathConf[i] === 'number') {
|
||||||
mathConf[i] = <number>mathConf[i] * -1;
|
mathConf[i] = <number> mathConf[i] * -1;
|
||||||
} else {
|
} else {
|
||||||
(<SolvedStep>mathConf[i]).total = (<SolvedStep>mathConf[i]).total * -1;
|
(<SolvedStep> mathConf[i]).total = (<SolvedStep> mathConf[i]).total * -1;
|
||||||
(<SolvedStep>mathConf[i]).details = `-${(<SolvedStep>mathConf[i]).details}`;
|
(<SolvedStep> mathConf[i]).details = `-${(<SolvedStep> mathConf[i]).details}`;
|
||||||
}
|
}
|
||||||
mathConf.splice(i - 1, 1);
|
mathConf.splice(i - 1, 1);
|
||||||
i--;
|
i--;
|
||||||
|
|
|
@ -3,14 +3,14 @@ import { log, LogTypes as LT } from '@Log4Deno';
|
||||||
import { tokenizeCmd } from 'artigen/cmdTokenizer.ts';
|
import { tokenizeCmd } from 'artigen/cmdTokenizer.ts';
|
||||||
import { SolvedRoll } from 'artigen/solver.d.ts';
|
import { SolvedRoll } from 'artigen/solver.d.ts';
|
||||||
|
|
||||||
|
import { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||||
|
|
||||||
import { cmdSplitRegex, escapeCharacters } from 'artigen/utils/escape.ts';
|
import { cmdSplitRegex, escapeCharacters } from 'artigen/utils/escape.ts';
|
||||||
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||||
|
import { assertPrePostBalance } from 'src/artigen/utils/parenBalance.ts';
|
||||||
import { compareTotalRolls, compareTotalRollsReverse } from 'artigen/utils/sortFuncs.ts';
|
import { compareTotalRolls, compareTotalRollsReverse } from 'artigen/utils/sortFuncs.ts';
|
||||||
import { translateError } from 'artigen/utils/translateError.ts';
|
import { translateError } from 'artigen/utils/translateError.ts';
|
||||||
|
|
||||||
import { RollModifiers } from 'src/mod.d.ts';
|
|
||||||
import { assertPrePostBalance } from 'src/artigen/utils/parenBalance.ts';
|
|
||||||
|
|
||||||
// parseRoll(fullCmd, modifiers)
|
// parseRoll(fullCmd, modifiers)
|
||||||
// parseRoll handles converting fullCmd into a computer readable format for processing, and finally executes the solving
|
// parseRoll handles converting fullCmd into a computer readable format for processing, and finally executes the solving
|
||||||
export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll => {
|
export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll => {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { RollModifiers } from 'src/mod.d.ts';
|
import { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||||
|
|
||||||
import { DPercentConf } from 'artigen/solver.d.ts';
|
import { DPercentConf } from 'artigen/solver.d.ts';
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,12 @@ import { log, LogTypes as LT } from '@Log4Deno';
|
||||||
|
|
||||||
import config from '~config';
|
import config from '~config';
|
||||||
|
|
||||||
|
import { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||||
|
|
||||||
import { CountDetails, SolvedRoll } from 'artigen/solver.d.ts';
|
import { CountDetails, SolvedRoll } from 'artigen/solver.d.ts';
|
||||||
|
|
||||||
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||||
|
|
||||||
import { RollModifiers } from 'src/mod.d.ts';
|
|
||||||
|
|
||||||
export const failColor = 0xe71212;
|
export const failColor = 0xe71212;
|
||||||
export const warnColor = 0xe38f28;
|
export const warnColor = 0xe38f28;
|
||||||
export const successColor = 0x0f8108;
|
export const successColor = 0x0f8108;
|
||||||
|
|
|
@ -4,11 +4,12 @@ import { log, LogTypes as LT } from '@Log4Deno';
|
||||||
import config from '~config';
|
import config from '~config';
|
||||||
import { DEVMODE } from '~flags';
|
import { DEVMODE } from '~flags';
|
||||||
|
|
||||||
|
import { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||||
|
|
||||||
import dbClient from 'db/client.ts';
|
import dbClient from 'db/client.ts';
|
||||||
import { queries } from 'db/common.ts';
|
import { queries } from 'db/common.ts';
|
||||||
|
|
||||||
import { generateRollError } from 'src/commandUtils.ts';
|
import { generateRollError } from 'src/commandUtils.ts';
|
||||||
import { RollModifiers } from 'src/mod.d.ts';
|
|
||||||
import utils from 'src/utils.ts';
|
import utils from 'src/utils.ts';
|
||||||
|
|
||||||
export const getModifiers = (m: DiscordenoMessage, args: string[], command: string, originalCommand: string): RollModifiers => {
|
export const getModifiers = (m: DiscordenoMessage, args: string[], command: string, originalCommand: string): RollModifiers => {
|
||||||
|
|
|
@ -3,6 +3,8 @@ import { log, LogTypes as LT } from '@Log4Deno';
|
||||||
|
|
||||||
import config from '~config';
|
import config from '~config';
|
||||||
|
|
||||||
|
import { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||||
|
|
||||||
import { sendRollRequest } from 'artigen/managers/queueManager.ts';
|
import { sendRollRequest } from 'artigen/managers/queueManager.ts';
|
||||||
|
|
||||||
import dbClient from 'db/client.ts';
|
import dbClient from 'db/client.ts';
|
||||||
|
@ -11,7 +13,6 @@ import { queries } from 'db/common.ts';
|
||||||
import stdResp from 'endpoints/stdResponses.ts';
|
import stdResp from 'endpoints/stdResponses.ts';
|
||||||
import { verifyQueryHasParams } from 'endpoints/utils.ts';
|
import { verifyQueryHasParams } from 'endpoints/utils.ts';
|
||||||
|
|
||||||
import { RollModifiers } from 'src/mod.d.ts';
|
|
||||||
import utils from 'src/utils.ts';
|
import utils from 'src/utils.ts';
|
||||||
|
|
||||||
const apiWarning = `The following roll was conducted using my built in API. If someone in this channel did not request this roll, please report API abuse here: <${config.api.supportURL}>`;
|
const apiWarning = `The following roll was conducted using my built in API. If someone in this channel did not request this roll, please report API abuse here: <${config.api.supportURL}>`;
|
||||||
|
|
|
@ -7,23 +7,6 @@ export type EmojiConf = {
|
||||||
deleteSender: boolean;
|
deleteSender: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
// RollModifiers is the structure to keep track of the decorators applied to a roll command
|
|
||||||
export type RollModifiers = {
|
|
||||||
noDetails: boolean;
|
|
||||||
superNoDetails: boolean;
|
|
||||||
spoiler: string;
|
|
||||||
maxRoll: boolean;
|
|
||||||
minRoll: boolean;
|
|
||||||
nominalRoll: boolean;
|
|
||||||
gmRoll: boolean;
|
|
||||||
gms: string[];
|
|
||||||
order: string;
|
|
||||||
count: boolean;
|
|
||||||
commaTotals: boolean;
|
|
||||||
valid: boolean;
|
|
||||||
apiWarn: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
// PastCommandCount is used in calculating the hourly rate of commands
|
// PastCommandCount is used in calculating the hourly rate of commands
|
||||||
export type PastCommandCount = {
|
export type PastCommandCount = {
|
||||||
command: string;
|
command: string;
|
||||||
|
|
Loading…
Reference in New Issue