itchat监听微信撤回消息

import itchat
from itchat.content import *
import re
msg_infomation = {}
# 监听发送消息
@itchat.msg_register([TEXT])
def handle_receive_msg(msg):
    print(msg)
    msg_from = itchat.search_friends(userName=msg["FromUserName"])["NickName"]
    print(msg_from)
    # 获取元素中需要的信息
    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
        }
        }
    )
    print(msg_infomation)
# 监听撤回消息
@itchat.msg_register([NOTE])
def infomation(msg):
    print(msg)
    content = msg.get("Content")
    print(content)
    if "撤回了一条消息" in content:
        print(1, content)
        old_msg_id = re.search("<msgid>(.*?)</msgid>", msg["Content"]).group(1)
        print(old_msg_id)
        print(msg_infomation.get(old_msg_id))
# 微信登录操作
itchat.auto_login(hotReload=True)
# 保证程序一直运行
itchat.run()

# 课后作业:把未完成的完成

 

转载于:https://www.cnblogs.com/zhangboblogs/p/10108584.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值