oicq-icalingua-plus-plus 1.22.0
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/LICENSE +373 -0
- package/README.md +73 -0
- package/bin/oicq +2 -0
- package/http-api/README.md +187 -0
- package/http-api/api.js +217 -0
- package/http-api/config.sample.js +44 -0
- package/http-api/core.js +480 -0
- package/http-api/cq-notice.js +39 -0
- package/http-api/filter.js +128 -0
- package/http-api/index.js +39 -0
- package/index.d.ts +1214 -0
- package/index.js +34 -0
- package/lib/algo/jce/index.js +63 -0
- package/lib/algo/jce/jce.js +341 -0
- package/lib/algo/pb.js +159 -0
- package/lib/algo/protobuf.min.js +8 -0
- package/lib/algo/tea.js +121 -0
- package/lib/client-ext.js +312 -0
- package/lib/client-net.js +147 -0
- package/lib/client.js +594 -0
- package/lib/common.js +252 -0
- package/lib/core/friendlist.js +415 -0
- package/lib/core/nessy.js +148 -0
- package/lib/core/ref.d.ts +1 -0
- package/lib/core/sysmsg.js +388 -0
- package/lib/core/troop.js +586 -0
- package/lib/device.js +181 -0
- package/lib/exception.js +57 -0
- package/lib/message/builder.js +1093 -0
- package/lib/message/chat.js +276 -0
- package/lib/message/face.js +293 -0
- package/lib/message/file.js +425 -0
- package/lib/message/history.js +73 -0
- package/lib/message/image.js +533 -0
- package/lib/message/multi.js +242 -0
- package/lib/message/music.js +172 -0
- package/lib/message/parser.js +774 -0
- package/lib/message/ptt.js +389 -0
- package/lib/oicq.js +427 -0
- package/lib/onlinepush.js +616 -0
- package/lib/ref.d.ts +177 -0
- package/lib/service.js +204 -0
- package/lib/wtlogin/ecdh.js +15 -0
- package/lib/wtlogin/login-password.js +215 -0
- package/lib/wtlogin/login-qrcode.js +249 -0
- package/lib/wtlogin/tlv.js +331 -0
- package/lib/wtlogin/writer.js +88 -0
- package/lib/wtlogin/wt.js +422 -0
- package/package.json +50 -0
- package/util.js +115 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const https = require("https");
|
|
3
|
+
const pb = require("../algo/pb");
|
|
4
|
+
const jce = require("../algo/jce");
|
|
5
|
+
const { uinAutoCheck } = require("../common");
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @this {import("./ref").Client}
|
|
9
|
+
* @param {number} user_id
|
|
10
|
+
* @param {number} times 1~20
|
|
11
|
+
* @returns {import("./ref").ProtocolResponse}
|
|
12
|
+
*/
|
|
13
|
+
async function sendLike(user_id, times = 1) {
|
|
14
|
+
[user_id] = uinAutoCheck(user_id);
|
|
15
|
+
times = parseInt(times);
|
|
16
|
+
if (!(times > 0 && times <= 20))
|
|
17
|
+
times = 1;
|
|
18
|
+
const ReqFavorite = jce.encodeStruct([
|
|
19
|
+
jce.encodeNested([
|
|
20
|
+
this.uin, 1, this.seq_id + 1, 1, 0, Buffer.from("0C180001060131160131", "hex")
|
|
21
|
+
]),
|
|
22
|
+
user_id, 0, 1, times
|
|
23
|
+
]);
|
|
24
|
+
const extra = {
|
|
25
|
+
req_id: this.seq_id + 1,
|
|
26
|
+
service: "VisitorSvc",
|
|
27
|
+
method: "ReqFavorite",
|
|
28
|
+
};
|
|
29
|
+
const body = jce.encodeWrapper({ ReqFavorite }, extra);
|
|
30
|
+
const blob = await this.sendUni("VisitorSvc.ReqFavorite", body);
|
|
31
|
+
const rsp = jce.decode(blob);
|
|
32
|
+
return { result: rsp[0][3], emsg: rsp[0][4] };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 设置在线状态
|
|
37
|
+
* @this {import("./ref").Client}
|
|
38
|
+
* @param {number} status
|
|
39
|
+
* @returns {import("./ref").ProtocolResponse}
|
|
40
|
+
*/
|
|
41
|
+
async function setStatus(status) {
|
|
42
|
+
status = parseInt(status);
|
|
43
|
+
if (![11, 31, 41, 50, 60, 70].includes(status))
|
|
44
|
+
throw new Error("bad status");
|
|
45
|
+
let sub = 0;
|
|
46
|
+
if (status > 1000) {
|
|
47
|
+
sub = status, status = 11;
|
|
48
|
+
}
|
|
49
|
+
const SvcReqRegister = jce.encodeStruct([
|
|
50
|
+
this.uin,
|
|
51
|
+
7, 0, "", status, 0, 0, 0, 0, 0, 248,
|
|
52
|
+
this.device.version.sdk, 0, "", 0, null, this.device.guid, 2052, 0, this.device.model, this.device.model,
|
|
53
|
+
this.device.version.release, 1, 473, 0, null, 0, 0, "", 0, "",
|
|
54
|
+
"", "", null, 1, null, 0, null, sub, 0
|
|
55
|
+
]);
|
|
56
|
+
const extra = {
|
|
57
|
+
req_id: this.seq_id + 1,
|
|
58
|
+
service: "PushService",
|
|
59
|
+
method: "SvcReqRegister",
|
|
60
|
+
};
|
|
61
|
+
const body = jce.encodeWrapper({ SvcReqRegister }, extra);
|
|
62
|
+
const blob = await this.sendUni("StatSvc.SetStatusFromClient", body);
|
|
63
|
+
const rsp = jce.decode(blob);
|
|
64
|
+
let result = -1;
|
|
65
|
+
if (rsp[9]) {
|
|
66
|
+
result = 0;
|
|
67
|
+
this.online_status = status;
|
|
68
|
+
}
|
|
69
|
+
return { result };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @this {import("./ref").Client}
|
|
74
|
+
* @param {number} user_id
|
|
75
|
+
* @returns {import("./ref").ProtocolResponse}
|
|
76
|
+
*/
|
|
77
|
+
async function getLevelInfo(user_id = this.uin) {
|
|
78
|
+
[user_id] = uinAutoCheck(user_id);
|
|
79
|
+
const cookie = this.cookies["vip.qq.com"];
|
|
80
|
+
const url = `https://club.vip.qq.com/api/vip/getQQLevelInfo?requestBody={"iUin":${user_id}}`;
|
|
81
|
+
try {
|
|
82
|
+
let data = await new Promise((resolve, reject) => {
|
|
83
|
+
https.get(url, { headers: { cookie } }, (res) => {
|
|
84
|
+
if (res.statusCode !== 200) {
|
|
85
|
+
return reject("statusCode: " + res.statusCode);
|
|
86
|
+
}
|
|
87
|
+
res.setEncoding("utf-8");
|
|
88
|
+
let data = "";
|
|
89
|
+
res.on("data", chunk => data += chunk);
|
|
90
|
+
res.on("end", () => {
|
|
91
|
+
try {
|
|
92
|
+
data = JSON.parse(data);
|
|
93
|
+
if (data.ret !== 0) {
|
|
94
|
+
return reject(data.msg);
|
|
95
|
+
}
|
|
96
|
+
resolve(data.data.mRes);
|
|
97
|
+
} catch {
|
|
98
|
+
reject("response error");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
});
|
|
102
|
+
}).on("error", (e) => reject(e.message));
|
|
103
|
+
});
|
|
104
|
+
return { result: 0, data };
|
|
105
|
+
} catch (e) {
|
|
106
|
+
return { result: -1, emsg: e };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 获取漫游表情
|
|
112
|
+
* @this {import("../ref").Client}
|
|
113
|
+
* @returns {import("../ref").ProtocolResponse}
|
|
114
|
+
*/
|
|
115
|
+
async function getRoamingStamp(no_cache = false) {
|
|
116
|
+
if (!this.roaming_stamp)
|
|
117
|
+
this.roaming_stamp = [];
|
|
118
|
+
if (!this.roaming_stamp.length || no_cache) {
|
|
119
|
+
const body = pb.encode({
|
|
120
|
+
1: {
|
|
121
|
+
1: 109,
|
|
122
|
+
2: this.device.version.release,
|
|
123
|
+
3: this.apk.ver
|
|
124
|
+
},
|
|
125
|
+
2: this.uin,
|
|
126
|
+
3: 1,
|
|
127
|
+
});
|
|
128
|
+
const blob = await this.sendUni("Faceroam.OpReq", body);
|
|
129
|
+
const rsp = pb.decode(blob);
|
|
130
|
+
const result = rsp[1];
|
|
131
|
+
if (result !== 0) {
|
|
132
|
+
return { result, emsg: String(rsp[2]) };
|
|
133
|
+
}
|
|
134
|
+
if (rsp[4][1]) {
|
|
135
|
+
const bid = String(rsp[4][3]);
|
|
136
|
+
const faces = Array.isArray(rsp[4][1]) ? rsp[4][1] : [rsp[4][1]];
|
|
137
|
+
this.roaming_stamp = faces.map(x => `https://p.qpic.cn/${bid}/${this.uin}/${x}/0`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
result: 0,
|
|
142
|
+
data: this.roaming_stamp,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
module.exports = {
|
|
147
|
+
setStatus, sendLike, getLevelInfo, getRoamingStamp
|
|
148
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../ref";
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 系统消息相关处理(好友请求、群申请、群邀请)
|
|
3
|
+
* 相关api
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
const pb = require("../algo/pb");
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {number} user_id
|
|
10
|
+
* @param {bigint|number} seq
|
|
11
|
+
*/
|
|
12
|
+
function _genFriendRequestFlag(user_id, seq, single = false) {
|
|
13
|
+
let flag = user_id.toString(16).padStart(8, "0") + seq.toString(16);
|
|
14
|
+
if (single)
|
|
15
|
+
flag = "~" + flag;
|
|
16
|
+
return flag;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {string} flag
|
|
21
|
+
*/
|
|
22
|
+
function _parseFriendRequestFlag(flag) {
|
|
23
|
+
let single = false;
|
|
24
|
+
if (flag.startsWith("~")) {
|
|
25
|
+
flag = flag.slice(1);
|
|
26
|
+
single = true;
|
|
27
|
+
}
|
|
28
|
+
const user_id = parseInt(flag.slice(0, 8), 16);
|
|
29
|
+
const seq = BigInt("0x" + flag.slice(8));
|
|
30
|
+
return { user_id, seq, single };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {number} user_id
|
|
35
|
+
* @param {number} group_id
|
|
36
|
+
* @param {bigint|number} seq
|
|
37
|
+
* @param {0|1} invite
|
|
38
|
+
*/
|
|
39
|
+
function _genGroupRequestFlag(user_id, group_id, seq, invite) {
|
|
40
|
+
const buf = Buffer.allocUnsafe(8);
|
|
41
|
+
buf.writeUInt32BE(user_id), buf.writeUInt32BE(group_id, 4);
|
|
42
|
+
return buf.toString("hex") + invite + seq.toString(16);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param {string} flag
|
|
47
|
+
*/
|
|
48
|
+
function _parseGroupRequestFlag(flag) {
|
|
49
|
+
const user_id = parseInt(flag.slice(0, 8), 16);
|
|
50
|
+
const group_id = parseInt(flag.slice(8, 16), 16);
|
|
51
|
+
const invite = parseInt(flag.slice(16, 17));
|
|
52
|
+
const seq = BigInt("0x" + flag.slice(17));
|
|
53
|
+
return { user_id, group_id, seq, invite };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {import("./ref").Proto} proto
|
|
58
|
+
* @returns {import("./ref").FriendAddEventData}
|
|
59
|
+
*/
|
|
60
|
+
function _parseFrdSysMsg(proto) {
|
|
61
|
+
const time = proto[4];
|
|
62
|
+
const user_id = proto[5];
|
|
63
|
+
const nickname = String(proto[50][51]);
|
|
64
|
+
const flag = _genFriendRequestFlag(user_id, proto[3], proto[50][1] === 9 ? true : false);
|
|
65
|
+
const source = String(proto[50][5]);
|
|
66
|
+
const comment = String(proto[50][4] ? proto[50][4] : "");
|
|
67
|
+
const sex = proto[50][67] === 0 ? "male" : (proto[50][67] === 1 ? "famale" : "unknown");
|
|
68
|
+
const age = proto[50][68];
|
|
69
|
+
return { user_id, nickname, source, comment, sex, age, flag, time };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {import("./ref").Proto} proto
|
|
74
|
+
* @returns {import("./ref").GroupAddEventData | import("./ref").GroupInviteEventData}
|
|
75
|
+
*/
|
|
76
|
+
function _parseGrpSysMsg(proto) {
|
|
77
|
+
const type = proto[50][12];
|
|
78
|
+
const time = proto[4];
|
|
79
|
+
const group_id = proto[50][10];
|
|
80
|
+
const group_name = String(proto[50][52]);
|
|
81
|
+
const data = { time, group_id, group_name };
|
|
82
|
+
let invite = 0;
|
|
83
|
+
if (type === 2) { //invite
|
|
84
|
+
data.user_id = proto[50][11];
|
|
85
|
+
data.nickname = String(proto[50][53]);
|
|
86
|
+
data.role = proto[50][13] === 1 ? "member" : "admin";
|
|
87
|
+
invite = 1;
|
|
88
|
+
} else { //add
|
|
89
|
+
data.user_id = proto[5];
|
|
90
|
+
data.nickname = String(proto[50][51]);
|
|
91
|
+
data.comment = String(proto[50][4]);
|
|
92
|
+
data.inviter_id = proto[50][11];
|
|
93
|
+
data.tips = String(proto[50][32]);
|
|
94
|
+
}
|
|
95
|
+
data.flag = _genGroupRequestFlag(data.user_id, group_id, proto[3], invite);
|
|
96
|
+
return data;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const frd_buf = pb.encode({
|
|
100
|
+
1: 20,
|
|
101
|
+
4: 1000,
|
|
102
|
+
5: 2,
|
|
103
|
+
6: {
|
|
104
|
+
4: 1,
|
|
105
|
+
7: 1,
|
|
106
|
+
9: 1,
|
|
107
|
+
10: 1,
|
|
108
|
+
15: 1,
|
|
109
|
+
},
|
|
110
|
+
7: 0,
|
|
111
|
+
8: 0,
|
|
112
|
+
9: 0,
|
|
113
|
+
10: 1,
|
|
114
|
+
11: 2
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 获取好友请求
|
|
119
|
+
* @this {import("./ref").Client}
|
|
120
|
+
*/
|
|
121
|
+
async function getNewFriend() {
|
|
122
|
+
try {
|
|
123
|
+
const blob = await this.sendUni("ProfileService.Pb.ReqSystemMsgNew.Friend", frd_buf);
|
|
124
|
+
let rsp = pb.decode(blob)[9];
|
|
125
|
+
if (!Array.isArray(rsp))
|
|
126
|
+
rsp = [rsp];
|
|
127
|
+
for (let v of rsp) {
|
|
128
|
+
if (v[50][1] === 9 && String(v[50][6]) === "") { //single
|
|
129
|
+
const data = _parseFrdSysMsg(v);
|
|
130
|
+
if (this.msgExists(data.user_id, 191, v[3], data.time))
|
|
131
|
+
continue;
|
|
132
|
+
this.sl.set(data.user_id, {
|
|
133
|
+
user_id: data.user_id,
|
|
134
|
+
nickname: data.nickname,
|
|
135
|
+
sex: "unknown",
|
|
136
|
+
age: 0,
|
|
137
|
+
area: "unknown",
|
|
138
|
+
});
|
|
139
|
+
this.getStrangerInfo(data.user_id, true);
|
|
140
|
+
this.logger.info(`${data.user_id}(${data.nickname}) 将你添加为单向好友 (flag: ${data.flag})`);
|
|
141
|
+
this.em("request.friend.single", data);
|
|
142
|
+
}
|
|
143
|
+
if (v[50][1] === 1) {
|
|
144
|
+
const data = _parseFrdSysMsg(v);
|
|
145
|
+
if (this.msgExists(data.user_id, 187, v[3], data.time))
|
|
146
|
+
continue;
|
|
147
|
+
this.logger.info(`收到 ${data.user_id}(${data.nickname}) 的加好友请求 (flag: ${data.flag})`);
|
|
148
|
+
this.em("request.friend.add", data);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} catch (e) {
|
|
152
|
+
this.logger.warn("获取好友请求失败。");
|
|
153
|
+
this.logger.warn(e);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const grp_buf = pb.encode({
|
|
158
|
+
1: 20,
|
|
159
|
+
4: 1000,
|
|
160
|
+
5: 3,
|
|
161
|
+
6: {
|
|
162
|
+
1: 1,
|
|
163
|
+
2: 1,
|
|
164
|
+
3: 1,
|
|
165
|
+
5: 1,
|
|
166
|
+
6: 1,
|
|
167
|
+
7: 1,
|
|
168
|
+
8: 1,
|
|
169
|
+
9: 1,
|
|
170
|
+
10: 1,
|
|
171
|
+
11: 1,
|
|
172
|
+
12: 1,
|
|
173
|
+
13: 1,
|
|
174
|
+
14: 1,
|
|
175
|
+
15: 1,
|
|
176
|
+
16: 1,
|
|
177
|
+
17: 1,
|
|
178
|
+
},
|
|
179
|
+
7: 0,
|
|
180
|
+
8: 0,
|
|
181
|
+
9: 0,
|
|
182
|
+
10: 1,
|
|
183
|
+
11: 1,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const grp_buf_risk = pb.encode({
|
|
187
|
+
1: 20,
|
|
188
|
+
4: 1000,
|
|
189
|
+
5: 3,
|
|
190
|
+
6: {
|
|
191
|
+
1: 1,
|
|
192
|
+
2: 1,
|
|
193
|
+
3: 1,
|
|
194
|
+
5: 1,
|
|
195
|
+
6: 1,
|
|
196
|
+
7: 1,
|
|
197
|
+
8: 1,
|
|
198
|
+
9: 1,
|
|
199
|
+
10: 1,
|
|
200
|
+
11: 1,
|
|
201
|
+
12: 1,
|
|
202
|
+
13: 1,
|
|
203
|
+
14: 1,
|
|
204
|
+
15: 1,
|
|
205
|
+
16: 1,
|
|
206
|
+
17: 1,
|
|
207
|
+
},
|
|
208
|
+
7: 0,
|
|
209
|
+
8: 0,
|
|
210
|
+
9: 0,
|
|
211
|
+
10: 1,
|
|
212
|
+
11: 2,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 获取群请求
|
|
217
|
+
* @this {import("./ref").Client}
|
|
218
|
+
*/
|
|
219
|
+
async function getNewGroup() {
|
|
220
|
+
try {
|
|
221
|
+
let arr = [];
|
|
222
|
+
{
|
|
223
|
+
const blob = await this.sendUni("ProfileService.Pb.ReqSystemMsgNew.Group", grp_buf);
|
|
224
|
+
let rsp = pb.decode(blob)[10];
|
|
225
|
+
if (rsp)
|
|
226
|
+
arr = arr.concat(rsp);
|
|
227
|
+
}
|
|
228
|
+
{
|
|
229
|
+
const blob = await this.sendUni("ProfileService.Pb.ReqSystemMsgNew.Group", grp_buf_risk);
|
|
230
|
+
let rsp = pb.decode(blob)[10];
|
|
231
|
+
if (rsp)
|
|
232
|
+
arr = arr.concat(rsp);
|
|
233
|
+
}
|
|
234
|
+
for (let v of arr) {
|
|
235
|
+
if (v[50][1] !== 1)
|
|
236
|
+
continue;
|
|
237
|
+
const type = v[50][12];
|
|
238
|
+
const data = _parseGrpSysMsg(v);
|
|
239
|
+
if (this.msgExists(data.group_id, type, v[3], data.time))
|
|
240
|
+
continue;
|
|
241
|
+
if (type === 1 || type === 22) {
|
|
242
|
+
this.logger.info(`用户 ${data.user_id}(${data.nickname}) 请求加入群 ${data.group_id}(${data.group_name}) (flag: ${data.flag})`);
|
|
243
|
+
this.em("request.group.add", data);
|
|
244
|
+
} else if (type === 2) {
|
|
245
|
+
this.logger.info(`用户 ${data.user_id}(${data.nickname}) 邀请你加入群 ${data.group_id}(${data.group_name}) (flag: ${data.flag})`);
|
|
246
|
+
this.em("request.group.invite", data);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
} catch (e) {
|
|
250
|
+
this.logger.warn("获取群请求失败。");
|
|
251
|
+
this.logger.warn(e);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* 获取系统消息
|
|
257
|
+
* @this {import("./ref").Client}
|
|
258
|
+
* @returns {import("./ref").ProtocolResponse}
|
|
259
|
+
*/
|
|
260
|
+
async function getSysMsg() {
|
|
261
|
+
const data = [];
|
|
262
|
+
|
|
263
|
+
const frd_tsk = (async () => {
|
|
264
|
+
const blob = await this.sendUni("ProfileService.Pb.ReqSystemMsgNew.Friend", frd_buf);
|
|
265
|
+
let rsp = pb.decode(blob)[9];
|
|
266
|
+
if (!rsp)
|
|
267
|
+
return;
|
|
268
|
+
if (!Array.isArray(rsp))
|
|
269
|
+
rsp = [rsp];
|
|
270
|
+
const dbl = [];
|
|
271
|
+
for (let proto of rsp) {
|
|
272
|
+
if (proto[50][1] === 9 && String(proto[50][6]) === "" && !dbl.includes(proto[5])) {
|
|
273
|
+
dbl.push(proto[5]);
|
|
274
|
+
data.push(Object.assign(this.parseEventType("request.friend.single"), _parseFrdSysMsg(proto)));
|
|
275
|
+
} else if (proto[50][1] === 1) {
|
|
276
|
+
data.push(Object.assign(this.parseEventType("request.friend.add"), _parseFrdSysMsg(proto)));
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
})();
|
|
280
|
+
|
|
281
|
+
const grp_tsk = (async () => {
|
|
282
|
+
let arr = [];
|
|
283
|
+
{
|
|
284
|
+
const blob = await this.sendUni("ProfileService.Pb.ReqSystemMsgNew.Group", grp_buf);
|
|
285
|
+
let rsp = pb.decode(blob)[10];
|
|
286
|
+
if (rsp)
|
|
287
|
+
arr = arr.concat(rsp);
|
|
288
|
+
}
|
|
289
|
+
{
|
|
290
|
+
const blob = await this.sendUni("ProfileService.Pb.ReqSystemMsgNew.Group", grp_buf_risk);
|
|
291
|
+
let rsp = pb.decode(blob)[10];
|
|
292
|
+
if (rsp)
|
|
293
|
+
arr = arr.concat(rsp);
|
|
294
|
+
}
|
|
295
|
+
for (let proto of arr) {
|
|
296
|
+
if (proto[50][1] !== 1)
|
|
297
|
+
continue;
|
|
298
|
+
const type = proto[50][12];
|
|
299
|
+
let sub_type;
|
|
300
|
+
if (type === 1 || type === 22) {
|
|
301
|
+
sub_type = "add";
|
|
302
|
+
} else if (type === 2) {
|
|
303
|
+
sub_type = "invite";
|
|
304
|
+
} else {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
data.push(Object.assign(this.parseEventType("request.group." + sub_type), _parseGrpSysMsg(proto)));
|
|
308
|
+
}
|
|
309
|
+
})();
|
|
310
|
+
|
|
311
|
+
await Promise.all([frd_tsk, grp_tsk]);
|
|
312
|
+
return { result: 0, data };
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* 处理好友请求
|
|
317
|
+
* @this {import("./ref").Client}
|
|
318
|
+
* @returns {import("./ref").ProtocolResponse}
|
|
319
|
+
*/
|
|
320
|
+
async function friendAction(flag, approve = true, remark = "", block = false) {
|
|
321
|
+
const { user_id, seq, single } = _parseFriendRequestFlag(flag);
|
|
322
|
+
let body;
|
|
323
|
+
if (single) {
|
|
324
|
+
body = pb.encode({
|
|
325
|
+
1: 1,
|
|
326
|
+
2: seq,
|
|
327
|
+
3: user_id,
|
|
328
|
+
4: 10,
|
|
329
|
+
5: 2004,
|
|
330
|
+
6: 1,
|
|
331
|
+
7: 0,
|
|
332
|
+
8: {
|
|
333
|
+
1: approve ? 2 : 3,
|
|
334
|
+
52: String(remark),
|
|
335
|
+
53: block ? 1 : 0
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
} else {
|
|
339
|
+
body = pb.encode({
|
|
340
|
+
1: 1,
|
|
341
|
+
2: seq,
|
|
342
|
+
3: user_id,
|
|
343
|
+
4: 1,
|
|
344
|
+
5: 6,
|
|
345
|
+
6: 7,
|
|
346
|
+
8: {
|
|
347
|
+
1: approve ? 2 : 3,
|
|
348
|
+
52: String(remark),
|
|
349
|
+
53: block ? 1 : 0
|
|
350
|
+
},
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
const blob = await this.sendUni("ProfileService.Pb.ReqSystemMsgAction.Friend", body);
|
|
354
|
+
const rsp = pb.decode(blob)[1];
|
|
355
|
+
return { result: rsp[1], emsg: rsp[2] ? String(rsp[2]) : undefined };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* 处理群请求
|
|
360
|
+
* @this {import("./ref").Client}
|
|
361
|
+
* @returns {import("./ref").ProtocolResponse}
|
|
362
|
+
*/
|
|
363
|
+
async function groupAction(flag, approve = true, reason = "", block = false) {
|
|
364
|
+
const { user_id, group_id, seq, invite } = _parseGroupRequestFlag(flag);
|
|
365
|
+
const body = pb.encode({
|
|
366
|
+
1: 1,
|
|
367
|
+
2: seq,
|
|
368
|
+
3: user_id,
|
|
369
|
+
4: 1,
|
|
370
|
+
5: 3,
|
|
371
|
+
6: invite ? 10016 : 31,
|
|
372
|
+
7: invite ? 2 : 1,
|
|
373
|
+
8: {
|
|
374
|
+
1: approve ? 11 : 12,
|
|
375
|
+
2: group_id,
|
|
376
|
+
50: String(reason),
|
|
377
|
+
53: block ? 1 : 0,
|
|
378
|
+
},
|
|
379
|
+
});
|
|
380
|
+
const blob = await this.sendUni("ProfileService.Pb.ReqSystemMsgAction.Group", body);
|
|
381
|
+
const rsp = pb.decode(blob)[1];
|
|
382
|
+
return { result: rsp[1], emsg: rsp[2] ? String(rsp[2]) : undefined };
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
module.exports = {
|
|
386
|
+
getNewFriend, getNewGroup,
|
|
387
|
+
getSysMsg, friendAction, groupAction,
|
|
388
|
+
};
|