新增添加群成员为好友接口

This commit is contained in:
evilbeast
2022-08-27 11:36:07 +08:00
parent c261a9bdf5
commit 0cd080dcaf
13 changed files with 236 additions and 107 deletions
+32
View File
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
import sys
import time
import ntchat
wechat = ntchat.WeChat()
# 打开pc微信, smart: 是否管理已经登录的微信
wechat.open(smart=True)
# 注册消息回调
@wechat.msg_register(ntchat.MT_RECV_PICTURE_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"]
room_wxid = data["room_wxid"]
# 判断消息不是自己发的并且不是群消息时,回复对方
if from_wxid != self_wxid and not room_wxid:
time.sleep(3)
wechat_instance.send_image(to_wxid=from_wxid, file_path=data["image"])
# 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码
try:
while True:
time.sleep(0.5)
except KeyboardInterrupt:
ntchat.exit_()
sys.exit()
-1
View File
@@ -6,7 +6,6 @@ import ntchat
wechat = ntchat.WeChat()
# 打开pc微信, smart: 是否管理已经登录的微信
wechat.open(smart=True)
+2
View File
@@ -25,6 +25,8 @@ class NtChatWindow(XWindow):
def on_btn_open_clicked(self, sender, _):
self.wechat_instance = ntchat.WeChat()
self.wechat_instance.open(smart=True)
# 监听所有通知消息
self.wechat_instance.on(ntchat.MT_ALL, self.on_recv_message)
def on_btn_send_clicked(self, sender, _):