import itchat
from itchat.content import *
import re
msg_infomation = {}
@itchat.msg_register([TEXT])
def handle_receive_msg(msg):
msg_from = itchat.search_friends(userName=msg['FromUserName'])['NickName']
msg_time = msg['CreateTime']
msg_id = msg['MsgId']
msg_content = msg['Text']
msg_infomation.update(
{
msg_id:{
'msg_from':msg_from,
'msg_time':msg_time,
'msg_content':msg_content
}
}
)
#监听撤回消息
#@itchat.msg_register(NOTE,isFriendChat=True,isCroupChat=True,isMpChat=True)
@itchat.msg_register([NOTE])
def information(msg):
if '撤回了一条消息' in msg['Content']:
old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>",msg['Content']).group()#<msgid>XXX<msgid>
print('~~~~~~~~~~~~')
print(msg_infomation.get(old_msg_id))
#二维码微信登录
itchat.auto_login(enableCmdQR=True,hotReload=True)
itchat.run()