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 { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||
|
||||
import { tokenizeMath } from 'artigen/math/mathTokenizer.ts';
|
||||
|
||||
import { closeInternal, internalWrapRegex, openInternal } from 'artigen/utils/escape.ts';
|
||||
import { loggingEnabled } from 'artigen/utils/logFlag.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
|
||||
export const tokenizeCmd = (cmd: string[], modifiers: RollModifiers, topLevel: boolean): [ReturnData[], CountDetails[]] => {
|
||||
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 { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||
|
||||
import { genFateRoll, genRoll } from 'artigen/utils/generateRoll.ts';
|
||||
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||
import { compareOrigIdx, compareRolls } from 'artigen/utils/sortFuncs.ts';
|
||||
|
||||
import { RollModifiers } from 'src/mod.d.ts';
|
||||
|
||||
// Call with loopCountCheck(++loopCount);
|
||||
// Will ensure if maxLoops is 10, 10 loops will be allowed, 11 will not.
|
||||
const loopCountCheck = (loopCount: number): void => {
|
||||
|
|
|
@ -2,16 +2,15 @@ import { log, LogTypes as LT } from '@Log4Deno';
|
|||
|
||||
import { RollFormat } from 'artigen/solver.d.ts';
|
||||
|
||||
import { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||
import { executeRoll } from 'artigen/dice/executeRoll.ts';
|
||||
|
||||
import { rollCounter } from 'artigen/utils/counter.ts';
|
||||
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||
|
||||
import { RollModifiers } from 'src/mod.d.ts';
|
||||
|
||||
// generateSolvedRoll(rollConf, modifiers) returns one SolvedStep
|
||||
// generateSolvedRoll handles creating and formatting the completed rolls into the SolvedStep format
|
||||
export const generateSolvedRoll = (rollConf: string, modifiers: RollModifiers): RollFormat => {
|
||||
// generateFormattedRoll(rollConf, modifiers) returns one SolvedStep
|
||||
// generateFormattedRoll handles creating and formatting the completed rolls into the SolvedStep format
|
||||
export const generateFormattedRoll = (rollConf: string, modifiers: RollModifiers): RollFormat => {
|
||||
let tempTotal = 0;
|
||||
let tempDetails = '[';
|
||||
let tempCrit = false;
|
|
@ -1,5 +1,7 @@
|
|||
import { SolvedRoll } from 'artigen/solver.d.ts';
|
||||
|
||||
import { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||
|
||||
import { removeWorker } from 'artigen/managers/countManager.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 utils from 'src/utils.ts';
|
||||
import { RollModifiers } from 'src/mod.d.ts';
|
||||
|
||||
export const terminateWorker = async (rollWorker: Worker, rollRequest: QueuedRoll) => {
|
||||
rollWorker.terminate();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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
|
||||
interface BaseQueuedRoll {
|
||||
|
|
|
@ -2,7 +2,8 @@ import { log, LogTypes as LT } from '@Log4Deno';
|
|||
|
||||
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';
|
||||
|
||||
|
@ -11,8 +12,6 @@ import { legalMathOperators } from 'artigen/utils/legalMath.ts';
|
|||
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||
import { assertParenBalance } from 'artigen/utils/parenBalance.ts';
|
||||
|
||||
import { RollModifiers } from 'src/mod.d.ts';
|
||||
|
||||
const operators = ['(', ')', '^', '*', '/', '%', '+', '-'];
|
||||
|
||||
export const tokenizeMath = (cmd: string, modifiers: RollModifiers): [ReturnData[], CountDetails[]] => {
|
||||
|
@ -102,7 +101,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers): [ReturnData
|
|||
containsCrit: false,
|
||||
containsFail: false,
|
||||
},
|
||||
]
|
||||
],
|
||||
);
|
||||
i += 2;
|
||||
} 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;
|
||||
} else if (![...operators, ...legalMathOperators].includes(strMathConfI)) {
|
||||
// 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;
|
||||
countDetails.push(formattedRoll.countDetails);
|
||||
}
|
||||
|
@ -128,10 +127,10 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers): [ReturnData
|
|||
} else {
|
||||
// Handle normally, just set current item to negative
|
||||
if (typeof mathConf[i] === 'number') {
|
||||
mathConf[i] = <number>mathConf[i] * -1;
|
||||
mathConf[i] = <number> mathConf[i] * -1;
|
||||
} else {
|
||||
(<SolvedStep>mathConf[i]).total = (<SolvedStep>mathConf[i]).total * -1;
|
||||
(<SolvedStep>mathConf[i]).details = `-${(<SolvedStep>mathConf[i]).details}`;
|
||||
(<SolvedStep> mathConf[i]).total = (<SolvedStep> mathConf[i]).total * -1;
|
||||
(<SolvedStep> mathConf[i]).details = `-${(<SolvedStep> mathConf[i]).details}`;
|
||||
}
|
||||
mathConf.splice(i - 1, 1);
|
||||
i--;
|
||||
|
|
|
@ -3,14 +3,14 @@ import { log, LogTypes as LT } from '@Log4Deno';
|
|||
import { tokenizeCmd } from 'artigen/cmdTokenizer.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 { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||
import { assertPrePostBalance } from 'src/artigen/utils/parenBalance.ts';
|
||||
import { compareTotalRolls, compareTotalRollsReverse } from 'artigen/utils/sortFuncs.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 handles converting fullCmd into a computer readable format for processing, and finally executes the solving
|
||||
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';
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@ import { log, LogTypes as LT } from '@Log4Deno';
|
|||
|
||||
import config from '~config';
|
||||
|
||||
import { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||
|
||||
import { CountDetails, SolvedRoll } from 'artigen/solver.d.ts';
|
||||
|
||||
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||
|
||||
import { RollModifiers } from 'src/mod.d.ts';
|
||||
|
||||
export const failColor = 0xe71212;
|
||||
export const warnColor = 0xe38f28;
|
||||
export const successColor = 0x0f8108;
|
||||
|
|
|
@ -4,11 +4,12 @@ import { log, LogTypes as LT } from '@Log4Deno';
|
|||
import config from '~config';
|
||||
import { DEVMODE } from '~flags';
|
||||
|
||||
import { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||
|
||||
import dbClient from 'db/client.ts';
|
||||
import { queries } from 'db/common.ts';
|
||||
|
||||
import { generateRollError } from 'src/commandUtils.ts';
|
||||
import { RollModifiers } from 'src/mod.d.ts';
|
||||
import utils from 'src/utils.ts';
|
||||
|
||||
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 { RollModifiers } from 'artigen/dice/dice.d.ts';
|
||||
|
||||
import { sendRollRequest } from 'artigen/managers/queueManager.ts';
|
||||
|
||||
import dbClient from 'db/client.ts';
|
||||
|
@ -11,7 +13,6 @@ import { queries } from 'db/common.ts';
|
|||
import stdResp from 'endpoints/stdResponses.ts';
|
||||
import { verifyQueryHasParams } from 'endpoints/utils.ts';
|
||||
|
||||
import { RollModifiers } from 'src/mod.d.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}>`;
|
||||
|
|
|
@ -7,23 +7,6 @@ export type EmojiConf = {
|
|||
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
|
||||
export type PastCommandCount = {
|
||||
command: string;
|
||||
|
|
Loading…
Reference in New Issue