3

私はこのような基本的な IRC ボットを持っています (以下を参照) _5_minsLoopingCall

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)

signedOn関数で関数の動作を変更するにはどうすればtask.LoopingCallよいですか、またはより良い方法がありますか?

編集:私は解決策に本当に近かったです。以下は私が行ったことです

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)
4

1 に答える 1

2
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)
于 2012-12-05T15:28:20.440 に答える