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

Commit

Permalink
Merge pull request #92 from takayama-lily/dev
Browse files Browse the repository at this point in the history
-
  • Loading branch information
takayama-lily authored Nov 18, 2020
2 parents 6df879c + 1ace89b commit ff6cf5b
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 51 deletions.
2 changes: 2 additions & 0 deletions client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// <reference types="node" />

import * as events from 'events';
import * as log4js from 'log4js';

export type Uin = string | number;

Expand Down Expand Up @@ -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; //直接关闭连接
Expand Down
6 changes: 6 additions & 0 deletions docs/event.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` 群员增加
Expand Down
4 changes: 3 additions & 1 deletion docs/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
|撤回|||
|修改名片|||
|修改群名|||
|群公告|||
|修改群头像|||
|发群公告|||
|其他设置|||
|群文件|||
|设置头衔|||
Expand All @@ -49,6 +50,7 @@
|群申请|||
|邀请好友|||
|添加群|||
|戳一戳|||

----

Expand Down
12 changes: 2 additions & 10 deletions lib/individual.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/message/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class Builder {
//只有md5和size
else {
size = parseInt(file.substr(32));
size = size > 0 ? size : 0;
size = size > 0 ? size : 1;
}
}

Expand Down
20 changes: 11 additions & 9 deletions lib/message/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";
Expand All @@ -90,25 +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/${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/${from}-${o[7]}-${o[13].raw.toString("hex").toUpperCase()}/0?term=2`;
break;
case 53:
if (o[1] === 3) {
Expand All @@ -127,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;
Expand Down
60 changes: 40 additions & 20 deletions lib/online-push.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {genC2CMessageId, genGroupMessageId} = require("./common");

/**
* OnlinePush回执
* @this {import("./ref").Client}
* @param {Number} svrip
* @param {Number} seq
* @param {Buffer[]} rubbish
Expand Down Expand Up @@ -159,7 +160,35 @@ 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);
},
0x115: function(buf, time) {
// 正在输入
},
}

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};
}


Expand Down Expand Up @@ -209,25 +238,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) {
Expand Down Expand Up @@ -307,6 +320,9 @@ const push732 = {
},
};

/**
* @this {import("./ref").Client}
*/
function onOnlinePush(blob, seq) {
const nested = jce.decodeWrapper(blob);
const parent = jce.decode(nested);
Expand All @@ -322,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);
}
Expand All @@ -335,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);
Expand Down
2 changes: 0 additions & 2 deletions lib/ref.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/// <reference types="node" />

import * as oicq from '../client';
import * as log4js from 'log4js';

//////////

Expand Down Expand Up @@ -93,7 +92,6 @@ export interface Statistics {
//////////

export class Client extends oicq.Client {
logger: log4js.Logger;
reconn_flag: boolean;
config: oicq.ConfBot;
status: Symbol;
Expand Down
14 changes: 8 additions & 6 deletions lib/troop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oicq",
"version": "1.10.8",
"version": "1.10.9",
"description": "QQ protocol!",
"main": "client.js",
"scripts": {
Expand Down

0 comments on commit ff6cf5b

Please sign in to comment.