Over a million developers have joined DZone.

Ruby IRC Socket

·
I simple IRC socket using the irc-socket gem. Documentation available at http://rdoc.injekt.net/irc-socket


require 'rubygems'
require 'irc-socket'

IRCSocket.new("irc.myserver.net") do |irc|
  irc.nick "mrbot"
  irc.user "mrbot", 0, "*", "irc-socket bot"

  while line = irc.read
    data = line.split

    if data[0] == 'PING'
      irc.pong data[1]
    end

    # Wait until end of motd before attempting to join
    if data[1] == '376'
      irc.join "#channel"
      irc.privmsg "#channel", "Hi there!"
      irc.privmsg "mynick", "Hi there in private message"
      irc.notice "#channel", "Notice message!"
      irc.part "#channel"
    end
  
    puts line
  end
end
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}