Skip to content

Commit

Permalink
プラグイン Random_Generator にコマンドを追加した。
Browse files Browse the repository at this point in the history
指定した表の説明を返します。以下、サンプルです。

```
<nick> .rg-info SVOC
<RGRB> rg[nick]<SVOC>: 形容詞・主語・目的語・述語を並べ、謎の短文を作ります。 ☆

```
  • Loading branch information
koi-chan committed Feb 20, 2015
1 parent 6cea7cb commit 724f183
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/rgrb/plugin/random_generator/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ def rg(table)
replace_var_with_value(get_value_from(table), table)
end

# 指定した表の Description を返す
# @param [String] table 表名
# @return [String]
# @raise [TableNotFound] 表が見つからなかった場合
def info(table_name)
fail(TableNotFound, table_name) unless @table[table_name]

@table[table_name].description
end

# 表から値を取得して返す
# @param [String] table_name 表名
# @return [String]
Expand Down
17 changes: 17 additions & 0 deletions lib/rgrb/plugin/random_generator/irc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class IrcAdapter

set(plugin_name: 'RandomGenerator')
match(/rg[  ]+(#{TABLE_RE}(?: +#{TABLE_RE})*)/o, method: :rg)
match(/rg-info[  ]+(#{TABLE_RE}(?: +#{TABLE_RE})*)/o, method: :info)

def initialize(*args)
super
Expand Down Expand Up @@ -45,6 +46,22 @@ def rg(m, tables_str)
sleep(1)
end
end

def info(m, tables_str)
header = "rg[#{m.user.nick}]"

tables_str.split(' ').each do |table|
body =
begin
"<#{table}>: #{@generator.info(table)} ☆"
rescue TableNotFound => not_found
": 「#{not_found.table}」なんて表は見つからないのですわっ。"
end
m.target.send(header + body, true)

sleep(1)
end
end
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/rgrb/plugin/random_generator/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ def public?
def sample(random: Random::DEFAULT)
@values.sample(random: random)
end

# 表の説明を返す
# @return [String]
def desctiption()
@description
end
end
end
end
Expand Down

0 comments on commit 724f183

Please sign in to comment.