Dominiek.com
Dominiek ter Heide
about 1 year ago
Tweet this Bookmark and Share

Code update: Ruby-EyeAreSee

At 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

blog comments powered by Disqus

About

I'm a 22 year old Web Developer who is currently engaged in RubyOnRails consulting. Apart from obsessing about many technology related topics, I enjoy traveling and international life. In the coming months I intend to boost up my entrepreneurial activities, so stay tuned!

Creative Commons License

All content on this blog is available under the Creative Commons Attribution 3.0 License. Dominiek.com is running Kakuteru a new Semantic-Web enabled lifestreamer. Design and interaction inspired by Yonfook's Sweetcron. Most icons used are by Joseph North.