You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
from wxauto import WeChat |
|
import time |
|
|
|
wx_client = WeChat() |
|
wait = 0.5 |
|
|
|
|
|
def get_user_message(name, keyword=None): |
|
wx_client.ChatWith(name) |
|
msgs = wx_client.GetAllMessage() |
|
for msg in msgs: |
|
print(msg) |
|
if keyword in msg: |
|
print(f"找到信息:{msg}") |
|
return msg |
|
|
|
def listen_msg_by_person(keyword=None): |
|
print('准备就绪等待消息...') |
|
while True: |
|
msgs = wx_client.GetListenMessage() |
|
for chat in msgs: |
|
who = chat.who |
|
last_msgs = msgs.get(chat) |
|
for msg in last_msgs: |
|
content = msg.content |
|
print(f'{who}: {content}') |
|
if keyword in content: |
|
print(f"找到信息:{content}") |
|
return content |
|
time.sleep(wait) |
|
|
|
def listen_msg(listen_list=['Honey'], keyword=None): |
|
for person in listen_list: |
|
wx_client.AddListenChat(who=person, savepic=False) |
|
return listen_msg_by_person(keyword) |
|
|
|
|
|
if __name__ == '__main__': |
|
listen_list = ['Honey', '分身199'] |
|
# listen_list = ['Honey'] |
|
# get_user_message('Honey', '玩具乐器五折券') |
|
listen_msg(listen_list, '玩具乐器五折券') |
|
|