读取IRC服务器命令返回数据的Python IRC机器人

0 投票
1 回答
831 浏览
提问于 2025-04-17 14:26

我有一个和PHP IRC 机器人读取IRC服务器命令返回的数据类似的问题。

我正在使用一个用Python写的IRC机器人,这个机器人在网上很常见。

我需要向IRC服务器发送一个"NAMES"命令,这样服务器就会返回一个当前在频道里的用户名列表。但是我似乎无法接收到这个列表,没有收到服务器的回复——这个机器人能接收到并打印其他用户发送的消息,但自己发送的消息和命令的输出却收不到。

为了打印数据,我使用了以下代码:

while True:
    data = irc.recv ( 4096 )
    (...)
    print data

为了发送NAMES命令,我尝试了以下代码:

irc.send ( 'NAMES #channel\r\n' )

还有:

irc.send ( 'PRIVMSG #channel :/names\r\n' )

完整代码可以在pastebin.com找到:http://pastebin.com/xjymEjPu

1 个回答

0

我刚刚在脚本的输出中看到了NAMES列表。

:botty!~botty@durrrrrrrrr JOIN :#channel
:retribution.sg.as.irchighway.net 353 botty = #channel :botty IlPalazzo-ojiisan @Nibelung 
:retribution.sg.as.irchighway.net 366 botty #channel :End of /NAMES list.
:retribution.sg.as.irchighway.net 353 botty = #channel :botty IlPalazzo-ojiisan @Nibelung 
:retribution.sg.as.irchighway.net 366 botty #channel :End of /NAMES list.

不过,这并不是最后出现的内容。也许你错过了?它是在一组全局通知的上面,而那些通知是最后返回的几行。

撰写回答