-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.ts
49 lines (43 loc) · 1.27 KB
/
index.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
import { WechatyBuilder } from 'wechaty'
import { Contact as ContactType } from 'wechaty-puppet/types'
import Qrterminal from 'qrcode-terminal'
import * as Sentry from '@sentry/node'
import * as message from './event/message'
import * as friendShip from './event/friend-ship'
import * as roomJoin from './event/room-join'
import { schedule } from './schedule'
import config from './config'
Sentry.init({
dsn: config.sentryDsn
})
const bot = WechatyBuilder.build({
// name: 'wechat-shanyue',
puppetOptions: {
uos: true, // 开启uos协议
},
puppet: 'wechaty-puppet-wechat',
})
function handleScan(qrcode: string) {
Qrterminal.generate(qrcode, { small: true })
}
bot
.on('scan', handleScan)
.on('room-join', roomJoin.handleRoomJoin)
.on('friendship', friendShip.handleFriendShip)
.on('message', message.handleMessage)
.on('login', () => {
console.log(bot.name(), '登录成功')
setTimeout(() => {
bot.Contact.findAll().then(async (contacts) => {
const friends = contacts.filter(contact => {
return contact.type() === ContactType.Individual
})
console.log('您的好友数量', friends.length)
})
}, 10000)
schedule(bot)
})
.on('error', (error) => {
Sentry.captureException(error)
})
.start()