-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (37 loc) · 985 Bytes
/
index.js
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
const { WechatyBuilder } = require("wechaty");
const onScan = require("./listener/scan.js");
const onLogin = require("./listener/login.js");
const onMessage = require("./listener/message.js");
const onFriendship = require("./listener/friendship.js");
const onError = require("./listener/error.js");
const bot = WechatyBuilder.build({
name: "ayu",
puppet: "wechaty-puppet-wechat",
puppetOptions: {
uos: true,
},
});
global['ContactSelf'] = null
global['Message'] = null
bot.on("login", async user => {
global['ContactSelf'] = user
onLogin(user, bot);
});
bot.on("message", async msg => {
if (msg.self()) return
global['Message'] = msg
onMessage(msg, bot);
});
bot.on("scan", async (qrcode, status) => {
onScan(qrcode, status);
});
bot.on("friendship", async friendship => {
onFriendship(friendship, bot);
});
bot.on("error", (error) => {
onError(error)
})
bot
.start()
.then(() => console.log("开始登陆微信"))
.catch(e => console.error(e));