[Twisted-Python] irc bot, reacting to: irc_ERR_NOSUCHNICK. after the code where the reactor was started

peter commercials24 at yahoo.de
Wed Oct 7 00:38:45 MDT 2015


On 10/05/2015 11:12 PM, Glyph Lefkowitz wrote:
>
>> On Oct 5, 2015, at 2:33 AM, peter <commercials24 at yahoo.de 
>> <mailto:commercials24 at 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?
>
>  1. Use Endpoints
>     <https://twistedmatrix.com/documents/15.4.0/core/howto/endpoints.html>
>     so you get a nice `Deferred´ back from connectTCP.
>  2. Add a callback to that Deferred.
>  3. 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 at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

im sure youre solution is just fine, could you show me how you would 
contruct isBotOnline?
im assuming that code would go into the class "mybot", next to 
irc_ERR_NOSUCKNICK?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20151007/9f7f436e/attachment-0002.html>


More information about the Twisted-Python mailing list