IRC Python 机器人:最好的方法
我想构建一个基本上执行以下操作的机器人:
- 倾听房间内的声音并与用户交互,并鼓励他们私信机器人。
- 一旦用户私信了,机器人就会使用各种人工智能技术与客户互动。
我应该只使用 IRC 库或 python 中的套接字,还是需要更多的机器人框架。
你会怎么办?
谢谢!
这是我当前正在使用的代码,但是我还没有让它工作。
#!/usr/bin/python
import socket
network = 'holmes.freenet.net'
port = 6667
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( network, port ) )
irc.send ( 'NICK PyIRC\r\n' )
irc.send ( 'USER PyIRC PyIRC PyIRC :Python IRC\r\n' )
irc.send ( 'JOIN #pyirc\r\n' )
irc.send ( 'PRIVMSG #pyirc :Can you hear me?\r\n' )
irc.send ( 'PART #pyirc\r\n' )
irc.send ( 'QUIT\r\n' )
irc.close()
I want to build a bot that basically does the following:
- Listens to the room and interacts with users and encourages them to PM the bot.
- Once a user has PMed the bot engage with the client using various AI techniques.
Should I just use the IRC library or Sockets in python or do I need more of a bot framework.
What would you do?
Thanks!
Here is the code I'm currently using, however, I haven't gotten it to work.
#!/usr/bin/python
import socket
network = 'holmes.freenet.net'
port = 6667
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( network, port ) )
irc.send ( 'NICK PyIRC\r\n' )
irc.send ( 'USER PyIRC PyIRC PyIRC :Python IRC\r\n' )
irc.send ( 'JOIN #pyirc\r\n' )
irc.send ( 'PRIVMSG #pyirc :Can you hear me?\r\n' )
irc.send ( 'PART #pyirc\r\n' )
irc.send ( 'QUIT\r\n' )
irc.close()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用 Twisted 或 Asynchat 如果你想要一个合理的设计。 可以只使用套接字来完成,但为什么要从头开始呢?
Use Twisted or Asynchat if you want to have a sane design. It is possible to just do it with sockets but why bother doing it from scratch?
如果您想涉及 AI 技术,那么我建议您查看 Python 的 AIML 包。 ALICE 机器人也采用同样的技术。
If you want to have AI techniques involved, then I suggest you look at the AIML package for Python. It is the same technology that ALICE bots are done in.
如果您想要创建 AI 部分,为什么还要自己编写 IRC 连接所需的所有代码呢?
我建议使用 SupyBot,并简单地将您的 AI 代码编写为它的插件。 有相当容易理解的文档和大量示例代码可供查找。 此外,它还附带了大量的插件,可用于各种用途,可以补充您的人工智能。
If what you want is to create the AI portion, why bother writing all the code needed for the IRC connection by yourself?
I suggest using SupyBot, and simply write your AI-code as a plugin for it. There is reasonably understandable documentation and lots of example-code to find. Also, it comes with a decent amount of plugins for all sorts of uses that might complement your AI.
当我在大约 2 年后回复时,我只是为 Google 员工写下这篇文章 :-P
在这里尝试一下我的“又一个无用的 IRC 机器人” https://github.com/julienpalard/yauib 允许您使用您想要的任何语言对机器人的每个功能进行编码。
As I'm replying ~2 years later, I'm writing this just for Googlers :-P
Just try my 'Yet Another Useless IRC Bot' here https://github.com/julienpalard/yauib permitting you to code each feature of your bot using whatever language you want.
我使用 IRC bot 制作了一个(非常蹩脚,并且很长一段时间都在重构) ="http://python-irclib.sourceforge.net/" rel="nofollow noreferrer">irclib。 该文档几乎没有,但它使您不必执行所有套接字连接等操作,这是我真的不想处理的事情。 不过,对于每个人来说。
I made a (very crappy, and for a long time being refactored) IRC bot using irclib. The documentation is next-to-nothing, but it gets rid of making you have to do all that socket connecting and such, which is stuff I really don't want to deal with. To each his own, though.
使用现有的 IRC 库而不是自己实现协议。
Use an existing IRC library instead of implementing the protocol yourself.