使用 oyoyo 构建的 Python IRC 机器人中的命令
我最近发现了 oyoyo Python IRC 框架,因为从我的新手角度来看它看起来不错,我有选择用它构建一个 IRC 机器人(Twisted 似乎有点令人畏惧)。我查看了示例,但我不确定如何实施更多命令。我会在 privmsg 函数中有很多 if 语句吗?以及如何触发这些 if 语句?虽然我不是一个完全的菜鸟,但我仍然是一个新手,所以如果这是一个愚蠢的问题,请不要评判我。
I have recently found the oyoyo Python IRC framework and as it looks decent from my newbie perspective, I have chosen to build an IRC bot with it (Twisted seems a bit daunting). I have looked at the example, but I am not sure how I would implement more commands. Would I just have a lot of if statements in the privmsg function? And how would trigger these if statements? While I am not a complete noob, I am still a newbie, so please don't judge me if this is a stupid question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
twisted 中的 IRC 机器人 演示了您如何机器人可以响应多个命令。
您定义多个
command_*()
方法并从privmsg()
方法调用它们。getattr(self, 'command_'+command_name, None)
检索要调用的适当方法。IRC bot in twisted demonstrates how your bot can respond to several commands.
You define several
command_*()
methods and call them fromprivmsg()
method.getattr(self, 'command_'+command_name, None)
retrieves appropriate method to call.