Skip to content

Commit

Permalink
secret-dice: ConfigureAdapter/Generator モジュールで有効化される設定項目の初期化に関わるバグを修正
Browse files Browse the repository at this point in the history
PR #134

@data_path, @config_id は、initialize の後に初期化される。
そのため、これらの変数を使う初期化は configure メソッドで行なわなければならない。
  • Loading branch information
koi-chan committed Jul 21, 2019
1 parent 9063adc commit 69a0fd4
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/rgrb/plugin/dice_roll/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ def initialize
super
@random = Random.new
@mutex_secret_dice = Mutex.new
end

# プラグインの設定を行う
# @return [self]
def configure(config_data)
super

@db_dir = "#{@data_path}/#{@config_id}"
# ToDo: ボット起動時のインスタンス化されるタイミングでは、
# @data_path, @config_id が初期化されていない(nil になっている)
#prepare_db_dir
prepare_db_dir

@db_secret_dice = "#{@db_dir}/secret_dice"
end
Expand Down Expand Up @@ -69,7 +73,6 @@ def dxx_dice_ja(rolls_ja)
# @param [String] message ダイスロール実行結果
# @return [void]
def save_secret_roll(target, message)
@db_secret_dice = "#{@data_path}/#{@config_id}/secret_dice"
@mutex_secret_dice.synchronize do
GDBM.open(@db_secret_dice) do |db|
store = db.has_key?(target) ? JSON.parse(db[target]) : []
Expand All @@ -82,8 +85,6 @@ def save_secret_roll(target, message)
# @param [String] target
# @return [Array, nil]
def open_dice(target)
@db_secret_dice = "#{@data_path}/#{@config_id}/secret_dice"

@mutex_secret_dice.synchronize do
GDBM.open(@db_secret_dice) do |db|
if db.has_key?(target)
Expand Down Expand Up @@ -112,12 +113,15 @@ def dxx_roll(rolls)
end

# 日本語ダイスコマンドを数字に変換する
# Trpg::Detatoko プラグインにて呼び出しているので public メソッド
# @param [String] japanese 日本語(ア段)
# @return [String]
def ja_to_i(japanese)
japanese.tr('あかさたなはまやらわ', '1234567890').to_i
end

private

# データベースディレクトリを準備する
# @return [void]
def prepare_db_dir
Expand Down

0 comments on commit 69a0fd4

Please sign in to comment.