[Twisted-Python] IRCClient (ircLogBot.py) send a message every 5 minutes

Glyph Lefkowitz glyph at twistedmatrix.com
Mon Mar 30 14:39:15 MDT 2015


> On Mar 26, 2015, at 11:18 AM, Laurens Vets <laurens at daemon.be> wrote:
> 
> Hello,
> 
> I'm trying to get to know the Twisted framework by extending the ircLogBot.py example. I want to be able to get a list of all names in a channel (by sending NAMES) and I want to rerun this every 5 minutes.
> 
> I've been able to get the NAMES on a channel join by doing this in LogBot:
> 
> def joined(self, channel):
>    self.names(channel)
> 
> def names(self, channel):
>    self.sendLine("NAMES %s" % channel)
> 
> def irc_unknown(self, prefix, command, params):
>    if command == 'RPL_NAMREPLY':
>        self.handle_namereply(*params)
> 
> def handle_namereply(self, myname, channeltype, channelname, users):
>    self.logger.log("Handling namereply %r %r %r %r" % (myname, channeltype, channelname, users))
> 
> The problem I face is that I have no idea where to put a LoopingCall to run this same command every 5 minutes. Where would be the best place to place this?

I would probably start such a LoopingCall in LogBot.connectionMade, and make sure to stop it in LogBot.connectionLost.  That way only an active connection will attempt to send NAMES to itself.

Does that make sense for your application?

Thanks for using Twisted,

-glyph



More information about the Twisted-Python mailing list