Note that there are some explanatory texts on larger screens.

plurals
  1. PORecurring function call with twisted
    primarykey
    data
    text
    <p>I have a basic IRC bot that looks something like this (see below), what I would like to do is use something like the <code>_5_mins</code> function to be called every 5 mins with a <code>LoopingCall</code></p> <pre><code>import sys import re from twisted.internet import reactor, task, defer, protocol from twisted.python import log from twisted.words.protocols import irc from twisted.application import internet, service import time HOST, PORT = 'irc.freenode.net', 6667 class IrcProtocol(irc.IRCClient): nickname = 'BOTSNAME' password = 'NICKPASSWORD' timeout = 600.0 def signedOn(self): pMess = "IDENTIFY %s" % self.password self.msg("NickServ",pMess) time.sleep(10) for channel in self.factory.channels: self.join(channel) def _5_mins(self): self.msg(self.factory.channels[0],"5 minutes have elapsed") class IrcFactory(protocol.ReconnectingClientFactory): channels = ['#BOTCHANNEL'] protocol = IrcProtocol if __name__ == '__main__': reactor.connectTCP(HOST, PORT, IrcFactory()) log.startLogging(sys.stdout) reactor.run() elif __name__ == '__builtin__': application = service.Application('IrcBot') ircService = internet.TCPClient(HOST, PORT, IrcFactory()) ircService.setServiceParent(application) </code></pre> <p>How do I alter the <code>signedOn</code> function work with the <code>task.LoopingCall</code> function or is there a better way?</p> <p>EDIT: I was really close to a solution, the following is what I have gone with</p> <pre><code>def signedOn(self): pMess = "IDENTIFY %s" % self.password self.msg("NickServ",pMess) time.sleep(10) for channel in self.factory.channels: self.join(channel) lc = task.LoopingCall(self._5_mins) lc.start(self.timeout) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload