-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
55 lines (48 loc) · 1.33 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
50
51
52
53
54
55
import { generate } from 'qrcode-terminal';
import { Wechaty, log } from 'wechaty';
import { PuppetPadplus } from 'wechaty-puppet-padplus';
import { name, token } from './config/base';
import { messageListener } from './listener/messageListener';
import { friendshipListener } from './listener/friendship';
import express = require('express');
import bodyParser = require('body-parser');
import { Schedule } from './tools/scheduleTool';
import { CacheTools } from './tools/cacheTool';
const puppet = new PuppetPadplus({
token,
});
export const bot = new Wechaty({
puppet,
name,
});
bot
.on('scan', (qrcode, status) => {
if (status === 0) {
generate(qrcode, {
small: true
})
} else if (status === -2007) {
generate(qrcode, {
small: true
})
}
})
.on('login', user => {
console.info(`Login: ${user}`);
})
.on('message', messageListener)
.on('friendship', friendshipListener)
.start();
export const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
const listener = app.listen(0, async () => {
let address = listener.address();
if (typeof address !== 'string') {
address = JSON.stringify(address);
}
log.info(`Listening on address ${address}`);
})
Schedule.minStart();
CacheTools.initSubscription();
// CacheTools.requestInfo();