怎么把SentText 改成异步的啊!
Xuzan9396 opened this issue · 3 comments
Xuzan9396 commented
我是通过com注入
class MyWeChatEventSink(wxRobot.WeChatEventSink):
def __init__(self, wxBot: wxRobot.WeChatRobot):
self.wxBot = wxBot
def send_text(self, sender, text): # 我需要改成异步
self.wxBot.SendText(sender, text)
time.sleep(20) # 睡眠5秒
def OnGetMessageEvent(self, msg):
msg = json.loads(msg[0])
print("类型:" + str(type(msg)))
print(msg )
if msg is not None:
print("消息内容:" + str(msg.get('message')))
message = msg.get('message')
if message is None:
return
content = str(message).strip()
sender = msg.get('sender')
isSendMsg = msg.get('isSendMsg')
if isSendMsg is None or isSendMsg == 1:
return
if content != "" and sender == "xxxxx" and isSendMsg == 0:
if self.wxBot is not None:
self.send_text(sender, "hello world")
if __name__ == '__main__':
pid_list = wxRobot.get_wechat_pid_list()
wx = WeChatRobot(pid_list[0])
try:
wx.StartService()
wx.StartReceiveMessage()
eventSink = MyWeChatEventSink(wx)
wxRobot.register_msg_event(pid_list[0],eventSink)
except Exception as e:
print(e)
wx.StopService()
cheungchazz commented
你这个time.sleep(20)就阻塞线程了
Xuzan9396 commented
不是的,我是想异步处理消息,time.sleep(20) 是我模拟业务处理的场景
hd5870m commented
我改过其他人的hook程序,可以实现