Skip to content

Instantly share code, notes, and snippets.

@youfou
Last active December 27, 2017 03:00
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youfou/e1ccbb4dea75790daaabac2b19ccd802 to your computer and use it in GitHub Desktop.
Save youfou/e1ccbb4dea75790daaabac2b19ccd802 to your computer and use it in GitHub Desktop.
将被撤回的微信消息发送到文件传输助手
from xml.etree import ElementTree as ETree
from wxpy import *
bot = Bot()
# 通过 NOTE 消息找到 bot.messages 中被撤回的消息
# 并转发到机器人的文件传输助手
@bot.register(msg_types=NOTE)
def get_revoked(msg):
# 检查 NOTE 中是否有撤回信息
revoked = ETree.fromstring(msg.raw['Content']).find('revokemsg')
if revoked:
# 根据找到的撤回消息 id 找到 bot.messages 中的原消息
revoked_msg = bot.messages.search(id=int(revoked.find('msgid').text))[0]
# 原发送者 (群聊时为群员)
sender = msg.member or msg.sender
# 把消息转发到文件传输助手
revoked_msg.forward(
bot.file_helper,
prefix='{} 撤回了:'.format(sender.name)
)
embed()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment