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)
Run Code Online (Sandbox Code Playgroud)
这个IRC机器人没有连接到IRC服务器,我做错了什么?
它失败了这条消息:
:irc.shakeababy.net 461 * USER :Not enough parameters
Run Code Online (Sandbox Code Playgroud)
所以改变你的代码.例如,这个工作:
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
Run Code Online (Sandbox Code Playgroud)
有关USER的更多信息,请参阅http://en.wikipedia.org/wiki/List_of_Internet_Relay_Chat_commands#USER