-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAPI.js
More file actions
48 lines (42 loc) · 1.5 KB
/
API.js
File metadata and controls
48 lines (42 loc) · 1.5 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
37
38
39
40
41
42
43
44
45
46
47
48
on("chat:message", function(msg) {
switch (msg.type){
case "rollresult":
let check = JSON.parse(msg.content);
var ret = msg.type + "§" + msg.who + "§" + msg.origRoll + "§";
var perc = 0;
var diceCount = 0;
check.rolls.forEach(function(r){
if (r.type === "R"){
ret += (" ")
perc += (r.dice*r.sides) - r.dice
diceCount += r.dice;
r.results.forEach(function(i){
ret += (" " + i.v);
})
}
})
perc = Math.floor(100* ((check.total-diceCount)/perc))
log(ret + "§" + perc + "§" + check.total);
break;
case "whisper":
log(msg.type + "§" + msg.who + "§"+ msg.target_name + "§" + processInlinerolls(msg));
break;
default:
log(msg.type + "§" + msg.who + "§" + processInlinerolls(msg));
}
});
function processInlinerolls(msg) {
if (_.has(msg, 'inlinerolls')) {
return _.chain(msg.inlinerolls)
.reduce(function(previous, current, index) {
previous['$[[' + index + ']]'] = current.results.total || 0;
return previous;
},{})
.reduce(function(previous, current, index) {
return previous.replace(index, current);
}, msg.content)
.value();
} else {
return msg.content;
}
}