cinchではまったところ.
IRCのbot作成時、cinchを使ってみた。 結構癖があり、ソースみないとよくわからんことが多々あったので、めもめも。
doc - http://rubydoc.info/github/cinchrb/cinch/Cinch
はまったところ
noticeでメッセージを受ける.
matchのところで、react_onを:channelにすればOK (defaultは:message)
class CvBot
include Cinch::Plugin
...
match /cv (.+)/, group: :blegh, method: :handle_message, react_on: :channel
...
end
noticeでメッセージを発信する.
Cinch::Targetを利用すれば良い.
class CvBot
include Cinch::Plugin
...
def handle_message (m, word)
m.target.notice "hello notice message"
end
end
Pluginにパラメータを渡す.
required_optionがどこでとれるのかわからんかったけど、テストコードをみて判断できた。 https://github.com/cinchrb/cinch/blob/edcd787a809a4ee809d624683c5afc9b0918c3fe/test/lib/cinch/plugin.rb
class CvBot
include Cinch::Plugin
...
set :required_options, [:opt]
...
def handle_message(m, word)
p config[:opt] # it puts "hello option"
end
end
bot = Cinch::Bot.new do
configure do |c|
c.plugins.plugins = [CvBot]
c.plugins.options[CvBot] = {opt: "hello option"}
end
end