Skip to content

Commit

Permalink
Update mutli roll logic
Browse files Browse the repository at this point in the history
This commit moves send response logic to a new method. It also updates
multi roll logic support allowing for roll sets.
  • Loading branch information
Humblemonk committed Jul 6, 2024
1 parent 99fcd93 commit 9556d9d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 48 deletions.
30 changes: 7 additions & 23 deletions dice_maiden.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Dice bot for Discord
# Author: Humblemonk
# Version: 9.0.5
# Version: 9.0.6
# 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!
require_relative 'src/dice_maiden_logic'
require_relative 'src/earthdawn_logic'
require_relative 'src/respond_logic'

require 'discordrb'
require 'dicebag'
Expand Down Expand Up @@ -52,7 +53,7 @@
inc_cmd = lambda do |event|
# Locking the thread to prevent messages going to the wrong server
mutex.lock
response_array = []
@response_array = []
begin
inc_event_roll = event.options.values.join('')
rolls_array = inc_event_roll.split(/\s*;\s*/).take(4)
Expand Down Expand Up @@ -136,16 +137,10 @@
roll_count += 1
end
next if error_encountered

log_roll(event) if @launch_option == 'debug'
if @comment.to_s.empty? || @comment.to_s.nil?
event.respond(content: "#{@user} Request: `[#{@roll_request.strip}]` Rolls:\n#{@roll_set_results}Results Total: `#{@roll_set_total}`")
else
event.respond(content: "#{@user} Rolls:\n#{@roll_set_results}Results Total: `#{@roll_set_total}`\nReason: `#{@comment}`")
end
next
end

log_roll(event) if @launch_option == 'debug'

# Output aliasing
@tally = alias_output_pass(@tally)

Expand All @@ -157,7 +152,7 @@

@has_comment = !@comment.to_s.empty? && !@comment.to_s.nil?

response_array.push(build_response)
@response_array.push(build_response)
end
next if check_donate(event) == true
next if check_help(event) == true
Expand All @@ -180,18 +175,7 @@
end
end
end
# Print dice results to Discord channel
# reduce noisy errors by checking if response array is empty due to responding earlier
if response_array.empty?
# do nothing
elsif check_wrath == true
respond_wrath(event, @dnum)
elsif @private_roll
event.respond(content: response_array.join("\n").to_s, ephemeral: true)
else
event.respond(content: response_array.join("\n").to_s)
check_fury(event)
end
send_response(event)
mutex.unlock
end

Expand Down
4 changes: 4 additions & 0 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 9.0.6 -2024-07-
### Added
- Updated multi roll logic to support roll sets

## 9.0.5 -2024-07-02
### Added
- Added additional info to the bot info command
Expand Down
25 changes: 0 additions & 25 deletions src/dice_maiden_logic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -648,28 +648,3 @@ def botch_counter
end
" Botches: `#{@botch_count}`"
end

def build_response
response = "#{@user} Request: `[#{@roll_request.strip}]`"
unless @simple_output
response += " Roll: `#{@tally}`"
response += " Rerolls: `#{@reroll_count}`" if @show_rerolls
end
response += botch_counter if @show_botch
response += " #{@dice_result}" unless @no_result

if @hsn
response += " Body: `#{@hsn_body}`, Stun: `#{@hsn_stun}`"
end

if @hsk
response += " Body: `#{@hsk_body}`, Stun Multiplier: `#{@hsk_multiplier}`, Stun: `#{@hsk_stun}`"
end

if @hsh
response += " Hits DCV `#{@dice_result.scan(/\d+/)}`"
end

response += " Reason: `#{@comment}`" if @has_comment
response
end
43 changes: 43 additions & 0 deletions src/respond_logic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

def build_response
response = "#{@user} Request: `[#{@roll_request.strip}]`"
if @roll_set
response += if @comment.to_s.empty? || @comment.to_s.nil?
" Rolls:\n#{@roll_set_results}Results Total: `#{@roll_set_total}`"
else
" Rolls:\n#{@roll_set_results}Results Total: `#{@roll_set_total}`\nReason: `#{@comment}`"
end
return response
end
unless @simple_output
response += " Roll: `#{@tally}`"
response += " Rerolls: `#{@reroll_count}`" if @show_rerolls
end
response += botch_counter if @show_botch
response += " #{@dice_result}" unless @no_result

response += " Body: `#{@hsn_body}`, Stun: `#{@hsn_stun}`" if @hsn

response += " Body: `#{@hsk_body}`, Stun Multiplier: `#{@hsk_multiplier}`, Stun: `#{@hsk_stun}`" if @hsk

response += " Hits DCV `#{@dice_result.scan(/\d+/)}`" if @hsh

response += " Reason: `#{@comment}`" if @has_comment
response
end

def send_response(event)
# Print dice results to Discord channel
# reduce noisy errors by checking if response array is empty due to responding earlier
if @response_array.empty?
# do nothing
elsif check_wrath == true
respond_wrath(event, @dnum)
elsif @private_roll
event.respond(content: @response_array.join("\n").to_s, ephemeral: true)
else
event.respond(content: @response_array.join("\n").to_s)
check_fury(event)
end
end

0 comments on commit 9556d9d

Please sign in to comment.