mirai-js 2.4.3 → 2.6.1
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/.github/FUNDING.yml +1 -1
- package/README.md +5 -0
- package/demo.js +92 -14
- package/dist/browser/mirai-js.js +1 -1
- package/dist/node/BaseType.d.ts +73 -0
- package/dist/node/Bot.d.ts +2 -2
- package/dist/node/Bot.js +1 -1
- package/dist/node/ForwardNode.d.ts +15 -0
- package/dist/node/ForwardNode.js +70 -0
- package/dist/node/Message.d.ts +24 -2
- package/dist/node/Message.js +82 -1
- package/dist/node/core/sendFriendMessage.js +68 -0
- package/package.json +1 -1
- package/src/BaseType.d.ts +73 -0
- package/src/Bot.d.ts +2 -2
- package/src/Bot.js +1 -1
- package/src/Message.d.ts +24 -2
- package/src/Message.js +118 -1
- package/src/core/{sendFirendMessage.js → sendFriendMessage.js} +0 -0
- package/.github/dependabot.yml +0 -14
package/dist/node/BaseType.d.ts
CHANGED
@@ -40,6 +40,8 @@ interface MessageType {
|
|
40
40
|
// App
|
41
41
|
content?: string;
|
42
42
|
|
43
|
+
// Forward
|
44
|
+
nodeList?: ForwardNode[];
|
43
45
|
}
|
44
46
|
|
45
47
|
// 用于 Bot 获得消息链,Message 使用了该扩展
|
@@ -47,6 +49,17 @@ interface MessageChainGetable {
|
|
47
49
|
getMessageChain(): MessageType[];
|
48
50
|
}
|
49
51
|
|
52
|
+
/**
|
53
|
+
* @description 合并转发类型Forward内消息节点的类型定义
|
54
|
+
*/
|
55
|
+
interface ForwardNode {
|
56
|
+
senderId?: number;
|
57
|
+
time?: number;
|
58
|
+
senderName?: string;
|
59
|
+
messageChain?: MessageType[] | MessageChainGetable;
|
60
|
+
messageId?: MessageId;
|
61
|
+
}
|
62
|
+
|
50
63
|
/**
|
51
64
|
* @description Bot 实现的接口,其他类访问 bot.config
|
52
65
|
* 的途径,避免其他类直接访问实现,用来解耦
|
@@ -104,6 +117,60 @@ type SEX = 'UNKNOWN' | 'MALE' | 'FEMALE'
|
|
104
117
|
// 消息处理器
|
105
118
|
type Processor = (data: any) => Promise<any> | any;
|
106
119
|
|
120
|
+
// QQ 自带表情
|
121
|
+
type FaceType =
|
122
|
+
| '惊讶' | '撇嘴' | '色' | '发呆' | '得意'
|
123
|
+
| '流泪' | '害羞' | '闭嘴' | '睡' | '大哭'
|
124
|
+
| '尴尬' | '发怒' | '调皮' | '呲牙' | '微笑'
|
125
|
+
| '难过' | '酷' | '抓狂' | '吐' | '偷笑'
|
126
|
+
| '可爱' | '白眼' | '傲慢' | '饥饿' | '困'
|
127
|
+
| '惊恐' | '流汗' | '憨笑' | '悠闲' | '奋斗'
|
128
|
+
| '咒骂' | '疑问' | '嘘' | '晕' | '折磨'
|
129
|
+
| '衰' | '骷髅' | '敲打' | '再见' | '发抖'
|
130
|
+
| '爱情' | '跳跳' | '猪头' | '拥抱' | '蛋糕'
|
131
|
+
| '闪电' | '炸弹' | '刀' | '足球' | '便便'
|
132
|
+
| '咖啡' | '饭' | '玫瑰' | '凋谢' | '爱心'
|
133
|
+
| '心碎' | '礼物' | '太阳' | '月亮' | '赞'
|
134
|
+
| '踩' | '握手' | '胜利' | '飞吻' | '怄火'
|
135
|
+
| '西瓜' | '冷汗' | '擦汗' | '抠鼻' | '鼓掌'
|
136
|
+
| '糗大了' | '坏笑' | '左哼哼' | '右哼哼' | '哈欠'
|
137
|
+
| '鄙视' | '委屈' | '快哭了' | '阴险' | '左亲亲'
|
138
|
+
| '吓' | '可怜' | '菜刀' | '啤酒' | '篮球'
|
139
|
+
| '乒乓' | '示爱' | '瓢虫' | '抱拳' | '勾引'
|
140
|
+
| '拳头' | '差劲' | '爱你' | '不' | '好'
|
141
|
+
| '转圈' | '磕头' | '回头' | '跳绳' | '挥手'
|
142
|
+
| '激动' | '街舞' | '献吻' | '左太极' | '右太极'
|
143
|
+
| '双喜' | '鞭炮' | '灯笼' | 'K歌' | '喝彩'
|
144
|
+
| '祈祷' | '爆筋' | '棒棒糖' | '喝奶' | '飞机'
|
145
|
+
| '钞票' | '药' | '手枪' | '茶' | '眨眼睛'
|
146
|
+
| '泪奔' | '无奈' | '卖萌' | '小纠结' | '喷血'
|
147
|
+
| '斜眼笑' | 'doge' | '惊喜' | '骚扰' | '笑哭'
|
148
|
+
| '我最美' | '河蟹' | '羊驼' | '幽灵' | '蛋'
|
149
|
+
| '菊花' | '红包' | '大笑' | '不开心' | '冷漠'
|
150
|
+
| '呃' | '好棒' | '拜托' | '点赞' | '无聊'
|
151
|
+
| '托脸' | '吃' | '送花' | '害怕' | '花痴'
|
152
|
+
| '小样儿' | '飙泪' | '我不看' | '托腮' | '啵啵'
|
153
|
+
| '糊脸' | '拍头' | '扯一扯' | '舔一舔' | '蹭一蹭'
|
154
|
+
| '拽炸天' | '顶呱呱' | '抱抱' | '暴击' | '开枪'
|
155
|
+
| '撩一撩' | '拍桌' | '拍手' | '恭喜' | '干杯'
|
156
|
+
| '嘲讽' | '哼' | '佛系' | '掐一掐' | '惊呆'
|
157
|
+
| '颤抖' | '啃头' | '偷看' | '扇脸' | '原谅'
|
158
|
+
| '喷脸' | '生日快乐' | '头撞击' | '甩头' | '扔狗'
|
159
|
+
| '加油必胜' | '加油抱抱' | '口罩护体' | '搬砖中' | '忙到飞起'
|
160
|
+
| '脑阔疼' | '沧桑' | '捂脸' | '辣眼睛' | '哦哟'
|
161
|
+
| '头秃' | '问号脸' | '暗中观察' | 'emm' | '吃瓜'
|
162
|
+
| '呵呵哒' | '我酸了' | '太南了' | '辣椒酱' | '汪汪'
|
163
|
+
| '汗' | '打脸' | '击掌' | '无眼笑' | '敬礼'
|
164
|
+
| '狂笑' | '面无表情' | '摸鱼' | '魔鬼笑' | '哦'
|
165
|
+
| '请' | '睁眼' | '敲开心' | '震惊' | '让我康康'
|
166
|
+
| '摸锦鲤' | '期待' | '拿到红包' | '真好' | '拜谢'
|
167
|
+
| '元宝' | '牛啊' | '胖三斤' | '好闪' | '左拜年'
|
168
|
+
| '右拜年' | '红包包' | '右亲亲' | '牛气冲天' | '喵喵'
|
169
|
+
| '求红包' | '谢红包' | '新年烟花' | '打call' | '变形'
|
170
|
+
| '嗑到了' | '仔细分析' | '加油' | '我没事' | '菜狗'
|
171
|
+
| '崇拜' | '比心' | '庆祝' | '老色痞' | '拒绝'
|
172
|
+
| '嫌弃' | '吃糖';
|
173
|
+
|
107
174
|
// 消息处理器类型
|
108
175
|
export {
|
109
176
|
// 接口
|
@@ -112,6 +179,9 @@ export {
|
|
112
179
|
// 消息类型
|
113
180
|
MessageType,
|
114
181
|
|
182
|
+
// MessageType.nodeList 的元素类型
|
183
|
+
ForwardNode,
|
184
|
+
|
115
185
|
// 图片 id 语音 id 消息 id
|
116
186
|
ImageId, VoiceId, MessageId,
|
117
187
|
|
@@ -120,4 +190,7 @@ export {
|
|
120
190
|
|
121
191
|
// 消息处理器
|
122
192
|
Processor,
|
193
|
+
|
194
|
+
// QQ 自带表情
|
195
|
+
FaceType
|
123
196
|
};
|
package/dist/node/Bot.d.ts
CHANGED
@@ -55,7 +55,7 @@ export class Bot implements BotConfigGetable {
|
|
55
55
|
* @param keepProcessor 可选,是否保留事件处理器,默认值为 false,不保留
|
56
56
|
* @param keepConfig 可选,是否保留 session baseUrl qq averifyKey,默认值为 false,不保留
|
57
57
|
*/
|
58
|
-
close({ keepProcessor, keepConfig }
|
58
|
+
close({ keepProcessor, keepConfig }?: Bot.CloseOptions): Promise<void>;
|
59
59
|
|
60
60
|
/**
|
61
61
|
* ! messageChain 将在未来被移除
|
@@ -326,7 +326,7 @@ declare namespace Bot {
|
|
326
326
|
baseUrl?: string;
|
327
327
|
verifyKey?: string;
|
328
328
|
qq?: number;
|
329
|
-
singleMode
|
329
|
+
singleMode?: boolean;
|
330
330
|
}
|
331
331
|
|
332
332
|
interface CloseOptions {
|
package/dist/node/Bot.js
CHANGED
@@ -9,7 +9,7 @@ const _bind = require('./core/verify');
|
|
9
9
|
|
10
10
|
const _sendCommand = require('./core/sendCommand');
|
11
11
|
|
12
|
-
const _sendFriendMessage = require('./core/
|
12
|
+
const _sendFriendMessage = require('./core/sendFriendMessage');
|
13
13
|
|
14
14
|
const _sendGroupMessage = require('./core/sendGroupMessage');
|
15
15
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { ForwardNodeGetable, ForwardNodeType, MessageId } from './BaseType';
|
2
|
+
|
3
|
+
// Bot.sendForward 的 nodeList 参数是一个 ForwardNode 类型的实例
|
4
|
+
// 方法内部通过 ForwardNodeType 接口的 getForwardNode 方法拿到消息链
|
5
|
+
export class ForwardNode implements ForwardNodeGetable {
|
6
|
+
private nodeList: ForwardNodeType[];
|
7
|
+
|
8
|
+
// 自行添加一个消息节点
|
9
|
+
addForwardNode(nodeList: ForwardNodeType): ForwardNode;
|
10
|
+
// 使用 MessageId 添加一个消息节点
|
11
|
+
addForwardNodeById(ID: MessageId): ForwardNode;
|
12
|
+
|
13
|
+
// implements ForwardNodeGetable
|
14
|
+
getForwardNode(): ForwardNodeType[];
|
15
|
+
}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
// 用于与 Bot.sendForward 耦合的接口
|
4
|
+
const {
|
5
|
+
ForwardNodeGetable,
|
6
|
+
MessageChainGetable
|
7
|
+
} = require('./interface');
|
8
|
+
|
9
|
+
class ForwardNode_Data {
|
10
|
+
constructor({
|
11
|
+
senderId,
|
12
|
+
time,
|
13
|
+
senderName,
|
14
|
+
messageChain
|
15
|
+
}) {
|
16
|
+
this.senderId = senderId;
|
17
|
+
this.time = time;
|
18
|
+
this.senderName = senderName;
|
19
|
+
this.messageChain = messageChain;
|
20
|
+
}
|
21
|
+
|
22
|
+
}
|
23
|
+
|
24
|
+
class ForwardNode_Id {
|
25
|
+
constructor({
|
26
|
+
messageId
|
27
|
+
}) {
|
28
|
+
this.messageId = messageId;
|
29
|
+
}
|
30
|
+
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* @description 本框架抽象的消息节点
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
class ForwardNode extends ForwardNodeGetable {
|
38
|
+
constructor() {
|
39
|
+
super();
|
40
|
+
this.nodeList = [];
|
41
|
+
} // 手动添加节点
|
42
|
+
|
43
|
+
|
44
|
+
addForwardNode(nodeList) {
|
45
|
+
if (nodeList.messageChain instanceof MessageChainGetable) {
|
46
|
+
nodeList.messageChain = nodeList.messageChain.getMessageChain();
|
47
|
+
}
|
48
|
+
|
49
|
+
this.nodeList.push(new ForwardNode_Data(nodeList));
|
50
|
+
return this;
|
51
|
+
} // 使用 messageId 添加节点
|
52
|
+
|
53
|
+
|
54
|
+
addForwardNodeById(messageId) {
|
55
|
+
this.nodeList.push(new ForwardNode_Id({
|
56
|
+
messageId
|
57
|
+
}));
|
58
|
+
return this;
|
59
|
+
} // get 原接口格式的信息链
|
60
|
+
|
61
|
+
|
62
|
+
getForwardNode() {
|
63
|
+
return this.nodeList;
|
64
|
+
}
|
65
|
+
|
66
|
+
}
|
67
|
+
|
68
|
+
module.exports = {
|
69
|
+
ForwardNode
|
70
|
+
};
|
package/dist/node/Message.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
// Message 通过实现 MessageChaingetable 与 Bot.sendMessage 通信
|
2
2
|
// 消息链元素类型和图片 id 类型
|
3
|
-
import { MessageChainGetable, MessageType, ImageId } from './BaseType';
|
3
|
+
import { MessageChainGetable, MessageType, ImageId, FaceType, MessageId, ForwardNode, } from './BaseType';
|
4
4
|
|
5
5
|
// Bot.sendMessage 的 message 参数是一个 Message 类型的实例
|
6
6
|
// 方法内部通过 getMessageChainable 接口的 getMessageChain 方法拿到消息链
|
@@ -36,9 +36,31 @@ export class Message implements MessageChainGetable {
|
|
36
36
|
// json
|
37
37
|
addJson(json: string): Message;
|
38
38
|
|
39
|
-
//
|
39
|
+
// app
|
40
40
|
addApp(content: string): Message;
|
41
41
|
|
42
|
+
// face
|
43
|
+
addFace(name: FaceType): Message;
|
44
|
+
|
42
45
|
// implements MessageChainGetable
|
43
46
|
getMessageChain(): MessageType[];
|
47
|
+
|
48
|
+
// factory
|
49
|
+
static createForwardMessage(): ForwardMessage;
|
44
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): Message;
|
62
|
+
addForwardNode(messageId: MessageId): ForwardMessage;
|
63
|
+
|
64
|
+
// implements MessageChainGetable
|
65
|
+
getMessageChain(): MessageType[];
|
66
|
+
}
|
package/dist/node/Message.js
CHANGED
@@ -154,9 +154,37 @@ class App extends MessageType {
|
|
154
154
|
this.content = content;
|
155
155
|
}
|
156
156
|
|
157
|
+
}
|
158
|
+
|
159
|
+
class ForwardNodeList extends MessageType {
|
160
|
+
constructor({
|
161
|
+
nodeList
|
162
|
+
}) {
|
163
|
+
super({
|
164
|
+
type: 'Forward'
|
165
|
+
});
|
166
|
+
this.nodeList = nodeList;
|
167
|
+
}
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
const faceMap = new Map([['惊讶', 0], ['撇嘴', 1], ['色', 2], ['发呆', 3], ['得意', 4], ['流泪', 5], ['害羞', 6], ['闭嘴', 7], ['睡', 8], ['大哭', 9], ['尴尬', 10], ['发怒', 11], ['调皮', 12], ['呲牙', 13], ['微笑', 14], ['难过', 15], ['酷', 16], ['抓狂', 18], ['吐', 19], ['偷笑', 20], ['可爱', 21], ['白眼', 22], ['傲慢', 23], ['饥饿', 24], ['困', 25], ['惊恐', 26], ['流汗', 27], ['憨笑', 28], ['悠闲', 29], ['奋斗', 30], ['咒骂', 31], ['疑问', 32], ['嘘', 33], ['晕', 34], ['折磨', 35], ['衰', 36], ['骷髅', 37], ['敲打', 38], ['再见', 39], ['发抖', 41], ['爱情', 42], ['跳跳', 43], ['猪头', 46], ['拥抱', 49], ['蛋糕', 53], ['闪电', 54], ['炸弹', 55], ['刀', 56], ['足球', 57], ['便便', 59], ['咖啡', 60], ['饭', 61], ['玫瑰', 63], ['凋谢', 64], ['爱心', 66], ['心碎', 67], ['礼物', 69], ['太阳', 74], ['月亮', 75], ['赞', 76], ['踩', 77], ['握手', 78], ['胜利', 79], ['飞吻', 85], ['怄火', 86], ['西瓜', 89], ['冷汗', 96], ['擦汗', 97], ['抠鼻', 98], ['鼓掌', 99], ['糗大了', 100], ['坏笑', 101], ['左哼哼', 102], ['右哼哼', 103], ['哈欠', 104], ['鄙视', 105], ['委屈', 106], ['快哭了', 107], ['阴险', 108], ['左亲亲', 109], ['吓', 110], ['可怜', 111], ['菜刀', 112], ['啤酒', 113], ['篮球', 114], ['乒乓', 115], ['示爱', 116], ['瓢虫', 117], ['抱拳', 118], ['勾引', 119], ['拳头', 120], ['差劲', 121], ['爱你', 122], ['不', 123], ['好', 124], ['转圈', 125], ['磕头', 126], ['回头', 127], ['跳绳', 128], ['挥手', 129], ['激动', 130], ['街舞', 131], ['献吻', 132], ['左太极', 133], ['右太极', 134], ['双喜', 136], ['鞭炮', 137], ['灯笼', 138], ['K歌', 140], ['喝彩', 144], ['祈祷', 145], ['爆筋', 146], ['棒棒糖', 147], ['喝奶', 148], ['飞机', 151], ['钞票', 158], ['药', 168], ['手枪', 169], ['茶', 171], ['眨眼睛', 172], ['泪奔', 173], ['无奈', 174], ['卖萌', 175], ['小纠结', 176], ['喷血', 177], ['斜眼笑', 178], ['doge', 179], ['惊喜', 180], ['骚扰', 181], ['笑哭', 182], ['我最美', 183], ['河蟹', 184], ['羊驼', 185], ['幽灵', 187], ['蛋', 188], ['菊花', 190], ['红包', 192], ['大笑', 193], ['不开心', 194], ['冷漠', 197], ['呃', 198], ['好棒', 199], ['拜托', 200], ['点赞', 201], ['无聊', 202], ['托脸', 203], ['吃', 204], ['送花', 205], ['害怕', 206], ['花痴', 207], ['小样儿', 208], ['飙泪', 210], ['我不看', 211], ['托腮', 212], ['啵啵', 214], ['糊脸', 215], ['拍头', 216], ['扯一扯', 217], ['舔一舔', 218], ['蹭一蹭', 219], ['拽炸天', 220], ['顶呱呱', 221], ['抱抱', 222], ['暴击', 223], ['开枪', 224], ['撩一撩', 225], ['拍桌', 226], ['拍手', 227], ['恭喜', 228], ['干杯', 229], ['嘲讽', 230], ['哼', 231], ['佛系', 232], ['掐一掐', 233], ['惊呆', 234], ['颤抖', 235], ['啃头', 236], ['偷看', 237], ['扇脸', 238], ['原谅', 239], ['喷脸', 240], ['生日快乐', 241], ['头撞击', 242], ['甩头', 243], ['扔狗', 244], ['加油必胜', 245], ['加油抱抱', 246], ['口罩护体', 247], ['搬砖中', 260], ['忙到飞起', 261], ['脑阔疼', 262], ['沧桑', 263], ['捂脸', 264], ['辣眼睛', 265], ['哦哟', 266], ['头秃', 267], ['问号脸', 268], ['暗中观察', 269], ['emm', 270], ['吃瓜', 271], ['呵呵哒', 272], ['我酸了', 273], ['太南了', 274], ['辣椒酱', 276], ['汪汪', 277], ['汗', 278], ['打脸', 279], ['击掌', 280], ['无眼笑', 281], ['敬礼', 282], ['狂笑', 283], ['面无表情', 284], ['摸鱼', 285], ['魔鬼笑', 286], ['哦', 287], ['请', 288], ['睁眼', 289], ['敲开心', 290], ['震惊', 291], ['让我康康', 292], ['摸锦鲤', 293], ['期待', 294], ['拿到红包', 295], ['真好', 296], ['拜谢', 297], ['元宝', 298], ['牛啊', 299], ['胖三斤', 300], ['好闪', 301], ['左拜年', 302], ['右拜年', 303], ['红包包', 304], ['右亲亲', 305], ['牛气冲天', 306], ['喵喵', 307], ['求红包', 308], ['谢红包', 309], ['新年烟花', 310], ['打call', 311], ['变形', 312], ['嗑到了', 313], ['仔细分析', 314], ['加油', 315], ['我没事', 316], ['菜狗', 317], ['崇拜', 318], ['比心', 319], ['庆祝', 320], ['老色痞', 321], ['拒绝', 322], ['嫌弃', 323], ['吃糖', 324]]);
|
172
|
+
|
173
|
+
class Face extends MessageType {
|
174
|
+
constructor({
|
175
|
+
faceId,
|
176
|
+
name
|
177
|
+
}) {
|
178
|
+
super({
|
179
|
+
type: 'Face'
|
180
|
+
});
|
181
|
+
this.faceId = faceId;
|
182
|
+
this.name = name;
|
183
|
+
}
|
184
|
+
|
157
185
|
}
|
158
186
|
/**
|
159
|
-
* @description
|
187
|
+
* @description 本框架抽象的消息类型
|
160
188
|
*/
|
161
189
|
|
162
190
|
|
@@ -281,6 +309,20 @@ class Message extends MessageChainGetable {
|
|
281
309
|
this.messageChain.push(new App({
|
282
310
|
content
|
283
311
|
}));
|
312
|
+
return this;
|
313
|
+
} // face
|
314
|
+
|
315
|
+
|
316
|
+
addFace(name) {
|
317
|
+
const idx = faceMap.get(name);
|
318
|
+
|
319
|
+
if (idx) {
|
320
|
+
this.messageChain.push(new Face({
|
321
|
+
faceId: idx,
|
322
|
+
name
|
323
|
+
}));
|
324
|
+
}
|
325
|
+
|
284
326
|
return this;
|
285
327
|
} // get 原接口格式的信息链
|
286
328
|
|
@@ -289,6 +331,45 @@ class Message extends MessageChainGetable {
|
|
289
331
|
return this.messageChain;
|
290
332
|
}
|
291
333
|
|
334
|
+
static createForwardMessage() {
|
335
|
+
return new ForwardMessage();
|
336
|
+
}
|
337
|
+
|
338
|
+
}
|
339
|
+
|
340
|
+
class ForwardMessage extends MessageChainGetable {
|
341
|
+
constructor() {
|
342
|
+
super();
|
343
|
+
this.messageChain = [];
|
344
|
+
this.nodeList = [];
|
345
|
+
}
|
346
|
+
|
347
|
+
addForwardNode(nodeOrId) {
|
348
|
+
if (typeof nodeOrId === 'number') {
|
349
|
+
this.nodeList.push({
|
350
|
+
messageId: nodeOrId
|
351
|
+
});
|
352
|
+
} else if (typeof nodeOrId == 'object') {
|
353
|
+
if (nodeOrId.messageChain instanceof MessageChainGetable) {
|
354
|
+
nodeOrId.messageChain = nodeOrId.messageChain.getMessageChain();
|
355
|
+
}
|
356
|
+
|
357
|
+
this.nodeList.push(nodeOrId);
|
358
|
+
}
|
359
|
+
/* else ignore */
|
360
|
+
|
361
|
+
|
362
|
+
return this;
|
363
|
+
} // implements MessageChainGetable
|
364
|
+
|
365
|
+
|
366
|
+
getMessageChain() {
|
367
|
+
this.messageChain.push(new ForwardNodeList({
|
368
|
+
nodeList: this.nodeList
|
369
|
+
}));
|
370
|
+
return this.messageChain;
|
371
|
+
}
|
372
|
+
|
292
373
|
}
|
293
374
|
|
294
375
|
module.exports = {
|
@@ -0,0 +1,68 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const {
|
4
|
+
errCodeMap
|
5
|
+
} = require('../util/errCode');
|
6
|
+
|
7
|
+
const axios = require('axios').default;
|
8
|
+
|
9
|
+
const {
|
10
|
+
URL
|
11
|
+
} = require('../polyfill/URL');
|
12
|
+
|
13
|
+
const errorHandler = require('../util/errorHandler');
|
14
|
+
|
15
|
+
const path = require('path');
|
16
|
+
|
17
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
18
|
+
/**
|
19
|
+
* @description 向 qq 好友发送消息
|
20
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
21
|
+
* @param {string} sessionKey 会话标识
|
22
|
+
* @param {number} target 目标好友 qq 号
|
23
|
+
* @param {number} quote 消息引用,使用发送时返回的 messageId
|
24
|
+
* @param {MessageType[]} messageChain 消息链,MessageType 数组
|
25
|
+
* @returns {Object} 结构 { message, code, messageId }
|
26
|
+
*/
|
27
|
+
|
28
|
+
module.exports = async ({
|
29
|
+
baseUrl,
|
30
|
+
sessionKey,
|
31
|
+
target,
|
32
|
+
quote,
|
33
|
+
messageChain
|
34
|
+
}) => {
|
35
|
+
try {
|
36
|
+
// 拼接 url
|
37
|
+
const url = new URL('/sendFriendMessage', baseUrl).toString(); // 请求
|
38
|
+
|
39
|
+
const responseData = await axios.post(url, {
|
40
|
+
sessionKey,
|
41
|
+
target,
|
42
|
+
quote,
|
43
|
+
messageChain
|
44
|
+
});
|
45
|
+
|
46
|
+
try {
|
47
|
+
var {
|
48
|
+
data: {
|
49
|
+
msg: message,
|
50
|
+
code,
|
51
|
+
messageId
|
52
|
+
}
|
53
|
+
} = responseData;
|
54
|
+
} catch (error) {
|
55
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
56
|
+
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
57
|
+
|
58
|
+
|
59
|
+
if (code in errCodeMap) {
|
60
|
+
throw new Error(message);
|
61
|
+
}
|
62
|
+
|
63
|
+
return messageId;
|
64
|
+
} catch (error) {
|
65
|
+
console.error(`mirai-js: error ${locationStr}`);
|
66
|
+
errorHandler(error);
|
67
|
+
}
|
68
|
+
};
|
package/package.json
CHANGED
package/src/BaseType.d.ts
CHANGED
@@ -40,6 +40,8 @@ interface MessageType {
|
|
40
40
|
// App
|
41
41
|
content?: string;
|
42
42
|
|
43
|
+
// Forward
|
44
|
+
nodeList?: ForwardNode[];
|
43
45
|
}
|
44
46
|
|
45
47
|
// 用于 Bot 获得消息链,Message 使用了该扩展
|
@@ -47,6 +49,17 @@ interface MessageChainGetable {
|
|
47
49
|
getMessageChain(): MessageType[];
|
48
50
|
}
|
49
51
|
|
52
|
+
/**
|
53
|
+
* @description 合并转发类型Forward内消息节点的类型定义
|
54
|
+
*/
|
55
|
+
interface ForwardNode {
|
56
|
+
senderId?: number;
|
57
|
+
time?: number;
|
58
|
+
senderName?: string;
|
59
|
+
messageChain?: MessageType[] | MessageChainGetable;
|
60
|
+
messageId?: MessageId;
|
61
|
+
}
|
62
|
+
|
50
63
|
/**
|
51
64
|
* @description Bot 实现的接口,其他类访问 bot.config
|
52
65
|
* 的途径,避免其他类直接访问实现,用来解耦
|
@@ -104,6 +117,60 @@ type SEX = 'UNKNOWN' | 'MALE' | 'FEMALE'
|
|
104
117
|
// 消息处理器
|
105
118
|
type Processor = (data: any) => Promise<any> | any;
|
106
119
|
|
120
|
+
// QQ 自带表情
|
121
|
+
type FaceType =
|
122
|
+
| '惊讶' | '撇嘴' | '色' | '发呆' | '得意'
|
123
|
+
| '流泪' | '害羞' | '闭嘴' | '睡' | '大哭'
|
124
|
+
| '尴尬' | '发怒' | '调皮' | '呲牙' | '微笑'
|
125
|
+
| '难过' | '酷' | '抓狂' | '吐' | '偷笑'
|
126
|
+
| '可爱' | '白眼' | '傲慢' | '饥饿' | '困'
|
127
|
+
| '惊恐' | '流汗' | '憨笑' | '悠闲' | '奋斗'
|
128
|
+
| '咒骂' | '疑问' | '嘘' | '晕' | '折磨'
|
129
|
+
| '衰' | '骷髅' | '敲打' | '再见' | '发抖'
|
130
|
+
| '爱情' | '跳跳' | '猪头' | '拥抱' | '蛋糕'
|
131
|
+
| '闪电' | '炸弹' | '刀' | '足球' | '便便'
|
132
|
+
| '咖啡' | '饭' | '玫瑰' | '凋谢' | '爱心'
|
133
|
+
| '心碎' | '礼物' | '太阳' | '月亮' | '赞'
|
134
|
+
| '踩' | '握手' | '胜利' | '飞吻' | '怄火'
|
135
|
+
| '西瓜' | '冷汗' | '擦汗' | '抠鼻' | '鼓掌'
|
136
|
+
| '糗大了' | '坏笑' | '左哼哼' | '右哼哼' | '哈欠'
|
137
|
+
| '鄙视' | '委屈' | '快哭了' | '阴险' | '左亲亲'
|
138
|
+
| '吓' | '可怜' | '菜刀' | '啤酒' | '篮球'
|
139
|
+
| '乒乓' | '示爱' | '瓢虫' | '抱拳' | '勾引'
|
140
|
+
| '拳头' | '差劲' | '爱你' | '不' | '好'
|
141
|
+
| '转圈' | '磕头' | '回头' | '跳绳' | '挥手'
|
142
|
+
| '激动' | '街舞' | '献吻' | '左太极' | '右太极'
|
143
|
+
| '双喜' | '鞭炮' | '灯笼' | 'K歌' | '喝彩'
|
144
|
+
| '祈祷' | '爆筋' | '棒棒糖' | '喝奶' | '飞机'
|
145
|
+
| '钞票' | '药' | '手枪' | '茶' | '眨眼睛'
|
146
|
+
| '泪奔' | '无奈' | '卖萌' | '小纠结' | '喷血'
|
147
|
+
| '斜眼笑' | 'doge' | '惊喜' | '骚扰' | '笑哭'
|
148
|
+
| '我最美' | '河蟹' | '羊驼' | '幽灵' | '蛋'
|
149
|
+
| '菊花' | '红包' | '大笑' | '不开心' | '冷漠'
|
150
|
+
| '呃' | '好棒' | '拜托' | '点赞' | '无聊'
|
151
|
+
| '托脸' | '吃' | '送花' | '害怕' | '花痴'
|
152
|
+
| '小样儿' | '飙泪' | '我不看' | '托腮' | '啵啵'
|
153
|
+
| '糊脸' | '拍头' | '扯一扯' | '舔一舔' | '蹭一蹭'
|
154
|
+
| '拽炸天' | '顶呱呱' | '抱抱' | '暴击' | '开枪'
|
155
|
+
| '撩一撩' | '拍桌' | '拍手' | '恭喜' | '干杯'
|
156
|
+
| '嘲讽' | '哼' | '佛系' | '掐一掐' | '惊呆'
|
157
|
+
| '颤抖' | '啃头' | '偷看' | '扇脸' | '原谅'
|
158
|
+
| '喷脸' | '生日快乐' | '头撞击' | '甩头' | '扔狗'
|
159
|
+
| '加油必胜' | '加油抱抱' | '口罩护体' | '搬砖中' | '忙到飞起'
|
160
|
+
| '脑阔疼' | '沧桑' | '捂脸' | '辣眼睛' | '哦哟'
|
161
|
+
| '头秃' | '问号脸' | '暗中观察' | 'emm' | '吃瓜'
|
162
|
+
| '呵呵哒' | '我酸了' | '太南了' | '辣椒酱' | '汪汪'
|
163
|
+
| '汗' | '打脸' | '击掌' | '无眼笑' | '敬礼'
|
164
|
+
| '狂笑' | '面无表情' | '摸鱼' | '魔鬼笑' | '哦'
|
165
|
+
| '请' | '睁眼' | '敲开心' | '震惊' | '让我康康'
|
166
|
+
| '摸锦鲤' | '期待' | '拿到红包' | '真好' | '拜谢'
|
167
|
+
| '元宝' | '牛啊' | '胖三斤' | '好闪' | '左拜年'
|
168
|
+
| '右拜年' | '红包包' | '右亲亲' | '牛气冲天' | '喵喵'
|
169
|
+
| '求红包' | '谢红包' | '新年烟花' | '打call' | '变形'
|
170
|
+
| '嗑到了' | '仔细分析' | '加油' | '我没事' | '菜狗'
|
171
|
+
| '崇拜' | '比心' | '庆祝' | '老色痞' | '拒绝'
|
172
|
+
| '嫌弃' | '吃糖';
|
173
|
+
|
107
174
|
// 消息处理器类型
|
108
175
|
export {
|
109
176
|
// 接口
|
@@ -112,6 +179,9 @@ export {
|
|
112
179
|
// 消息类型
|
113
180
|
MessageType,
|
114
181
|
|
182
|
+
// MessageType.nodeList 的元素类型
|
183
|
+
ForwardNode,
|
184
|
+
|
115
185
|
// 图片 id 语音 id 消息 id
|
116
186
|
ImageId, VoiceId, MessageId,
|
117
187
|
|
@@ -120,4 +190,7 @@ export {
|
|
120
190
|
|
121
191
|
// 消息处理器
|
122
192
|
Processor,
|
193
|
+
|
194
|
+
// QQ 自带表情
|
195
|
+
FaceType
|
123
196
|
};
|
package/src/Bot.d.ts
CHANGED
@@ -55,7 +55,7 @@ export class Bot implements BotConfigGetable {
|
|
55
55
|
* @param keepProcessor 可选,是否保留事件处理器,默认值为 false,不保留
|
56
56
|
* @param keepConfig 可选,是否保留 session baseUrl qq averifyKey,默认值为 false,不保留
|
57
57
|
*/
|
58
|
-
close({ keepProcessor, keepConfig }
|
58
|
+
close({ keepProcessor, keepConfig }?: Bot.CloseOptions): Promise<void>;
|
59
59
|
|
60
60
|
/**
|
61
61
|
* ! messageChain 将在未来被移除
|
@@ -326,7 +326,7 @@ declare namespace Bot {
|
|
326
326
|
baseUrl?: string;
|
327
327
|
verifyKey?: string;
|
328
328
|
qq?: number;
|
329
|
-
singleMode
|
329
|
+
singleMode?: boolean;
|
330
330
|
}
|
331
331
|
|
332
332
|
interface CloseOptions {
|
package/src/Bot.js
CHANGED
@@ -3,7 +3,7 @@ const _releaseSession = require('./core/releaseSession');
|
|
3
3
|
const _verify = require('./core/auth');
|
4
4
|
const _bind = require('./core/verify');
|
5
5
|
const _sendCommand = require('./core/sendCommand');
|
6
|
-
const _sendFriendMessage = require('./core/
|
6
|
+
const _sendFriendMessage = require('./core/sendFriendMessage');
|
7
7
|
const _sendGroupMessage = require('./core/sendGroupMessage');
|
8
8
|
const _sendTempMessage = require('./core/sendTempMessage');
|
9
9
|
const _sendNudge = require('./core/sendNudge');
|
package/src/Message.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
// Message 通过实现 MessageChaingetable 与 Bot.sendMessage 通信
|
2
2
|
// 消息链元素类型和图片 id 类型
|
3
|
-
import { MessageChainGetable, MessageType, ImageId } from './BaseType';
|
3
|
+
import { MessageChainGetable, MessageType, ImageId, FaceType, MessageId, ForwardNode, } from './BaseType';
|
4
4
|
|
5
5
|
// Bot.sendMessage 的 message 参数是一个 Message 类型的实例
|
6
6
|
// 方法内部通过 getMessageChainable 接口的 getMessageChain 方法拿到消息链
|
@@ -36,9 +36,31 @@ export class Message implements MessageChainGetable {
|
|
36
36
|
// json
|
37
37
|
addJson(json: string): Message;
|
38
38
|
|
39
|
-
//
|
39
|
+
// app
|
40
40
|
addApp(content: string): Message;
|
41
41
|
|
42
|
+
// face
|
43
|
+
addFace(name: FaceType): Message;
|
44
|
+
|
42
45
|
// implements MessageChainGetable
|
43
46
|
getMessageChain(): MessageType[];
|
47
|
+
|
48
|
+
// factory
|
49
|
+
static createForwardMessage(): ForwardMessage;
|
44
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): Message;
|
62
|
+
addForwardNode(messageId: MessageId): ForwardMessage;
|
63
|
+
|
64
|
+
// implements MessageChainGetable
|
65
|
+
getMessageChain(): MessageType[];
|
66
|
+
}
|