【问题标题】:Extending the bot in python's IRC library在 python 的 IRC 库中扩展机器人
【发布时间】:2016-11-02 03:39:47
【问题描述】:

我正在尝试扩展 IRC library here 附带的示例机器人。我已经重复了上述机器人here的代码。

我的问题是我不太清楚需要修改哪些内容才能使机器人能够响应事件,例如获取消息 - 我看不到任何事件调度程序。

我能做的是

bot = irc.bot.SingleServerIRCBot(server_list = [('irc.whatever.net.', 6667)],realname = 'irclibbot',nickname = 'irclibbot',)
bot.start()

它运行良好 - 连接到网络等等,但它什么也没做。甚至不响应 VERSION 和 PING 等基本 CTCP 事件。

这是如何工作的?

【问题讨论】:

    标签: python bots irc


    【解决方案1】:

    查看this example 了解您需要做什么。

    class TestBot(irc.bot.SingleServerIRCBot):
        def __init__(self, channel, nickname, server, port=6667):
            irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
        def on_nicknameinuse(self, c, e):
            c.nick(c.get_nickname() + "_")
    
        def on_welcome(self, c, e):
            c.join(self.channel)
    
        def on_privmsg(self, c, e):
            self.do_command(e, e.arguments[0])
    

    定义您自己的继承自实际irc.bot.SingleServerIRCBot 类的类。然后,事件将自动绑定到名为on_'event' 的方法,如on_privmsgon_part 等。

    Here你可以找到支持的事件的参考。

    【讨论】:

      猜你喜欢
      • 2016-01-10
      • 1970-01-01
      • 2013-11-30
      • 2011-07-28
      • 2015-11-21
      • 2015-01-21
      • 2011-08-02
      • 1970-01-01
      • 2012-06-07
      相关资源
      最近更新 更多