-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwechat.py
More file actions
49 lines (41 loc) · 1.25 KB
/
wechat.py
File metadata and controls
49 lines (41 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from time import sleep
import pyperclip
import pyperclipimg
from mcp.server.fastmcp import FastMCP
import pyautogui
# Create an MCP server
mcp = FastMCP("微信助手")
pyautogui.PAUSE = 0.05
@mcp.tool()
def open_wechat() -> None:
"""打开微信"""
pyautogui.hotkey('command', 'space', interval=0.1)
pyperclip.copy('微信')
pyautogui.hotkey('command', 'v')
pyautogui.press('enter')
@mcp.tool()
def search_friend(name: str) -> None:
"""搜索好友, 需要先打开微信"""
pyautogui.hotkey('command', 'f')
pyperclip.copy(name)
pyautogui.hotkey('command', 'v')
sleep(0.5)
pyautogui.press('enter')
# 如果当前已经在聊天窗口, 则需要切屏才能定位光标
pyautogui.hotkey('command', 'tab')
pyautogui.hotkey('command', 'tab')
@mcp.tool()
def send_message(message: str) -> None:
"""发送消息, 需要先搜索好友"""
pyperclip.copy(message)
pyautogui.hotkey('command', 'v')
pyautogui.press('enter')
@mcp.tool()
def send_image(image_path: str) -> None:
"""发送图片, 需要先搜索好友"""
# 将图片内容复制到剪贴板
pyperclipimg.copy(image_path)
pyautogui.hotkey('command', 'v')
pyautogui.press('enter')
if __name__ == "__main__":
mcp.run()