forked from wechaty/matrix-appservice
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebug-wechaty.js
70 lines (56 loc) · 1.94 KB
/
debug-wechaty.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
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
/*
This script is for debug wechaty dependented in the envirenment of this project.
In my envirenment(x64 centos7 wechaty-puppet-wechat@0.28.1), bot.start() will throw a Error (Error: Could not find expected browser (chrome) locally. Run `npm install` to download the correct Chromium revision (848005)).
It similliar to https://github.com/berstend/puppeteer-extra/issues/471 and
https://stackoverflow.com/questions/53997175/puppeteer-error-chromium-revision-is-not-downloaded.
I avoid it by install chrome and modify memory data, but it should be fixed in futrue.
*/
const dotenv = require('dotenv')
dotenv.config()
const { Wechaty,WechatyOptions } = require('wechaty');
const name = 'wechat-puppet-wechat';
let bot = '';
let puppetOptions={}
if (process.env.WECHATY_PUPPET_PUPPETEER_ENDPOINT){
puppetOptions.endpoint = process.env.WECHATY_PUPPET_PUPPETEER_ENDPOINT
}
console.log()
bot = new Wechaty({
name, // generate xxxx.memory-card.json and save login data for the next login
puppetOptions,
});
// 二维码生成
function onScan(qrcode, status) {
require('qrcode-terminal').generate(qrcode); // 在console端显示二维码
const qrcodeImageUrl = [
'https://wechaty.js.org/qrcode/',
encodeURIComponent(qrcode),
].join('');
console.log(qrcodeImageUrl);
}
// 登录
async function onLogin(user) {
console.log(`贴心小助理${user}登录了`);
// if (config.AUTOREPLY) {
// console.log(`已开启机器人自动聊天模式`);
// }
// 登陆后创建定时任务
// await initDay();
}
//登出
function onLogout(user) {
console.log(`小助手${user} 已经登出`);
}
bot.on('scan', onScan);
bot.on('login', onLogin);
bot.on('logout', onLogout);
// // for my envirenment only, avoid used
// console.log(process.arch); // x64
// Object.defineProperty(process, 'arch', {
// value: 'arm64',
// });
// console.log(process.arch);
bot
.start()
.then(() => console.log('开始登陆微信'))
.catch((e) => console.error(e));