From b9c7fac98489eae2f7bb2146ad99af6faa2d38c8 Mon Sep 17 00:00:00 2001 From: Ean Milligan Date: Tue, 29 Apr 2025 18:02:51 -0400 Subject: [PATCH] add comma totals decorator --- README.md | 1 + src/commands/roll/getModifiers.ts | 6 +++++- src/commands/rollDecorators.ts | 5 +++++ src/endpoints/gets/apiRoll.ts | 1 + src/mod.d.ts | 1 + src/solver/parser.ts | 11 ++++++++--- 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f2b9bf8..f45be71 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ The Artificer comes with a few supplemental commands to the main rolling command * `-n` - Nominal Roll - Rolls the theoretical nominal roll, cannot be used with `-m`, `-max`, or `-min` * `-gm @user1 @user2 ... @userN` - GM Roll - Rolls the requested roll in GM mode, suppressing all publicly shown results and details and sending the results directly to the specified GMs * `-o a` or `-o d` - Order Roll - Rolls the requested roll and orders the results in the requested direction + * `-ct` - Comma Totals - Adds commas to totals for readability * 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/commands/roll/getModifiers.ts b/src/commands/roll/getModifiers.ts index c87abf9..9d1e6d6 100644 --- a/src/commands/roll/getModifiers.ts +++ b/src/commands/roll/getModifiers.ts @@ -25,8 +25,9 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri gmRoll: false, gms: [], order: '', - valid: false, count: false, + commaTotals: false, + valid: false, apiWarn: '', }; @@ -99,6 +100,9 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri modifiers.order = args[i].toLowerCase()[0]; break; + case '-ct': + modifiers.commaTotals = true; + break; default: // Default case should not mess with the array defaultCase = true; diff --git a/src/commands/rollDecorators.ts b/src/commands/rollDecorators.ts index 5336390..6dc9ff9 100644 --- a/src/commands/rollDecorators.ts +++ b/src/commands/rollDecorators.ts @@ -71,6 +71,11 @@ Available directions: \`d\` - Descending (greatest to least)`, inline: true, }, + { + name: '`-ct` - Comma Totals', + value: 'Adds commas to totals for readability', + inline: true, + }, ], }, ], diff --git a/src/endpoints/gets/apiRoll.ts b/src/endpoints/gets/apiRoll.ts index 8b45343..707ff47 100644 --- a/src/endpoints/gets/apiRoll.ts +++ b/src/endpoints/gets/apiRoll.ts @@ -91,6 +91,7 @@ export const apiRoll = async (query: Map, apiUserid: bigint): Pr gms: query.has('gms') ? (query.get('gms') || '').split(',') : [], order: query.has('o') ? query.get('o')?.toLowerCase() || '' : '', count: query.has('c'), + commaTotals: query.has('ct'), valid: true, apiWarn: hideWarn ? '' : apiWarning, }; diff --git a/src/mod.d.ts b/src/mod.d.ts index 476a743..2ea4800 100644 --- a/src/mod.d.ts +++ b/src/mod.d.ts @@ -22,6 +22,7 @@ export type RollModifiers = { gms: string[]; order: string; count: boolean; + commaTotals: boolean; valid: boolean; apiWarn: string; }; diff --git a/src/solver/parser.ts b/src/solver/parser.ts index 2b2c761..851b04c 100644 --- a/src/solver/parser.ts +++ b/src/solver/parser.ts @@ -258,13 +258,18 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll // Populate line2 (the results) and line3 (the details) with their data if (modifiers.order === '') { - line2 += `${preFormat}${e.rollTotal}${postFormat}${escapeCharacters(e.rollPostFormat, '|*_~`')} `; + line2 += `${preFormat}${modifiers.commaTotals ? e.rollTotal.toLocaleString() : e.rollTotal}${postFormat}${ + escapeCharacters( + e.rollPostFormat, + '|*_~`', + ) + } `; } else { // If order is on, turn rolls into csv without formatting - line2 += `${preFormat}${e.rollTotal}${postFormat}, `; + line2 += `${preFormat}${modifiers.commaTotals ? e.rollTotal.toLocaleString() : e.rollTotal}${postFormat}, `; } - line3 += `\`${e.initConfig}\` = ${e.rollDetails} = ${preFormat}${e.rollTotal}${postFormat}\n`; + line3 += `\`${e.initConfig}\` = ${e.rollDetails} = ${preFormat}${modifiers.commaTotals ? e.rollTotal.toLocaleString() : e.rollTotal}${postFormat}\n`; }); // If order is on, remove trailing ", "