Python IRC 客户端:从头开始编写还是为现有框架编写插件?
对于我们公司,我希望有一个基于 Python 的 IRC 机器人,它可以检查我们客户的网站是否仍在运行。 更具体地说:我想列出一些应该每 15 分钟访问一次的 URL。 如果失败,应在 5 分钟后再次检查 URL。 如果检索 URL 仍然没有导致 HTTP 状态代码 200,则它应该在通道中回显失败的 URL,以便我们可以对其进行调查。
我不久前为 Supybot 编写了一个插件,基本上可以粗略地完成上述一些操作但有效的方法。 如果我想将当前代码的功能扩展到上述“规范”,我需要进行一些重大重构; 基本上这意味着从头开始。
这就提出了一个问题:我应该为 Supybot 编写一个更好的插件来满足新的要求,还是干脆去做其他的事情? 我应该从头开始(学习最多,实现 相关的 RFC 我自己,花费的时间比计划的要多)或者是否有一个合适的框架来处理基本的 IRC 内容?
For our company I'd like to have a Python based IRC bot which checks whether the websites of our clients are still up and running. More specific: I want to list a number of URL which should be visited every, say, 15 minutes. If it fails, the URL should be checked again after 5 minutes. If retrieving the URL still doesn't result in an HTTP status code 200, it should echo the failing URL in the channel so we can investigate it.
I've written a plugin for Supybot some time ago that basically does some of the above in a crude but effective way. If I want to expand the functionality of the current code to the above 'specs' I need to do some major refactoring; basically it would mean starting from scratch.
Which raises the question: should I write a better plugin for Supybot, matching the new requirements, or go for something else altogether? Should I start from scratch (learning the most, implementing the relevant RFCs myself, spending more time than planned) or is there a suitable framework which handles the basic IRC stuff?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我投票支持 Supybot 的全新插件。 了解更多 ;)
如果您不会做那么多,请尝试 python irclib< /a>。 它是 IRC 的(仍在维护的)Python 库。
Twisted 也可以,但是有点太多了......
I vote for a completely new plugin for Supybot. Learn more ;)
If you won't do so much, try python irclib. It's a (still maintained) python lib for IRC.
Twisted may also be ok, but it's a little but too much...
对我来说,这听起来像是您的应用程序想要与 IRC 进行对话,而我的直觉反应是使用 Twisted,它有 IRC 客户端。 这可能是也可能不是适合您的解决方案,但至少值得研究。
To me it sounds like a case of your application wanting to talk IRC, and my gut reaction would be to use Twisted, which has IRC clients. This may or may not be the right solution for you, but at least it's worth investigating.
我最终决定为我的机器人创建 use Twisted 。 至于原因:
Supybot 已经拥有很多功能。 这可能是一件好事:只需创建一个简单的插件,将其连接起来并开始使用机器人即可。 缺点是您可能不喜欢已经提供的某些功能。 举个例子:我不喜欢它对所有内容做出响应(错误:“foo”不是一个有效的命令。)。 我确信它可以在某个地方以某种方式关闭,但这些小事情困扰着我。
另一方面,Python IRC 客户端库 感觉有点太简单了。 特别是因为我需要线程让机器人检查许多网站是否仍然存在,同时在频道中保持响应。
如果感觉 irclib 级别太低,那么从头开始编写一个机器人肯定会是这样。 虽然我确实想学习一些东西,但我也想专注于机器人的实际功能,而不是被“基本”的东西打扰太多(例如,我不一定想编写代码来识别机器人,我喜欢只是有一些配置设置来存储昵称和密码并为我处理这个问题。)
Twisted 有一个很好的例子 日志机器人 可以用作起点。 此外:将来编写一个小型网络服务器(显然使用 Twisted)来显示机器人的输出应该不会太难。
提示:除了 Twisted 文档之外,您还可以查看 Python 杂志 2008 年 10 月号,作者为 Doug Farrell 的文章“A Twisted Logging Server”。
感谢回答问题的人。 你让我走上了正确的道路。 :)
I finally decided to create use Twisted for my bot. As to the why:
Supybot already has a lot of functionality. And that can be a good thing: just create a simple plugin, hook it up and start using the bot. The downside is that you may not like some of the functionality already provided for. As an example: I didn't like the fact that it responded to everything (Error: "foo" is not a valid command.). I'm sure it can be turned off somehow somewhere, but these kind of small things bothered me.
The Python IRC client library on the other hand felt a little too bare bones. Especially since I needed threading to have the bot check a whether a number of websites are still alive while remaining responsive in the channel.
If the irclib felt like too low level, writing a bot from scratch would certainly be. While I definitely wanted to learn something, I also wanted to focus on the actual functionality of the bot, without being bothered too much by the 'basic' stuff (e.g. I don't necessarily want to write the code to identify the bot, I like to just have some configuration setting to store the nickname and password and handle this for me.)
Twisted has a nice example of a logging bot which can be used as a starting point. Furthermore: in the future it should not be too hard to write a small webserver (using Twisted obviously) to display the output of the bot.
Tip: besides the Twisted documentation you can also take a look at the October 2008 issue of Python Magazine for the article "A Twisted Logging Server" by Doug Farrell.
Thanks to the ones who answered the question. You set me on the right track. :)
编写一个简单的 IRC 机器人并不难。 我有一个一直用于我的机器人的模板,其范围从 SVN 机器人到投票状态机器人,再到检查某些 IP 连接并根据结果更改频道主题的机器人。
如果您愿意,我可以分享源代码,不过没有什么比自己编写源代码更好的了:)
Writing a simple IRC bot isn't that hard. I have a template I keep using for my bots, which range from SVN bots to voting-status bots to bots which check connections to certain IPs and change the channel's topic according to the result.
I can share the source if you'd like, though there's nothing like writing your own :)
irc3 是一个基于 asyncio 和 venusian 的可插入 irc 客户端库 https://irc3.readthedocs.org/
irc3 is a plugable irc client library based on asyncio and venusian https://irc3.readthedocs.org/