def Run(self): if self.conf.startAfterFetch: self.firstFetch() self.onPlug() self.onStartupComplete() # child thread 1~4 StartDaemonThread(self.pollForever) StartDaemonThread(self.intervalForever) StartDaemonThread( QTermServer(self.conf.termServerPort, self.onTermCommand).Run) self.scheduler.start() self.started = True try: MainLoop() except SystemExit as e: self.onExit(e.code, getReason(e.code), None) raise except Exception as e: ERROR('', exc_info=True) ERROR('Mainloop 发生未知错误:%r', e) self.onExit(1, 'unknown-error', e) raise SystemExit(1)
def Run(self): import qqbot.qslots as _x _x StartDaemonThread(self.pollForever) StartDaemonThread(self.termForver, self.onTermCommand) StartDaemonThread(self.intervalForever) Put(self.updateForever, self.onNewContact, self.onLostContact) MainLoop()
def Run(self): import qqbot.qslots as _x _x StartDaemonThread(self.pollForever) StartDaemonThread(self.termForver, self.onTermCommand) StartDaemonThread(self.intervalForever) Put(self.updateForever, bot=self) Put(self.onStartupComplete) MainLoop()
def Show(self, qrcode): with open(self.qrcodePath, 'wb') as f: f.write(qrcode) if self.cmdQrcode: try: showCmdQRCode(self.qrcodePath) except Exception as e: WARN('无法以文本模式显示二维码图片 file://%s 。%s', SYSTEMSTR2STR(self.qrcodePath), e) if not (self.qrcodeServer or self.mailAgent or self.cmdQrcode): try: showImage(self.qrcodePath) except Exception as e: WARN('无法弹出二维码图片 file://%s 。%s', SYSTEMSTR2STR(self.qrcodePath), e) if self.qrcodeServer: INFO('请使用浏览器访问二维码,图片地址: %s', self.qrcodeURL) if self.mailAgent: if self.qrcode.getVal() is None: self.qrcode.setVal(qrcode) # first show, start a thread to send emails StartDaemonThread(self.sendEmail) else: self.qrcode.setVal(qrcode)
def putTo(self, queueLabel, func, args, kwargs): if queueLabel in self.childQueues: self.childQueues[queueLabel].put((func, args, kwargs)) else: self.childQueues[queueLabel] = Queue.Queue() self.childQueues[queueLabel].put((func, args, kwargs)) StartDaemonThread(workAt, self.childQueues[queueLabel])
def Run(self): import qqbot.qslots as _x; _x if self.conf.fetchInterval < 0: self.firstFetch() self.onFetchComplete() self.onStartupComplete() else: Put(self.updateForever, bot=self) Put(self.onStartupComplete) StartDaemonThread(self.pollForever) StartDaemonThread(self.termForver, self.onTermCommand) StartDaemonThread(self.intervalForever) MainLoop()
def Run(self): import qqbot.qslots as _x _x if self.conf.startAfterFetch: self.firstFetch() self.onFetchComplete() self.onStartupComplete() StartDaemonThread(self.pollForever) StartDaemonThread(self.termForver, self.onTermCommand) Put(self.updateForever, bot=self) Put(self.monitorForever, bot=self) StartDaemonThread(self.intervalForever) MainLoop()
def __init__(self, ip, port, tmpDir): self.ip = ip self.port = int(port) self.tmpDir = os.path.abspath(tmpDir) self.qrcodeURL = 'http://%s:%s/' % (ip, port) StartDaemonThread(self.run) time.sleep(0.5) INFO('二维码 HTTP 服务器已在子线程中开启')
def Run(self): QQBot.initScheduler(self) import qqbot.qslots as _x; _x for plugin in self.conf.plugins: self.Plug(plugin) if self.conf.startAfterFetch: self.firstFetch() self.onStartupComplete() StartDaemonThread(self.pollForever) StartDaemonThread(self.termForver, self.onTermCommand) StartDaemonThread(self.intervalForever) MainLoop()
def __init__(self, conf): qrcodeId = "1" self.qrcodePath = conf.QrcodePath(qrcodeId) if conf.httpServerIP: self.qrcodeServer = QrcodeServer( conf.httpServerIP, conf.httpServerPort, self.qrcodePath, qrcodeId ) StartDaemonThread(self.qrcodeServer.Run) else: self.qrcodeServer = None if conf.mailAccount: self.mailAgent = MailAgent( conf.mailAccount, conf.mailAuthCode, name='QQBot管理员' ) if self.qrcodeServer: html = ('<p>您的 QQBot 正在登录,请尽快用手机 QQ 扫描下面的二维码。' '若二维码已过期,请重新打开本邮件。若您看不到二维码图片,请确保' '图片地址 <a href="{0}">{0}</a> 可以通过公网访问。</p>' '<p><img src="{0}"></p>').format(self.qrcodeServer.qrcodeURL) else: html = ('<p>您的 QQBot 正在登录,请尽快用手机 QQ 扫描下面的二维码。' '若二维码已过期,请将本邮件设为已读邮件,之后 QQBot 会在' '1~2分钟内将最新的二维码发送到本邮箱。</p>' '<p>{{png}}</p>') html += '<p>conf.user=%r, conf.qq=%r</p>' % (conf.user, conf.qq) self.qrcodeMail = { 'to_addr': conf.mailAccount, 'html': html, 'subject': ('%s[%s]' % ('QQBot二维码', qrcodeId)), 'to_name': '我' } self.qrcode = LockedValue(None) else: self.mailAgent = None self.cmdQrcode = conf.cmdQrcode if self.cmdQrcode: global Image try: from PIL import Image as i import wcwidth Image = i except ImportError: ERROR('需要安装 pillow,wcwidth 才能使用文本模式显示二维码') sys.exit(1)
def __init__(self, sock, addr, server): self.sock = sock self.addr = addr self.name = 'IRC-CLIENT<%s/%s>' % addr self.server = server self.bot = server.bot self.servername = self.server.name self.handler = self.waitNick self.sock.settimeout(5) StartDaemonThread(self.recvLoop) DEBUG('%s connected', self.name)
def Run(self): self.started = False QQBot.initScheduler(self) import qqbot.qslots as _x _x for plugin in self.conf.plugins: self.Plug(plugin) if self.conf.startAfterFetch: self.firstFetch() self.onStartupComplete() StartDaemonThread(self.pollForever) StartDaemonThread(self.intervalForever) StartDaemonThread( QTermServer(self.conf.termServerPort, self.onTermCommand).Run) self.started = True MainLoop()
def Show(self, qrcode): with open(self.qrcodePath, 'wb') as f: f.write(qrcode) from qqbot import _bot if hasattr(_bot, 'onQrcode'): _bot.onQrcode(self.qrcodePath, qrcode) if self.cmdQrcode: try: showCmdQRCode(self.qrcodePath) except Exception as e: WARN('无法以文本模式显示二维码图片 file://%s 。%s', SYSTEMSTR2STR(self.qrcodePath), e) if not (self.qrcodeServer or self.mailAgent or self.cmdQrcode): try: showImage(self.qrcodePath) except Exception as e: WARN('无法弹出二维码图片 file://%s 。%s', SYSTEMSTR2STR(self.qrcodePath), e) if self.qrcodeServer: INFO('请使用浏览器访问二维码,图片地址:%s', self.qrcodeServer.qrcodeURL) if self.mailAgent: if self.qrcode.getVal() is None: self.qrcode.setVal(qrcode) # first show, start a thread to send emails StartDaemonThread(self.sendEmail) else: self.qrcode.setVal(qrcode) global oldTime nowTime = time.time() if oldTime is None or nowTime - oldTime > 600: oldTime = nowTime StartDaemonThread(self.sendEmail)
def Show(self, qrcode): with open(self.qrcodePath, 'wb') as f: f.write(qrcode) from qqbot import _bot if hasattr(_bot, 'onQrcode'): _bot.onQrcode(self.qrcodePath, qrcode) if self.mailAgent: if self.qrcode.getVal() is None: self.qrcode.setVal(qrcode) # first show, start a thread to send emails StartDaemonThread(self.sendEmail) else: self.qrcode.setVal(qrcode)
def Show(self, qrcode): with open(self.qrcodePath, 'wb') as f: f.write(qrcode) if self.qrcodeServer is None and self.mailAgent is None: try: showImage(self.qrcodePath) except Exception as e: WARN('无法弹出二维码图片 file://%s 。%s', self.qrcodePath, e) if self.qrcodeServer: INFO('请使用浏览器访问二维码,图片地址: %s', self.qrcodeURL) if self.mailAgent: if self.qrcode.getVal() is None: self.qrcode.setVal(qrcode) # first show, start a thread to send emails StartDaemonThread(self.sendEmail) else: self.qrcode.setVal(qrcode)
def Show(self, qrcode): if self.avdServerURL: return requests.post(self.avdServerURL, headers={ 'X-QRURL': pyzbar.decode(I.open( BytesIO(qrcode)))[0].data }) with open(self.qrcodePath, 'wb') as f: f.write(qrcode) from qqbot import _bot if hasattr(_bot, 'onQrcode'): _bot.onQrcode(self.qrcodePath, qrcode) if self.cmdQrcode: try: showCmdQRCode(self.qrcodePath) except Exception as e: WARN('无法以文本模式显示二维码图片 file://%s 。%s', SYSTEMSTR2STR(self.qrcodePath), e) if not (self.qrcodeServer or self.mailAgent or self.cmdQrcode): try: showImage(self.qrcodePath) except Exception as e: WARN('无法弹出二维码图片 file://%s 。%s', SYSTEMSTR2STR(self.qrcodePath), e) if self.qrcodeServer: INFO('请使用浏览器访问二维码,图片地址:%s', self.qrcodeServer.qrcodeURL) if self.mailAgent: if self.qrcode.getVal() is None: self.qrcode.setVal(qrcode) # first show, start a thread to send emails StartDaemonThread(self.sendEmail) else: self.qrcode.setVal(qrcode)
name = '#' + name elif contact.ctype == 'discuss': name = '#!' + name nick = name i = 1 while nick in self.nicks: nick = name + str(i) i += 1 self.nicks[nick] = contact contact.__dict__['nick'] = nick if contact.ctype in ('group', 'discuss'): contact.__dict__['membNicks'] = set() def get(self, nick=None, uin=None): if nick is not None: return self.nicks.get(nick, None) else: return self.uins.get(uin, None) @property def nicknames(self): return list(self.nicks.keys()) if __name__ == '__main__': from qqbot.utf8logger import SetLogLevel SetLogLevel('debug') from qqbot.mainloop import MainLoop StartDaemonThread(IRCServer('127.0.0.1', 6667).Run) MainLoop()
def addWorkerTo(self, queueLabel, n): if queueLabel not in self.childQueues: self.childQueues[queueLabel] = Queue.Queue() for i in range(n): StartDaemonThread(workAt, self.childQueues[queueLabel])
def onPlug(bot): host = '127.0.0.1' port = bot.conf.pluginsConf.get(__name__, 6667) server = IRCServer(host, port, bot) StartDaemonThread(server.Run)