From c82eaaf0e723a3355e8beba8c5c18a9418191a3c Mon Sep 17 00:00:00 2001 From: takayama Date: Mon, 24 May 2021 13:02:19 +0900 Subject: [PATCH] update sysmsg --- lib/core/sysmsg.js | 64 ++++++++++++++++++++++------------------------ lib/extension.js | 2 +- lib/oicq.js | 2 +- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/lib/core/sysmsg.js b/lib/core/sysmsg.js index 2ceb2d39..0ae8517b 100644 --- a/lib/core/sysmsg.js +++ b/lib/core/sysmsg.js @@ -112,20 +112,24 @@ const frd_buf = pb.encode({ async function getNewFriend() { try { const blob = await this.sendUni("ProfileService.Pb.ReqSystemMsgNew.Friend", frd_buf); - const rsp = pb.decode(blob)[9]; - const proto = Array.isArray(rsp) ? rsp[0] : rsp; - const data = _parseFrdSysMsg(proto); - if (this.msgExists(data.user_id, 187, proto[3], data.time)) - return; - this.logger.info(`收到 ${data.user_id}(${data.nickname}) 的加好友请求 (flag: ${data.flag})`); - this.em("request.friend.add", data); + let rsp = pb.decode(blob)[9]; + if (!Array.isArray(rsp)) + rsp = [rsp]; + for (let v of rsp) { + if (v[50][1] !== 1) + continue; + const data = _parseFrdSysMsg(v); + if (this.msgExists(data.user_id, 187, v[3], data.time)) + continue; + this.logger.info(`收到 ${data.user_id}(${data.nickname}) 的加好友请求 (flag: ${data.flag})`); + this.em("request.friend.add", data); + } } catch (e) { this.logger.debug("获取好友请求失败。"); this.logger.debug(e); } } -const notify_types = { 84: 1, 87: 2, 525: 22 }; const grp_buf = pb.encode({ 1: 20, 4: 1000, @@ -157,34 +161,28 @@ const grp_buf = pb.encode({ /** * 获取群请求 * @this {import("./ref").Client} - * @param {84|87|525} type 84申请 87邀请 525申请(来自群员的邀请) */ -async function getNewGroup(type) { +async function getNewGroup() { try { const blob = await this.sendUni("ProfileService.Pb.ReqSystemMsgNew.Group", grp_buf); - const rsp = pb.decode(blob)[10]; - let v; + let rsp = pb.decode(blob)[10]; if (!Array.isArray(rsp)) - v = rsp; - else { - for (let vv of rsp) { - if (vv[50][1] !== 1 || vv[50][12] !== notify_types[type]) - continue; - if (!v || vv[4] > v[4]) - v = vv; + rsp = [rsp]; + for (let v of rsp) { + if (v[50][1] !== 1) + continue; + const type = v[50][12]; + const data = _parseGrpSysMsg(v); + if (this.msgExists(data.group_id, type, v[3], data.time)) + continue; + if (type === 1 || type === 22) { + this.logger.info(`用户 ${data.user_id}(${data.nickname}) 请求加入群 ${data.group_id}(${data.group_name}) (flag: ${data.flag})`); + this.em("request.group.add", data); + } else if (type === 2) { + this.logger.info(`用户 ${data.user_id}(${data.nickname}) 邀请你加入群 ${data.group_id}(${data.group_name}) (flag: ${data.flag})`); + this.em("request.group.invite", data); } } - if (!v) return; - const data = _parseGrpSysMsg(v); - if (this.msgExists(data.group_id, type, v[3], data.time)) - return; - if (type === 84 || type === 525) { - this.logger.info(`用户 ${data.user_id}(${data.nickname}) 请求加入群 ${data.group_id}(${data.group_name}) (flag: ${data.flag})`); - this.em("request.group.add", data); - } else if (type === 87) { - this.logger.info(`用户 ${data.user_id}(${data.nickname}) 邀请你加入群 ${data.group_id}(${data.group_name}) (flag: ${data.flag})`); - this.em("request.group.invite", data); - } } catch (e) { this.logger.debug("获取群请求失败。"); this.logger.debug(e); @@ -205,9 +203,9 @@ async function getSysMsg() { if (!Array.isArray(rsp)) rsp = [rsp]; for (let proto of rsp) { - try { - data.push(Object.assign(this.parseEventType("request.friend.add"), _parseFrdSysMsg(proto))); - } catch { } + if (proto[50][1] !== 1) + continue; + data.push(Object.assign(this.parseEventType("request.friend.add"), _parseFrdSysMsg(proto))); } })(); diff --git a/lib/extension.js b/lib/extension.js index 41de9dc9..4a964363 100644 --- a/lib/extension.js +++ b/lib/extension.js @@ -78,7 +78,7 @@ Client.prototype.em = function (name = "", data = {}) { }; Client.prototype.msgExists = function (from, type, seq, time) { - if (timestamp() - time >= 60) + if (timestamp() - time >= 60 || time < this.stat.start_time) return true; const id = [from, type, seq].join("-"); const set = this.seq_cache.get(time); diff --git a/lib/oicq.js b/lib/oicq.js index fb822d18..b9244ebf 100644 --- a/lib/oicq.js +++ b/lib/oicq.js @@ -88,7 +88,7 @@ function onPushNotify(blob) { case 84: case 87: case 525: - return sysmsg.getNewGroup.call(this, nested[5]); + return sysmsg.getNewGroup.call(this); case 187: return sysmsg.getNewFriend.call(this); }