-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclueScrollHandler.js
More file actions
36 lines (32 loc) · 1.13 KB
/
clueScrollHandler.js
File metadata and controls
36 lines (32 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { formatValue } from './helperFunctions';
import { CLUE } from '../constants';
/**
* Formats a clue scroll's rewards
* @param {Map<{ ID: string, URL: string }, string>} msgMap - The message map to update
* @param {string} playerName - The player's name
* @param {Object<string, any>} extra - Additional information
* @param {string} URL - The associated URL
* @returns {Map<{ ID: string, URL: string }, string>} The updated message map
*/
function clueScrollHandler(msgMap, playerName, extra, URL) {
const { clueType, numberCompleted, items } = extra;
const totalValue = items.reduce(
(acc, item) => acc + item.quantity * item.priceEach,
0
);
const message = `**${playerName}** has completed **${numberCompleted.toLocaleString()} ${clueType}** clue${
numberCompleted > 1 ? `s` : ``
}! | Total Value: **${formatValue(totalValue).replace(/[()]/g, '')}**
**Rewards:**
${items
.map(
(item) =>
`- ${item.quantity}x ${item.name} **${formatValue(
item.priceEach * item.quantity
)}**`
)
.join('\n')}`;
msgMap.set({ ID: CLUE, URL }, message);
return msgMap;
}
export default clueScrollHandler;