diff --git a/dice_maiden.rb b/dice_maiden.rb index 5e1e45b..e1a50a2 100755 --- a/dice_maiden.rb +++ b/dice_maiden.rb @@ -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' @@ -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) @@ -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) @@ -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 @@ -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 diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 3b86e48..781131f 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -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 diff --git a/src/dice_maiden_logic.rb b/src/dice_maiden_logic.rb index b455400..38827e0 100644 --- a/src/dice_maiden_logic.rb +++ b/src/dice_maiden_logic.rb @@ -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 diff --git a/src/respond_logic.rb b/src/respond_logic.rb new file mode 100644 index 0000000..f87f422 --- /dev/null +++ b/src/respond_logic.rb @@ -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