|
@@ -48,7 +48,8 @@ def handler_single_voice(msg): |
|
|
|
|
|
|
|
|
class WechatChannel(Channel): |
|
|
class WechatChannel(Channel): |
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
pass |
|
|
|
|
|
|
|
|
self.userName = None |
|
|
|
|
|
self.nickName = None |
|
|
|
|
|
|
|
|
def startup(self): |
|
|
def startup(self): |
|
|
|
|
|
|
|
@@ -65,6 +66,9 @@ class WechatChannel(Channel): |
|
|
itchat.auto_login(enableCmdQR=2, hotReload=hotReload) |
|
|
itchat.auto_login(enableCmdQR=2, hotReload=hotReload) |
|
|
else: |
|
|
else: |
|
|
raise e |
|
|
raise e |
|
|
|
|
|
self.userName = itchat.instance.storageClass.userName |
|
|
|
|
|
self.nickName = itchat.instance.storageClass.nickName |
|
|
|
|
|
logger.info("Wechat login success, username: {}, nickname: {}".format(self.userName, self.nickName)) |
|
|
# start message listener |
|
|
# start message listener |
|
|
itchat.run() |
|
|
itchat.run() |
|
|
|
|
|
|
|
@@ -82,8 +86,16 @@ class WechatChannel(Channel): |
|
|
if conf().get('speech_recognition') != True: |
|
|
if conf().get('speech_recognition') != True: |
|
|
return |
|
|
return |
|
|
logger.debug("[WX]receive voice msg: " + msg['FileName']) |
|
|
logger.debug("[WX]receive voice msg: " + msg['FileName']) |
|
|
|
|
|
to_user_id = msg['ToUserName'] |
|
|
from_user_id = msg['FromUserName'] |
|
|
from_user_id = msg['FromUserName'] |
|
|
other_user_id = msg['User']['UserName'] |
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
other_user_id = msg['User']['UserName'] # 对手方id |
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
logger.warn("[WX]get other_user_id failed: " + str(e)) |
|
|
|
|
|
if from_user_id == self.userName: |
|
|
|
|
|
other_user_id = to_user_id |
|
|
|
|
|
else: |
|
|
|
|
|
other_user_id = from_user_id |
|
|
if from_user_id == other_user_id: |
|
|
if from_user_id == other_user_id: |
|
|
context = Context(ContextType.VOICE,msg['FileName']) |
|
|
context = Context(ContextType.VOICE,msg['FileName']) |
|
|
context.kwargs = {'isgroup': False, 'msg': msg, 'receiver': other_user_id, 'session_id': other_user_id} |
|
|
context.kwargs = {'isgroup': False, 'msg': msg, 'receiver': other_user_id, 'session_id': other_user_id} |
|
@@ -96,7 +108,14 @@ class WechatChannel(Channel): |
|
|
content = msg['Text'] |
|
|
content = msg['Text'] |
|
|
from_user_id = msg['FromUserName'] |
|
|
from_user_id = msg['FromUserName'] |
|
|
to_user_id = msg['ToUserName'] # 接收人id |
|
|
to_user_id = msg['ToUserName'] # 接收人id |
|
|
other_user_id = msg['User']['UserName'] # 对手方id |
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
other_user_id = msg['User']['UserName'] # 对手方id |
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
logger.warn("[WX]get other_user_id failed: " + str(e)) |
|
|
|
|
|
if from_user_id == self.userName: |
|
|
|
|
|
other_user_id = to_user_id |
|
|
|
|
|
else: |
|
|
|
|
|
other_user_id = from_user_id |
|
|
create_time = msg['CreateTime'] # 消息时间 |
|
|
create_time = msg['CreateTime'] # 消息时间 |
|
|
match_prefix = check_prefix(content, conf().get('single_chat_prefix')) |
|
|
match_prefix = check_prefix(content, conf().get('single_chat_prefix')) |
|
|
if conf().get('hot_reload') == True and int(create_time) < int(time.time()) - 60: #跳过1分钟前的历史消息 |
|
|
if conf().get('hot_reload') == True and int(create_time) < int(time.time()) - 60: #跳过1分钟前的历史消息 |
|
|