-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,74 @@ | ||
#!/usr/bin/python | ||
# coding: utf-8 | ||
|
||
import sys | ||
# sys.path.insert(0, "..") | ||
import time | ||
from threading import Thread | ||
|
||
from qqrobot.core.qsession import BaseSession | ||
|
||
# TODO: | ||
# - celery 一直有问题,提交任务之后 worker 执行报错,待解决,暂时用线程代替 | ||
# from celeryMQ.app import qqrobotMQ | ||
|
||
bot = BaseSession() | ||
|
||
# @qqrobotMQ.task | ||
# def add(x, y): | ||
# return x + y | ||
# | ||
# @qqrobotMQ.task | ||
# def async_send_msg(msg, from_uin, msg_type, *args, **kw): | ||
# bot.send_msg(msg, from_uin, msg_type, *args, **kw) | ||
|
||
def async_send_msg(msg, from_uin, msg_type, *args, **kw): | ||
Thread(target=bot.send_msg, | ||
args=(msg, from_uin, msg_type, args, kw)).start() | ||
|
||
|
||
def run(): | ||
global bot | ||
bot.log.info("扫描二维码") | ||
bot.get_QRcode() | ||
IS_LOGIN = False | ||
while not IS_LOGIN: | ||
time.sleep(1.5) | ||
res = bot.is_login().split(',')[-2] | ||
bot.log.info(res) | ||
IS_LOGIN = True if '登录成功' in res else False | ||
bot.log.info('获取ptwebqq...') | ||
bot.get_ptwebqq() | ||
bot.log.info('获取vfwebqq...') | ||
bot.get_vfwebqq() | ||
bot.log.info('获取psessionid...') | ||
bot.get_psessionid() | ||
bot.log.info('等待消息...') | ||
STOP, IS_OPEN = False, True | ||
while not STOP: | ||
time.sleep(1) | ||
try: | ||
msg = bot.poll() | ||
if msg: | ||
msg_content, from_uin, msg_type = msg | ||
else: | ||
continue | ||
if (IS_OPEN is True) and ('STOP' not in msg_content): | ||
# msg = "{0}[{1}]".format(SEND_MSG, random.randint(0, 10)) | ||
# send_status = bot.send_msg(msg, from_uin, msg_type) | ||
# LOG.info('回复 {0}: {1}'.format(from_uin, send_status)) | ||
# async_send_msg.delay(msg_content, from_uin, msg_type) | ||
async_send_msg(msg_content, from_uin, msg_type) | ||
elif 'STOP' in msg_content: | ||
bot.log.info('CLOSE...') | ||
async_send_msg('CLOSED', from_uin, msg_type) | ||
IS_OPEN = False | ||
elif 'START' in msg_content: | ||
bot.log.info('STARTED') | ||
async_send_msg('OPENED', from_uin, msg_type) | ||
IS_OPEN = True | ||
except KeyboardInterrupt: | ||
bot.log.info('See You...') | ||
STOP = True | ||
except: | ||
bot.log.error(sys.exc_info()) |