mirror of
https://github.com/smallevilbeast/ntchat.git
synced 2025-05-23 05:16:07 +08:00
29 lines
695 B
Python
29 lines
695 B
Python
# -*- coding: utf-8 -*-
|
|
import sys
|
|
import ntchat
|
|
|
|
wechat = ntchat.WeChat()
|
|
|
|
# 打开pc微信, smart: 是否管理已经登录的微信
|
|
wechat.open(smart=False)
|
|
|
|
|
|
# 注册消息回调
|
|
@wechat.msg_register(ntchat.MT_RECV_TEXT_MSG)
|
|
def on_recv_text_msg(wechat_instance: ntchat.WeChat, message):
|
|
data = message["data"]
|
|
from_wxid = data["from_wxid"]
|
|
self_wxid = wechat_instance.get_login_info()["wxid"]
|
|
|
|
# 判断消息不是自己发的,并回复对方
|
|
if from_wxid != self_wxid:
|
|
wechat_instance.send_text(to_wxid=from_wxid, content=f"你发送的消息是: {data['msg']}")
|
|
|
|
|
|
try:
|
|
while True:
|
|
pass
|
|
except KeyboardInterrupt:
|
|
ntchat.exit_()
|
|
sys.exit()
|