Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
update sysmsg
Browse files Browse the repository at this point in the history
  • Loading branch information
takayama-lily committed May 24, 2021
1 parent 6b049e9 commit c82eaaf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 35 deletions.
64 changes: 31 additions & 33 deletions lib/core/sysmsg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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)));
}
})();

Expand Down
2 changes: 1 addition & 1 deletion lib/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/oicq.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit c82eaaf

Please sign in to comment.