Note: This project does not use Hook technology; it simply performs physical copy-paste operations. However, replying too quickly may still pose a risk of being banned.
This project is a Python-based WeChat automation chatbot. It detects new messages on the WeChat desktop application, extracts user queries, and sends them to an AI chatbot API for responses. The bot replies in real-time, creating a seamless interaction experience.
- 📍 Customizable: Set specific locations for message detection and input.
- 🎨 Color-Based Detection: Detect new messages based on screen pixel colors.
- 🌐 AI Integration: Supports custom AI chatbot API for generating responses.
- 🔄 Automated Replies: Automatically replies to tagged messages with AI responses.
- Python 3.8+
- Required Python packages:
pyautogui
requests
pyperclip
pillow
Install dependencies:
pip install -r requirements.txt
- Clone this repository:
git clone https://github.com/li-yang-cn/wechat-ai-chatbot.git cd wechat-ai-chatbot
- Edit the configuration in the script:
- Set
AI_URL
to your chatbot API endpoint. - Adjust color settings for your WeChat theme.
- Set
- Run the script:
python wechat_bot.py
- Follow on-screen instructions to select message and input box locations.
- Let the bot handle messages tagged with
@Libot
.
- Ensure WeChat is open on your desktop and configured in the foreground.
- Use with appropriate permissions and AI API credentials.
This project is open-source and licensed under the MIT License.
你是一名python编程专家,请帮我实现一个微信自动聊天机器人。需要的功能如下:
1. 通过监控屏幕的特定区域,检测聊天框固定位置的颜色(白色为有消息,灰色为空白),来判断是不是收到了新的消息。如果收到了新的消息,就又击复制。
2. python脚本检测是不是新的内容,并且是不是以“@Libot”开头,如果是,则调用LLM聊天机器人的URL来获取到响应,放到剪贴板。
3. 得到响应之后,点击聊天框的位置粘贴并回车发送。发送后清空剪贴板并继续循环监控。
程序设计的函数如下:
1. funtion select_location()。
读取屏幕坐标。通过用户点击光标来实现检测位置的标记。return点坐标。
2. function detect_color(location)
输入屏幕坐标,返回此处像素点的颜色。
3. function call_ai(url,question)
输入URL和问题,调用URL得到响应。return响应的文本。添加异常处理机制,如果调用失败,return对应的错误信息文本。
4. function copy_question(location)
前往location(x,y)的位置,点击鼠标右键,光标移动x+3,y-3再点击左键来实现复制。
5. function paste_answer(answer)
光标点击输入框,点击回车,发送消息。
6. 主函数
配置环境变量到代码中。包括AI_URL,消息白色的RGB,空白灰色的RGB,获取消息的间隔。
初始化时配置读取监控问题的坐标点,输入框的坐标点。
每隔1秒获取消息位置的颜色detect_color(location),判断是否有变化,如果有变化,则copy_question(location)。检查上一个问题是否相同,如果相同则循环监控;如果不同,则try function call_ai(url,question),得到answer之后,paste_answer(answer)。然后循环监控。
请帮我先实现框架,再实现详细的代码设计。
我要把这个项目发布到Github上,请帮我实现中英文双语的README.MD文档。