@@ -77,7 +77,7 @@ generator.engines = NumberGenerator.engines.nodeCrypto;
77
77
plugin . addTopicEvents = async function ( { types } ) {
78
78
types . dice = {
79
79
icon : 'fa-dice' ,
80
- translation : translateDiceEvent
80
+ translation : translateDiceEvent ,
81
81
} ;
82
82
return { types } ;
83
83
} ;
@@ -91,7 +91,9 @@ function renderTimeago(timestamp) {
91
91
}
92
92
93
93
async function translateDiceEvent ( event ) {
94
- const diceText = createText ( event . total , event . rolls , event . diceUsed , event . parsedNotation ) ;
94
+ const diceText = event . text === undefined ?
95
+ createText ( event . total , JSON . parse ( event . rolls ) , JSON . parse ( event . diceUsed ) , event . parsedNotation ) :
96
+ event . text ;
95
97
const text = `${ diceText } ${ renderUser ( event . user ) } ${ renderTimeago ( event . timestampISO ) } ` ;
96
98
return utils . decodeHTMLEntities ( await translator . translate ( text ) ) ;
97
99
}
@@ -101,7 +103,7 @@ function createText(total, rolls, diceUsed, notation) {
101
103
let text = '[[dice:roll-one-die-0]] ' ;
102
104
let { sides } = diceUsed [ 0 ] ;
103
105
let iconValue = total ;
104
- if ( diceUsed [ 0 ] instanceof FudgeDice ) {
106
+ if ( diceUsed [ 0 ] . name === 'fudge' ) {
105
107
sides = 'F' ;
106
108
// eslint-disable-next-line no-nested-ternary
107
109
iconValue = total === 1 ? 'plus' : ( total === - 1 ? 'minus' : 'zero' ) ;
@@ -141,7 +143,7 @@ function parseRollGroup(rolls, diceEntry, diceString, i = 10) {
141
143
if ( i < 0 ) {
142
144
throw new Error ( '[[dice:too-many-nested-groups]]' ) ;
143
145
}
144
- if ( diceEntry instanceof RollGroup ) {
146
+ if ( diceEntry . isRollGroup ) {
145
147
for (
146
148
const [
147
149
groupIndex ,
@@ -167,17 +169,17 @@ function parseRollGroup(rolls, diceEntry, diceString, i = 10) {
167
169
return diceString ;
168
170
}
169
171
let { sides } = diceEntry ;
170
- if ( diceEntry instanceof FudgeDice ) {
172
+ if ( diceEntry ) {
171
173
sides = 'F' ;
172
174
}
173
- if ( rolls instanceof RollResults ) {
175
+ if ( rolls . name === 'fudge' ) {
174
176
rolls = rolls . rolls ;
175
177
}
176
178
for ( const roll of rolls ) {
177
179
if ( typeof roll !== 'object' ) continue ;
178
180
if ( dice . includes ( `d${ sides } ` ) ) {
179
181
let iconValue = roll . value ;
180
- if ( diceEntry instanceof FudgeDice ) {
182
+ if ( diceEntry . name === 'fudge' ) {
181
183
if ( roll . value === 1 ) iconValue = 'plus' ;
182
184
else if ( roll . value === - 1 ) iconValue = 'minus' ;
183
185
else iconValue = 'zero' ;
@@ -219,8 +221,8 @@ async function parseCommands(post) {
219
221
const event = {
220
222
type : 'dice' ,
221
223
total,
222
- rolls,
223
- diceUsed,
224
+ rolls : JSON . stringify ( rolls ) ,
225
+ diceUsed : JSON . stringify ( diceUsed ) ,
224
226
parsedNotation,
225
227
uid : post . uid ,
226
228
} ;
0 commit comments