forked from padlocal/wechaty-puppet-padlocal-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
82 lines (63 loc) · 2.54 KB
/
main.ts
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import {log, ScanStatus, WechatyBuilder} from "wechaty";
import {PuppetPadlocal} from "wechaty-puppet-padlocal";
import {dingDongBot, getMessagePayload, LOGPRE} from "./helper";
/****************************************
* 去掉注释,可以完全打开调试日志
****************************************/
// log.level("silly");
const puppet = new PuppetPadlocal({
token: ">>>> YOUR_PADLOCAL_TOKEN <<<<"
})
const bot = WechatyBuilder.build({
name: "PadLocalDemo",
puppet,
})
.on("scan", (qrcode, status) => {
if (status === ScanStatus.Waiting && qrcode) {
const qrcodeImageUrl = [
'https://wechaty.js.org/qrcode/',
encodeURIComponent(qrcode),
].join('')
log.info(LOGPRE, `onScan: ${ScanStatus[status]}(${status})`);
console.log("\n==================================================================");
console.log("\n* Two ways to sign on with qr code");
console.log("\n1. Scan following QR code:\n");
require('qrcode-terminal').generate(qrcode, {small: true}) // show qrcode on console
console.log(`\n2. Or open the link in your browser: ${qrcodeImageUrl}`);
console.log("\n==================================================================\n");
} else {
log.info(LOGPRE, `onScan: ${ScanStatus[status]}(${status})`);
}
})
.on("login", (user) => {
log.info(LOGPRE, `${user} login`);
})
.on("logout", (user, reason) => {
log.info(LOGPRE, `${user} logout, reason: ${reason}`);
})
.on("message", async (message) => {
log.info(LOGPRE, `on message: ${message.toString()}`);
await getMessagePayload(message);
await dingDongBot(message);
})
.on("room-invite", async (roomInvitation) => {
log.info(LOGPRE, `on room-invite: ${roomInvitation}`);
})
.on("room-join", (room, inviteeList, inviter, date) => {
log.info(LOGPRE, `on room-join, room:${room}, inviteeList:${inviteeList}, inviter:${inviter}, date:${date}`);
})
.on("room-leave", (room, leaverList, remover, date) => {
log.info(LOGPRE, `on room-leave, room:${room}, leaverList:${leaverList}, remover:${remover}, date:${date}`);
})
.on("room-topic", (room, newTopic, oldTopic, changer, date) => {
log.info(LOGPRE, `on room-topic, room:${room}, newTopic:${newTopic}, oldTopic:${oldTopic}, changer:${changer}, date:${date}`);
})
.on("friendship", (friendship) => {
log.info(LOGPRE, `on friendship: ${friendship}`);
})
.on("error", (error) => {
log.error(LOGPRE, `on error: ${error}`);
})
bot.start().then(() => {
log.info(LOGPRE, "started.");
});