-
Notifications
You must be signed in to change notification settings - Fork 36
/
helper.ts
93 lines (62 loc) · 2.64 KB
/
helper.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
83
84
85
86
87
88
89
90
91
92
93
import {log, Message} from "wechaty";
import * as PUPPET from "wechaty-puppet";
export const LOGPRE = "[PadLocalDemo]"
export async function getMessagePayload(message: Message) {
switch (message.type()) {
case PUPPET.types.Message.Text:
log.silly(LOGPRE, `get message text: ${message.text()}`);
break;
case PUPPET.types.Message.Attachment:
case PUPPET.types.Message.Audio: {
const attachFile = await message.toFileBox();
const dataBuffer = await attachFile.toBuffer();
log.info(LOGPRE, `get message audio or attach: ${dataBuffer.length}`);
break;
}
case PUPPET.types.Message.Video: {
const videoFile = await message.toFileBox();
const videoData = await videoFile.toBuffer();
log.info(LOGPRE, `get message video: ${videoData.length}`);
break;
}
case PUPPET.types.Message.Emoticon: {
const emotionFile = await message.toFileBox();
const emotionJSON = emotionFile.toJSON();
log.info(LOGPRE, `get message emotion json: ${JSON.stringify(emotionJSON)}`);
const emotionBuffer: Buffer = await emotionFile.toBuffer();
log.info(LOGPRE, `get message emotion: ${emotionBuffer.length}`);
break;
}
case PUPPET.types.Message.Image: {
const messageImage = await message.toImage();
const thumbImage = await messageImage.thumbnail();
const thumbImageData = await thumbImage.toBuffer();
log.info(LOGPRE, `get message image, thumb: ${thumbImageData.length}`);
const hdImage = await messageImage.hd();
const hdImageData = await hdImage.toBuffer();
log.info(LOGPRE, `get message image, hd: ${hdImageData.length}`);
const artworkImage = await messageImage.artwork();
const artworkImageData = await artworkImage.toBuffer();
log.info(LOGPRE, `get message image, artwork: ${artworkImageData.length}`);
break;
}
case PUPPET.types.Message.Url: {
const urlLink = await message.toUrlLink();
log.info(LOGPRE, `get message url: ${JSON.stringify(urlLink)}`);
const urlThumbImage = await message.toFileBox();
const urlThumbImageData = await urlThumbImage.toBuffer();
log.info(LOGPRE, `get message url thumb: ${urlThumbImageData.length}`);
break;
}
case PUPPET.types.Message.MiniProgram: {
const miniProgram = await message.toMiniProgram();
log.info(LOGPRE, `MiniProgramPayload: ${JSON.stringify(miniProgram)}`);
break;
}
}
}
export async function dingDongBot(message: Message) {
if (message.to()?.self() && message.text().indexOf("ding") !== -1) {
await message.talker().say(message.text().replace("ding", "dong"));
}
}