From 9f977be6cc4f7353a86c4b47800b1820babc77d4 Mon Sep 17 00:00:00 2001 From: takayama Date: Tue, 17 Nov 2020 19:24:40 +0900 Subject: [PATCH 1/7] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=B2=A1=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/individual.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/individual.js b/lib/individual.js index daac42cb..9de8f618 100644 --- a/lib/individual.js +++ b/lib/individual.js @@ -18,18 +18,10 @@ async function getImgBuf(file) { if (file.startsWith("base64://")) { buf = Buffer.from(file.replace("base64://", ""), "base64"); } else if (file.startsWith("http")) { - try { - buf = await downloadWebImage(file); - } catch (e) { - throw new Error(e); - } + buf = await downloadWebImage(file); } else { file = file.replace(/^file:\/{2,3}/, ""); - try { - buf = await readFile(file); - } catch (e) { - throw new Error(e); - } + buf = await readFile(file); } } return buf; From 61378e99f66e8799f5410985fe4132b12b81777f Mon Sep 17 00:00:00 2001 From: takayama Date: Tue, 17 Nov 2020 19:58:49 +0900 Subject: [PATCH 2/7] pic size --- lib/message/builder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/message/builder.js b/lib/message/builder.js index c0a10131..f74fc1cc 100644 --- a/lib/message/builder.js +++ b/lib/message/builder.js @@ -254,7 +254,7 @@ class Builder { //只有md5和size else { size = parseInt(file.substr(32)); - size = size > 0 ? size : 0; + size = size > 0 ? size : 1; } } From 4667c5cb2bb15d8062220d15a7371bca84e0d7f6 Mon Sep 17 00:00:00 2001 From: takayama Date: Tue, 17 Nov 2020 22:59:57 +0900 Subject: [PATCH 3/7] export logger --- client.d.ts | 2 ++ lib/ref.d.ts | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client.d.ts b/client.d.ts index 07dd5357..fb2ed5f1 100644 --- a/client.d.ts +++ b/client.d.ts @@ -3,6 +3,7 @@ /// import * as events from 'events'; +import * as log4js from 'log4js'; export type Uin = string | number; @@ -181,6 +182,7 @@ export interface EventData { export class Client extends events.EventEmitter { private constructor(); + logger: log4js.Logger; login(password_md5?: Buffer | string): void; captchaLogin(captcha: string): void; terminate(): void; //直接关闭连接 diff --git a/lib/ref.d.ts b/lib/ref.d.ts index eef1943c..2ef41165 100644 --- a/lib/ref.d.ts +++ b/lib/ref.d.ts @@ -3,7 +3,6 @@ /// import * as oicq from '../client'; -import * as log4js from 'log4js'; ////////// @@ -93,7 +92,6 @@ export interface Statistics { ////////// export class Client extends oicq.Client { - logger: log4js.Logger; reconn_flag: boolean; config: oicq.ConfBot; status: Symbol; From 0bfb1e33f9d26f8497ef91d10f8a6d558c9524a2 Mon Sep 17 00:00:00 2001 From: takayama Date: Wed, 18 Nov 2020 02:04:43 +0900 Subject: [PATCH 4/7] fix https://github.com/takayama-lily/onebot/issues/15 --- lib/message/parser.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/message/parser.js b/lib/message/parser.js index fc27d9d5..b53ba839 100644 --- a/lib/message/parser.js +++ b/lib/message/parser.js @@ -102,6 +102,8 @@ async function parseMessage(rich, from = 0) { msg.data.file = o[7].raw.toString("hex") + (o[2]?o[2]:""); if (o[15]) msg.data.url = "http://c2cpicdw.qpic.cn" + o[15].raw; + else + msg.data.url = `http://c2cpicdw.qpic.cn/offpic_new/0/${o[10].raw}/0?term=2]`; break; case 8: //customFace // console.log(Object.getPrototypeOf(o)) @@ -109,6 +111,8 @@ async function parseMessage(rich, from = 0) { msg.data.file = o[13].raw.toString("hex") + (o[25]?o[25]:""); if (o[16]) msg.data.url = "http://gchat.qpic.cn" + o[16].raw; + else + msg.data.url = `http://gchat.qpic.cn/gchatpic_new/0/0-0-${o[13].raw.toString("hex").toUpperCase()}/0?term=2`; break; case 53: if (o[1] === 3) { From 44e3f492ada91964dd5c6ec0005b87f5c03cb775 Mon Sep 17 00:00:00 2001 From: takayama Date: Wed, 18 Nov 2020 03:53:42 +0900 Subject: [PATCH 5/7] add friend poke --- docs/event.md | 6 ++++++ docs/project.md | 4 +++- lib/online-push.js | 49 +++++++++++++++++++++++++++------------------- lib/troop.js | 14 +++++++------ 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/docs/event.md b/docs/event.md index dd8dfc1c..5860507e 100644 --- a/docs/event.md +++ b/docs/event.md @@ -175,6 +175,12 @@ client.on("notice", (data)=>console.log(data)); //监听所有的通知事件 + *`nickname`* + *`signature`* + + `notice.friend.poke` 好友戳一戳事件 + + *`operator_id`* 操作者 + + *`user_id`* 目标 + + *`action`* 动作名 + + *`suffix`* 动作后缀 + + **notice.group** + `notice.group.increase` 群员增加 diff --git a/docs/project.md b/docs/project.md index 1bbfe741..a276c9de 100644 --- a/docs/project.md +++ b/docs/project.md @@ -36,7 +36,8 @@ |撤回|◯|◯| |修改名片|◯|| |修改群名|◯|◯| -|群公告|◯|◯| +|修改群头像|◯|| +|发群公告|◯|◯| |其他设置|✕|◯| |群文件|✕|◯| |设置头衔|◯|◯| @@ -49,6 +50,7 @@ |群申请|◯|◯| |邀请好友|◯|| |添加群|◯|| +|戳一戳|◯|◯| ---- diff --git a/lib/online-push.js b/lib/online-push.js index 2a12675a..76e5599e 100644 --- a/lib/online-push.js +++ b/lib/online-push.js @@ -159,7 +159,32 @@ const push528 = { if (typeof sub0x27[data[2]] === "function") sub0x27[data[2]].call(this, data, time); }, - 0x44: function(buf, time) {}, + 0x122: function(buf, time) { + const data = pb.decode(buf); + const eve = {time}; + Object.assign(eve, parsePoke.call(this, data)); + this.em("notice.friend.poke", eve); + }, +} + +function parsePoke(data) { + let user_id, operator_id, action, suffix; + for (let o of data[7]) { + const name = String(o[1].raw); + if (name === "action_str") + action = String(o[2].raw); + if (name === "uin_str1") + operator_id = parseInt(String(o[2].raw)); + if (name === "uin_str2") + user_id = parseInt(String(o[2].raw)); + if (name === "suffix_str") + suffix = String(o[2].raw); + } + if (!operator_id) + operator_id = this.uin; + if (!user_id) + user_id = this.uin; + return {user_id, operator_id, action, suffix}; } @@ -209,25 +234,9 @@ const push732 = { 0x14: function(group_id, buf, time) { const data = pb.decode(buf.slice(7))[26]; if (data) { - let user_id, operator_id, action, suffix; - for (let o of data[7]) { - const name = String(o[1].raw); - if (name === "action_str") - action = String(o[2].raw); - if (name === "uin_str1") - operator_id = parseInt(String(o[2].raw)); - if (name === "uin_str2") - user_id = parseInt(String(o[2].raw)); - if (name === "suffix_str") - suffix = String(o[2].raw); - } - if (!operator_id) - return; - if (!user_id) - user_id = this.uin; - this.em("notice.group.poke", { - group_id, user_id, operator_id, action, suffix, time - }); + const eve = {group_id, time}; + Object.assign(eve, parsePoke.call(this, data)); + this.em("notice.group.poke", eve); } }, 0x06: function(group_id, buf, time) { diff --git a/lib/troop.js b/lib/troop.js index 2bb24ff4..bf0b84fb 100644 --- a/lib/troop.js +++ b/lib/troop.js @@ -194,16 +194,18 @@ async function quitGroup(group_id, dismiss = false) { /** * @this {import("./ref").Client} - * @param {Number} group_id - * @param {Number} user_id + * @param {Number} group_id 发送的对象,可以是好友uin + * @param {Number} user_id 戳一戳的对象 * @returns {import("./ref").ProtocolResponse} */ async function pokeMember(group_id, user_id) { var [group_id, user_id] = uinAutoCheck(group_id, user_id); - const body = pb.encode({ - 1: user_id, - 2: group_id - }); + const o = {1: user_id}; + if (this.gl.has(group_id) || !this.fl.has(group_id)) + o[2] = group_id; + else + o[5] = group_id; + const body = pb.encode(o); await this.sendUNI("OidbSvc.0xed3", body); } From 0bb72e9f9110a9509b90524e46e60616a5670ceb Mon Sep 17 00:00:00 2001 From: takayama Date: Wed, 18 Nov 2020 18:10:00 +0900 Subject: [PATCH 6/7] fix https://github.com/takayama-lily/onebot/issues/18 fix https://github.com/takayama-lily/onebot/issues/15 --- lib/message/parser.js | 20 +++++++++----------- lib/online-push.js | 11 +++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/message/parser.js b/lib/message/parser.js index b53ba839..1f0ec1c2 100644 --- a/lib/message/parser.js +++ b/lib/message/parser.js @@ -52,7 +52,7 @@ async function parseMessage(rich, from = 0) { extra = o; break; case 37: //generalFlags - if (o[7]) + if (o[6] === 1 && o[7]) return await parseMultiMsg.call(this, o[7].raw, from); break; case 12: //xml @@ -61,17 +61,17 @@ async function parseMessage(rich, from = 0) { ignore_text = true; } catch (e) {} break; - case 51: + case 51: //json try { [msg.type, msg.data] = await parseJsonElem.call(this, o); ignore_text = true; } catch (e) {} break; - case 5: + case 5: //file [msg.type, msg.data] = await parseTransElem.call(this, o, from); ignore_text = true; break; - case 1: + case 1: //text if (ignore_text) break; if (bface_tmp && o[1]) { msg.data.file = bface_tmp, msg.type = "bface"; @@ -90,29 +90,27 @@ async function parseMessage(rich, from = 0) { } msg.data.text = String(o[1].raw); break; - case 2: + case 2: //face msg.type = "face", msg.data.id = o[1]; break; - case 6: + case 6: //bface bface_tmp = o[4].raw.toString("hex") + o[7].raw.toString("hex") + o[5]; break; case 4: //notOnlineImage - // console.log(Object.getPrototypeOf(o)) msg.type = "image"; msg.data.file = o[7].raw.toString("hex") + (o[2]?o[2]:""); if (o[15]) msg.data.url = "http://c2cpicdw.qpic.cn" + o[15].raw; else - msg.data.url = `http://c2cpicdw.qpic.cn/offpic_new/0/${o[10].raw}/0?term=2]`; + msg.data.url = `http://c2cpicdw.qpic.cn/offpic_new/${from}/${o[10].raw}/0?term=2`; break; case 8: //customFace - // console.log(Object.getPrototypeOf(o)) msg.type = "image"; msg.data.file = o[13].raw.toString("hex") + (o[25]?o[25]:""); if (o[16]) msg.data.url = "http://gchat.qpic.cn" + o[16].raw; else - msg.data.url = `http://gchat.qpic.cn/gchatpic_new/0/0-0-${o[13].raw.toString("hex").toUpperCase()}/0?term=2`; + msg.data.url = `http://gchat.qpic.cn/gchatpic_new/0/${from}-${o[7]}-${o[13].raw.toString("hex").toUpperCase()}/0?term=2`; break; case 53: if (o[1] === 3) { @@ -131,7 +129,7 @@ async function parseMessage(rich, from = 0) { msg.data.text = String(o[2][2].raw); } break; - case 9999: + case 9999: //ptt [msg.type, msg.data] = await parsePttElem.call(this, o, from); ignore_text = true; break; diff --git a/lib/online-push.js b/lib/online-push.js index 76e5599e..dff3f253 100644 --- a/lib/online-push.js +++ b/lib/online-push.js @@ -6,6 +6,7 @@ const {genC2CMessageId, genGroupMessageId} = require("./common"); /** * OnlinePush回执 + * @this {import("./ref").Client} * @param {Number} svrip * @param {Number} seq * @param {Buffer[]} rubbish @@ -165,6 +166,9 @@ const push528 = { Object.assign(eve, parsePoke.call(this, data)); this.em("notice.friend.poke", eve); }, + 0x115: function(buf, time) { + // 正在输入 + }, } function parsePoke(data) { @@ -316,6 +320,9 @@ const push732 = { }, }; +/** + * @this {import("./ref").Client} + */ function onOnlinePush(blob, seq) { const nested = jce.decodeWrapper(blob); const parent = jce.decode(nested); @@ -331,6 +338,7 @@ function onOnlinePush(blob, seq) { if (v[2] === 528) { const decoded = jce.decode(v[6]); const type = decoded[0], buf = decoded[10]; + // console.log(type, buf.toString("hex").replace(/(.)(.)/g, '$1$2 ')) if (typeof push528[type] === "function") push528[type].call(this, buf, time); } @@ -344,6 +352,9 @@ function onOnlinePush(blob, seq) { handleOnlinePush.call(this, parent[3], seq, rubbish); } +/** + * @this {import("./ref").Client} + */ function onOnlinePushTrans(blob, seq) { const push = pb.decode(blob); handleOnlinePush.call(this, push[11], seq); From 1ace89bcf4cc9efa0cd8df56f348fea1c935fed1 Mon Sep 17 00:00:00 2001 From: takayama Date: Wed, 18 Nov 2020 18:17:01 +0900 Subject: [PATCH 7/7] up ver to 1.10.9 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 06e8e7a9..dc2b00cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "oicq", - "version": "1.10.8", + "version": "1.10.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 23c67743..4eb8f1fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "oicq", - "version": "1.10.8", + "version": "1.10.9", "description": "QQ protocol!", "main": "client.js", "scripts": {