Skip to content

Instantly share code, notes, and snippets.

@mechamogera
Created October 24, 2012 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mechamogera/3944397 to your computer and use it in GitHub Desktop.
Save mechamogera/3944397 to your computer and use it in GitHub Desktop.
net/ircでのIRCbot実装例
gem 'net-irc'
require 'net/irc'
require 'yaml'
data = YAML.load(DATA)
class TestBot < Net::IRC::Client
attr_accessor :target_channels
def initialize(*args)
@target_channels = []
super(*args)
end
def on_rpl_welcome(m)
@target_channels.each do |channel|
post(JOIN, channel)
end
end
def talk(msg, channels = @target_channels)
channels.each do |channel|
post(PRIVMSG, channel, msg)
end
end
end
irc = TestBot.new(data[:server],
data[:port],
:nick => data[:name],
:user => data[:name],
:real => data[:name])
irc.target_channels = data[:channels]
Thread.start do
sleep 5
irc.talk("test")
end
irc.start
__END__
:server: example.com
:channels:
- '#hoge'
:name: aaaa
:port: 6667
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment