LoginSignup
5
4

More than 5 years have passed since last update.

IRC BotをCinchで簡単に作れた

Last updated at Posted at 2016-01-05

参考

準備

sudo gem install cinch
ircbot.rb
#!/usr/bin/ruby
require 'cinch'

bot = Cinch::Bot.new do
  configure do |c|
    c.server = "localhost"
    c.port = "8888"
    c.nick = "cinch"
    c.channels = ["#chat", "#todo"]
    c.password = "xahH7eo2"
  end

  on :message, /@cinch / do |m|
    command = m.message.match(/@cinch (\w.*)/)[1]
    require "open3"
    out, err, status = Open3.capture3(command)
    m.reply out
  end
end

bot.start
起動
./ircbot.rb

使い方

  • cinchが居るIRCチャンネル上から以下命令で、任意のコマンドの標準出力が1行ずつ投稿される。
  • ホワイトリスト形式にすれば安心して使えるかも。
@cinch コマンド
@cinch ps -ef | grep http[d] | wc -l
@cinch w
5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4