18
18
msgfmtr MessageFormatter
19
19
urlRE = regexp .MustCompile (`https?://(\S+)` )
20
20
unsetBBcodeTags = []string {"center" , "color" , "img" , "quote" , "size" }
21
- diceRoller = regexp .MustCompile (`(?i)\ [(\d*)d(\d+)(?:([+-])(\d+))?\]` )
21
+ diceRoller = regexp .MustCompile (`(?i)(\S*)\ [(\d*)d(\d+)(?:([+-])(\d+))?\](\S*) ` )
22
22
)
23
23
24
24
// InitPosting prepares the formatter and the temp post pruner
@@ -142,13 +142,13 @@ func ApplyDiceRoll(p *gcsql.Post) (rollSum int, err error) {
142
142
continue
143
143
}
144
144
numDice := 1
145
- if roll [1 ] != "" {
146
- numDice , err = strconv .Atoi (roll [1 ])
145
+ if roll [2 ] != "" {
146
+ numDice , err = strconv .Atoi (roll [2 ])
147
147
if err != nil {
148
148
return 0 , err
149
149
}
150
150
}
151
- dieSize , err := strconv .Atoi (roll [2 ])
151
+ dieSize , err := strconv .Atoi (roll [3 ])
152
152
if err != nil {
153
153
return 0 , err
154
154
}
@@ -157,27 +157,27 @@ func ApplyDiceRoll(p *gcsql.Post) (rollSum int, err error) {
157
157
}
158
158
for i := 0 ; i < numDice ; i ++ {
159
159
rollSum += rand .Intn (dieSize ) + 1 // skipcq: GSC-G404
160
- switch roll [3 ] {
160
+ switch roll [4 ] {
161
161
case "+" :
162
- mod , err := strconv .Atoi (roll [4 ])
162
+ mod , err := strconv .Atoi (roll [5 ])
163
163
if err != nil {
164
164
return 0 , err
165
165
}
166
166
rollSum += mod
167
167
case "-" :
168
- mod , err := strconv .Atoi (roll [4 ])
168
+ mod , err := strconv .Atoi (roll [5 ])
169
169
if err != nil {
170
170
return 0 , err
171
171
}
172
172
rollSum -= mod
173
173
}
174
174
}
175
- words [w ] = fmt .Sprintf (`<span class="dice-roll">%dd%d` , numDice , dieSize )
176
- if roll [3 ] != "" {
177
- words [w ] += roll [3 ] + roll [4 ]
175
+ words [w ] = fmt .Sprintf (`%s <span class="dice-roll">%dd%d` , roll [ 1 ] , numDice , dieSize )
176
+ if roll [4 ] != "" {
177
+ words [w ] += roll [4 ] + roll [5 ]
178
178
}
179
- words [w ] += fmt .Sprintf (" = %d</span>" , rollSum )
179
+ words [w ] += fmt .Sprintf (" = %d</span>%s " , rollSum , roll [ 6 ] )
180
180
}
181
- p .Message = template .HTML (strings .Join (words , " " ))
181
+ p .Message = template .HTML (strings .Join (words , " " )) // skipcq: GSC-G203
182
182
return
183
183
}
0 commit comments