Skip to content

Commit 43f014f

Browse files
authored
fix: work with past rolls
1 parent 2abf9b0 commit 43f014f

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

library.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ generator.engines = NumberGenerator.engines.nodeCrypto;
7777
plugin.addTopicEvents = async function ({ types }) {
7878
types.dice = {
7979
icon: 'fa-dice',
80-
translation: translateDiceEvent
80+
translation: translateDiceEvent,
8181
};
8282
return { types };
8383
};
@@ -91,7 +91,9 @@ function renderTimeago(timestamp) {
9191
}
9292

9393
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;
9597
const text = `${diceText} ${renderUser(event.user)} ${renderTimeago(event.timestampISO)}`;
9698
return utils.decodeHTMLEntities(await translator.translate(text));
9799
}
@@ -101,7 +103,7 @@ function createText(total, rolls, diceUsed, notation) {
101103
let text = '[[dice:roll-one-die-0]] ';
102104
let { sides } = diceUsed[0];
103105
let iconValue = total;
104-
if (diceUsed[0] instanceof FudgeDice) {
106+
if (diceUsed[0].name === 'fudge') {
105107
sides = 'F';
106108
// eslint-disable-next-line no-nested-ternary
107109
iconValue = total === 1 ? 'plus' : (total === -1 ? 'minus' : 'zero');
@@ -141,7 +143,7 @@ function parseRollGroup(rolls, diceEntry, diceString, i = 10) {
141143
if (i < 0) {
142144
throw new Error('[[dice:too-many-nested-groups]]');
143145
}
144-
if (diceEntry instanceof RollGroup) {
146+
if (diceEntry.isRollGroup) {
145147
for (
146148
const [
147149
groupIndex,
@@ -167,17 +169,17 @@ function parseRollGroup(rolls, diceEntry, diceString, i = 10) {
167169
return diceString;
168170
}
169171
let { sides } = diceEntry;
170-
if (diceEntry instanceof FudgeDice) {
172+
if (diceEntry) {
171173
sides = 'F';
172174
}
173-
if (rolls instanceof RollResults) {
175+
if (rolls.name === 'fudge') {
174176
rolls = rolls.rolls;
175177
}
176178
for (const roll of rolls) {
177179
if (typeof roll !== 'object') continue;
178180
if (dice.includes(`d${sides}`)) {
179181
let iconValue = roll.value;
180-
if (diceEntry instanceof FudgeDice) {
182+
if (diceEntry.name === 'fudge') {
181183
if (roll.value === 1) iconValue = 'plus';
182184
else if (roll.value === -1) iconValue = 'minus';
183185
else iconValue = 'zero';
@@ -219,8 +221,8 @@ async function parseCommands(post) {
219221
const event = {
220222
type: 'dice',
221223
total,
222-
rolls,
223-
diceUsed,
224+
rolls: JSON.stringify(rolls),
225+
diceUsed: JSON.stringify(diceUsed),
224226
parsedNotation,
225227
uid: post.uid,
226228
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nodebb-plugin-ws-dice",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "A dice plugin integrated with topic events",
55
"main": "library.js",
66
"scripts": {

pnpm-lock.yaml

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)