MCPcopy
hub / github.com/cluic/wxauto / SendMsg

Method SendMsg

wxauto/elements.py:224–255  ·  view source on GitHub ↗

发送文本消息 Args: msg (str): 要发送的文本消息 at (str|list, optional): 要@的人,可以是一个人或多个人,格式为str或list,例如:"张三"或["张三", "李四"]

(self, msg, at=None)

Source from the content-addressed store, hash-verified

222 self.editbox.SendKeys('{Enter}')
223
224 def SendMsg(self, msg, at=None):
225 """发送文本消息
226
227 Args:
228 msg (str): 要发送的文本消息
229 at (str|list, optional): 要@的人,可以是一个人或多个人,格式为str或list,例如:"张三"或["张三", "李四"]
230 """
231 wxlog.debug(f"发送消息:{self.who} --> {msg}")
232 self._show()
233 if not self.editbox.HasKeyboardFocus:
234 self.editbox.Click(simulateMove=False)
235
236 if at:
237 if isinstance(at, str):
238 at = [at]
239 for i in at:
240 self.editbox.SendKeys('@'+i)
241 atwnd = self.UiaAPI.PaneControl(ClassName='ChatContactMenu')
242 if atwnd.Exists(maxSearchSeconds=0.1):
243 atwnd.SendKeys('{ENTER}')
244 if msg and not msg.startswith('\n'):
245 msg = '\n' + msg
246
247 t0 = time.time()
248 while True:
249 if time.time() - t0 > 10:
250 raise TimeoutError(f'发送消息超时 --> {self.who} - {msg}')
251 SetClipboardText(msg)
252 self.editbox.SendKeys('{Ctrl}v')
253 if self.editbox.GetValuePattern().Value:
254 break
255 self.editbox.SendKeys('{Enter}')
256
257 def SendFiles(self, filepath):
258 """向当前聊天窗口发送文件

Callers 2

AtAllMethod · 0.95
SendMsgMethod · 0.95

Calls 7

_showMethod · 0.95
ClickMethod · 0.80
SendKeysMethod · 0.80
PaneControlMethod · 0.80
ExistsMethod · 0.80
SetClipboardTextFunction · 0.70
GetValuePatternMethod · 0.45

Tested by

no test coverage detected