The monster demo
Unlike all existing demos that emphasizes on one specific side of the customization, this demo tries to incorporate anything that I think useful for a normal bot user. Hence the name, the "monster" demo. It all begins when I was a JavaScript newbie, I felt the most helpful thing is not a 6-line demo code, but a comprehensive one that include all useful features, because newbie like me can't put them together.
This demo is a one-stop demo that includes everything useful for people to get an easier start. Because it is much simpler to remove an module from it, rather than figuring out how to put all these jigsaw puzzles together.
The following are the list of useful features incorporated into this demo:
- Pure ES6 JavaScript code, no Typescript and no need the superficial transpiling step
- All even handling in separated code, instead of everything in a big file
- Can read from a config file
- Can do rooms/messages matching using regexp that are defined in the config file
- Can do hot reload, when the
.jsscripts/files are updated- Hot reload/import even handling code, without restarting the program
- Hot reload/import configuration files as well
- Auto-save all media files, i.e., incorporates
media-file-bot.tsinto this getting started demo - Emoji cleansing -- to simplify emoji from
<img class="qqemoji qqemoji13" text="[呲牙]_web" src="https://wx.qq.com/zh_CN/htmledition/v2/images/spacer.gif" />to merely[呲牙] - Add error handling in
on-message.jsto catch errors instead of failing the program - Graceful exit on
SIGINT/SIGTERMetc, i.e., to write key info into file, on receiving killing signals (e.g.,SIGINT (2), SIGTERM(3)), before termination, so as to do a "graceful shutdown".
All in all, it will be a turn key solution for getting started with wechaty customization seriously, a true blue-print solution for people to get started using wechaty.
Run
docker run -t -i --rm --name wechaty --mount type=bind,source="$(pwd)",target=/bot zixia/wechaty index.js
Or
./run-monster-bot.sh
About hot-import
Hot import Wechaty listenser functions after change the source code without restart the program
This directory is an example of how to use hot-import
feature introduced in this commit.
The hot-import is based on an npm package hot-import
About Pure ES6 instead of Typescript
When I code customization code for wechaty, I write everything in pure ES6 instead of Typescript, and there are strong reasons for that. For details, check out my blog entry,