Created
October 24, 2012 06:32
-
-
Save mechamogera/3944397 to your computer and use it in GitHub Desktop.
net/ircでのIRCbot実装例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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