Skip to content

Commit

Permalink
Merge pull request #236 from bcdice/remove_SEND_STR_MAX
Browse files Browse the repository at this point in the history
メッセージの最大文字数制限を撤廃する
  • Loading branch information
ysakasin authored Jul 7, 2020
2 parents 1880d5b + 1e8c64a commit 9197c57
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 63 deletions.
2 changes: 0 additions & 2 deletions src/cgiDiceBot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ def initialize
@rands = nil # テスト以外ではnilで良い。ダイス目操作パラメータ
@isTest = false
@bcdice = nil

$SEND_STR_MAX = 99999 # 最大送信文字数(本来は500byte上限)
end

attr_reader :isSecret
Expand Down
3 changes: 0 additions & 3 deletions src/configBcDice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

$bcDiceVersion = "2.06.01"

# @deprecated IRCボット機能の削除に伴い廃止予定。
$SEND_STR_MAX = 405; # 最大送信文字数(本来は500byte上限)

$DICE_MAXCNT = 200; # ダイスが振れる最大個数
$DICE_MAXNUM = 1000; # ダイスの最大面数
$isHandSort = true; # 手札をソートする必要があるか?
Expand Down
8 changes: 2 additions & 6 deletions src/diceBot/BattleTech.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,9 @@ def getHitResult(count, damageFunc, tail)
resultTexts << hitResult
end

totalResultText = resultTexts.join("\n")

if totalResultText.length >= $SEND_STR_MAX
totalResultText = "..."
end
resultTexts.push(" > #{hitCount}回命中")

totalResultText += "\n#{hitCount}回命中"
totalResultText = resultTexts.join("\n")
totalResultText += " 命中箇所:" + getTotalDamage(damages) if hitCount > 0

return totalResultText
Expand Down
37 changes: 2 additions & 35 deletions src/diceBot/DoubleCross.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def execute(bot)
loop_count += 1
end

return result_str(value_groups, loop_count)
return result_str(value_groups)
end

private
Expand All @@ -99,29 +99,13 @@ def node_expression

# 判定結果の文字列を返す
# @param [Array<ValueGroup>] value_groups 出目のグループの配列
# @param [Integer] loop_count 回転数
# @return [String]
def result_str(value_groups, loop_count)
def result_str(value_groups)
fumble = value_groups[0].values.all? { |value| value == 1 }
# TODO: Ruby 2.4以降では Array#sum が使える
sum = value_groups.map(&:max).reduce(0, &:+)
achieved_value = fumble ? 0 : (sum + @modifier)

long_str = result_str_long(value_groups, achieved_value, fumble)

if long_str.length > $SEND_STR_MAX
return result_str_short(loop_count, achieved_value, fumble)
end

return long_str
end

# ダイスロール結果の長い文字列表記を返す
# @param [Array<ValueGroup>] value_groups 出目のグループの配列
# @param [Integer] achieved_value 達成値
# @param [Boolean] fumble ファンブルしたか
# @return [String]
def result_str_long(value_groups, achieved_value, fumble)
parts = [
"(#{@expression})",
"#{value_groups.join('+')}#{@modifier_str}",
Expand All @@ -132,23 +116,6 @@ def result_str_long(value_groups, achieved_value, fumble)
return parts.compact.join(' > ')
end

# ダイスロール結果の短い文字列表記を返す
# @param [Integer] loop_count 回転数
# @param [Integer] achieved_value 達成値
# @param [Boolean] fumble ファンブルしたか
# @return [String]
def result_str_short(loop_count, achieved_value, fumble)
parts = [
"(#{@expression})",
'...',
"回転数#{loop_count}",
achieved_value_with_if_fumble(achieved_value, fumble),
compare_result(achieved_value, fumble)
]

return parts.compact.join(' > ')
end

# ファンブルかどうかを含む達成値の表記を返す
# @param [Integer] achieved_value 達成値
# @param [Boolean] fumble ファンブルしたか
Expand Down
4 changes: 0 additions & 4 deletions src/diceBot/RecordOfSteam.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ def rollDiceCommand(command)

output = "(#{command}) > #{rollResult}"

if output.length > $SEND_STR_MAX
output = "(#{command}) > ..."
end

roundCountText = getRoundCountText(roundCount)
successText = getSuccessText(successCount)
specialText = getSpecialText(specialCount)
Expand Down
16 changes: 3 additions & 13 deletions src/diceBot/SwordWorld.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ def rating(string) # レーティング表
break unless dice >= crit
end

limitLength = $SEND_STR_MAX - output.length
output += getResultText(totalValue, addValue, diceResults, diceResultTotals,
rateResults, diceOnlyTotal, round, limitLength, half)
rateResults, diceOnlyTotal, round, half)

return output
end
Expand Down Expand Up @@ -414,12 +413,10 @@ def rollDice(_values)
# @param rateResults [Array<String>]
# @param dice_total [Integer]
# @param round [Integer]
# @param limitLength [Integer]
# @param half [Boolean]
def getResultText(rating_total, modifier, diceResults, diceResultTotals,
rateResults, dice_total, round, limitLength, half)
rateResults, dice_total, round, half)
sequence = []
short = ["..."]

sequence.push("2D:[#{diceResults.join(' ')}]=#{diceResultTotals.join(',')}")

Expand All @@ -443,7 +440,6 @@ def getResultText(rating_total, modifier, diceResults, diceResultTotals,
if round > 1
round_text = "#{round - 1}回転"
sequence.push(round_text)
short.push(round_text)
end

total = rating_total + modifier
Expand All @@ -453,14 +449,8 @@ def getResultText(rating_total, modifier, diceResults, diceResultTotals,

total_text = total.to_s
sequence.push(total_text)
short.push(total_text)

ret = sequence.join(" > ")
if ret.length > limitLength
short.join(" > ")
else
ret
end
return sequence.join(" > ")
end

def setRatingTable(tnick)
Expand Down

0 comments on commit 9197c57

Please sign in to comment.