使用python irc库定期执行任务 [英] Perform tasks periodically with python irc library

查看:57
本文介绍了使用python irc库定期执行任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以使定期任务自动化:例如使用python irclib

Is there a way to automate periodic tasks: like sending messages to other users or channels, etc. using python irclib or twisted-based youmomdotcom python irc bot.

基于 irclib 的irc客户端示例:

Example of irclib based irc client:

from irc import client
class OurIRCClient(client.SimpleIRCClient):
    def __init__(self):
        client.SimpleIRCClient.__init__(self)

import sys
client = OurIRCClient()

try:
    client.connect("irc.freenode.net", 6667, myUserId)
    print "connected to irc.freenode.net"
except:
    sys.exit(-1)
    "error: coouldn't connect to irc server"
client.connection.join("#django-hotclub")
client.start()

推荐答案

正如Glyph所指出的,我已经覆盖了irc客户端类的实例方法 connectionMade ,并使其使用了 LoopingCall .

As Glyph pointed out, i've overridden the instance method connectionMade of the irc client class and made it use LoopingCall.

 def connectionMade(self):
        irc.IRCClient.connectionMade(self)
        task.LoopingCall(lambda : (self.msg(counterpartID, "hi there"))).start(5.0)

这篇关于使用python irc库定期执行任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆