From d386561855bd2df38dc55ee37c6247cf3762e3c9 Mon Sep 17 00:00:00 2001 From: Ean Milligan Date: Sun, 13 Jul 2025 06:04:50 -0400 Subject: [PATCH] add -ns decorator --- .bruno/Authenticated/Roll Requests/Roll Dice.bru | 3 ++- README.md | 1 + src/artigen/artigen.ts | 7 ++++--- src/artigen/dice/dice.d.ts | 1 + src/artigen/dice/getModifiers.ts | 5 +++++ src/commands/helpLibrary/decorators.ts | 13 +++++++++++++ src/endpoints/gets/apiRoll.ts | 1 + 7 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.bruno/Authenticated/Roll Requests/Roll Dice.bru b/.bruno/Authenticated/Roll Requests/Roll Dice.bru index 348c81c..213b7ef 100644 --- a/.bruno/Authenticated/Roll Requests/Roll Dice.bru +++ b/.bruno/Authenticated/Roll Requests/Roll Dice.bru @@ -5,7 +5,7 @@ meta { } get { - url: http://localhost:8166/api/roll?user=[discord-user-id]&channel=[discord-channel-id]&rollstr=[artificer-roll-cmd]&documentation=All items below are optional. Flags do not need values.&nd=[no-details-flag]&snd=[super-no-details-flag]&hr=[hide-raw-roll-details-flag]&s=[spoiler-results-flag]&m-or-max=[max-roll-flag, cannot be used with n flag]&min=[min-roll-flag, cannot be used with n, sn, or max]&n=[nominal-roll-flag, cannot be used with sn, max or min flag]&sn=[simulated-nominal-flag, can pass number with it, cannot be used with max, min, n. or cc]&gms=[csv-of-discord-user-ids-to-be-dmed-results]&o=[order-rolls, must be a or d]&c=[count-flag]&cc=[confirm-crit-flag, cannot be used with sn]&rd=[roll-dist-flag]&nv-or-vn=[number-variables-flag]&cd=[custom-dice, format value as name:[side1,side2,...,sideN], use ; to separate multiple custom dice] + url: http://localhost:8166/api/roll?user=[discord-user-id]&channel=[discord-channel-id]&rollstr=[artificer-roll-cmd]&documentation=All items below are optional. Flags do not need values.&nd=[no-details-flag]&snd=[super-no-details-flag]&hr=[hide-raw-roll-details-flag]&s=[spoiler-results-flag]&m-or-max=[max-roll-flag, cannot be used with n flag]&min=[min-roll-flag, cannot be used with n, sn, or max]&n=[nominal-roll-flag, cannot be used with sn, max or min flag]&sn=[simulated-nominal-flag, can pass number with it, cannot be used with max, min, n. or cc]&gms=[csv-of-discord-user-ids-to-be-dmed-results]&o=[order-rolls, must be a or d]&c=[count-flag]&cc=[confirm-crit-flag, cannot be used with sn]&rd=[roll-dist-flag]&nv-or-vn=[number-variables-flag]&cd=[custom-dice, format value as name:[side1,side2,...,sideN], use ; to separate multiple custom dice]&ns=[no-spaces, removes the default added space between rolls] body: none auth: inherit } @@ -30,4 +30,5 @@ params:query { rd: [roll-dist-flag] nv-or-vn: [number-variables-flag] cd: [custom-dice, format value as name:[side1,side2,...,sideN], use ; to separate multiple custom dice] + ns: [no-spaces, removes the default added space between rolls] } diff --git a/README.md b/README.md index 4eb141a..9b6f49b 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,7 @@ The Artificer comes with a few supplemental commands to the main rolling command * `-hr` - Hide Raw - Hide the raw input, showing only the results/details of the roll * `-nv` or `-vn` - Number Variables - Adds `xN` before each roll command in the details section for debug reasons * `-cd` - Custom Dice shapes - Allows a list of `name:[side1,side2,...,sideN]` separated by `;` to be passed to create special shaped dice + * `-ns` - No Spaces - Removes the default padding added space between rolls (`[[d4]][[d4]]` will output `22` instead of `2 2`) * The results have some formatting applied on them to provide details on what happened during this roll. * Critical successes will be **bolded** * Critical fails will be underlined diff --git a/src/artigen/artigen.ts b/src/artigen/artigen.ts index 6d405c9..e4dbab6 100644 --- a/src/artigen/artigen.ts +++ b/src/artigen/artigen.ts @@ -96,6 +96,7 @@ export const runCmd = (rollRequest: QueuedRoll): SolvedRoll => { "One or more of the rolls requested appear to be more complex than what the Nominal calculator is intended for. For a better approximation of this roll's nominal value, please rerun this roll with the `-sn` flag.\n"; } + const line2Space = rollRequest.modifiers.noSpaces ? '' : ' '; // Fill out all of the details and results now tempReturnData.forEach((e, i) => { loopCountCheck(); @@ -118,9 +119,9 @@ export const runCmd = (rollRequest: QueuedRoll): SolvedRoll => { // Populate line2 (the results) and line3 (the details) with their data if (rollRequest.modifiers.order === '') { - line2 += `${e.rollPreFormat ? escapeCharacters(e.rollPreFormat, '|*_~`') : ' '}${preFormat}${rollRequest.modifiers.commaTotals ? e.rollTotal.toLocaleString() : e.rollTotal}${postFormat}${ - e.rollPostFormat ? escapeCharacters(e.rollPostFormat, '|*_~`') : '' - }`; + line2 += `${e.rollPreFormat ? escapeCharacters(e.rollPreFormat, '|*_~`') : line2Space}${preFormat}${ + rollRequest.modifiers.commaTotals ? e.rollTotal.toLocaleString() : e.rollTotal + }${postFormat}${e.rollPostFormat ? escapeCharacters(e.rollPostFormat, '|*_~`') : ''}`; } else { // If order is on, turn rolls into csv without formatting line2 += `${preFormat}${rollRequest.modifiers.commaTotals ? e.rollTotal.toLocaleString() : e.rollTotal}${postFormat}, `; diff --git a/src/artigen/dice/dice.d.ts b/src/artigen/dice/dice.d.ts index c097fc8..6983752 100644 --- a/src/artigen/dice/dice.d.ts +++ b/src/artigen/dice/dice.d.ts @@ -63,6 +63,7 @@ export interface RollModifiers { rollDist: boolean; numberVariables: boolean; customDiceShapes: CustomDiceShapes; + noSpaces: boolean; yVars: Map; apiWarn: string; valid: boolean; diff --git a/src/artigen/dice/getModifiers.ts b/src/artigen/dice/getModifiers.ts index eb580a5..3499948 100644 --- a/src/artigen/dice/getModifiers.ts +++ b/src/artigen/dice/getModifiers.ts @@ -24,6 +24,7 @@ export const Modifiers = Object.freeze({ NumberVariables: '-nv', VariablesNumber: '-vn', CustomDiceShapes: '-cd', + NoSpaces: '-ns', }); // args will look like this: ['-sn', ' ', '10'] as spaces/newlines are split on their own @@ -46,6 +47,7 @@ export const getModifiers = (args: string[]): [RollModifiers, string[]] => { rollDist: false, numberVariables: false, customDiceShapes: new Map(), + noSpaces: false, yVars: new Map(), apiWarn: '', valid: true, @@ -199,6 +201,9 @@ export const getModifiers = (args: string[]): [RollModifiers, string[]] => { log(LT.LOG, `Generated Custom Dice: ${JSON.stringify(modifiers.customDiceShapes.entries().toArray())}`); break; } + case Modifiers.NoSpaces: + modifiers.noSpaces = true; + break; default: // Default case should not mess with the array defaultCase = true; diff --git a/src/commands/helpLibrary/decorators.ts b/src/commands/helpLibrary/decorators.ts index 7fdd3bb..199e691 100644 --- a/src/commands/helpLibrary/decorators.ts +++ b/src/commands/helpLibrary/decorators.ts @@ -194,6 +194,19 @@ If multiple custom dice are needed, separate their configurations with a \`;\`. ], }, ], + [ + '-ns', + { + name: 'No Spaces', + description: `**Usage:** \`-ns\` + +Removes the default padding added space between rolls.`, + example: [ + '`[[d4]][[d4]]` will normally return as `2 2` for readability', + '`[[d4]][[d4]] -ns` will remove the added padding to follow the exact input format and return as `22`', + ], + }, + ], ]); export const DecoratorsHelpPages: HelpPage = { diff --git a/src/endpoints/gets/apiRoll.ts b/src/endpoints/gets/apiRoll.ts index ea62fd9..7ec6f9b 100644 --- a/src/endpoints/gets/apiRoll.ts +++ b/src/endpoints/gets/apiRoll.ts @@ -102,6 +102,7 @@ export const apiRoll = async (query: Map, apiUserid: bigint): Pr rollDist: query.has('rd'), numberVariables: query.has('nv') || query.has('vn'), customDiceShapes: new Map(), + noSpaces: query.has('ns'), yVars: new Map(), apiWarn: hideWarn ? '' : apiWarning, valid: true,