tags:

views:

406

answers:

3
require "socket"

server = "irc.rizon.net"
port = "6667"
nick = "Ruby IRC Bot"
channel = "#0x40"

s = TCPSocket.open(server, port)
s.print("USER Testing", 0)
s.print("NICK #{nick}", 0)
s.print("JOIN #{channel}", 0)

This irc bot don't connect to the IRC server, What are i'm doing wrong?

+4  A: 

It faild with this message :

:irc.shakeababy.net 461 * USER :Not enough parameters

So change your code. For example, this one works :

require "socket"

server = "irc.rizon.net"
port = "6667"
nick = "Ruby IRC Bot"
channel = "#0x40"

s = TCPSocket.open(server, port)
print("addr: ", s.addr.join(":"), "\n")
print("peer: ", s.peeraddr.join(":"), "\n")
s.puts "USER testing 0 * Testing"
s.puts "NICK #{nick}"
s.puts "JOIN #{channel}"
s.puts "PRIVMSG #{channel} :Hello from IRB Bot"

until s.eof? do
  msg = s.gets
  puts msg
end

For more information about USER, see http://en.wikipedia.org/wiki/List_of_Internet_Relay_Chat_commands#USER

Greg

greg
+1  A: 

I wrote a tiny IRC bot framework you may wish to use (as a reference): http://github.com/radar/summer.

Ryan Bigg
A: 

http://code.google.com/p/squick/ I'm working on a simple extensible IRC bot in ruby right now, you might find it worth checking out and if you have any questions send me an email I'd be happy to help.

Charlie