Code update: Ruby-EyeAreSee
on January 18, 2007At the moment I’m working on a little web-IRC client. My intention was to use the Ruby-IRC Framework, but I’ve decided to write my own API for the following reasons:
- It is impossible to establish multiple connections (multi-user) in the same process
- Event-handlers can not be flexible.
- After disconnecting it’s almost impossible to reconnect using the same instance or a new one.
Now I have a slim SSL capable IRC API that fulfills all my needs.
Click here to view examples and documentation
Click here to download the API (Beer-Ware Licensed)
example IRC client:
require 'EyeAreSee'
irc = EyeAreSee.new("EyeAreSee", "irc.darkwired.org", :ssl => true, :channel => "#test")
# catch all lines for debugging
irc.on_message { |line|
puts "debug: "+line if $DEBUG
}
# catch all server messages, eg nickname already in use
irc.on_server_message { |event|
next if event[:code] == 372
puts event[:code].to_s+": "+event[:message]
}
# handle 372 messages (Message of the Day)
irc.on_server_message(372) { |event|
puts "motd: "+event[:message]
}
# display all messages directed to the #test channel
irc.on_message("privmsg", :to => "#test") { |event|
puts event[:from_nickname].to_s+" says: "+event[:message].to_s
}
# auto-response to private message from specific user
irc.on_message("privmsg", :to => "EyeAreSee", :from_nickname => "Drakonen") { |event|
sleep(rand*10)
responses = ["hmmmz", "boeiend", "interessant"]
irc.message event[:from_nickname], responses[(rand*3).to_i]
}
# display all messages directed to the #test channel
irc.on_message("privmsg", :to => "#test", :message => "please go away EyeAreSee") { |event|
irc.message("#test", "OK "+event[:from_nickname]+", bye everyone!")
irc.quit
}
irc.start
irc.start #reconnect once after a quit