From cad8f58942dc7a5ba98f78e3227407a0fa805993 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Wed, 22 Jul 2020 23:17:14 +0900 Subject: [PATCH 01/37] Add DockerHub badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f478500..b8de4e7 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ BCDiceを提供するWebAPIサーバー [![Action Status](https://github.com/bcdice/bcdice-api/workflows/Test/badge.svg?branch=master)](https://github.com/bcdice/bcdice-api/actions) +[![Docker repository](https://img.shields.io/docker/pulls/bcdice/bcdice-api?logo=docker&logoColor=fff)](https://hub.docker.com/r/bcdice/bcdice-api) ## Demo From 7ffd54ada53e91e0efdb67fa39448ba1b2f65aea Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sun, 20 Dec 2020 21:33:17 +0900 Subject: [PATCH 02/37] =?UTF-8?q?BCDice=203.0.0-alpha.2=E3=81=AB=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- Gemfile.lock | 8 ++++++-- bcdice | 2 +- lib/bcdice_api/app.rb | 8 ++++---- test/test_dicebot.rb | 7 +------ 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index f541e93..8c48805 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' -gem 'bcdice', '3.0.0.pre.alpha.1' +gem 'bcdice', '3.0.0.pre.alpha.2' gem 'sinatra', '~>2.0' gem 'sinatra-contrib', '~>2.0' diff --git a/Gemfile.lock b/Gemfile.lock index 43d35d6..6e364aa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,7 +3,11 @@ GEM specs: ast (2.4.0) backports (3.16.1) - bcdice (3.0.0.pre.alpha.1) + bcdice (3.0.0.pre.alpha.2) + i18n (~> 1.8.5) + concurrent-ruby (1.1.7) + i18n (1.8.5) + concurrent-ruby (~> 1.0) jaro_winkler (1.5.4) multi_json (1.14.1) mustermann (1.1.1) @@ -58,7 +62,7 @@ PLATFORMS ruby DEPENDENCIES - bcdice (= 3.0.0.pre.alpha.1) + bcdice (= 3.0.0.pre.alpha.2) puma (~> 4.3) rack-test (~> 1.1) rake (~> 13.0) diff --git a/bcdice b/bcdice index d3282bc..dea62b7 160000 --- a/bcdice +++ b/bcdice @@ -1 +1 @@ -Subproject commit d3282bc77b8a3d934251c00ec48100cad902423b +Subproject commit dea62b7b94600f8b54ffec016ba6abd7426dd88d diff --git a/lib/bcdice_api/app.rb b/lib/bcdice_api/app.rb index 8ce378c..5369a90 100644 --- a/lib/bcdice_api/app.rb +++ b/lib/bcdice_api/app.rb @@ -35,13 +35,13 @@ def diceroll(system, command) raise CommandError if result.nil? - dices = dicebot.randomizer.rand_results.map { |dice| { faces: dice[1], value: dice[0] } } - detailed_rands = dicebot.randomizer.detailed_rand_results.map(&:to_h) + dices = result.rands.map { |dice| { faces: dice[1], value: dice[0] } } + detailed_rands = result.detailed_rands.map(&:to_h) { ok: true, - result: ": #{result}", - secret: dicebot.secret?, + result: ": #{result.text}", + secret: result.secret?, dices: dices, detailed_rands: detailed_rands } diff --git a/test/test_dicebot.rb b/test/test_dicebot.rb index ce23a42..d2ae34c 100644 --- a/test/test_dicebot.rb +++ b/test/test_dicebot.rb @@ -18,18 +18,13 @@ def app data_set = {} files = Dir.glob('bcdice/test/data/*.toml') - class_name_to_id = BCDice.all_game_systems.map do |k| - name = k.name.split('::').last - [name, k::ID] - end.to_h - files.each do |filename| filename_base = File.basename(filename, '.toml') data = Tomlrb.load_file(filename, symbolize_keys: true) data[:test].each.with_index(1) do |test_case, index| test_case[:filename] = filename - test_case[:game_system] = class_name_to_id[test_case[:game_system]] + test_case[:game_system] = test_case[:game_system] test_case[:output] = ": #{test_case[:output]}" unless test_case[:output].empty? test_case[:output] = nil if test_case[:output].empty? # TOMLではnilを表現できないので空文字で代用 test_case[:secret] ||= false From 13e3860a8210ddb8ecb9fc64d9f3dcbec9cdf4d1 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Fri, 25 Dec 2020 16:47:39 +0900 Subject: [PATCH 03/37] Fix prefixes --- lib/bcdice_api/app.rb | 2 +- test/test_api.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bcdice_api/app.rb b/lib/bcdice_api/app.rb index 5369a90..bed3cfc 100644 --- a/lib/bcdice_api/app.rb +++ b/lib/bcdice_api/app.rb @@ -80,7 +80,7 @@ def diceroll(system, command) 'name' => dicebot::NAME, 'gameType' => dicebot::ID, 'sortKey' => dicebot::SORT_KEY, - 'prefixs' => dicebot.prefixes_pattern, + 'prefixs' => dicebot.prefixes, 'info' => dicebot::HELP_MESSAGE } diff --git a/test/test_api.rb b/test/test_api.rb index 82d0387..9ca07d9 100644 --- a/test/test_api.rb +++ b/test/test_api.rb @@ -57,7 +57,7 @@ def test_systeminfo assert json['systeminfo'] assert_equal json['systeminfo']['gameType'], 'DiceBot' assert_false json['systeminfo']['name'].empty? - assert json['systeminfo']['prefixs'] + assert_instance_of Array, json['systeminfo']['prefixs'] pend 'DiceBot::HELP_MESSAGE will be supported in BCDice v3' assert_false json['systeminfo']['info'].empty? From 9789e254ac1a9e3883bdab753bef2da506bf9989 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Fri, 25 Dec 2020 22:07:23 +0900 Subject: [PATCH 04/37] =?UTF-8?q?/v1/names=E3=81=AE=E8=A1=A8=E7=A4=BA?= =?UTF-8?q?=E9=A0=86=E3=82=92=E7=9B=B4=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/bcdice_api/dicebots.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/bcdice_api/dicebots.rb b/lib/bcdice_api/dicebots.rb index fd91ff9..d78d3ed 100644 --- a/lib/bcdice_api/dicebots.rb +++ b/lib/bcdice_api/dicebots.rb @@ -20,7 +20,10 @@ def load_plugins end end - DICEBOTS = BCDice.all_game_systems.map { |klass| [klass::ID, klass] }.to_h + DICEBOTS = BCDice.all_game_systems + .sort_by { |klass| klass::SORT_KEY } + .map { |klass| [klass::ID, klass] } + .to_h SYSTEMS = DICEBOTS.keys .sort From c8e3cd1d44141f9b64ec5e2f68f5ee21d2581089 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Mon, 28 Dec 2020 22:46:53 +0900 Subject: [PATCH 05/37] API v2 --- .rubocop.yml | 15 +--- Rakefile | 8 ++ lib/bcdice_api/app.rb | 8 +- lib/bcdice_api/v2/app.rb | 114 +++++++++++++++++++++++++++ test/test_api_v2.rb | 165 +++++++++++++++++++++++++++++++++++++++ test/test_dicebot_v2.rb | 57 ++++++++++++++ 6 files changed, 349 insertions(+), 18 deletions(-) create mode 100644 lib/bcdice_api/v2/app.rb create mode 100644 test/test_api_v2.rb create mode 100644 test/test_dicebot_v2.rb diff --git a/.rubocop.yml b/.rubocop.yml index 8e184de..1a4f8a5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,24 +5,11 @@ AllCops: - "vendor/**/*" Metrics: - Exclude: - - "lib/bcdice_wrap.rb" - - "lib/bcdice_api/app.rb" - -Metrics/ClassLength: - Exclude: - - "test/**/*" - -Metrics/AbcSize: Exclude: - "test/**/*" - "lib/bcdice_wrap.rb" - "lib/bcdice_api/app.rb" - -Metrics/BlockLength: - Exclude: - - "test/**/*" - - "lib/bcdice_api/app.rb" + - "lib/bcdice_api/v2/app.rb" Lint/RaiseException: Enabled: true diff --git a/Rakefile b/Rakefile index 7fc9412..bab5345 100644 --- a/Rakefile +++ b/Rakefile @@ -12,6 +12,14 @@ Rake::TestTask.new do |t| t.verbose = true end +namespace :test do + Rake::TestTask.new(:v2) do |t| + t.libs += ['lib'] + t.test_files = ['test/test_api_v2.rb', 'test/test_dicebot_v2.rb'] + t.verbose = true + end +end + RuboCop::RakeTask.new Rake::Task[:test].enhance do diff --git a/lib/bcdice_api/app.rb b/lib/bcdice_api/app.rb index bed3cfc..1826566 100644 --- a/lib/bcdice_api/app.rb +++ b/lib/bcdice_api/app.rb @@ -6,6 +6,8 @@ require 'sinatra/reloader' if development? require 'exception' +require_relative 'v2/app' + module BCDiceAPI class App < Sinatra::Application class << self @@ -20,6 +22,8 @@ class << self register Sinatra::Reloader end + use V2::App + helpers Sinatra::Jsonp helpers do @@ -48,10 +52,6 @@ def diceroll(system, command) end end - before do - response.headers['Access-Control-Allow-Origin'] = '*' - end - get '/' do 'Hello. This is BCDice-API.' end diff --git a/lib/bcdice_api/v2/app.rb b/lib/bcdice_api/v2/app.rb new file mode 100644 index 0000000..c133f2e --- /dev/null +++ b/lib/bcdice_api/v2/app.rb @@ -0,0 +1,114 @@ +# frozen_string_literal: true + +require 'sinatra' +require 'sinatra/base' +require 'sinatra/jsonp' + +require 'sinatra/reloader' if development? + +require 'bcdice/user_defined_dice_table' + +module BCDiceAPI + module V2 + class App < Sinatra::Base + class << self + attr_accessor :test_rands + end + + before do + response.headers['Access-Control-Allow-Origin'] = '*' + end + + helpers Sinatra::Jsonp + + helpers do + def roll(id, command) + klass = BCDiceAPI::DICEBOTS[id] + raise UnsupportedDicebot if klass.nil? + raise CommandError if command.nil? || command.empty? + + game_system = klass.new(command) + game_system.randomizer = RandomizerMock.new(App.test_rands) if App.test_rands + + result = game_system.eval + raise CommandError if result.nil? + + { + ok: true, + text: result.text, + secret: result.secret?, + success: result.success?, + failure: result.failure?, + critical: result.critical?, + fumble: result.fumble?, + rands: result.detailed_rands.map(&:to_h) + } + end + end + + get '/v2/version' do + jsonp api: BCDiceAPI::VERSION, bcdice: BCDice::VERSION + end + + get '/v2/admin' do + jsonp BCDiceAPI::ADMIN + end + + get '/v2/game_system' do + game_system = BCDice.all_game_systems.sort_by { |game| game::SORT_KEY } .map do |game| + { id: game::ID, name: game::NAME, sort_key: game::SORT_KEY } + end + + jsonp game_system: game_system + end + + get '/v2/game_system/:id' do |id| + game_system = BCDice.game_system_class(id) + raise UnsupportedDicebot if game_system.nil? + + ret = { + ok: true, + id: game_system::ID, + name: game_system::NAME, + sort_key: game_system::SORT_KEY, + command_pattern: game_system.command_pattern.source, + help_message: game_system::HELP_MESSAGE + } + + jsonp ret + end + + get '/v2/game_system/:id/roll' do |id| + jsonp roll(id, params[:command]) + end + + post '/v2/game_system/:id/roll' do |id| + jsonp roll(id, params[:command]) + end + + post '/v2/original_table' do + table = BCDice::UserDefinedDiceTable.new(params[:table]) + + jsonp text: params[:table] + + ret = { + ok: true, + text: table.roll, + rands: table.randomizer.detailed_rand_results.map(&:to_h) + } + + jsonp ret + end + + error UnsupportedDicebot do + status 400 + jsonp ok: false, reason: 'unsupported game system' + end + + error CommandError do + status 400 + jsonp ok: false, reason: 'unsupported command' + end + end + end +end diff --git a/test/test_api_v2.rb b/test/test_api_v2.rb new file mode 100644 index 0000000..c8caa67 --- /dev/null +++ b/test/test_api_v2.rb @@ -0,0 +1,165 @@ +# frozen_string_literal: true + +ENV['RACK_ENV'] = 'test' +require 'test/unit' +require 'rack/test' + +require 'cgi' + +require 'bcdice_api' + +class V2APITest < Test::Unit::TestCase + include Rack::Test::Methods + + def app + BCDiceAPI::App + end + + def test_version + get '/v2/version' + json = JSON.parse(last_response.body) + + assert last_response.ok? + assert_equal '*', last_response.headers['Access-Control-Allow-Origin'] + assert json.key?('bcdice') + assert json.key?('api') + end + + def test_game_system_list + get '/v2/game_system' + json = JSON.parse(last_response.body) + + assert last_response.ok? + assert_false json['game_system'].empty? + assert_instance_of Array, json['game_system'] + + first = json['game_system'].first + assert first.key?('name') + assert first.key?('id') + assert first.key?('sort_key') + end + + def test_game_system_info + get '/v2/game_system/DiceBot' + json = JSON.parse(last_response.body) + + assert last_response.ok? + assert json['ok'] + assert_equal json['id'], 'DiceBot' + assert_instance_of String, json['name'] + assert_instance_of String, json['command_pattern'] + assert_instance_of String, json['sort_key'] + assert_instance_of String, json['help_message'] + assert_false json['name'].empty? + assert_false json['command_pattern'].empty? + assert_false json['sort_key'].empty? + + pend 'DiceBot::HELP_MESSAGE will be supported in BCDice v3' + assert_false json['help_message'].empty? + end + + def test_diceroll + get '/v2/game_system/DiceBot/roll?command=1d100<=70' + + json = JSON.parse(last_response.body) + + assert last_response.ok? + assert json['ok'] + assert json['text'] + assert_false json['secret'] + assert_boolean json['success'] + assert_boolean json['failure'] + assert_false json['critical'] + assert_false json['fumble'] + assert_instance_of Array, json['rands'] + end + + def test_diceroll_with_post + post '/v2/game_system/DiceBot/roll', { command: '1d100<=70' } + + json = JSON.parse(last_response.body) + + assert last_response.ok? + assert json['ok'] + assert json['text'] + assert_false json['secret'] + assert_boolean json['success'] + assert_boolean json['failure'] + assert_false json['critical'] + assert_false json['fumble'] + assert_instance_of Array, json['rands'] + end + + def test_detailed + get '/v2/game_system/Cthulhu7th/roll?command=CC1' + + json = JSON.parse(last_response.body) + + assert last_response.ok? + assert json['ok'] + assert_not_empty(json['rands'].select { |r| r['kind'] == 'tens_d10' }) + end + + def test_unexpected_game_system + get '/v2/game_system/Hoge/roll?command=1d100<=70' + + json = JSON.parse(last_response.body) + + assert last_response.bad_request? + assert_false json['ok'] + assert_equal json['reason'], 'unsupported game system' + end + + def test_unexpected_command + get '/v2/game_system/DiceBot/roll?command=a' + + json = JSON.parse(last_response.body) + + assert last_response.bad_request? + assert_false json['ok'] + assert_equal json['reason'], 'unsupported command' + end + + def test_no_command + get '/v2/game_system/DiceBot/roll' + + json = JSON.parse(last_response.body) + + assert last_response.bad_request? + assert_false json['ok'] + assert_equal json['reason'], 'unsupported command' + end + + def test_blank_command + get '/v2/game_system/DiceBot/roll?command=' + + json = JSON.parse(last_response.body) + + assert last_response.bad_request? + assert_false json['ok'] + assert_equal json['reason'], 'unsupported command' + end + + def test_original_table + table_text = <<~TABLE + 飲み物表 + 1D6 + 1:水 + 2:緑茶 + 3:麦茶 + 4:コーラ + 5:オレンジジュース + 6:選ばれし者の知的飲料 + TABLE + + post '/v2/original_table', { table: table_text } + + json = JSON.parse(last_response.body) + + assert last_response.ok? + assert_true json['ok'] + assert_instance_of String, json['text'] + assert_true json['text'].start_with?('飲み物表(') + assert_instance_of Array, json['rands'] + end +end diff --git a/test/test_dicebot_v2.rb b/test/test_dicebot_v2.rb new file mode 100644 index 0000000..172de5d --- /dev/null +++ b/test/test_dicebot_v2.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +ENV['RACK_ENV'] = 'test' +require 'test/unit' +require 'rack/test' +require 'tomlrb' + +require 'bcdice_api' + +class V2DicebotTest < Test::Unit::TestCase + include Rack::Test::Methods + + def app + BCDiceAPI::App + end + + data do + data_set = {} + files = Dir.glob('bcdice/test/data/*.toml') + + files.each do |filename| + filename_base = File.basename(filename, '.toml') + data = Tomlrb.load_file(filename, symbolize_keys: true) + + data[:test].each.with_index(1) do |test_case, index| + test_case[:filename] = filename + test_case[:output] = nil if test_case[:output].empty? # TOMLではnilを表現できないので空文字で代用 + test_case[:secret] ||= false + test_case[:success] ||= false + test_case[:failure] ||= false + test_case[:critical] ||= false + test_case[:fumble] ||= false + + key = [filename_base, index, test_case[:input]].join(':') + + data_set[key] = test_case + end + end + + data_set + end + def test_diceroll(data) + BCDiceAPI::V2::App.test_rands = data[:rands].map { |r| [r[:value], r[:sides]] } + + get "/v2/game_system/#{data[:game_system]}/roll", command: data[:input] + + json = JSON.parse(last_response.body) + assert_equal data[:output], json['text'] + return unless data[:output] + + assert_equal data[:secret], json['secret'] + assert_equal data[:success], json['success'] + assert_equal data[:failure], json['failure'] + assert_equal data[:critical], json['critical'] + assert_equal data[:fumble], json['fumble'] + end +end From cd09a2d02fe7f4d20225561a9168ca40aab99d58 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Mon, 28 Dec 2020 23:53:09 +0900 Subject: [PATCH 06/37] =?UTF-8?q?v2=E3=81=A7=E3=81=AFJSONP=E3=81=AF?= =?UTF-8?q?=E4=BD=BF=E3=82=8F=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/bcdice_api/v2/app.rb | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/bcdice_api/v2/app.rb b/lib/bcdice_api/v2/app.rb index c133f2e..eb0d8fd 100644 --- a/lib/bcdice_api/v2/app.rb +++ b/lib/bcdice_api/v2/app.rb @@ -2,7 +2,7 @@ require 'sinatra' require 'sinatra/base' -require 'sinatra/jsonp' +require 'sinatra/json' require 'sinatra/reloader' if development? @@ -19,8 +19,6 @@ class << self response.headers['Access-Control-Allow-Origin'] = '*' end - helpers Sinatra::Jsonp - helpers do def roll(id, command) klass = BCDiceAPI::DICEBOTS[id] @@ -47,11 +45,11 @@ def roll(id, command) end get '/v2/version' do - jsonp api: BCDiceAPI::VERSION, bcdice: BCDice::VERSION + json api: BCDiceAPI::VERSION, bcdice: BCDice::VERSION end get '/v2/admin' do - jsonp BCDiceAPI::ADMIN + json BCDiceAPI::ADMIN end get '/v2/game_system' do @@ -59,7 +57,7 @@ def roll(id, command) { id: game::ID, name: game::NAME, sort_key: game::SORT_KEY } end - jsonp game_system: game_system + json game_system: game_system end get '/v2/game_system/:id' do |id| @@ -75,21 +73,21 @@ def roll(id, command) help_message: game_system::HELP_MESSAGE } - jsonp ret + json ret end get '/v2/game_system/:id/roll' do |id| - jsonp roll(id, params[:command]) + json roll(id, params[:command]) end post '/v2/game_system/:id/roll' do |id| - jsonp roll(id, params[:command]) + json roll(id, params[:command]) end post '/v2/original_table' do table = BCDice::UserDefinedDiceTable.new(params[:table]) - jsonp text: params[:table] + json text: params[:table] ret = { ok: true, @@ -97,17 +95,17 @@ def roll(id, command) rands: table.randomizer.detailed_rand_results.map(&:to_h) } - jsonp ret + json ret end error UnsupportedDicebot do status 400 - jsonp ok: false, reason: 'unsupported game system' + json ok: false, reason: 'unsupported game system' end error CommandError do status 400 - jsonp ok: false, reason: 'unsupported command' + json ok: false, reason: 'unsupported command' end end end From 66ed4a0ae7aff55beae9154819cda842046147b9 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Fri, 1 Jan 2021 17:10:32 +0900 Subject: [PATCH 07/37] BCDice 3.0.0-rc.1 --- Gemfile | 2 +- Gemfile.lock | 44 +++++++++++++++++++--------------------- bcdice | 2 +- lib/bcdice_api/v2/app.rb | 11 ++-------- test/test_api.rb | 29 -------------------------- 5 files changed, 25 insertions(+), 63 deletions(-) diff --git a/Gemfile b/Gemfile index 8c48805..e906ffa 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' -gem 'bcdice', '3.0.0.pre.alpha.2' +gem 'bcdice', '3.0.0.pre.rc.1' gem 'sinatra', '~>2.0' gem 'sinatra-contrib', '~>2.0' diff --git a/Gemfile.lock b/Gemfile.lock index 6e364aa..a276a5e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,31 +1,30 @@ GEM remote: https://rubygems.org/ specs: - ast (2.4.0) - backports (3.16.1) - bcdice (3.0.0.pre.alpha.2) + ast (2.4.1) + bcdice (3.0.0.pre.rc.1) i18n (~> 1.8.5) concurrent-ruby (1.1.7) i18n (1.8.5) concurrent-ruby (~> 1.0) jaro_winkler (1.5.4) - multi_json (1.14.1) + multi_json (1.15.0) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) - nio4r (2.5.2) - parallel (1.19.1) - parser (2.7.1.0) - ast (~> 2.4.0) - power_assert (1.1.6) - puma (4.3.5) + nio4r (2.5.4) + parallel (1.20.1) + parser (3.0.0.0) + ast (~> 2.4.1) + power_assert (1.2.0) + puma (4.3.7) nio4r (~> 2.0) rack (2.2.3) - rack-protection (2.0.8.1) + rack-protection (2.1.0) rack rack-test (1.1.0) rack (>= 1.0, < 3) rainbow (3.0.0) - rake (13.0.1) + rake (13.0.3) rexml (3.2.4) rubocop (0.81.0) jaro_winkler (~> 1.5.1) @@ -35,34 +34,33 @@ GEM rexml ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 2.0) - ruby-progressbar (1.10.1) + ruby-progressbar (1.11.0) ruby2_keywords (0.0.2) - sinatra (2.0.8.1) + sinatra (2.1.0) mustermann (~> 1.0) - rack (~> 2.0) - rack-protection (= 2.0.8.1) + rack (~> 2.2) + rack-protection (= 2.1.0) tilt (~> 2.0) - sinatra-contrib (2.0.8.1) - backports (>= 2.8.2) + sinatra-contrib (2.1.0) multi_json mustermann (~> 1.0) - rack-protection (= 2.0.8.1) - sinatra (= 2.0.8.1) + rack-protection (= 2.1.0) + sinatra (= 2.1.0) tilt (~> 2.0) sinatra-jsonp (0.5.0) multi_json (~> 1.8) sinatra (>= 1.0) - test-unit (3.3.5) + test-unit (3.3.9) power_assert tilt (2.0.10) - tomlrb (1.3.0) + tomlrb (2.0.1) unicode-display_width (1.7.0) PLATFORMS ruby DEPENDENCIES - bcdice (= 3.0.0.pre.alpha.2) + bcdice (= 3.0.0.pre.rc.1) puma (~> 4.3) rack-test (~> 1.1) rake (~> 13.0) diff --git a/bcdice b/bcdice index dea62b7..52d3d6d 160000 --- a/bcdice +++ b/bcdice @@ -1 +1 @@ -Subproject commit dea62b7b94600f8b54ffec016ba6abd7426dd88d +Subproject commit 52d3d6df692cddd93fc000dbc6730b47a92aa267 diff --git a/lib/bcdice_api/v2/app.rb b/lib/bcdice_api/v2/app.rb index eb0d8fd..4ea3ef2 100644 --- a/lib/bcdice_api/v2/app.rb +++ b/lib/bcdice_api/v2/app.rb @@ -86,16 +86,9 @@ def roll(id, command) post '/v2/original_table' do table = BCDice::UserDefinedDiceTable.new(params[:table]) + result = table.roll - json text: params[:table] - - ret = { - ok: true, - text: table.roll, - rands: table.randomizer.detailed_rand_results.map(&:to_h) - } - - json ret + json ok: true, text: result.text, rands: result.detailed_rands.map(&:to_h) end error UnsupportedDicebot do diff --git a/test/test_api.rb b/test/test_api.rb index 9ca07d9..0c4a067 100644 --- a/test/test_api.rb +++ b/test/test_api.rb @@ -98,35 +98,6 @@ def test_detailed 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') - data('Cの後に数字のみが続く場合', 'C42') - data('空白で始まる場合', ' C(1+2)') - def test_calc(command) - get "/v1/diceroll?system=DiceBot&command=#{CGI.escape(command)}" - - json = JSON.parse(last_response.body) - - assert last_response.ok? - assert json['ok'] - assert json['result'].start_with?(': 計算結果 > ') - assert_equal json['dices'], [] - assert_false json['secret'] - end - - data('括弧が閉じられていない場合', 'C(1+2') - data('計算コマンドの後に文字列が存在する場合(空白なし)', 'C(10+5)mokekeke') - def test_pseudo_calc(command) - get "/v1/diceroll?system=DiceBot&command=#{CGI.escape(command)}" - - json = JSON.parse(last_response.body) - - assert last_response.bad_request? - assert_false json['ok'] - assert_equal json['reason'], 'unsupported command' - end - def test_unexpected_dicebot get '/v1/diceroll?system=Hoge&command=1d100<=70' From b064c96e0d15e10a06845b0ae646543f9f42f736 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sat, 2 Jan 2021 01:09:56 +0900 Subject: [PATCH 08/37] =?UTF-8?q?/v1=E3=81=A8/v2=E3=82=92=E5=AE=8C?= =?UTF-8?q?=E5=85=A8=E3=81=AB=E5=88=86=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .rubocop.yml | 4 +- config.ru | 2 +- lib/bcdice_api/app.rb | 117 ++---------------- lib/bcdice_api/base.rb | 27 ++++ lib/bcdice_api/controller/root.rb | 21 ++++ lib/bcdice_api/controller/v1.rb | 91 ++++++++++++++ .../{v2/app.rb => controller/v2.rb} | 43 +++---- server.rb | 2 +- test/test_api.rb | 2 +- test/test_api_v2.rb | 2 +- test/test_dicebot.rb | 4 +- test/test_dicebot_v2.rb | 4 +- 12 files changed, 178 insertions(+), 141 deletions(-) create mode 100644 lib/bcdice_api/base.rb create mode 100644 lib/bcdice_api/controller/root.rb create mode 100644 lib/bcdice_api/controller/v1.rb rename lib/bcdice_api/{v2/app.rb => controller/v2.rb} (76%) diff --git a/.rubocop.yml b/.rubocop.yml index 1a4f8a5..4198bf1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,8 +8,8 @@ Metrics: Exclude: - "test/**/*" - "lib/bcdice_wrap.rb" - - "lib/bcdice_api/app.rb" - - "lib/bcdice_api/v2/app.rb" + - "lib/bcdice_api/controller/v1.rb" + - "lib/bcdice_api/controller/v2.rb" Lint/RaiseException: Enabled: true diff --git a/config.ru b/config.ru index bfd03aa..d4632b1 100644 --- a/config.ru +++ b/config.ru @@ -5,4 +5,4 @@ $LOAD_PATH.unshift File.join(__dir__, 'lib') require 'bcdice_api' -run BCDiceAPI::App +run BCDiceAPI::APP diff --git a/lib/bcdice_api/app.rb b/lib/bcdice_api/app.rb index 1826566..e72b723 100644 --- a/lib/bcdice_api/app.rb +++ b/lib/bcdice_api/app.rb @@ -1,112 +1,15 @@ # frozen_string_literal: true -require 'sinatra' -require 'sinatra/base' -require 'sinatra/jsonp' -require 'sinatra/reloader' if development? -require 'exception' - -require_relative 'v2/app' +require_relative 'controller/root' +require_relative 'controller/v1' +require_relative 'controller/v2' module BCDiceAPI - class App < Sinatra::Application - class << self - attr_accessor :test_rands - end - - configure :production do - set :dump_errors, false - end - - configure :development do - register Sinatra::Reloader - end - - use V2::App - - helpers Sinatra::Jsonp - - helpers do - def diceroll(system, command) - dicebot_klass = BCDiceAPI::DICEBOTS[system] - raise UnsupportedDicebot if dicebot_klass.nil? - raise CommandError if command.nil? || command.empty? - - dicebot = dicebot_klass.new(command) - dicebot.randomizer = RandomizerMock.new(App.test_rands) if App.test_rands - - result = dicebot.eval - - raise CommandError if result.nil? - - dices = result.rands.map { |dice| { faces: dice[1], value: dice[0] } } - detailed_rands = result.detailed_rands.map(&:to_h) - - { - ok: true, - result: ": #{result.text}", - secret: result.secret?, - dices: dices, - detailed_rands: detailed_rands - } - end - end - - get '/' do - 'Hello. This is BCDice-API.' - end - - get '/v1/version' do - jsonp api: BCDiceAPI::VERSION, bcdice: BCDice::VERSION - end - - get '/v1/admin' do - jsonp BCDiceAPI::ADMIN - end - - get '/v1/systems' do - jsonp systems: BCDiceAPI::SYSTEMS - end - - get '/v1/names' do - jsonp names: BCDiceAPI::NAMES - end - - get '/v1/systeminfo' do - dicebot = BCDiceAPI::DICEBOTS[params[:system]] - raise UnsupportedDicebot if dicebot.nil? - - systeminfo = { - 'name' => dicebot::NAME, - 'gameType' => dicebot::ID, - 'sortKey' => dicebot::SORT_KEY, - 'prefixs' => dicebot.prefixes, - 'info' => dicebot::HELP_MESSAGE - } - - jsonp ok: true, systeminfo: systeminfo - end - - get '/v1/diceroll' do - jsonp diceroll(params[:system], params[:command]) - end - - not_found do - jsonp ok: false, reason: 'not found' - end - - error UnsupportedDicebot do - status 400 - jsonp ok: false, reason: 'unsupported dicebot' - end - - error CommandError do - status 400 - jsonp ok: false, reason: 'unsupported command' - end - - error do - jsonp ok: false - end - end + APP = Rack::URLMap.new( + { + '/' => Controller::Root, + '/v1' => Controller::V1, + '/v2' => Controller::V2 + } + ) end diff --git a/lib/bcdice_api/base.rb b/lib/bcdice_api/base.rb new file mode 100644 index 0000000..1fe08bf --- /dev/null +++ b/lib/bcdice_api/base.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'sinatra' +require 'sinatra/base' +require 'sinatra/json' +require 'sinatra/reloader' if development? +require 'exception' + +module BCDiceAPI + class Base < Sinatra::Base + class << self + attr_accessor :test_rands + end + + configure :production do + set :dump_errors, false + end + + configure :development do + register Sinatra::Reloader + end + + before do + response.headers['Access-Control-Allow-Origin'] = '*' + end + end +end diff --git a/lib/bcdice_api/controller/root.rb b/lib/bcdice_api/controller/root.rb new file mode 100644 index 0000000..dfa2717 --- /dev/null +++ b/lib/bcdice_api/controller/root.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require_relative '../base' + +module BCDiceAPI + module Controller + class Root < Base + get '/' do + 'Hello. This is BCDice-API.' + end + + not_found do + json ok: false, reason: 'not found' + end + + error do + json ok: false + end + end + end +end diff --git a/lib/bcdice_api/controller/v1.rb b/lib/bcdice_api/controller/v1.rb new file mode 100644 index 0000000..c30e7f4 --- /dev/null +++ b/lib/bcdice_api/controller/v1.rb @@ -0,0 +1,91 @@ +# frozen_string_literal: true + +require 'sinatra/jsonp' +require_relative '../base' + +module BCDiceAPI + module Controller + class V1 < Base + helpers Sinatra::Jsonp + + helpers do + def diceroll(system, command) + dicebot_klass = BCDiceAPI::DICEBOTS[system] + raise UnsupportedDicebot if dicebot_klass.nil? + raise CommandError if command.nil? || command.empty? + + dicebot = dicebot_klass.new(command) + dicebot.randomizer = RandomizerMock.new(V1.test_rands) if V1.test_rands + + result = dicebot.eval + + raise CommandError if result.nil? + + dices = result.rands.map { |dice| { faces: dice[1], value: dice[0] } } + detailed_rands = result.detailed_rands.map(&:to_h) + + { + ok: true, + result: ": #{result.text}", + secret: result.secret?, + dices: dices, + detailed_rands: detailed_rands + } + end + end + + get '/version' do + jsonp api: BCDiceAPI::VERSION, bcdice: BCDice::VERSION + end + + get '/admin' do + jsonp BCDiceAPI::ADMIN + end + + get '/systems' do + jsonp systems: BCDiceAPI::SYSTEMS + end + + get '/names' do + jsonp names: BCDiceAPI::NAMES + end + + get '/systeminfo' do + dicebot = BCDiceAPI::DICEBOTS[params[:system]] + raise UnsupportedDicebot if dicebot.nil? + + systeminfo = { + 'name' => dicebot::NAME, + 'gameType' => dicebot::ID, + 'sortKey' => dicebot::SORT_KEY, + 'prefixs' => dicebot.prefixes, + 'info' => dicebot::HELP_MESSAGE + } + + jsonp ok: true, systeminfo: systeminfo + end + + get '/diceroll' do + jsonp diceroll(params[:system], params[:command]) + end + + not_found do + jsonp ok: false, reason: 'not found' + end + + error UnsupportedDicebot do + status 400 + jsonp ok: false, reason: 'unsupported dicebot' + end + + error CommandError do + status 400 + jsonp ok: false, reason: 'unsupported command' + end + + error do + jsonp ok: false + end + end + end +end diff --git a/lib/bcdice_api/v2/app.rb b/lib/bcdice_api/controller/v2.rb similarity index 76% rename from lib/bcdice_api/v2/app.rb rename to lib/bcdice_api/controller/v2.rb index 4ea3ef2..cdab866 100644 --- a/lib/bcdice_api/v2/app.rb +++ b/lib/bcdice_api/controller/v2.rb @@ -1,24 +1,11 @@ # frozen_string_literal: true -require 'sinatra' -require 'sinatra/base' -require 'sinatra/json' - -require 'sinatra/reloader' if development? - require 'bcdice/user_defined_dice_table' +require_relative '../base' module BCDiceAPI - module V2 - class App < Sinatra::Base - class << self - attr_accessor :test_rands - end - - before do - response.headers['Access-Control-Allow-Origin'] = '*' - end - + module Controller + class V2 < Base helpers do def roll(id, command) klass = BCDiceAPI::DICEBOTS[id] @@ -26,7 +13,7 @@ def roll(id, command) raise CommandError if command.nil? || command.empty? game_system = klass.new(command) - game_system.randomizer = RandomizerMock.new(App.test_rands) if App.test_rands + game_system.randomizer = RandomizerMock.new(V2.test_rands) if V2.test_rands result = game_system.eval raise CommandError if result.nil? @@ -44,15 +31,15 @@ def roll(id, command) end end - get '/v2/version' do + get '/version' do json api: BCDiceAPI::VERSION, bcdice: BCDice::VERSION end - get '/v2/admin' do + get '/admin' do json BCDiceAPI::ADMIN end - get '/v2/game_system' do + get '/game_system' do game_system = BCDice.all_game_systems.sort_by { |game| game::SORT_KEY } .map do |game| { id: game::ID, name: game::NAME, sort_key: game::SORT_KEY } end @@ -60,7 +47,7 @@ def roll(id, command) json game_system: game_system end - get '/v2/game_system/:id' do |id| + get '/game_system/:id' do |id| game_system = BCDice.game_system_class(id) raise UnsupportedDicebot if game_system.nil? @@ -76,21 +63,25 @@ def roll(id, command) json ret end - get '/v2/game_system/:id/roll' do |id| + get '/game_system/:id/roll' do |id| json roll(id, params[:command]) end - post '/v2/game_system/:id/roll' do |id| + post '/game_system/:id/roll' do |id| json roll(id, params[:command]) end - post '/v2/original_table' do + post '/original_table' do table = BCDice::UserDefinedDiceTable.new(params[:table]) result = table.roll json ok: true, text: result.text, rands: result.detailed_rands.map(&:to_h) end + not_found do + json ok: false, reason: 'not found' + end + error UnsupportedDicebot do status 400 json ok: false, reason: 'unsupported game system' @@ -100,6 +91,10 @@ def roll(id, command) status 400 json ok: false, reason: 'unsupported command' end + + error do + json ok: false + end end end end diff --git a/server.rb b/server.rb index 908956b..1e0ffd6 100644 --- a/server.rb +++ b/server.rb @@ -6,4 +6,4 @@ require 'bcdice_api' -BCDiceAPI::App.run! +BCDiceAPI::APP.run! diff --git a/test/test_api.rb b/test/test_api.rb index 0c4a067..18c19be 100644 --- a/test/test_api.rb +++ b/test/test_api.rb @@ -12,7 +12,7 @@ class APITest < Test::Unit::TestCase include Rack::Test::Methods def app - BCDiceAPI::App + BCDiceAPI::APP end def test_ping diff --git a/test/test_api_v2.rb b/test/test_api_v2.rb index c8caa67..ed941ab 100644 --- a/test/test_api_v2.rb +++ b/test/test_api_v2.rb @@ -12,7 +12,7 @@ class V2APITest < Test::Unit::TestCase include Rack::Test::Methods def app - BCDiceAPI::App + BCDiceAPI::APP end def test_version diff --git a/test/test_dicebot.rb b/test/test_dicebot.rb index d2ae34c..bdb3956 100644 --- a/test/test_dicebot.rb +++ b/test/test_dicebot.rb @@ -11,7 +11,7 @@ class DicebotTest < Test::Unit::TestCase include Rack::Test::Methods def app - BCDiceAPI::App + BCDiceAPI::APP end data do @@ -42,7 +42,7 @@ def app data_set end def test_diceroll(data) - BCDiceAPI::App.test_rands = data[:rands].map { |r| [r[:value], r[:sides]] } + BCDiceAPI::Controller::V1.test_rands = data[:rands].map { |r| [r[:value], r[:sides]] } get '/v1/diceroll', system: data[:game_system], command: data[:input] diff --git a/test/test_dicebot_v2.rb b/test/test_dicebot_v2.rb index 172de5d..dd157b6 100644 --- a/test/test_dicebot_v2.rb +++ b/test/test_dicebot_v2.rb @@ -11,7 +11,7 @@ class V2DicebotTest < Test::Unit::TestCase include Rack::Test::Methods def app - BCDiceAPI::App + BCDiceAPI::APP end data do @@ -40,7 +40,7 @@ def app data_set end def test_diceroll(data) - BCDiceAPI::V2::App.test_rands = data[:rands].map { |r| [r[:value], r[:sides]] } + BCDiceAPI::Controller::V2.test_rands = data[:rands].map { |r| [r[:value], r[:sides]] } get "/v2/game_system/#{data[:game_system]}/roll", command: data[:input] From 39ae3ddacd78d51cd0dc81f53badda0c1e3d3ba9 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sat, 2 Jan 2021 01:25:06 +0900 Subject: [PATCH 09/37] Fix load_plugins --- lib/bcdice_api/dicebots.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bcdice_api/dicebots.rb b/lib/bcdice_api/dicebots.rb index d78d3ed..cf085b9 100644 --- a/lib/bcdice_api/dicebots.rb +++ b/lib/bcdice_api/dicebots.rb @@ -7,7 +7,6 @@ module BCDiceAPI class << self private - # @return [Array] 追加のダイスボット def load_plugins query = File.join(__dir__, '../../plugins', '*.rb') @@ -15,11 +14,12 @@ def load_plugins id = File.basename(plugin, '.rb') require "plugins/#{id}" - Object.const_get(id) end end end + load_plugins() + DICEBOTS = BCDice.all_game_systems .sort_by { |klass| klass::SORT_KEY } .map { |klass| [klass::ID, klass] } From d1e7d3f88659c7cb2816ac35ec4d8b892cc1f83d Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sat, 2 Jan 2021 02:48:56 +0900 Subject: [PATCH 10/37] =?UTF-8?q?/v2=E3=81=AEAPI=E3=83=89=E3=82=AD?= =?UTF-8?q?=E3=83=A5=E3=83=A1=E3=83=B3=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api_v2.md | 314 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 314 insertions(+) create mode 100644 docs/api_v2.md diff --git a/docs/api_v2.md b/docs/api_v2.md new file mode 100644 index 0000000..fc603ed --- /dev/null +++ b/docs/api_v2.md @@ -0,0 +1,314 @@ +# `/v2` API詳細 + +## 注意事項 + +`/v1`ではJSONPに対応していましたが、セキュリティ上の都合により`/v2`では非対応となりました。 + + +## Version + +BCDice-APIのバージョンと、提供するBCDiceのバージョンが返却されます。 + +### URL + +`/v2/version` + +### 引数 + +なし + +### レスポンス例 + +```json +{ + "api" : "2.0.0", + "bcdice" : "3.0.0" +} +``` + + +## Admin + +BCDice-APIを提供する管理者の名前と連絡先が返却されます。 + +これらの設定はサーバー管理者の意図で設定されない場合があります。 +設定されていない場合、各項はから空文字列 `""` となります。 + +### URL + +`/v2/admin` + +### 引数 + +なし + +### レスポンス例 + +```json +{ + "name": "user-name", + "url": "https://your-information-page/url", + "email": "your@email.address" +} +``` + +### 内容 + +| Key | Description | +| :---- | :---------- | +| `name` | 管理者の名前 | +| `url` | 利用規約等が書かれたページのURL | +| `email` | 連絡先メールアドレス | + +### 設定方法 + +設定方法は2種類あります。優先度は 環境変数 > 設定ファイル です。 + +#### 1. 設定ファイル + +`config/admin.yaml` を設置します。内容は `config/admin.yaml.example` を参考にしてください。 + +#### 2. 環境変数 + +| ENV | JSON key | +| :----------------------- | :------- | +| `BCDICE_API_ADMIN_NAME` | `name` | +| `BCDICE_API_ADMIN_URL` | `url` | +| `BCDICE_API_ADMIN_EMAIL` | `email` | + + +## Game System + +BCDice-APIで利用できるゲームシステムの一覧が返却されます。 +一覧は`sort_key`でソートされた状態で返却されます。 + +### URL + +`/v2/game_system` + +### 引数 + +なし + +### レスポンス例 + +```json +{ + "game_system": [ + { + "id": "DiceBot", + "name": "DiceBot", + "sort_key": "*たいすほつと" + }, + { + "id": "EarthDawn", + "name": "アースドーン", + "sort_key": "ああすとおん" + }, + { + "id": "EarthDawn3", + "name": "アースドーン3版", + "sort_key": "ああすとおん3" + }, + { + "id": "EarthDawn4", + "name": "アースドーン4版", + "sort_key": "ああすとおん4" + } + ] +} +``` + +### 内容 + +| Key | Description | +| :--------- | :---------- | +| `id` | ゲームシステムのID | +| `name` | ゲームシステムの名前 | +| `sort_key` | ゲームシステムをソートするためのキー | + + +## Game System Info + +指定したゲームシステムの詳細情報を取得します。 + +### URL + +`/v2/game_system/{id}` + +### 引数 + +パラメータ | 種別 | 例 | 説明 +--------- | ----- | ----- | ----- +`{id}` | URLに埋め込む | `Gorilla` | ゲームシステムのID + + +### レスポンス例 + +```json +{ + "ok": true, + "id": "Gorilla", + "name": "ゴリラTRPG", + "sort_key": "こりらTRPG", + "command_pattern": "^S?([+\\-\\dD(\\[]+|\\d+B\\d+|C|choice|D66|(repeat|rep|x)\\d+|\\d+R\\d+|\\d+U\\d+|BCDiceVersion|G.*)", + "help_message": "2D6ロール時のゴリティカル自動判定を行います。\n\nG = 2D6のショートカット\n\n例) G>=7 : 2D6して7以上なら成功\n" +} +``` + +### 内容 + +| Key | Description | +| :--------- | :---------- | +| `id` | ゲームシステムのID | +| `name` | ゲームシステムの名前 | +| `sort_key` | ゲームシステムをソートするためのキー | +| `command_pattern` | 実行可能なコマンドか判定するための正規表現。これにマッチするテキストがコマンドとして実行できる可能性がある。利用する際には大文字か小文字かを無視すること | +| `help_message` | ヘルプメッセージ | + + +## Dice Roll + +ダイスロールを行う。GET/POSTの両方で実行可能 + +### URL + +`/v2/game_system/{id}/roll` + +### 引数 + +パラメータ | 種別 | 例 | 説明 +--------- | ----- | ----- | ----- +`{id}` | URLに埋め込む | `Gorilla` | ゲームシステムのID +`command` | GET/POSTパラメータ | `4d10>=15` | コマンドの文字列 + +### レスポンス例 + +```json +{ + "ok": true, + "text": "(4D10>=15) > 25[8,3,5,9] > 25 > 成功", + "secret": false, + "success": true, + "failure": false, + "critical": false, + "fumble": false, + "rands": [ + { + "kind": "normal", + "sides": 10, + "value": 8 + }, + { + "kind": "normal", + "sides": 10, + "value": 3 + }, + { + "kind": "normal", + "sides": 10, + "value": 5 + }, + { + "kind": "normal", + "sides": 10, + "value": 9 + } + ] +} +``` + + +### 内容 + +| Key | Description | +| :--------- | :---------- | +| `text` | コマンドの出力 | +| `secret` | シークレットダイスか | +| `success` | 結果が成功か | +| `failure` | 結果が失敗か | +| `critical` | 結果がクリティカルか | +| `fumble` | 結果がファンブルか | +| `rands` | ダイス目の詳細。次の節を参照 | + +### `rands` + +| Key | Description | +| :------ | :---------- | +| `kind` | ダイスロールの種類。`'nomal'`, `'tens_d10'`, `'d9'`の3種類 | +| `sides` | ダイスロールしたダイスの面数 | +| `value` | 出目の値 | + +#### 各kindの例 + +- `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}` + +## Original Table + +オリジナル表を実行する。POSTでのみ実行可能 + +### URL + +`/v2/original_table` + +### 引数 + +パラメータ | 種別 | 例 | 説明 +-------- | ----- | ----- | ----- +`table` | POSTパラメータ | - | オリジナル表のテキスト + +オリジナル表の形式は[オリジナル表・BCDiceコマンドガイド](https://docs.bcdice.org/original_table.html)を参照すること + +### レスポンス例 + +```json +{ + "ok": true, + "text": "飲み物表(6) > 選ばれし者の知的飲料", + "rands": [ + { + "kind": "normal", + "sides": 6, + "value": 6 + } + ] +} +``` + +## Error + +### ゲームシステムがない場合 + +`/v2/game_system/{id}`, `/v2/game_system/{id}/roll` + +HTTP status code: 400 Bad Request + +```json +{ + "ok": false, + "reason": "unsupported game system" +} +``` + +### コマンドがない場合 + +`/v2/game_system/{id}/roll` + +HTTP status code: 400 Bad Request + +```json +{ + "ok": false, + "reason": "unsupported command" +} +``` From 68224b9af713d2fc766644ae868964398594b32a Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sat, 2 Jan 2021 13:54:50 +0900 Subject: [PATCH 11/37] Cop --- lib/bcdice_api/dicebots.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bcdice_api/dicebots.rb b/lib/bcdice_api/dicebots.rb index cf085b9..623bc72 100644 --- a/lib/bcdice_api/dicebots.rb +++ b/lib/bcdice_api/dicebots.rb @@ -18,7 +18,7 @@ def load_plugins end end - load_plugins() + load_plugins DICEBOTS = BCDice.all_game_systems .sort_by { |klass| klass::SORT_KEY } From 3beedc9887d3ef727a77bb2b62d1edd7be809a0a Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sun, 24 Jan 2021 19:47:29 +0900 Subject: [PATCH 12/37] BCDice 3.0.0-rc.2 --- Gemfile | 2 +- Gemfile.lock | 6 +++--- bcdice | 2 +- test/test_api.rb | 1 - test/test_api_v2.rb | 1 - 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index e906ffa..e260379 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' -gem 'bcdice', '3.0.0.pre.rc.1' +gem 'bcdice', '3.0.0.pre.rc.2' gem 'sinatra', '~>2.0' gem 'sinatra-contrib', '~>2.0' diff --git a/Gemfile.lock b/Gemfile.lock index a276a5e..2d47ce1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,10 +2,10 @@ GEM remote: https://rubygems.org/ specs: ast (2.4.1) - bcdice (3.0.0.pre.rc.1) + bcdice (3.0.0.pre.rc.2) i18n (~> 1.8.5) concurrent-ruby (1.1.7) - i18n (1.8.5) + i18n (1.8.7) concurrent-ruby (~> 1.0) jaro_winkler (1.5.4) multi_json (1.15.0) @@ -60,7 +60,7 @@ PLATFORMS ruby DEPENDENCIES - bcdice (= 3.0.0.pre.rc.1) + bcdice (= 3.0.0.pre.rc.2) puma (~> 4.3) rack-test (~> 1.1) rake (~> 13.0) diff --git a/bcdice b/bcdice index 52d3d6d..859fe58 160000 --- a/bcdice +++ b/bcdice @@ -1 +1 @@ -Subproject commit 52d3d6df692cddd93fc000dbc6730b47a92aa267 +Subproject commit 859fe585446bd1d3c647a59375c2b8b515ea780e diff --git a/test/test_api.rb b/test/test_api.rb index 18c19be..c439614 100644 --- a/test/test_api.rb +++ b/test/test_api.rb @@ -59,7 +59,6 @@ def test_systeminfo assert_false json['systeminfo']['name'].empty? assert_instance_of Array, json['systeminfo']['prefixs'] - pend 'DiceBot::HELP_MESSAGE will be supported in BCDice v3' assert_false json['systeminfo']['info'].empty? assert_false json['systeminfo']['sortKey'].empty? end diff --git a/test/test_api_v2.rb b/test/test_api_v2.rb index ed941ab..405e17b 100644 --- a/test/test_api_v2.rb +++ b/test/test_api_v2.rb @@ -54,7 +54,6 @@ def test_game_system_info assert_false json['command_pattern'].empty? assert_false json['sort_key'].empty? - pend 'DiceBot::HELP_MESSAGE will be supported in BCDice v3' assert_false json['help_message'].empty? end From d2f06b79504356bb1fc027ce6de7ac1db86ee715 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sun, 24 Jan 2021 22:07:24 +0900 Subject: [PATCH 13/37] BCDice 3.0.0 --- Gemfile | 2 +- Gemfile.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index e260379..7fdc53b 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' -gem 'bcdice', '3.0.0.pre.rc.2' +gem 'bcdice', '~>3.0.0' gem 'sinatra', '~>2.0' gem 'sinatra-contrib', '~>2.0' diff --git a/Gemfile.lock b/Gemfile.lock index 2d47ce1..c3ac69c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,9 +2,9 @@ GEM remote: https://rubygems.org/ specs: ast (2.4.1) - bcdice (3.0.0.pre.rc.2) + bcdice (3.0.0) i18n (~> 1.8.5) - concurrent-ruby (1.1.7) + concurrent-ruby (1.1.8) i18n (1.8.7) concurrent-ruby (~> 1.0) jaro_winkler (1.5.4) @@ -60,7 +60,7 @@ PLATFORMS ruby DEPENDENCIES - bcdice (= 3.0.0.pre.rc.2) + bcdice (~> 3.0.0) puma (~> 4.3) rack-test (~> 1.1) rake (~> 13.0) From e7cf18f25c4392b247d956b52f0eab8b779bdb3a Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sun, 24 Jan 2021 22:29:41 +0900 Subject: [PATCH 14/37] Release 2.0.0 --- CHANGELOG.md | 5 +++++ README.md | 18 ++++++++++-------- lib/bcdice_api/version.rb | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d505fee..d98d497 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.0.0 + +- 新しいAPIバージョン `/v2` を作成。詳しくはAPIドキュメントを参照してください +- BCDice 3.0.0 + ## 1.0.0 - BCDice Ver2.07.01 にアップデート diff --git a/README.md b/README.md index b8de4e7..0758ec6 100644 --- a/README.md +++ b/README.md @@ -58,14 +58,16 @@ $ APP_ENV=production bundle exec rackup -E deployment ## API -Method | Description --------------------------------- | ----- -[/v1/version](/docs/api.md#version) | BCDiceとAPIサーバーのバージョン -[/v1/admin](/docs/api.md#admin) | APIサーバ提供者の名前と連絡先 -[/v1/systems](/docs/api.md#systems) | ダイスボットのシステムID一覧 -[/v1/names](/docs/api.md#names) | ダイスボットのシステムIDとシステム名前の一覧 -[/v1/systeminfo](/docs/api.md#systeminfo) | ダイスボットのシステム情報取得 -[/v1/diceroll](/docs/api.md#diceroll) | ダイスボットのコマンドを実行 +[`/v2`](https://github.com/bcdice/bcdice-api/blob/master/docs/api_v2.md) + +Method | Description +------------------------- | ----- +/v2/version | BCDiceとAPIサーバーのバージョン +/v2/admin | APIサーバ提供者の名前と連絡先 +/v2/game_system | ゲームシステムの一覧 +/v2/game_system/{id} | ゲームシステムの情報 +/v2/game_system/{id}/roll | ダイスロール +/v2/original_table | オリジナル表の実行 ## Plugin diff --git a/lib/bcdice_api/version.rb b/lib/bcdice_api/version.rb index f74c53a..378cb0f 100644 --- a/lib/bcdice_api/version.rb +++ b/lib/bcdice_api/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module BCDiceAPI - VERSION = '1.0.0' + VERSION = '2.0.0' end From 73b0b2a4344379ad2fe8c767c301995307ae660e Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Wed, 3 Feb 2021 21:51:35 +0900 Subject: [PATCH 15/37] ignore bcdice/ on docker --- .dockerignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index e0e7610..c8abba1 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ .git/ -vendor/ \ No newline at end of file +vendor/ +bcdice/ \ No newline at end of file From 276583b716503e09923ad46397d14395906362fe Mon Sep 17 00:00:00 2001 From: yoshi Date: Mon, 8 Mar 2021 16:43:50 +0900 Subject: [PATCH 16/37] fix docs: faces -> sides --- docs/api.md | 16 ++++++++-------- docs/api_v2.md | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/api.md b/docs/api.md index 7925514..f1c9813 100644 --- a/docs/api.md +++ b/docs/api.md @@ -197,10 +197,10 @@ WebAPIで利用できるダイスボットのシステムID一覧が返却され {"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} + {"kind" : "nomal", "sides" : 10, "value" : 8}, + {"kind" : "nomal", "sides" : 10, "value" : 2}, + {"kind" : "nomal", "sides" : 10, "value" : 1}, + {"kind" : "nomal", "sides" : 10, "value" : 9} ] } ``` @@ -216,14 +216,14 @@ WebAPIで利用できるダイスボットのシステムID一覧が返却され - `nomal` - 通常のダイスロール - - `{"kind" : "nomal", "faces" : 10, "value" : 8}` + - `{"kind" : "nomal", "sides" : 10, "value" : 8}` - `tens_d10` - 十の位のダイス - - `{"kind" : "tens_d10", "faces" : 10, "value" : 80}` - - `{"kind" : "tens_d10", "faces" : 10, "value" : 0}` + - `{"kind" : "tens_d10", "sides" : 10, "value" : 80}` + - `{"kind" : "tens_d10", "sides" : 10, "value" : 0}` - `00` は0として扱われます - `d9` - 十面体を0〜9のダイスとして扱う - - `{"kind" : "d9", "faces" : 10, "value" : 0}` + - `{"kind" : "d9", "sides" : 10, "value" : 0}` Since: 0.9.0, BCDice Ver2.04.00 diff --git a/docs/api_v2.md b/docs/api_v2.md index fc603ed..5e64566 100644 --- a/docs/api_v2.md +++ b/docs/api_v2.md @@ -243,15 +243,15 @@ BCDice-APIで利用できるゲームシステムの一覧が返却されます - `nomal` - 通常のダイスロール - - `{"kind" : "nomal", "faces" : 10, "value" : 8}` + - `{"kind" : "nomal", "sides" : 10, "value" : 8}` - `tens_d10` - 十の位のダイス - - `{"kind" : "tens_d10", "faces" : 10, "value" : 80}` - - `{"kind" : "tens_d10", "faces" : 10, "value" : 0}` + - `{"kind" : "tens_d10", "sides" : 10, "value" : 80}` + - `{"kind" : "tens_d10", "sides" : 10, "value" : 0}` - `00` は0として扱われます - `d9` - 十面体を0〜9のダイスとして扱う - - `{"kind" : "d9", "faces" : 10, "value" : 0}` + - `{"kind" : "d9", "sides" : 10, "value" : 0}` ## Original Table From e849efdb3b9f92dd07e7f51e7bb7ec348ee3d4ac Mon Sep 17 00:00:00 2001 From: Hideyo Mikisato Date: Fri, 26 Mar 2021 00:57:26 +0900 Subject: [PATCH 17/37] follow bcdice 3.x version --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 7fdc53b..260c9cb 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' -gem 'bcdice', '~>3.0.0' +gem 'bcdice', '~>3.0' gem 'sinatra', '~>2.0' gem 'sinatra-contrib', '~>2.0' From 91717ba34c6caa2636cc90826e3f3bb2b4c772a7 Mon Sep 17 00:00:00 2001 From: Hideyo Mikisato Date: Fri, 26 Mar 2021 01:06:56 +0900 Subject: [PATCH 18/37] =?UTF-8?q?lock=E3=81=AE=E6=96=B9=E3=82=82=E6=9B=B8?= =?UTF-8?q?=E3=81=8D=E6=8F=9B=E3=81=88=E3=82=8B=E5=BF=85=E8=A6=81=E3=81=8C?= =?UTF-8?q?=E3=81=82=E3=82=8A=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index c3ac69c..1a82bcf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,21 +1,21 @@ GEM remote: https://rubygems.org/ specs: - ast (2.4.1) - bcdice (3.0.0) + ast (2.4.2) + bcdice (3.1.1) i18n (~> 1.8.5) concurrent-ruby (1.1.8) - i18n (1.8.7) + i18n (1.8.9) concurrent-ruby (~> 1.0) jaro_winkler (1.5.4) multi_json (1.15.0) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) - nio4r (2.5.4) + nio4r (2.5.7) parallel (1.20.1) parser (3.0.0.0) ast (~> 2.4.1) - power_assert (1.2.0) + power_assert (2.0.0) puma (4.3.7) nio4r (~> 2.0) rack (2.2.3) @@ -35,7 +35,7 @@ GEM ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 2.0) ruby-progressbar (1.11.0) - ruby2_keywords (0.0.2) + ruby2_keywords (0.0.4) sinatra (2.1.0) mustermann (~> 1.0) rack (~> 2.2) @@ -50,7 +50,7 @@ GEM sinatra-jsonp (0.5.0) multi_json (~> 1.8) sinatra (>= 1.0) - test-unit (3.3.9) + test-unit (3.4.0) power_assert tilt (2.0.10) tomlrb (2.0.1) @@ -60,7 +60,7 @@ PLATFORMS ruby DEPENDENCIES - bcdice (~> 3.0.0) + bcdice (~> 3.0) puma (~> 4.3) rack-test (~> 1.1) rake (~> 13.0) From 1bce044b17197d511e0569147f21995311a07f49 Mon Sep 17 00:00:00 2001 From: Hideyo Mikisato Date: Fri, 26 Mar 2021 01:58:44 +0900 Subject: [PATCH 19/37] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E7=94=A8?= =?UTF-8?q?=E3=81=AE=E3=82=B5=E3=83=96=E3=83=A2=E3=82=B8=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=82=92=E6=9C=80=E6=96=B0=E3=81=AB=E8=BF=BD=E5=BE=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bcdice | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bcdice b/bcdice index 859fe58..ff1c486 160000 --- a/bcdice +++ b/bcdice @@ -1 +1 @@ -Subproject commit 859fe585446bd1d3c647a59375c2b8b515ea780e +Subproject commit ff1c4869d9e92a2f5b3e2958986500fed82ff444 From acd57da2c346572f4b78fdc9d91bb8bada07ef68 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Apr 2021 20:30:06 +0000 Subject: [PATCH 20/37] Bump rexml from 3.2.4 to 3.2.5 Bumps [rexml](https://github.com/ruby/rexml) from 3.2.4 to 3.2.5. - [Release notes](https://github.com/ruby/rexml/releases) - [Changelog](https://github.com/ruby/rexml/blob/master/NEWS.md) - [Commits](https://github.com/ruby/rexml/compare/v3.2.4...v3.2.5) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1a82bcf..8255eca 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -25,7 +25,7 @@ GEM rack (>= 1.0, < 3) rainbow (3.0.0) rake (13.0.3) - rexml (3.2.4) + rexml (3.2.5) rubocop (0.81.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) From a6e45c02e3a695d98bcca5cda6768019124e1c10 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Wed, 26 May 2021 20:26:25 +0900 Subject: [PATCH 21/37] Update BCDice to 3.3.0 --- Gemfile.lock | 10 +++++----- bcdice | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8255eca..1d47ba0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,10 +2,10 @@ GEM remote: https://rubygems.org/ specs: ast (2.4.2) - bcdice (3.1.1) + bcdice (3.3.0) i18n (~> 1.8.5) concurrent-ruby (1.1.8) - i18n (1.8.9) + i18n (1.8.10) concurrent-ruby (~> 1.0) jaro_winkler (1.5.4) multi_json (1.15.0) @@ -13,10 +13,10 @@ GEM ruby2_keywords (~> 0.0.1) nio4r (2.5.7) parallel (1.20.1) - parser (3.0.0.0) + parser (3.0.1.1) ast (~> 2.4.1) power_assert (2.0.0) - puma (4.3.7) + puma (4.3.8) nio4r (~> 2.0) rack (2.2.3) rack-protection (2.1.0) @@ -50,7 +50,7 @@ GEM sinatra-jsonp (0.5.0) multi_json (~> 1.8) sinatra (>= 1.0) - test-unit (3.4.0) + test-unit (3.4.1) power_assert tilt (2.0.10) tomlrb (2.0.1) diff --git a/bcdice b/bcdice index ff1c486..26b6984 160000 --- a/bcdice +++ b/bcdice @@ -1 +1 @@ -Subproject commit ff1c4869d9e92a2f5b3e2958986500fed82ff444 +Subproject commit 26b69848cdf3ee3e1801fd7163c0144478a7e16b From 01181ca2dda143bf0c70dbbd1593caeba29a5739 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Wed, 26 May 2021 20:30:12 +0900 Subject: [PATCH 22/37] Release 2.0.1 --- CHANGELOG.md | 5 +++++ lib/bcdice_api/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d98d497..b788624 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.0.1 + +- セキュリティアップデート : Puma, rexml +- BCDice 3.3.0 + ## 2.0.0 - 新しいAPIバージョン `/v2` を作成。詳しくはAPIドキュメントを参照してください diff --git a/lib/bcdice_api/version.rb b/lib/bcdice_api/version.rb index 378cb0f..1f8cc91 100644 --- a/lib/bcdice_api/version.rb +++ b/lib/bcdice_api/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module BCDiceAPI - VERSION = '2.0.0' + VERSION = '2.0.1' end From fb78e57da7bedae14ed45643d8253f3dc9be3c49 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Thu, 27 May 2021 23:00:32 +0900 Subject: [PATCH 23/37] Support Ruby 3.0, Drop Ruby 2.5 --- .github/workflows/test.yml | 2 +- .rubocop.yml | 1 + .ruby-version | 2 +- Gemfile | 2 +- Gemfile.lock | 19 +++++++++++-------- lib/bcdice_api/controller/v2.rb | 2 +- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 937a77f..ca5618e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: [2.5, 2.6, 2.7] + ruby: [2.6, 2.7, 3.0] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 diff --git a/.rubocop.yml b/.rubocop.yml index 4198bf1..503a8b5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,5 @@ AllCops: + NewCops: disable Exclude: - "bcdice/**/*" - "config/**/*" diff --git a/.ruby-version b/.ruby-version index 860487c..cb2b00e 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.1 +3.0.1 diff --git a/Gemfile b/Gemfile index 260c9cb..b016f67 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ gem 'puma', '~>4.3' group :development, :test do gem 'rack-test', '~>1.1' gem 'rake', '~>13.0' - gem 'rubocop', '~> 0.81.0', require: false + gem 'rubocop', '~> 1.15.0', require: false gem 'test-unit', '~>3.3' gem 'tomlrb' end diff --git a/Gemfile.lock b/Gemfile.lock index 1d47ba0..c1e44cc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,6 @@ GEM concurrent-ruby (1.1.8) i18n (1.8.10) concurrent-ruby (~> 1.0) - jaro_winkler (1.5.4) multi_json (1.15.0) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) @@ -25,15 +24,19 @@ GEM rack (>= 1.0, < 3) rainbow (3.0.0) rake (13.0.3) + regexp_parser (2.1.1) rexml (3.2.5) - rubocop (0.81.0) - jaro_winkler (~> 1.5.1) + rubocop (1.15.0) parallel (~> 1.10) - parser (>= 2.7.0.1) + parser (>= 3.0.0.0) rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) rexml + rubocop-ast (>= 1.5.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.7.0) + parser (>= 3.0.1.1) ruby-progressbar (1.11.0) ruby2_keywords (0.0.4) sinatra (2.1.0) @@ -54,7 +57,7 @@ GEM power_assert tilt (2.0.10) tomlrb (2.0.1) - unicode-display_width (1.7.0) + unicode-display_width (2.0.0) PLATFORMS ruby @@ -64,7 +67,7 @@ DEPENDENCIES puma (~> 4.3) rack-test (~> 1.1) rake (~> 13.0) - rubocop (~> 0.81.0) + rubocop (~> 1.15.0) sinatra (~> 2.0) sinatra-contrib (~> 2.0) sinatra-jsonp (~> 0.5.0) @@ -72,4 +75,4 @@ DEPENDENCIES tomlrb BUNDLED WITH - 2.1.4 + 2.2.3 diff --git a/lib/bcdice_api/controller/v2.rb b/lib/bcdice_api/controller/v2.rb index cdab866..6dea96e 100644 --- a/lib/bcdice_api/controller/v2.rb +++ b/lib/bcdice_api/controller/v2.rb @@ -40,7 +40,7 @@ def roll(id, command) end get '/game_system' do - game_system = BCDice.all_game_systems.sort_by { |game| game::SORT_KEY } .map do |game| + game_system = BCDice.all_game_systems.sort_by { |game| game::SORT_KEY }.map do |game| { id: game::ID, name: game::NAME, sort_key: game::SORT_KEY } end From 66a01d632111996559996c211dd77ae7891ba291 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Tue, 1 Feb 2022 09:05:43 +0900 Subject: [PATCH 24/37] Update BCDice to 3.5.0 and puma security fix --- Gemfile.lock | 32 ++++++++++++++++---------------- bcdice | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index c1e44cc..262b50a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,29 +2,29 @@ GEM remote: https://rubygems.org/ specs: ast (2.4.2) - bcdice (3.3.0) + bcdice (3.5.0) i18n (~> 1.8.5) - concurrent-ruby (1.1.8) - i18n (1.8.10) + concurrent-ruby (1.1.9) + i18n (1.8.11) concurrent-ruby (~> 1.0) multi_json (1.15.0) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) - nio4r (2.5.7) - parallel (1.20.1) - parser (3.0.1.1) + nio4r (2.5.8) + parallel (1.21.0) + parser (3.1.0.0) ast (~> 2.4.1) - power_assert (2.0.0) - puma (4.3.8) + power_assert (2.0.1) + puma (4.3.10) nio4r (~> 2.0) rack (2.2.3) rack-protection (2.1.0) rack rack-test (1.1.0) rack (>= 1.0, < 3) - rainbow (3.0.0) - rake (13.0.3) - regexp_parser (2.1.1) + rainbow (3.1.1) + rake (13.0.6) + regexp_parser (2.2.0) rexml (3.2.5) rubocop (1.15.0) parallel (~> 1.10) @@ -35,10 +35,10 @@ GEM rubocop-ast (>= 1.5.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.7.0) + rubocop-ast (1.15.1) parser (>= 3.0.1.1) ruby-progressbar (1.11.0) - ruby2_keywords (0.0.4) + ruby2_keywords (0.0.5) sinatra (2.1.0) mustermann (~> 1.0) rack (~> 2.2) @@ -53,11 +53,11 @@ GEM sinatra-jsonp (0.5.0) multi_json (~> 1.8) sinatra (>= 1.0) - test-unit (3.4.1) + test-unit (3.5.3) power_assert tilt (2.0.10) tomlrb (2.0.1) - unicode-display_width (2.0.0) + unicode-display_width (2.1.0) PLATFORMS ruby @@ -75,4 +75,4 @@ DEPENDENCIES tomlrb BUNDLED WITH - 2.2.3 + 2.2.15 diff --git a/bcdice b/bcdice index 26b6984..6f16f34 160000 --- a/bcdice +++ b/bcdice @@ -1 +1 @@ -Subproject commit 26b69848cdf3ee3e1801fd7163c0144478a7e16b +Subproject commit 6f16f349d6d4ceb0e011b104221911fb93c85d1e From 555c336a82bdd8d6656cdd285d762489f7b86172 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Tue, 1 Feb 2022 09:11:02 +0900 Subject: [PATCH 25/37] With Ruby 3.1.0 --- .github/workflows/test.yml | 2 +- .ruby-version | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ca5618e..2732a15 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: [2.6, 2.7, 3.0] + ruby: [2.6, 2.7, 3.0, 3.1] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 diff --git a/.ruby-version b/.ruby-version index cb2b00e..fd2a018 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.0.1 +3.1.0 From 2d81ab27ec5ddef74919ee37d69c26ddf52af172 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Mon, 21 Mar 2022 00:20:20 +0900 Subject: [PATCH 26/37] Update puma to 5.6 --- Gemfile | 2 +- Gemfile.lock | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index b016f67..472145b 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gem 'sinatra', '~>2.0' gem 'sinatra-contrib', '~>2.0' gem 'sinatra-jsonp', '~>0.5.0' -gem 'puma', '~>4.3' +gem 'puma', '~>5.6' group :development, :test do gem 'rack-test', '~>1.1' diff --git a/Gemfile.lock b/Gemfile.lock index 262b50a..01689b5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,19 +12,19 @@ GEM ruby2_keywords (~> 0.0.1) nio4r (2.5.8) parallel (1.21.0) - parser (3.1.0.0) + parser (3.1.1.0) ast (~> 2.4.1) power_assert (2.0.1) - puma (4.3.10) + puma (5.6.2) nio4r (~> 2.0) rack (2.2.3) - rack-protection (2.1.0) + rack-protection (2.2.0) rack rack-test (1.1.0) rack (>= 1.0, < 3) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.2.0) + regexp_parser (2.2.1) rexml (3.2.5) rubocop (1.15.0) parallel (~> 1.10) @@ -35,20 +35,20 @@ GEM rubocop-ast (>= 1.5.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.15.1) - parser (>= 3.0.1.1) + rubocop-ast (1.16.0) + parser (>= 3.1.1.0) ruby-progressbar (1.11.0) ruby2_keywords (0.0.5) - sinatra (2.1.0) + sinatra (2.2.0) mustermann (~> 1.0) rack (~> 2.2) - rack-protection (= 2.1.0) + rack-protection (= 2.2.0) tilt (~> 2.0) - sinatra-contrib (2.1.0) + sinatra-contrib (2.2.0) multi_json mustermann (~> 1.0) - rack-protection (= 2.1.0) - sinatra (= 2.1.0) + rack-protection (= 2.2.0) + sinatra (= 2.2.0) tilt (~> 2.0) sinatra-jsonp (0.5.0) multi_json (~> 1.8) @@ -64,7 +64,7 @@ PLATFORMS DEPENDENCIES bcdice (~> 3.0) - puma (~> 4.3) + puma (~> 5.6) rack-test (~> 1.1) rake (~> 13.0) rubocop (~> 1.15.0) From aad6e9873651914fbeb1887164cc69d4406807cb Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Mon, 21 Mar 2022 00:50:30 +0900 Subject: [PATCH 27/37] Update bundler --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 01689b5..26cbb9b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,4 +75,4 @@ DEPENDENCIES tomlrb BUNDLED WITH - 2.2.15 + 2.3.9 From b3983b5d263c9bb4865eff5b63520214643ee6f2 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Mon, 21 Mar 2022 01:09:16 +0900 Subject: [PATCH 28/37] Update .ruby-version --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index fd2a018..94ff29c 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.1.0 +3.1.1 From 1ad248cdd7863c842e4d2eb07ead83baea481f48 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 30 Mar 2022 22:25:48 +0000 Subject: [PATCH 29/37] Bump puma from 5.6.2 to 5.6.4 Bumps [puma](https://github.com/puma/puma) from 5.6.2 to 5.6.4. - [Release notes](https://github.com/puma/puma/releases) - [Changelog](https://github.com/puma/puma/blob/master/History.md) - [Commits](https://github.com/puma/puma/compare/v5.6.2...v5.6.4) --- updated-dependencies: - dependency-name: puma dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 26cbb9b..948f233 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -15,7 +15,7 @@ GEM parser (3.1.1.0) ast (~> 2.4.1) power_assert (2.0.1) - puma (5.6.2) + puma (5.6.4) nio4r (~> 2.0) rack (2.2.3) rack-protection (2.2.0) From 27f8a7716c34af9d5201e1bd48870cc3a032c6cc Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Wed, 4 May 2022 13:07:01 +0900 Subject: [PATCH 30/37] Update BCDice to 3.6.0 --- Gemfile.lock | 4 ++-- bcdice | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 948f233..308d24e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,9 +2,9 @@ GEM remote: https://rubygems.org/ specs: ast (2.4.2) - bcdice (3.5.0) + bcdice (3.6.0) i18n (~> 1.8.5) - concurrent-ruby (1.1.9) + concurrent-ruby (1.1.10) i18n (1.8.11) concurrent-ruby (~> 1.0) multi_json (1.15.0) diff --git a/bcdice b/bcdice index 6f16f34..aa81520 160000 --- a/bcdice +++ b/bcdice @@ -1 +1 @@ -Subproject commit 6f16f349d6d4ceb0e011b104221911fb93c85d1e +Subproject commit aa815209e53d452ae40215945a6ad98fc3571b8b From 86f15a2b5b3916e5191b12a7db90357b2e3c14cd Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Wed, 4 May 2022 13:09:59 +0900 Subject: [PATCH 31/37] Release 2.1.0 --- CHANGELOG.md | 6 ++++++ lib/bcdice_api/version.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b788624..0da655a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.1.0 +- BCDice 3.6.0 +- Ruby 3.0, 3.1をサポート対象に +- Ruby 2.5をサポート対象外に +- Pumaを5.Xにアップデート + ## 2.0.1 - セキュリティアップデート : Puma, rexml diff --git a/lib/bcdice_api/version.rb b/lib/bcdice_api/version.rb index 1f8cc91..4ab9b84 100644 --- a/lib/bcdice_api/version.rb +++ b/lib/bcdice_api/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module BCDiceAPI - VERSION = '2.0.1' + VERSION = '2.1.0' end From 3912f16efe2b578c70c2140e78453a8b53a16fe6 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sun, 30 Oct 2022 12:30:59 +0900 Subject: [PATCH 32/37] Update .ruby-version to Ruby 3.1.2 --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index 94ff29c..ef538c2 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.1.1 +3.1.2 From b54c821013806677c7d324839c57151c486b1fa9 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sun, 30 Oct 2022 12:36:52 +0900 Subject: [PATCH 33/37] Update BCDice to 3.7.0 --- Gemfile.lock | 2 +- bcdice | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 308d24e..1589651 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ GEM remote: https://rubygems.org/ specs: ast (2.4.2) - bcdice (3.6.0) + bcdice (3.7.0) i18n (~> 1.8.5) concurrent-ruby (1.1.10) i18n (1.8.11) diff --git a/bcdice b/bcdice index aa81520..11ed721 160000 --- a/bcdice +++ b/bcdice @@ -1 +1 @@ -Subproject commit aa815209e53d452ae40215945a6ad98fc3571b8b +Subproject commit 11ed721340cbebd629b263537e4044921a5bccc7 From 6a5c3b0c133d1062262b80f44f27d28c2eaf8e46 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sun, 30 Oct 2022 12:37:46 +0900 Subject: [PATCH 34/37] Update gems Security fix --- Gemfile.lock | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1589651..f54c1d1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,23 +8,23 @@ GEM i18n (1.8.11) concurrent-ruby (~> 1.0) multi_json (1.15.0) - mustermann (1.1.1) + mustermann (2.0.2) ruby2_keywords (~> 0.0.1) nio4r (2.5.8) - parallel (1.21.0) - parser (3.1.1.0) + parallel (1.22.1) + parser (3.1.2.1) ast (~> 2.4.1) - power_assert (2.0.1) - puma (5.6.4) + power_assert (2.0.2) + puma (5.6.5) nio4r (~> 2.0) - rack (2.2.3) - rack-protection (2.2.0) + rack (2.2.4) + rack-protection (2.2.2) rack rack-test (1.1.0) rack (>= 1.0, < 3) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.2.1) + regexp_parser (2.6.0) rexml (3.2.5) rubocop (1.15.0) parallel (~> 1.10) @@ -35,29 +35,29 @@ GEM rubocop-ast (>= 1.5.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.16.0) + rubocop-ast (1.23.0) parser (>= 3.1.1.0) ruby-progressbar (1.11.0) ruby2_keywords (0.0.5) - sinatra (2.2.0) - mustermann (~> 1.0) + sinatra (2.2.2) + mustermann (~> 2.0) rack (~> 2.2) - rack-protection (= 2.2.0) + rack-protection (= 2.2.2) tilt (~> 2.0) - sinatra-contrib (2.2.0) + sinatra-contrib (2.2.2) multi_json - mustermann (~> 1.0) - rack-protection (= 2.2.0) - sinatra (= 2.2.0) + mustermann (~> 2.0) + rack-protection (= 2.2.2) + sinatra (= 2.2.2) tilt (~> 2.0) sinatra-jsonp (0.5.0) multi_json (~> 1.8) sinatra (>= 1.0) - test-unit (3.5.3) + test-unit (3.5.5) power_assert - tilt (2.0.10) - tomlrb (2.0.1) - unicode-display_width (2.1.0) + tilt (2.0.11) + tomlrb (2.0.3) + unicode-display_width (2.3.0) PLATFORMS ruby From 938269e9f1241c2f18e81870704ed272a909bbc5 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sun, 30 Oct 2022 12:42:00 +0900 Subject: [PATCH 35/37] fix ci --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2732a15..60788dc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: [2.6, 2.7, 3.0, 3.1] + ruby: ["2.6", "2.7", "3.0", "3.1"] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -15,5 +15,4 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - run: bundle install - run: bundle exec rake test From ac75e2cfbe7f2e4261337c5b23a50160f3b760d9 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sun, 30 Oct 2022 12:49:20 +0900 Subject: [PATCH 36/37] Release 2.1.1 --- CHANGELOG.md | 5 +++++ lib/bcdice_api/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0da655a..a054feb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.1.1 +- BCDice 3.7.0 +- セキュリティアップデート: Rack +- 依存Gemのアップデート + ## 2.1.0 - BCDice 3.6.0 - Ruby 3.0, 3.1をサポート対象に diff --git a/lib/bcdice_api/version.rb b/lib/bcdice_api/version.rb index 4ab9b84..83d103a 100644 --- a/lib/bcdice_api/version.rb +++ b/lib/bcdice_api/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module BCDiceAPI - VERSION = '2.1.0' + VERSION = '2.1.1' end From e4bc5f0aa4a5079a44c2517a5fe40b6c86455ac5 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Tue, 15 Nov 2022 09:22:32 +0900 Subject: [PATCH 37/37] Update docs --- README.md | 8 +------- docs/heroku.md | 8 ++++++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0758ec6..75679ac 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,6 @@ BCDiceを提供するWebAPIサーバー [![Action Status](https://github.com/bcdice/bcdice-api/workflows/Test/badge.svg?branch=master)](https://github.com/bcdice/bcdice-api/actions) [![Docker repository](https://img.shields.io/docker/pulls/bcdice/bcdice-api?logo=docker&logoColor=fff)](https://hub.docker.com/r/bcdice/bcdice-api) -## Demo - -下記URLは開発検証用のURLです、予告なしに挙動が変更されたり、可動していない場合があるので使用しないでください。 - -https://bcdice.herokuapp.com - ## Public servers 有志によって運営されている公開サーバーの一覧 @@ -76,7 +70,7 @@ Method | Description ## Documents -- [無料で独自ダイスボット入りのBCDice-APIサーバーを立てる](docs/heroku.md) (中級者向け) +- [Herokuで独自ダイスボット入りのBCDice-APIサーバーを立てる](docs/heroku.md) (中級者向け) ## Cases diff --git a/docs/heroku.md b/docs/heroku.md index 3c11245..f440afa 100644 --- a/docs/heroku.md +++ b/docs/heroku.md @@ -1,6 +1,10 @@ # Herokuへの設置 -このドキュメントでは[Heroku](https://jp.heroku.com/)を用いて、**無料で**独自ダイスボット入りのBCDice-APIサーバーの建て方を解説します。ツールの制約により、コマンドラインを用いる必要があるため中級者向けの資料となっています。 +このドキュメントでは[Heroku](https://jp.heroku.com/)を用いて、~~無料で~~独自ダイスボット入りのBCDice-APIサーバーの建て方を解説します。ツールの制約により、コマンドラインを用いる必要があるため中級者向けの資料となっています。 + +## 注意事項 + +**この文書はHerokuの無料プランを利用することを想定して書かれましたが、無料プランは2022年11月から廃止されました。** ## 対象読者 @@ -22,7 +26,7 @@ ## Herokuとは HerokuはクラウドプラットフォームやPaaSと呼ばれるもので、VPSと比べてアプリケーションの設置や管理を容易に行うことができます。 -Herokuでは[無料プラン](https://jp.heroku.com/pricing)が用意されており、独自サーバーを試しやすくなっています。 +~~Herokuでは[無料プラン](https://jp.heroku.com/pricing)が用意されており、独自サーバーを試しやすくなっています。~~ Herokuでは動作させるアプリケーションをGitで管理・送信する必要があり、このドキュメントでもGitを用います。