> On Oct 5, 2015, at 2:33 AM, peter <commercial...@yahoo.de> wrote: > > my bot inherits from irc.IRCClient, when it sends a message to another user > who isnt online irc_ERR_NOSUCHNICK(self, prefix, command) is called. > how can i react to that message, my code is called with: > > > class mybot(irc.IRCClient): > ... > if __name__ == "__main__": > > factory = XdccBotFactory( channel, nickname, xdccbot, xdccrequests ) > reactor.connectTCP( server, 6667, factory ) > > > > in irc_ERR_NOSUCHNICK... i got: > error_message = "%s bot is not connected to server" % > now.strftime("%Y-%m-%d %H:%M:%S") > log.warning(error_message) > > > which works. > but what i really would like to have is: > > > if __name__ == "__main__": > > factory = XdccBotFactory( channel, nickname, xdccbot, xdccrequests ) > reactor.connectTCP( server, 6667, factory ) > > if "bot not online": > "send message to antoher user" > > > so basically i need the information that irc_ERR_... was called after the > reactor was started. > how do you do that?
Use Endpoints <https://twistedmatrix.com/documents/15.4.0/core/howto/endpoints.html> so you get a nice `Deferred´ back from connectTCP. Add a callback to that Deferred. Add a method to `XdccBotFactory´ that returns a `Deferred´ that fires when its message is successfully sent and acknowledged, and then add a callback to that `Deferred´. If you were to use inlineCallbacks to inline the callbacks you're adding into one function, it might look something like this: > @inlineCallbacks > def main(reactor): > factory = XdccBotFactory(channel, nickname, xdccbot, xdccrequests) > endpoint = clientFromString(reactor, "...") > bot = yield endpoint.connect(factory) > online = yield bot.isBotOnline() > if online: > "send message to another user" > else: > "ok" Does this make sense? -glyph
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python