Skip to content

Commit

Permalink
Detailed rands
Browse files Browse the repository at this point in the history
  • Loading branch information
ysakasin committed Mar 27, 2020
1 parent 07082db commit 8cd9cd1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
28 changes: 27 additions & 1 deletion docs/api.md
Expand Up @@ -166,10 +166,36 @@ WebAPIで利用できるダイスボットのシステムID一覧が返却され
{"faces" : 10, "value" : 8},
{"faces" : 10, "value" : 2},
{"faces" : 10, "value" : 1},
{"faces" : 10, "value" : 9},
{"faces" : 10, "value" : 9}
],
"detailed_rands" : [
{"kind" : "nomal", "faces" : 10, "value" : 8},
{"kind" : "nomal", "faces" : 10, "value" : 2},
{"kind" : "nomal", "faces" : 10, "value" : 1},
{"kind" : "nomal", "faces" : 10, "value" : 9}
]
}
```

`secret` はシックレットダイスロールであるかを示します。
`dices` はダイス単位の結果を配列で返します。

### `detailed_rands`
`detailed_rands``dices` より詳細なダイスロール結果を表示します。
従来は判別できなかった、十の位のダイス(Tens D10)を判別するために追加されました。

例は以下の通りです。

- `nomal`
- 通常のダイスロール
- `{"kind" : "nomal", "faces" : 10, "value" : 8}`
- `tens_d10`
- 十の位のダイス
- `{"kind" : "tens_d10", "faces" : 10, "value" : 80}`
- `{"kind" : "tens_d10", "faces" : 10, "value" : 0}`
- `00` は0として扱われます
- `d9`
- 十面体を0〜9のダイスとして扱う
- `{"kind" : "d9", "faces" : 10, "value" : 0}`

Since: 0.9.0, BCDice Ver2.04.00
19 changes: 15 additions & 4 deletions server.rb
Expand Up @@ -40,12 +40,25 @@ def diceroll(system, command)
end

dices = bcdice.getRandResults.map {|dice| {faces: dice[1], value: dice[0]}}
detailed_rands = bcdice.detailed_rand_results.map do |dice|
dice = dice.to_h
dice[:faces] = dice[:sides]
dice.delete(:faces)

dice
end

if result.nil?
raise CommandError
end

return result, secret, dices
{
ok: true,
result: result,
secret: secret,
dices: dices,
detailed_rands: detailed_rands,
}
end
end

Expand Down Expand Up @@ -83,9 +96,7 @@ def diceroll(system, command)
end

get "/v1/diceroll" do
result, secret, dices = diceroll(params[:system], params[:command])

jsonp ok: true, result: result, secret: secret, dices: dices
jsonp diceroll(params[:system], params[:command])
end

not_found do
Expand Down
10 changes: 10 additions & 0 deletions test/test_api.rb
Expand Up @@ -83,6 +83,16 @@ def test_extratable
assert_false json["secret"]
end

def test_detailed
get "/v1/diceroll?system=Cthulhu7th&command=CC1"

json = JSON.parse(last_response.body)

assert last_response.ok?
assert json["ok"]
assert_not_empty json["detailed_rands"].select{ |r| r["kind"] == "tens_d10" }
end

data("単純な四則演算", "C(1+2-3*4/5)")
data("括弧を含む四則演算", "C(1+(2-3*4/(5/6))-7)")
data("計算コマンドの後に文字列が存在する場合(空白あり)", "C(10+5) mokekeke")
Expand Down

0 comments on commit 8cd9cd1

Please sign in to comment.