Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

メッセージの最大文字数制限を撤廃する #236

Merged
merged 2 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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