Skip to content

Commit

Permalink
Fix rerolls and add private roll support
Browse files Browse the repository at this point in the history
These changes resolve an issue where only the last part of a multi roll
is checked when it comes to rerolls.

This also adds support for private rolls. Now you can private message
the bot to hide both the roll syntax and the result but if that is too
much a hassle users can now do "/roll p 4d10" to get the result as a
private message in channel.

fixes #187
closes #120
  • Loading branch information
Humblemonk committed Apr 7, 2024
1 parent 94edd75 commit b1cec4f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Metrics/AbcSize:
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
# IgnoredMethods: refine
Metrics/BlockLength:
Max: 93
Max: 99

# Offense count: 3
# Configuration parameters: CountBlocks.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ Below are examples of the dice roll syntax.

`/roll s 4d6` : Simplify roll output by not showing the tally.

`/roll p 4d6` : Private roll results. Roll four six-sided dice and return the results privately. Note: the roll syntax is still public

`/roll 4d6 ! unsort` or `!roll ul 4d6`: Roll four six-sided dice and unsort the tally.

`/roll help` : Displays basic usage instructions.
Expand Down
8 changes: 7 additions & 1 deletion dice_maiden.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Dice bot for Discord
# Author: Humblemonk
# Version: 8.8.0
# Version: 8.8.1
# Copyright (c) 2017. All rights reserved.
# !/usr/bin/ruby
# If you wish to run a single instance of this bot, please follow the "Manual Install" section of the readme!
Expand Down Expand Up @@ -74,6 +74,10 @@
@wng = false
@dh = false
@ed = false
@private_roll = false
@reroll_check = 0
@reroll_indefinite_check = 0
@reroll_count = 0

check_roll_modes
next if @ed && !replace_earthdawn(event)
Expand Down Expand Up @@ -151,6 +155,8 @@
@has_comment = !@comment.to_s.empty? && !@comment.to_s.nil?
if check_wrath == true
respond_wrath(event, dnum)
elsif @private_roll
event.respond(content: build_response, ephemeral: true)
else
event.respond(content: build_response)
check_fury(event)
Expand Down
7 changes: 6 additions & 1 deletion doc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## 8.8..0 - 2024-04-07
## 8.8.1 - 2024-04-07
### Added
- Resolved an issue where reroll counts were not tallied accurately with multi dice roll

## 8.8.0 - 2024-04-07
### Added
- Added support for up to d1000 rolls
- Added support for private rolls(p cmd) e.g. /roll p 4d10

## 8.7.3 - 2024-04-04
### Added
Expand Down
14 changes: 10 additions & 4 deletions src/dice_maiden_logic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ def process_roll_token(_event, token)
end
token_total = dice_roll.result.total
# Check for reroll or indefinite reroll
reroll_check = dice_roll.result.sections[0].options[:reroll]
reroll_indefinite_check = dice_roll.result.sections[0].options[:reroll_indefinite]
if reroll_check > 0 || reroll_indefinite_check > 0
@reroll_count = dice_roll.result.sections[0].reroll_count
@reroll_check += dice_roll.result.sections[0].options[:reroll]
@reroll_indefinite_check += dice_roll.result.sections[0].options[:reroll_indefinite]
if @reroll_check > 0 || @reroll_indefinite_check > 0
@reroll_count += dice_roll.result.sections[0].reroll_count
@show_rerolls = true
else
@show_rerolls = false
Expand Down Expand Up @@ -681,6 +681,12 @@ def check_roll_modes
@input.sub!('ul', '')
end

# check for private rolls
if @input.match(/\s?(p)\s/i)
@private_roll = true
@input.sub!('p', '')
end

@ed = true if @input.match(/^\s?(ed\d+)/i) || @input.match(/^\s?(ed4e\d+)/i)
end

Expand Down

0 comments on commit b1cec4f

Please sign in to comment.