My Ruby IRC bot doesn't connect to the IRC server. What am I doing wrong?

筅森魡賤 提交于 2019-12-04 08:40:31
greg

It failed 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

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

Kinz

The "USER" input is formed like:

"USER misc misc misc :misc\r\n"

So:

s.print("USER #{nick} #{nick} #{nick} :#{nick}\r\n", 0)

should work. There are other ways to do it, but this is the quickest way I could come up with.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!