mirai-js 2.8.3 → 2.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/1.mp3 +0 -0
- package/README.md +2 -0
- package/demo.ts +3 -6
- package/dist/browser/mirai-js.js +1 -1
- package/dist/node/borwserEntry.js +21 -0
- package/dist/node/core/uploadVoice.js +1 -1
- package/dist/node/lib/index.ts +0 -0
- package/index.ts +36 -3
- package/package.json +1 -1
- package/src/borwserEntry.js +11 -0
- package/src/core/uploadVoice.js +1 -1
- package/src/lib/index.ts +0 -0
- package/srcold/BaseType.d.ts +419 -0
- package/srcold/Bot.d.ts +567 -0
- package/srcold/Bot.js +1208 -0
- package/srcold/FileManager.js +270 -0
- package/srcold/Message.d.ts +66 -0
- package/srcold/Message.js +314 -0
- package/srcold/Middleware.d.ts +170 -0
- package/srcold/Middleware.js +657 -0
- package/srcold/Waiter.d.ts +13 -0
- package/srcold/Waiter.js +24 -0
- package/srcold/core/anno/deleteAnno.js +43 -0
- package/srcold/core/anno/getAnno.js +44 -0
- package/srcold/core/anno/publishAnno.js +44 -0
- package/srcold/core/auth.js +40 -0
- package/srcold/core/fs/deleteGroupFile.js +45 -0
- package/srcold/core/fs/getGroupFileInfo.js +46 -0
- package/srcold/core/fs/getGroupFileList.js +47 -0
- package/srcold/core/fs/makeGroupDir.js +45 -0
- package/srcold/core/fs/moveGroupFile.js +47 -0
- package/srcold/core/fs/renameGroupFile.js +44 -0
- package/srcold/core/fs/uploadGroupFIle.js +58 -0
- package/srcold/core/getFriendList.js +37 -0
- package/srcold/core/getGroupConfig.js +37 -0
- package/srcold/core/getGroupList.js +37 -0
- package/srcold/core/getMemberInfo.js +41 -0
- package/srcold/core/getMemberList.js +49 -0
- package/srcold/core/getSessionConfig.js +39 -0
- package/srcold/core/getUserProfile.js +40 -0
- package/srcold/core/messageFromId.js +40 -0
- package/srcold/core/mute.js +41 -0
- package/srcold/core/muteAll.js +39 -0
- package/srcold/core/quitGroup.js +40 -0
- package/srcold/core/recall.js +39 -0
- package/srcold/core/releaseSession.js +41 -0
- package/srcold/core/removeFriend.js +40 -0
- package/srcold/core/removeMember.js +42 -0
- package/srcold/core/responseBotInvitedJoinGroupRequest.js +46 -0
- package/srcold/core/responseFirendRequest.js +45 -0
- package/srcold/core/responseMemberJoinRequest.js +47 -0
- package/srcold/core/sendCommand.js +41 -0
- package/srcold/core/sendFriendMessage.js +43 -0
- package/srcold/core/sendGroupMessage.js +43 -0
- package/srcold/core/sendImageMessage.js +4 -0
- package/srcold/core/sendNudge.js +43 -0
- package/srcold/core/sendTempMessage.js +55 -0
- package/srcold/core/setEssence.js +44 -0
- package/srcold/core/setGroupConfig.js +58 -0
- package/srcold/core/setMemberAdmin.js +44 -0
- package/srcold/core/setMemberInfo.js +48 -0
- package/srcold/core/setSessionConfig.js +41 -0
- package/srcold/core/startListeningBrowser.js +62 -0
- package/srcold/core/startListeningNode.js +74 -0
- package/srcold/core/stopListeningBrowser.js +34 -0
- package/srcold/core/stopListeningNode.js +34 -0
- package/srcold/core/unmute.js +40 -0
- package/srcold/core/unmuteAll.js +39 -0
- package/srcold/core/uploadImage.js +55 -0
- package/srcold/core/uploadVoice.js +54 -0
- package/srcold/core/verify.js +41 -0
- package/srcold/index.d.ts +10 -0
- package/srcold/index.js +21 -0
- package/srcold/interface.js +20 -0
- package/srcold/polyfill/URL.js +5 -0
- package/srcold/polyfill/wsListener.js +6 -0
- package/srcold/typeHelpers.d.ts +2 -0
- package/srcold/util/errCode.js +23 -0
- package/srcold/util/errorHandler.js +24 -0
- package/srcold/util/getInvalidParamsString.js +12 -0
- package/srcold/util/isBrowserEnv.js +3 -0
- package/srcold/util/random.js +6 -0
- package/webpack.config.js +3 -2
@@ -0,0 +1,270 @@
|
|
1
|
+
const { isBrowserEnv } = require('./util/isBrowserEnv');
|
2
|
+
const fs = isBrowserEnv() ? null : require('fs');
|
3
|
+
const path = isBrowserEnv() ? null : require('path');
|
4
|
+
const { promisify } = isBrowserEnv() ? { promisify: null } : require('util');
|
5
|
+
class FileManager {
|
6
|
+
constructor({ bot, group }) {
|
7
|
+
const baseUrl = bot.getBaseUrl();
|
8
|
+
const sessionKey = bot.sessionKey();
|
9
|
+
// core 柯里化,为内部类 File Directory 提供包装的接口
|
10
|
+
this._getGroupFileList = ({ dir }) => require('./core/fs/getGroupFileList')({
|
11
|
+
baseUrl, sessionKey, target: group, dir
|
12
|
+
});
|
13
|
+
|
14
|
+
this._getGroupFileInfo = ({ id }) => require('./core/fs/getGroupFileInfo')({
|
15
|
+
baseUrl, sessionKey, target: group, id
|
16
|
+
});
|
17
|
+
|
18
|
+
this._uploadFileAndSend = ({ type, path, file }) => require('./core/fs/uploadGroupFIle')({
|
19
|
+
baseUrl, sessionKey, type, target: group, path, file
|
20
|
+
});
|
21
|
+
|
22
|
+
this._groupFileDelete = ({ id }) => require('./core/fs/deleteGroupFile')({
|
23
|
+
baseUrl, sessionKey, target: group, id
|
24
|
+
});
|
25
|
+
|
26
|
+
this._makeGroupDir = ({ dir }) => require('./core/fs/makeGroupDir')({
|
27
|
+
baseUrl, sessionKey, target: group, dir
|
28
|
+
});
|
29
|
+
|
30
|
+
this._groupFileRename = ({ id, rename }) => require('./core/fs/renameGroupFile')({
|
31
|
+
baseUrl, sessionKey, target: group, id, rename
|
32
|
+
});
|
33
|
+
|
34
|
+
this._groupFileMove = ({ id, movePath }) => require('./core/fs/moveGroupFile')({
|
35
|
+
baseUrl, sessionKey, target: group, id, movePath
|
36
|
+
});
|
37
|
+
|
38
|
+
// 外部类实例引用
|
39
|
+
let FileManager_this = this;
|
40
|
+
|
41
|
+
class File {
|
42
|
+
constructor(fileObj) {
|
43
|
+
// 将 GET /groupFileList 与 GET /groupFileInfo 的信息放一起
|
44
|
+
this._details = {
|
45
|
+
name: fileObj?.name,
|
46
|
+
id: fileObj?.id,
|
47
|
+
path: fileObj?.path,
|
48
|
+
isFile: fileObj?.isFile,
|
49
|
+
};
|
50
|
+
|
51
|
+
// 按需请求,延后求值
|
52
|
+
/*{
|
53
|
+
id: undefined,
|
54
|
+
path: undefined,
|
55
|
+
name: undefined,
|
56
|
+
length: undefined,
|
57
|
+
downloadTimes: undefined,
|
58
|
+
uploaderId: undefined,
|
59
|
+
uploadTime: undefined,
|
60
|
+
lastModifyTime: undefined,
|
61
|
+
downloadUrl: undefined,
|
62
|
+
sha1: undefined,
|
63
|
+
md5: undefined,
|
64
|
+
};*/
|
65
|
+
}
|
66
|
+
|
67
|
+
/**
|
68
|
+
* @description 移除该文件
|
69
|
+
* @returns this
|
70
|
+
*/
|
71
|
+
async delete() {
|
72
|
+
await FileManager_this._groupFileDelete({
|
73
|
+
id: this._details.id,
|
74
|
+
});
|
75
|
+
return this;
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* @description 移动文件
|
80
|
+
* @returns this
|
81
|
+
*/
|
82
|
+
async move(path) {
|
83
|
+
if (!path) {
|
84
|
+
throw new Error('Bot.FileManager.File.move 缺少必要的 path 参数');
|
85
|
+
}
|
86
|
+
await FileManager_this._groupFileMove({
|
87
|
+
id: this._details.id,
|
88
|
+
movePath: path,
|
89
|
+
});
|
90
|
+
|
91
|
+
// 更新 fields
|
92
|
+
await this._requestFields();
|
93
|
+
return this;
|
94
|
+
}
|
95
|
+
|
96
|
+
/**
|
97
|
+
* @description 重命名文件
|
98
|
+
* @returns this
|
99
|
+
*/
|
100
|
+
async rename(name) {
|
101
|
+
if (!name) {
|
102
|
+
throw new Error('Bot.FileManager.File.rename 缺少必要的 name 参数');
|
103
|
+
}
|
104
|
+
await FileManager_this._groupFileRename({
|
105
|
+
id: this._details.id,
|
106
|
+
rename: name,
|
107
|
+
});
|
108
|
+
|
109
|
+
// 更新 fields
|
110
|
+
await this._requestFields();
|
111
|
+
return this;
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* @private
|
116
|
+
* @description 请求 file info 并合并对象至 this._details
|
117
|
+
*/
|
118
|
+
async _requestFields() {
|
119
|
+
return Object.assign(this._details, await FileManager_this._getGroupFileInfo({ id: await this.id() }));
|
120
|
+
}
|
121
|
+
|
122
|
+
/**
|
123
|
+
* @private
|
124
|
+
* @description 获取属性的抽象
|
125
|
+
*/
|
126
|
+
async _getField(field) {
|
127
|
+
if (!this._details[field]) {
|
128
|
+
await this._requestFields();
|
129
|
+
}
|
130
|
+
return this._details[field];
|
131
|
+
}
|
132
|
+
|
133
|
+
/**
|
134
|
+
* @description 文件属性
|
135
|
+
*/
|
136
|
+
async allFields() { return await this._requestFields(); }
|
137
|
+
async isDir() { return !(await this._getField('isFile')); }
|
138
|
+
async isFile() { return await this._getField('isFile'); }
|
139
|
+
async name() { return await this._getField('name'); }
|
140
|
+
async path() { return await this._getField('path'); }
|
141
|
+
async id() { return await this._getField('id'); }
|
142
|
+
async length() { return await this._getField('length'); }
|
143
|
+
async downloadTimes() { return await this._getField('downloadTimes'); }
|
144
|
+
async uploaderId() { return await this._getField('uploaderId'); }
|
145
|
+
async uploadTime() { return await this._getField('uploadTime'); }
|
146
|
+
async lastModifyTime() { return await this._getField('lastModifyTime'); }
|
147
|
+
async downloadUrl() { return await this._getField('downloadUrl'); }
|
148
|
+
async sha1() { return await this._getField('sha1'); }
|
149
|
+
async md5() { return await this._getField('md5'); }
|
150
|
+
}
|
151
|
+
|
152
|
+
class Directory {
|
153
|
+
constructor(fileObj) {
|
154
|
+
this._details = {
|
155
|
+
name: fileObj?.name,
|
156
|
+
id: fileObj?.id,
|
157
|
+
path: fileObj?.path,
|
158
|
+
isFile: fileObj?.isFile,
|
159
|
+
};
|
160
|
+
}
|
161
|
+
|
162
|
+
/**
|
163
|
+
* @private
|
164
|
+
* @description 获取属性的抽象
|
165
|
+
*/
|
166
|
+
async _getField(field) {
|
167
|
+
return this._details[field];
|
168
|
+
}
|
169
|
+
|
170
|
+
/**
|
171
|
+
* @description 目录属性
|
172
|
+
*/
|
173
|
+
async allFields() { return await this._details; }
|
174
|
+
async isDir() { return !(await this._getField('isFile')); }
|
175
|
+
async isFile() { return await this._getField('isFile'); }
|
176
|
+
async name() { return await this._getField('name'); }
|
177
|
+
async path() { return await this._getField('path'); }
|
178
|
+
async id() { return await this._getField('id'); }
|
179
|
+
|
180
|
+
/**
|
181
|
+
* @description 获取指定目录下的 文件/目录 数组
|
182
|
+
* @param {string} dir 可选,目录,默认为当前实例指代的目录
|
183
|
+
* @returns
|
184
|
+
*/
|
185
|
+
async getFileList(dir = this._details.path) {
|
186
|
+
return (await FileManager_this._getGroupFileList({ dir })).map(fileObj => FileManager_this._getInstance(fileObj));
|
187
|
+
}
|
188
|
+
|
189
|
+
/**
|
190
|
+
* @description 上传文件至当前实例指代的目录下
|
191
|
+
* @param {Buffer} file 二选一,文件二进制数据
|
192
|
+
* @param {string} filePath 二选一,文件路径
|
193
|
+
* @param {string} filename 可选,文件名,默认为指定路径的文件名
|
194
|
+
*/
|
195
|
+
async upload({ file, filePath, filename }) {
|
196
|
+
// 检查参数
|
197
|
+
if (isBrowserEnv && filePath) {
|
198
|
+
throw new Error('Bot.FileManager.Directory.upload 浏览器端不支持 filePath 参数');
|
199
|
+
}
|
200
|
+
if (!file && !filePath) {
|
201
|
+
throw new Error('Bot.FileManager.Directory.upload 缺少必要的 file 或 filePath 参数');
|
202
|
+
}
|
203
|
+
// 若传入 filename 则统一转换为 Buffer
|
204
|
+
if (filename) {
|
205
|
+
// 优先使用 file 的原值
|
206
|
+
file = file ?? await promisify(fs.readFile)(filename);
|
207
|
+
}
|
208
|
+
await this._uploadFileAndSend({
|
209
|
+
file,
|
210
|
+
type: 'group',
|
211
|
+
path: await this.path() + filename ?? path.parse(filePath).base,
|
212
|
+
});
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
// 内部类引用
|
217
|
+
this.File = File;
|
218
|
+
this.Directory = Directory;
|
219
|
+
}
|
220
|
+
|
221
|
+
/**
|
222
|
+
* @private
|
223
|
+
* @description 工厂方法,返回 File Directory 实例
|
224
|
+
* @param {Object} fileObj
|
225
|
+
* @returns
|
226
|
+
*/
|
227
|
+
_getInstance(fileObj) {
|
228
|
+
if (fileObj?.isFile === true) {
|
229
|
+
return new this.File(fileObj);
|
230
|
+
} else if (fileObj?.isFile === false) {
|
231
|
+
return new this.Directory(fileObj);
|
232
|
+
}
|
233
|
+
return undefined;
|
234
|
+
}
|
235
|
+
|
236
|
+
/**
|
237
|
+
* @description 获取指定目录下的 文件/目录 数组
|
238
|
+
* @param {string} dir 可选,目录,默认为根目录
|
239
|
+
* @returns
|
240
|
+
*/
|
241
|
+
async getFileList(dir) {
|
242
|
+
return (await this._getGroupFileList({ dir })).map(fileObj => this._getInstance(fileObj));
|
243
|
+
}
|
244
|
+
|
245
|
+
/**
|
246
|
+
* @description 上传文件至指定的绝对路径
|
247
|
+
* @param {string} uploadPath 必须,上传的绝对路径
|
248
|
+
* @param {Buffer} file 二选一,文件二进制数据
|
249
|
+
* @param {string} filePath 二选一,文件路径
|
250
|
+
*/
|
251
|
+
async uploadTo({ uploadPath, file, filePath }) {
|
252
|
+
// 检查参数
|
253
|
+
if (isBrowserEnv() && filePath) {
|
254
|
+
throw new Error('Bot.FileManager.uploadTo 浏览器端不支持 filePath 参数');
|
255
|
+
}
|
256
|
+
if (!file && !filePath) {
|
257
|
+
throw new Error('Bot.FileManager.uploadTo 缺少必要的 file 或 filePath 参数');
|
258
|
+
}
|
259
|
+
// 若传入 filename 则统一转换为 Buffer
|
260
|
+
if (filePath) {
|
261
|
+
// 优先使用 file 的原值
|
262
|
+
file = file ?? await promisify(fs.readFile)(filePath);
|
263
|
+
|
264
|
+
}
|
265
|
+
await this._uploadFileAndSend({ type: 'Group', path: uploadPath, file });
|
266
|
+
}
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
module.exports = { FileManager };
|
@@ -0,0 +1,66 @@
|
|
1
|
+
// Message 通过实现 MessageChaingetable 与 Bot.sendMessage 通信
|
2
|
+
// 消息链元素类型和图片 id 类型
|
3
|
+
import { MessageChainGetable, MessageType, ImageId, FaceType, MessageId, ForwardNode, } from './BaseType';
|
4
|
+
|
5
|
+
// Bot.sendMessage 的 message 参数是一个 Message 类型的实例
|
6
|
+
// 方法内部通过 getMessageChainable 接口的 getMessageChain 方法拿到消息链
|
7
|
+
export class Message implements MessageChainGetable {
|
8
|
+
private messageChain: MessageType[];
|
9
|
+
|
10
|
+
// Plain
|
11
|
+
addText(text: string): Message;
|
12
|
+
addPlain(text: string): Message;
|
13
|
+
|
14
|
+
// At
|
15
|
+
addAt(target: number): Message;
|
16
|
+
addAtAll(): Message;
|
17
|
+
|
18
|
+
// Image
|
19
|
+
addImageId(imageId: ImageId): Message;
|
20
|
+
addImageUrl(url: string): Message;
|
21
|
+
addImagePath(path: string): Message;
|
22
|
+
|
23
|
+
// FlashImage
|
24
|
+
addFlashImageId(imageId: ImageId): Message;
|
25
|
+
addFlashImageUrl(url: string): Message;
|
26
|
+
addFlashImagePath(path: string): Message;
|
27
|
+
|
28
|
+
// Voice
|
29
|
+
addVoiceId(imageId: ImageId): Message;
|
30
|
+
addVoiceUrl(url: string): Message;
|
31
|
+
addVoicePath(path: string): Message;
|
32
|
+
|
33
|
+
// xml
|
34
|
+
addXml(xml: string): Message;
|
35
|
+
|
36
|
+
// json
|
37
|
+
addJson(json: string): Message;
|
38
|
+
|
39
|
+
// app
|
40
|
+
addApp(content: string): Message;
|
41
|
+
|
42
|
+
// face
|
43
|
+
addFace(name: FaceType): Message;
|
44
|
+
|
45
|
+
// implements MessageChainGetable
|
46
|
+
getMessageChain(): MessageType[];
|
47
|
+
|
48
|
+
// factory
|
49
|
+
static createForwardMessage(): ForwardMessage;
|
50
|
+
}
|
51
|
+
|
52
|
+
export class ForwardMessage implements MessageChainGetable {
|
53
|
+
constructor(nodeList: ForwardNode[]);
|
54
|
+
private messageChain: MessageType[];
|
55
|
+
|
56
|
+
addForwardNode({
|
57
|
+
senderId,
|
58
|
+
time,
|
59
|
+
senderName,
|
60
|
+
messageChain
|
61
|
+
}: ForwardNode): this;
|
62
|
+
addForwardNode(messageId: MessageId): this;
|
63
|
+
|
64
|
+
// implements MessageChainGetable
|
65
|
+
getMessageChain(): MessageType[];
|
66
|
+
}
|
@@ -0,0 +1,314 @@
|
|
1
|
+
// 用于与 Bot.sendMessage 耦合的接口
|
2
|
+
const { MessageChainGetable } = require('./interface');
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @description http 接口需要的消息类型
|
6
|
+
*/
|
7
|
+
class MessageType {
|
8
|
+
constructor({ type }) {
|
9
|
+
this.type = type;
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
|
14
|
+
class Plain extends MessageType {
|
15
|
+
constructor({ text }) {
|
16
|
+
super({ type: 'Plain' });
|
17
|
+
this.text = text;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
class Text extends MessageType {
|
22
|
+
constructor({ text }) {
|
23
|
+
super({ type: 'Plain' });
|
24
|
+
this.text = text;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
class At extends MessageType {
|
29
|
+
constructor({ target, display }) {
|
30
|
+
super({ type: 'At' });
|
31
|
+
this.target = target;
|
32
|
+
|
33
|
+
// ? 不太清楚这个字段是干啥的
|
34
|
+
this.display = display;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
class AtAll extends MessageType {
|
39
|
+
constructor() {
|
40
|
+
super({ type: 'AtAll' });
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
class Image extends MessageType {
|
45
|
+
constructor({ imageId, url, path }) {
|
46
|
+
super({ type: 'Image' });
|
47
|
+
this.imageId = imageId;
|
48
|
+
this.url = url;
|
49
|
+
|
50
|
+
// 图片路径相对于 mirai-console
|
51
|
+
// 的 plugins/MiraiAPIHTTP/images
|
52
|
+
this.path = path;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
class FlashImage extends MessageType {
|
57
|
+
constructor({ imageId, url, path }) {
|
58
|
+
super({ type: 'FlashImage' });
|
59
|
+
this.imageId = imageId;
|
60
|
+
this.url = url;
|
61
|
+
|
62
|
+
// 图片路径相对于 mirai-console
|
63
|
+
// 的 plugins/MiraiAPIHTTP/images
|
64
|
+
this.path = path;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
class Voice extends MessageType {
|
69
|
+
constructor({ voiceId, url, path }) {
|
70
|
+
super({ type: 'Voice' });
|
71
|
+
this.voiceId = voiceId;
|
72
|
+
this.url = url;
|
73
|
+
|
74
|
+
// 语音路径相对于 mirai-console
|
75
|
+
// 的 plugins/MiraiAPIHTTP/voices
|
76
|
+
this.path = path;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
class Xml extends MessageType {
|
81
|
+
constructor({ xml }) {
|
82
|
+
super({ type: 'Xml' });
|
83
|
+
this.xml = xml;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
class Json extends MessageType {
|
88
|
+
constructor({ json }) {
|
89
|
+
super({ type: 'Json' });
|
90
|
+
this.json = json;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
class App extends MessageType {
|
95
|
+
constructor({ content }) {
|
96
|
+
super({ type: 'App' });
|
97
|
+
this.content = content;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
class ForwardNodeList extends MessageType {
|
102
|
+
constructor({ nodeList }) {
|
103
|
+
super({ type: 'Forward' });
|
104
|
+
this.nodeList = nodeList;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
const faceMap = new Map([
|
109
|
+
['惊讶', 0], ['撇嘴', 1], ['色', 2], ['发呆', 3], ['得意', 4],
|
110
|
+
['流泪', 5], ['害羞', 6], ['闭嘴', 7], ['睡', 8], ['大哭', 9],
|
111
|
+
['尴尬', 10], ['发怒', 11], ['调皮', 12], ['呲牙', 13], ['微笑', 14],
|
112
|
+
['难过', 15], ['酷', 16], ['抓狂', 18], ['吐', 19], ['偷笑', 20],
|
113
|
+
['可爱', 21], ['白眼', 22], ['傲慢', 23], ['饥饿', 24], ['困', 25],
|
114
|
+
['惊恐', 26], ['流汗', 27], ['憨笑', 28], ['悠闲', 29], ['奋斗', 30],
|
115
|
+
['咒骂', 31], ['疑问', 32], ['嘘', 33], ['晕', 34], ['折磨', 35],
|
116
|
+
['衰', 36], ['骷髅', 37], ['敲打', 38], ['再见', 39], ['发抖', 41],
|
117
|
+
['爱情', 42], ['跳跳', 43], ['猪头', 46], ['拥抱', 49], ['蛋糕', 53],
|
118
|
+
['闪电', 54], ['炸弹', 55], ['刀', 56], ['足球', 57], ['便便', 59],
|
119
|
+
['咖啡', 60], ['饭', 61], ['玫瑰', 63], ['凋谢', 64], ['爱心', 66],
|
120
|
+
['心碎', 67], ['礼物', 69], ['太阳', 74], ['月亮', 75], ['赞', 76],
|
121
|
+
['踩', 77], ['握手', 78], ['胜利', 79], ['飞吻', 85], ['怄火', 86],
|
122
|
+
['西瓜', 89], ['冷汗', 96], ['擦汗', 97], ['抠鼻', 98], ['鼓掌', 99],
|
123
|
+
['糗大了', 100], ['坏笑', 101], ['左哼哼', 102], ['右哼哼', 103], ['哈欠', 104],
|
124
|
+
['鄙视', 105], ['委屈', 106], ['快哭了', 107], ['阴险', 108], ['左亲亲', 109],
|
125
|
+
['吓', 110], ['可怜', 111], ['菜刀', 112], ['啤酒', 113], ['篮球', 114],
|
126
|
+
['乒乓', 115], ['示爱', 116], ['瓢虫', 117], ['抱拳', 118], ['勾引', 119],
|
127
|
+
['拳头', 120], ['差劲', 121], ['爱你', 122], ['不', 123], ['好', 124],
|
128
|
+
['转圈', 125], ['磕头', 126], ['回头', 127], ['跳绳', 128], ['挥手', 129],
|
129
|
+
['激动', 130], ['街舞', 131], ['献吻', 132], ['左太极', 133], ['右太极', 134],
|
130
|
+
['双喜', 136], ['鞭炮', 137], ['灯笼', 138], ['K歌', 140], ['喝彩', 144],
|
131
|
+
['祈祷', 145], ['爆筋', 146], ['棒棒糖', 147], ['喝奶', 148], ['飞机', 151],
|
132
|
+
['钞票', 158], ['药', 168], ['手枪', 169], ['茶', 171], ['眨眼睛', 172],
|
133
|
+
['泪奔', 173], ['无奈', 174], ['卖萌', 175], ['小纠结', 176], ['喷血', 177],
|
134
|
+
['斜眼笑', 178], ['doge', 179], ['惊喜', 180], ['骚扰', 181], ['笑哭', 182],
|
135
|
+
['我最美', 183], ['河蟹', 184], ['羊驼', 185], ['幽灵', 187], ['蛋', 188],
|
136
|
+
['菊花', 190], ['红包', 192], ['大笑', 193], ['不开心', 194], ['冷漠', 197],
|
137
|
+
['呃', 198], ['好棒', 199], ['拜托', 200], ['点赞', 201], ['无聊', 202],
|
138
|
+
['托脸', 203], ['吃', 204], ['送花', 205], ['害怕', 206], ['花痴', 207],
|
139
|
+
['小样儿', 208], ['飙泪', 210], ['我不看', 211], ['托腮', 212], ['啵啵', 214],
|
140
|
+
['糊脸', 215], ['拍头', 216], ['扯一扯', 217], ['舔一舔', 218], ['蹭一蹭', 219],
|
141
|
+
['拽炸天', 220], ['顶呱呱', 221], ['抱抱', 222], ['暴击', 223], ['开枪', 224],
|
142
|
+
['撩一撩', 225], ['拍桌', 226], ['拍手', 227], ['恭喜', 228], ['干杯', 229],
|
143
|
+
['嘲讽', 230], ['哼', 231], ['佛系', 232], ['掐一掐', 233], ['惊呆', 234],
|
144
|
+
['颤抖', 235], ['啃头', 236], ['偷看', 237], ['扇脸', 238], ['原谅', 239],
|
145
|
+
['喷脸', 240], ['生日快乐', 241], ['头撞击', 242], ['甩头', 243], ['扔狗', 244],
|
146
|
+
['加油必胜', 245], ['加油抱抱', 246], ['口罩护体', 247], ['搬砖中', 260], ['忙到飞起', 261],
|
147
|
+
['脑阔疼', 262], ['沧桑', 263], ['捂脸', 264], ['辣眼睛', 265], ['哦哟', 266],
|
148
|
+
['头秃', 267], ['问号脸', 268], ['暗中观察', 269], ['emm', 270], ['吃瓜', 271],
|
149
|
+
['呵呵哒', 272], ['我酸了', 273], ['太南了', 274], ['辣椒酱', 276], ['汪汪', 277],
|
150
|
+
['汗', 278], ['打脸', 279], ['击掌', 280], ['无眼笑', 281], ['敬礼', 282],
|
151
|
+
['狂笑', 283], ['面无表情', 284], ['摸鱼', 285], ['魔鬼笑', 286], ['哦', 287],
|
152
|
+
['请', 288], ['睁眼', 289], ['敲开心', 290], ['震惊', 291], ['让我康康', 292],
|
153
|
+
['摸锦鲤', 293], ['期待', 294], ['拿到红包', 295], ['真好', 296], ['拜谢', 297],
|
154
|
+
['元宝', 298], ['牛啊', 299], ['胖三斤', 300], ['好闪', 301], ['左拜年', 302],
|
155
|
+
['右拜年', 303], ['红包包', 304], ['右亲亲', 305], ['牛气冲天', 306], ['喵喵', 307],
|
156
|
+
['求红包', 308], ['谢红包', 309], ['新年烟花', 310], ['打call', 311], ['变形', 312],
|
157
|
+
['嗑到了', 313], ['仔细分析', 314], ['加油', 315], ['我没事', 316], ['菜狗', 317],
|
158
|
+
['崇拜', 318], ['比心', 319], ['庆祝', 320], ['老色痞', 321], ['拒绝', 322],
|
159
|
+
['嫌弃', 323], ['吃糖', 324]
|
160
|
+
]);
|
161
|
+
|
162
|
+
class Face extends MessageType {
|
163
|
+
constructor({
|
164
|
+
faceId,
|
165
|
+
name
|
166
|
+
}) {
|
167
|
+
super({
|
168
|
+
type: 'Face'
|
169
|
+
});
|
170
|
+
this.faceId = faceId;
|
171
|
+
this.name = name;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
/**
|
177
|
+
* @description 本框架抽象的消息类型
|
178
|
+
*/
|
179
|
+
class Message extends MessageChainGetable {
|
180
|
+
constructor() {
|
181
|
+
super();
|
182
|
+
this.messageChain = [];
|
183
|
+
}
|
184
|
+
|
185
|
+
// 文本
|
186
|
+
addText(text) {
|
187
|
+
this.messageChain.push(new Text({ text }));
|
188
|
+
return this;
|
189
|
+
}
|
190
|
+
addPlain(text) {
|
191
|
+
this.messageChain.push(new Plain({ text }));
|
192
|
+
return this;
|
193
|
+
}
|
194
|
+
|
195
|
+
// At@
|
196
|
+
addAt(target) {
|
197
|
+
this.messageChain.push(new At({ target }));
|
198
|
+
return this;
|
199
|
+
}
|
200
|
+
addAtAll() {
|
201
|
+
this.messageChain.push(new AtAll());
|
202
|
+
return this;
|
203
|
+
}
|
204
|
+
|
205
|
+
// 图片
|
206
|
+
addImageId(imageId) {
|
207
|
+
this.messageChain.push(new Image({ imageId }));
|
208
|
+
return this;
|
209
|
+
}
|
210
|
+
addImageUrl(url) {
|
211
|
+
this.messageChain.push(new Image({ url }));
|
212
|
+
return this;
|
213
|
+
}
|
214
|
+
addImagePath(path) {
|
215
|
+
this.messageChain.push(new Image({ path }));
|
216
|
+
return this;
|
217
|
+
}
|
218
|
+
|
219
|
+
// 闪照
|
220
|
+
addFlashImageId(imageId) {
|
221
|
+
this.messageChain.push(new FlashImage({ imageId }));
|
222
|
+
return this;
|
223
|
+
}
|
224
|
+
addFlashImageUrl(url) {
|
225
|
+
this.messageChain.push(new FlashImage({ url }));
|
226
|
+
return this;
|
227
|
+
}
|
228
|
+
addFlashImagePath(path) {
|
229
|
+
this.messageChain.push(new FlashImage({ path }));
|
230
|
+
return this;
|
231
|
+
}
|
232
|
+
|
233
|
+
// 语音
|
234
|
+
addVoiceId(voiceId) {
|
235
|
+
this.messageChain.push(new Voice({ voiceId }));
|
236
|
+
return this;
|
237
|
+
}
|
238
|
+
addVoiceUrl(url) {
|
239
|
+
this.messageChain.push(new Voice({ url }));
|
240
|
+
return this;
|
241
|
+
}
|
242
|
+
addVoicePath(path) {
|
243
|
+
this.messageChain.push(new Voice({ path }));
|
244
|
+
return this;
|
245
|
+
}
|
246
|
+
|
247
|
+
// xml
|
248
|
+
addXml(xml) {
|
249
|
+
this.messageChain.push(new Xml({ xml }));
|
250
|
+
return this;
|
251
|
+
}
|
252
|
+
|
253
|
+
// json
|
254
|
+
addJson(json) {
|
255
|
+
this.messageChain.push(new Json({ json }));
|
256
|
+
return this;
|
257
|
+
}
|
258
|
+
|
259
|
+
// app
|
260
|
+
addApp(content) {
|
261
|
+
this.messageChain.push(new App({ content }));
|
262
|
+
return this;
|
263
|
+
}
|
264
|
+
|
265
|
+
// face
|
266
|
+
addFace(name) {
|
267
|
+
const idx = faceMap.get(name);
|
268
|
+
if (idx) {
|
269
|
+
this.messageChain.push(new Face(
|
270
|
+
{ faceId: idx, name }
|
271
|
+
));
|
272
|
+
}
|
273
|
+
return this;
|
274
|
+
}
|
275
|
+
|
276
|
+
// get 原接口格式的信息链
|
277
|
+
getMessageChain() {
|
278
|
+
return this.messageChain;
|
279
|
+
}
|
280
|
+
|
281
|
+
static createForwardMessage() {
|
282
|
+
return new ForwardMessage();
|
283
|
+
}
|
284
|
+
}
|
285
|
+
|
286
|
+
class ForwardMessage extends MessageChainGetable {
|
287
|
+
constructor() {
|
288
|
+
super();
|
289
|
+
this.messageChain = [];
|
290
|
+
this.nodeList = [];
|
291
|
+
}
|
292
|
+
|
293
|
+
addForwardNode(nodeOrId) {
|
294
|
+
if (typeof nodeOrId === 'number') {
|
295
|
+
this.nodeList.push({
|
296
|
+
messageId: nodeOrId
|
297
|
+
});
|
298
|
+
} else if (typeof nodeOrId == 'object') {
|
299
|
+
if (nodeOrId.messageChain instanceof MessageChainGetable) {
|
300
|
+
nodeOrId.messageChain = nodeOrId.messageChain.getMessageChain();
|
301
|
+
}
|
302
|
+
this.nodeList.push(nodeOrId);
|
303
|
+
} /* else ignore */
|
304
|
+
return this;
|
305
|
+
}
|
306
|
+
|
307
|
+
// implements MessageChainGetable
|
308
|
+
getMessageChain() {
|
309
|
+
this.messageChain.push(new ForwardNodeList({ nodeList: this.nodeList }));
|
310
|
+
return this.messageChain;
|
311
|
+
}
|
312
|
+
}
|
313
|
+
|
314
|
+
module.exports = { Message };
|