oicq-icalingua-plus-plus 1.23.3 → 1.23.6
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/index.d.ts +2 -0
- package/lib/message/builder.js +64 -3
- package/lib/message/multi.js +96 -0
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -325,6 +325,7 @@ export interface ReplyElem {
|
|
|
325
325
|
type: "reply",
|
|
326
326
|
data: {
|
|
327
327
|
id: string, //message_id
|
|
328
|
+
text?: string, //消息文本内容,当获取原消息失败时使用
|
|
328
329
|
}
|
|
329
330
|
}
|
|
330
331
|
|
|
@@ -1215,4 +1216,5 @@ export interface FakeMessage {
|
|
|
1215
1216
|
message: Sendable, //可转发的有效元素理论上只有[文字、表情、图片],不支持CQ码
|
|
1216
1217
|
nickname?: string,
|
|
1217
1218
|
time?: number, //时间戳(秒),默认:当前时间
|
|
1219
|
+
id?: string, //消息id,用于获取消息气泡,默认不使用气泡
|
|
1218
1220
|
}
|
package/lib/message/builder.js
CHANGED
|
@@ -563,6 +563,42 @@ class Builder {
|
|
|
563
563
|
});
|
|
564
564
|
}
|
|
565
565
|
|
|
566
|
+
/**
|
|
567
|
+
* @private
|
|
568
|
+
* @param {string} text
|
|
569
|
+
* @param {Buffer} attr6
|
|
570
|
+
*/
|
|
571
|
+
getTextElem(text, attr6 = null) {
|
|
572
|
+
text = String(text);
|
|
573
|
+
let n = 0;
|
|
574
|
+
while (n < text.length) {
|
|
575
|
+
let m = n + 80;
|
|
576
|
+
let chunk = text.slice(n, m);
|
|
577
|
+
n = m;
|
|
578
|
+
if (text.length > n) {
|
|
579
|
+
// emoji切割问题
|
|
580
|
+
while (EMOJI_NOT_ENDING.includes(chunk[chunk.length - 1]) && text[n]) {
|
|
581
|
+
chunk += text[n];
|
|
582
|
+
++n;
|
|
583
|
+
}
|
|
584
|
+
while (EMOJI_NOT_STARTING.includes(text[n])) {
|
|
585
|
+
chunk += text[n];
|
|
586
|
+
++n;
|
|
587
|
+
while (EMOJI_NOT_ENDING.includes(chunk[chunk.length - 1]) && text[n]) {
|
|
588
|
+
chunk += text[n];
|
|
589
|
+
++n;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return {
|
|
594
|
+
1: {
|
|
595
|
+
1: chunk,
|
|
596
|
+
3: attr6
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
566
602
|
/**
|
|
567
603
|
* @private
|
|
568
604
|
* @param {import("../ref").ReplyElem["data"]} cq
|
|
@@ -571,14 +607,39 @@ class Builder {
|
|
|
571
607
|
if (this.reply)
|
|
572
608
|
return;
|
|
573
609
|
try {
|
|
574
|
-
|
|
575
|
-
|
|
610
|
+
let user_id, seq, random, time, flag, source;
|
|
611
|
+
try {
|
|
612
|
+
const _message = await this.getMsg(cq.id);
|
|
613
|
+
user_id = _message.user_id;
|
|
614
|
+
seq = _message.seq;
|
|
615
|
+
random = _message.random;
|
|
616
|
+
time = _message.time;
|
|
617
|
+
flag = _message.flag;
|
|
618
|
+
source = _message.msg[3][1][2];
|
|
619
|
+
} catch {
|
|
620
|
+
const parsed = Buffer.from(cq.id, "base64");
|
|
621
|
+
if (cq.id.length > 24) {
|
|
622
|
+
// Group
|
|
623
|
+
user_id = parsed.readUInt32BE(4);
|
|
624
|
+
seq = parsed.readUInt32BE(8);
|
|
625
|
+
random = parsed.readUInt32BE(12);
|
|
626
|
+
time = parsed.readUInt32BE(16);
|
|
627
|
+
} else {
|
|
628
|
+
// C2C
|
|
629
|
+
user_id = parsed.readUInt32BE(0);
|
|
630
|
+
seq = parsed.readUInt32BE(4);
|
|
631
|
+
random = parsed.readUInt32BE(8);
|
|
632
|
+
time = parsed.readUInt32BE(12);
|
|
633
|
+
flag = parsed.length >= 17 ? parsed.readUint8(16) : 0;
|
|
634
|
+
}
|
|
635
|
+
source = this.getTextElem(cq.text || " ");
|
|
636
|
+
}
|
|
576
637
|
if (Array.isArray(source)) {
|
|
577
638
|
const bufs = [];
|
|
578
639
|
for (let v of source)
|
|
579
640
|
bufs.push(v.toBuffer());
|
|
580
641
|
source = Buffer.concat(bufs);
|
|
581
|
-
} else {
|
|
642
|
+
} else if (source.toBuffer) {
|
|
582
643
|
source = source.toBuffer();
|
|
583
644
|
}
|
|
584
645
|
this.reply = pb.encode({
|
package/lib/message/multi.js
CHANGED
|
@@ -9,6 +9,9 @@ const pb = require("../algo/pb");
|
|
|
9
9
|
const common = require("../common");
|
|
10
10
|
const { highwayUploadStream } = require("../service");
|
|
11
11
|
const gzip = util.promisify(zlib.gzip);
|
|
12
|
+
const deflate = util.promisify(zlib.deflate);
|
|
13
|
+
const { getC2CMsgs, getGroupMsgs } = require("./history");
|
|
14
|
+
const BUF1 = Buffer.from([1]);
|
|
12
15
|
|
|
13
16
|
function buildTextElem(str) {
|
|
14
17
|
if (!str) str = "";
|
|
@@ -47,6 +50,47 @@ function buildFaceElem(id) {
|
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
52
|
|
|
53
|
+
async function buildXmlElem(xml, svcid = 60) {
|
|
54
|
+
svcid = parseInt(svcid);
|
|
55
|
+
return {
|
|
56
|
+
12: {
|
|
57
|
+
1: Buffer.concat([BUF1, await deflate(String(xml))]),
|
|
58
|
+
2: svcid > 0 ? svcid : 60,
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function buildJsonElem(obj) {
|
|
64
|
+
if (typeof obj !== "string")
|
|
65
|
+
obj = JSON.stringify(obj);
|
|
66
|
+
return {
|
|
67
|
+
51: {
|
|
68
|
+
1: Buffer.concat([BUF1, await deflate(obj)])
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @this {import("../ref").Client}
|
|
75
|
+
* @param {String} id
|
|
76
|
+
*/
|
|
77
|
+
async function getMsg(id) {
|
|
78
|
+
if (id.length > 24) {
|
|
79
|
+
const { group_id ,user_id, seq, random, time } = common.parseGroupMessageId(id);
|
|
80
|
+
const msgs = await getGroupMsgs.call(this, group_id, seq, seq);
|
|
81
|
+
return { user_id, seq, random, time, msg: msgs[0] };
|
|
82
|
+
} else {
|
|
83
|
+
const { user_id, seq, random, time, flag } = common.parseC2CMessageId(id);
|
|
84
|
+
const msgs = await getC2CMsgs.call(this, user_id, time, 10);
|
|
85
|
+
for (let i = msgs.length - 1; i >= 0; --i) {
|
|
86
|
+
const msg = msgs[i];
|
|
87
|
+
if (common.genRandom(msg[1][7]) === random)
|
|
88
|
+
return { user_id, seq, random, time, msg, flag };
|
|
89
|
+
}
|
|
90
|
+
throw new Error();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
50
94
|
/**
|
|
51
95
|
* @this {import("../ref").Client}
|
|
52
96
|
* @param {import("../ref").FakeMessage[]} iterable
|
|
@@ -110,6 +154,45 @@ async function makeForwardMsg(iterable, dm = false, target = 0) {
|
|
|
110
154
|
this.logger.warn(e.message);
|
|
111
155
|
}
|
|
112
156
|
break;
|
|
157
|
+
case "reply":
|
|
158
|
+
let user_id, seq, _random, time, source;
|
|
159
|
+
const parsed = Buffer.from(elem.data.id, "base64");
|
|
160
|
+
if (elem.data.id.length > 24) {
|
|
161
|
+
// Group
|
|
162
|
+
user_id = parsed.readUInt32BE(4);
|
|
163
|
+
seq = parsed.readUInt32BE(8);
|
|
164
|
+
_random = parsed.readUInt32BE(12);
|
|
165
|
+
time = parsed.readUInt32BE(16);
|
|
166
|
+
} else {
|
|
167
|
+
// C2C
|
|
168
|
+
user_id = parsed.readUInt32BE(0);
|
|
169
|
+
seq = parsed.readUInt32BE(4);
|
|
170
|
+
_random = parsed.readUInt32BE(8);
|
|
171
|
+
time = parsed.readUInt32BE(12);
|
|
172
|
+
}
|
|
173
|
+
source = buildTextElem(elem.data.text || " ");
|
|
174
|
+
elements.push({
|
|
175
|
+
45: {
|
|
176
|
+
1: [seq],
|
|
177
|
+
2: user_id,
|
|
178
|
+
3: time,
|
|
179
|
+
4: 1,
|
|
180
|
+
5: source,
|
|
181
|
+
6: 0,
|
|
182
|
+
8: {
|
|
183
|
+
3: common.genMessageUuid(_random)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
break;
|
|
188
|
+
case "xml":
|
|
189
|
+
elements.push(await buildXmlElem(elem.data.xml, elem.data.svcid));
|
|
190
|
+
brief += "[XML]";
|
|
191
|
+
break;
|
|
192
|
+
case "json":
|
|
193
|
+
elements.push(await buildJsonElem(elem.data.json));
|
|
194
|
+
brief += "[JSON]";
|
|
195
|
+
break;
|
|
113
196
|
}
|
|
114
197
|
}
|
|
115
198
|
}
|
|
@@ -144,6 +227,19 @@ async function makeForwardMsg(iterable, dm = false, target = 0) {
|
|
|
144
227
|
}
|
|
145
228
|
}
|
|
146
229
|
});
|
|
230
|
+
if (fake.id) {
|
|
231
|
+
try {
|
|
232
|
+
const { msg } = await getMsg.call(this, fake.id);
|
|
233
|
+
for (let i of msg[3][1][2]) {
|
|
234
|
+
if (i[9]) {
|
|
235
|
+
nodes[nodes.length - 1][3][1][2].push(i)
|
|
236
|
+
break
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
} catch {
|
|
240
|
+
this.logger.warn("invalid message id: " + fake.id);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
147
243
|
if (cnt < 4) {
|
|
148
244
|
++cnt
|
|
149
245
|
preview += `<title color="#777777" size="26">${common.escapeXml(fake.nickname)}: ${common.escapeXml(brief.slice(0, 50))}</title>`;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oicq-icalingua-plus-plus",
|
|
3
3
|
"app_name": "oicq-icalingua-plus-plus",
|
|
4
|
-
"version": "1.23.
|
|
5
|
-
"app_version": "1.23.
|
|
6
|
-
"upday": "2023/01/
|
|
4
|
+
"version": "1.23.6",
|
|
5
|
+
"app_version": "1.23.6",
|
|
6
|
+
"upday": "2023/01/10",
|
|
7
7
|
"protocol_version": "v11",
|
|
8
8
|
"description": "oicq(https://github.com/takayama-lily/oicq) v1 for Icalingua++",
|
|
9
9
|
"main": "index.js",
|