简体   繁体   English

我的Ruby IRC bot没有连接到IRC服务器。 我究竟做错了什么?

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

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 doesn't connect to the IRC server, What am I doing wrong? 这个IRC机器人没有连接到IRC服务器,我做错了什么?

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 有关USER的更多信息,请参阅http://en.wikipedia.org/wiki/List_of_Internet_Relay_Chat_commands#USER

我写了一个你可能希望使用的小型IRC bot框架(作为参考): http//github.com/radar/summer

The "USER" input is formed like: “USER”输入形成如下:

"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. 还有其他方法可以做到,但这是我能想到的最快捷方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM