How iwyxdxl/wechatbot_wxauto_se works
Project type and purpose
• This is a monolithic full‑stack Python application implementing an intelligent WeChat chat‑bot with an embedded WebUI.
• It automates WeChat via the Mwxauto library, processes incoming messages through LLMs (GPT, Gemini, etc.), handles reminders, memory, emotion/picture recognition, and exposes a Flask‑based UI for configuration and Prompt management.
File structure
• Top‑level scripts:
• Run.bat – bootstrap & launch
• bot.py – core message loop & automation entrypoint
• config_editor.py – Flask application for editing settings & prompts
• updater.py – self‑update logic
• Key directories:
• Mwxauto/ – Python package wrapping wxauto and related utilities (WeChat automation)
• emojis/ – emotion categories with image assets for replies
• prompts/ – markdown files defining initial Prompt templates
• templates/ – Jinja2 HTML templates for the WebUI (config editor, login, prompt CRUD)
• libs/ – vendored Python wheel dependencies (Flask, OpenAI SDK, SQLAlchemy, etc.)
• Config & data files:
• config.py & version.json & recurring_reminders.json – JSON or Python modules storing settings, scheduled tasks, version info
• Deployment:
• requirements.txt – fallback for pip
• Run.bat – installs deps from libs/ and invokes the bot
README for additional insights
• Describes features (multi‑user/group chat, image & emotion recognition, timed reminders, memory, WebUI, auto‑update).
• Points to original KouriChat repo and licensing.
• Quick‑start instructions reveal a two‑phase launch: WebUI for config → “Start Bot” → automation begins.
a. Main Components
• WeChat Client (Windows)
• Mwxauto Automation Layer (Python package)
• Bot Core
– Message Dispatcher
– Prompt Manager (loads/saves Prompt templates)
– Memory Manager (summarizes chat history)
– Reminder Scheduler
– Emotion/Picture Recognizers (Pillow, OCR)
• LLM & External Services
– GPT/Gemini/DeepSeek API endpoints
– Optional Web Search API
• WebUI (Flask App)
– Config Editor & Prompt CRUD interfaces
• Data Storage
– JSON files (config, reminders, version)
– Markdown folder (prompts)
b. Relationships & Interactions
1. Incoming chat message from WeChat Client → Mwxauto listens via UI automation.
2. Mwxauto forwards event to Bot Core → Bot Core selects Prompt from Prompt Manager → packages input for LLM.
3. Bot Core calls external LLM API → receives text response (or image/emotion result) → Memory Manager may update history → Bot Core instructs Mwxauto to send reply.
4. Reminder Scheduler triggers proactive messages via Bot Core & Mwxauto.
5. WebUI ↔ Bot Core: user edits config & Prompt via HTTP endpoints (Flask). Changes persist to JSON/MD files. Bot periodically reloads.
6. Updater checks remote version → downloads & applies updates.
c. Architectural Patterns
• Layered monolith: presentation (WebUI) / application (Bot Core) / automation (Mwxauto)
• MVC for WebUI (Flask + Jinja2 templates)
• Observer/Event‑Driven for message events and scheduler
d. Technologies & Libraries
• Python 3.9+, Flask & Flask‑CORS, Jinja2
• wxauto (via Mwxauto package) for UI automation
• OpenAI SDK, httpx, requests for API calls
• Pillow for image processing
• SQLAlchemy (if DB used) or file‑based storage
• asyncio/anyio for concurrency
Key points to capture
• Clearly distinguish the automation layer (Mwxauto) from the Bot logic.
• Both reactive (message→reply) and proactive (scheduled reminders) flows.
• WebUI as a sidecar component that modifies runtime behavior via shared storage or direct API.
• Don’t omit the Updater sub‑component checking version.json and downloading code.