python使用 wxpy 簡簡單單實現微信防撤回

2021-09-19 11:42:15 字數 961 閱讀 3614

import re

from wxpy import *

bot = bot(cache_path='xiaohao.pkl')

@bot.register()

def handlereceivemsg(msg):

raw = msg.raw

if raw['status'] == 4:

# 獲取被撤回訊息的id

oldmsgid = re.search(re.compile('(.*?)', re.s), raw['content']).group(1)

for one_msg in bot.messages[::-1]: #從後迴圈所有資訊

if oldmsgid==str(one_msg.id): #此msg就是撤回的資訊

#根據傳送者設定**字首

if one_msg.member:

the_sender='群[%s]中的 @%s '%(one_msg.chat.name,one_msg.member.name)

else:

the_sender=one_msg.chat.name

# 不是名片時,直接用forward**到檔案助手

if one_msg.type!='card':

one_msg.forward(bot.file_helper, prefix='%s\n撤回了一條%s訊息:'%(the_sender,one_msg.type))

else:

card=one_msg.card

name = card.name

if card.*** == 1:

*** = '男'

else:

*** = '女'

bot.file_helper.send('%s\n撤回了一張名片:\n名稱:%s,性別:%s'%(the_sender , name,***))

python的簡單使用 python模組簡單使用

建立你自己的模組是十分簡單的,你一直在這樣做!每個python程式也是乙個模組。你已經確保它具有.py副檔名了。下面這個例子將會使它更加清晰。建立你自己的模組 例8.3 如何建立你自己的模組 usr bin python filename mymodule.py defsayhi print hi,...

python使用wxpy輕鬆實現微信防撤回的方法

最近比較閒就隨便瞎看,看到了微信防撤回就順便跟著學著實現一下 使用的是wxpy,安裝方法pip install wxpy 我使用的是python2.7 這樣實現起來比較快,反正也只是練手 首現看了兩個別人實現的 然後看了看wxpy的文件 萌新,順便鍛鍊下看文件 我實現的 import wxpy im...

Python高階 wxpy學習 異常chu li

若響應中的錯誤碼不為 0,程式將丟擲 responseerror 異常。class wxpy.responseerror err code,err msg 源 當 baseresponse 的返回值不為 0 時丟擲的異常 err code 錯誤碼 int err msg 錯誤訊息 文字 但可能為空捕...