IRC 机器人:即使我做了 USER 和 NICK,MOTD 也没有出现
我正在用 python 为 hackthissite 挑战(prog 8)制作一个 IRC 机器人。 这是连接代码的摘录:
def ping():
ircsock.send("PONG :Pong\n")
ircsock.connect((server,6667))
ircsock.send("USER "+botnick+" "+server+" "+botnick+" :"+version+"\n")
ircsock.send("NICK "+botnick+"\n")
while(connect):
ircmsg = ircsock.recv(2048)
ircmsg = ircmsg.strip('\n\r')
print(ircmsg)
if(ircmsg.find("PING :") != -1):
ping()
我不认为这有什么问题。 所有变量都已定义并具有值,此代码在某些服务器(例如 freenode)上运行没有问题。但在其他服务器(foonetic、hackthissite)上,我得到以下输出:
:hub.irc.hackthissite.org NOTICE AUTH :*** Looking up your hostname...
:hub.irc.hackthissite.org NOTICE AUTH :*** Found your hostname
PING :3C8E9173
:[email protected] PRIVMSG Tadbot :VERSION
我不知道该怎么办。我尝试将机器人的版本发送回“:”和“!”之间的用户名,这(如预期)没有执行任何操作。在发生这种情况的服务器上,我永远不会收到 MOTD,因此当我尝试执行任何操作时都会收到“您尚未注册”错误。
谷歌得出了一些人们解释类似问题的结果,但他们总是忘记发送他们的用户和NICK,所以我真的不知道在这里做什么。
I'm making an IRC bot in python for the hackthissite challenge (prog 8).
Here's an excerpt of the connection code:
def ping():
ircsock.send("PONG :Pong\n")
ircsock.connect((server,6667))
ircsock.send("USER "+botnick+" "+server+" "+botnick+" :"+version+"\n")
ircsock.send("NICK "+botnick+"\n")
while(connect):
ircmsg = ircsock.recv(2048)
ircmsg = ircmsg.strip('\n\r')
print(ircmsg)
if(ircmsg.find("PING :") != -1):
ping()
I don't think that there's anything wrong with this.
All variables are defined and have a value, this code works without a problem on some servers (freenode for example). But on other servers (foonetic, hackthissite) I get the following output:
:hub.irc.hackthissite.org NOTICE AUTH :*** Looking up your hostname...
:hub.irc.hackthissite.org NOTICE AUTH :*** Found your hostname
PING :3C8E9173
:[email protected] PRIVMSG Tadbot :VERSION
I'm not sure what to do with this. I have tried sending back the version of my bot to the username between the ":" and the "!", which (as expected) didn't do anything. On servers where this happens, I never get my MOTD so I get the "You have not registered" error when I try to do anything.
Google yielded some results of people explaining similar problems, but it'd always be that they forgot to send their USER and NICK, so I'm really at a loss about what to do here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须向服务器的
PING
发送PONG
响应,否则服务器会认为连接已断开。您发布的示例中的正确回复是
3C8E9173,与服务器请求的字符串相同。
You must send the
PONG
response to the server'sPING
, otherwise the server will think the connection is dead.The correct reply in the example you posted would be
3C8E9173 being the same string as the server requested.
除了真相的正确答案之外,
VERSION
消息是一条CTCP消息。这通过PRIVMSG
的有效负载被不可打印的 ASCII\001
(CTRL-A) 字符包围来指示;它实际上是\001VERSION\001
。要回复它,您需要将
PRIVMSG
发送回源昵称,也格式化为 CTCP 消息:例如。\001VERSION Nyubis Python Bot\001
。In addition to Truth's correct answer, the
VERSION
message is a CTCP message. This is indicated by the payload of thePRIVMSG
being surrounded by unprintable ASCII\001
(CTRL-A) characters; it is actually\001VERSION\001
.To reply to it, you need to send a
PRIVMSG
back to the source nick also formatted as a CTCP message: eg.\001VERSION Nyubis Python Bot\001
.