Skip to content

Commit

Permalink
DiceRoll プラグインにて、日本語ダイス機能の有効・無効を切り替えられるように変更
Browse files Browse the repository at this point in the history
issue: #88
  • Loading branch information
koi-chan committed Sep 20, 2017
1 parent f73900e commit cfade44
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config/dice_roll.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ダイスロールプラグインの設定
DiceRoll:
# 日本語ダイス機能を有効化するか
JaDice: false
1 change: 1 addition & 0 deletions config/rgrb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Plugins:
# 設定ファイルは config/ 以下に配置する
# 設定 ID は config/ を基準とした相対パスから拡張子を除いたもの
Include:
- dice_roll
- keyword
- cre_twitter_citation
- server_connection_report/charybdis
Expand Down
13 changes: 13 additions & 0 deletions doc/plugins/dice_roll.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ _XX_ には 1~20 桁の数字を指定します。ただし、途中に 0 を
> foo -> d66 = [5,6] = 56
```

設定
----

設定ファイルに以下を追加して、プラグインの設定を行います。

```yaml
# ダイスロールプラグインの設定
DiceRoll:
# 日本語ダイス機能を有効化するか
# false (無効)以外の文字を入力すると true (有効)として扱う
JaDice: false
```

ToDo
----

Expand Down
2 changes: 2 additions & 0 deletions lib/rgrb/plugin/dice_roll/generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# vim: fileencoding=utf-8

require 'rgrb/plugin/configurable_generator'
require 'rgrb/plugin/dice_roll/dice_roll_result'

module RGRB
Expand All @@ -10,6 +11,7 @@ module Plugin
module DiceRoll
# DiceRoll の出力テキスト生成器
class Generator
include ConfigurableGenerator
EXCESS_DICE_MESSAGE = "ダイスが机から落ちてしまいましたの☆"

def initialize
Expand Down
12 changes: 11 additions & 1 deletion lib/rgrb/plugin/dice_roll/irc_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# vim: fileencoding=utf-8

require 'cinch'
require 'rgrb/plugin/configurable_adapter'
require 'rgrb/plugin/dice_roll/constants'
require 'rgrb/plugin/dice_roll/generator'
require 'rgrb/plugin/util/logging'
Expand All @@ -11,6 +12,7 @@ module DiceRoll
# DiceRoll の IRC アダプター
class IrcAdapter
include Cinch::Plugin
include ConfigurableAdapter
include Util::Logging

set(plugin_name: 'DiceRoll')
Expand All @@ -24,7 +26,11 @@ class IrcAdapter
def initialize(*args)
super

@generator = Generator.new
config_data = config[:plugin]
@jadice = true
@jadice = false if config_data['JaDice'] == false

prepare_generator
end

# 基本的なダイスロールの結果を返す
Expand All @@ -39,6 +45,8 @@ def basic_dice(m, n_dice, max)

def basic_dice_ja(m, n_dice, max)
log_incoming(m)
return unless @jadice

result = @generator.basic_dice_ja(n_dice, max)
message = "#{m.user.nick} -> #{result}"
m.target.send(message, true)
Expand All @@ -57,6 +65,8 @@ def dxx_dice(m, rolls)

def dxx_dice_ja(m, rolls)
log_incoming(m)
return unless @jadice

result = @generator.dxx_dice_ja(rolls)
message = "#{m.user.nick} -> #{result}"
m.target.send(message, true)
Expand Down

0 comments on commit cfade44

Please sign in to comment.