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

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
fix fl
optimize heartbeat
  • Loading branch information
takayama-lily committed Nov 25, 2020
1 parent 5f3840a commit 3b03a3d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bot.login(password);
# npm test
```

**文档**
**相关文档**

[功能实现程度](./docs/project.md)
[API](./docs/api.md)
Expand Down
15 changes: 8 additions & 7 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,23 @@ class AndroidClient extends Client {
this.doCircle();
try {
await wt.heartbeat.call(this);
if (Date.now() - this.send_timestamp >= 59000) {
if (!await core.getMsg.call(this)) {
if (!await core.getMsg.call(this) && this.isOnline())
this.destroy();
}
}
} catch {
core.getMsg.call(this);
try {
await wt.heartbeat.call(this);
} catch {
this.logger.warn("Heartbeat timeout!");
if (Date.now() - this.recv_timestamp > 3000)
if (Date.now() - this.recv_timestamp > 5000 && this.isOnline())
this.destroy();
}
}
}, 60000);
}, 30000);
}
stopHeartbeat() {
clearInterval(this.heartbeat);
Expand Down Expand Up @@ -372,8 +378,6 @@ class AndroidClient extends Client {
}
doCircle() {
wt.exchangeEMP.call(this);
if (Date.now() - this.send_timestamp >= 59000)
core.getMsg.call(this);
for (let time of this.seq_cache.keys()) {
if (timestamp() - time >= 60)
this.seq_cache.delete(time);
Expand Down Expand Up @@ -743,6 +747,3 @@ function createClient(uin, config = {}) {
module.exports = {
createClient, setGlobalConfig
};

const c = new AndroidClient(123456)
c.login().then(console.log)
12 changes: 6 additions & 6 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# API

+ [启动-创建实例](#createClient(uin[,config]))
+ [启动-创建实例](#createclientuinconfig)
+ [系统类API](#系统类API)
+ [应用类API](#应用类API)
+ [获取列表和资料](#获取好友群群员列表和资料)
Expand All @@ -29,7 +29,7 @@ const uin = 123456789, config = {};
const client = oicq.createClient(uin, config);
```

关于config请参考头文件中的 [ConfBot](../client.d.ts#ConfBot)
> 关于config请参考头文件中的 [ConfBot](../client.d.ts#ConfBot)
----

Expand Down Expand Up @@ -62,8 +62,6 @@ const client = oicq.createClient(uin, config);
}
```

使用 [CQHTTP](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md) 风格的命名和参数。

----

### 获取好友、群、群员列表和资料
Expand Down Expand Up @@ -93,7 +91,7 @@ message可以使用 `Array` 格式或 `String` 格式,支持CQ码
+ async `client.sendDiscussMsg(discuss_id, user_id, message[, auto_escape])`
+ async `client.deleteMsg(message_id)`

auto_escape参数:是否原样输出CQ码(既不解析),默认false
> auto_escape参数:是否原样输出CQ码(既不解析),默认false
----

Expand Down Expand Up @@ -122,6 +120,8 @@ message可以使用 `Array` 格式或 `String` 格式,支持CQ码

### 加群加好友、删好友、邀请好友、点赞

> 注意:加群加好友本身是风险接口,频繁调用会被风控(表现为几天内别人无法看到你的请求)
+ async `client.addGroup(group_id[, comment])`
+ async `client.addFriend(group_id, user_id[, comment])`
+ async `client.deleteFriend(user_id[, block])` block默认true
Expand Down Expand Up @@ -159,7 +159,7 @@ message可以使用 `Array` 格式或 `String` 格式,支持CQ码

### 重载好友列表、群列表

注意:一旦调用,重载完成之前bot不接受其他任何请求,也不会上报任何事件
> 注意:一旦调用,重载完成之前bot不接受其他任何请求,也不会上报任何事件
+ async `client.reloadFriendList()`
+ async `client.reloadGroupList()`
2 changes: 0 additions & 2 deletions docs/event.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ client.on("notice", (data)=>console.log(data)); //监听所有的通知事件

----

以下事件使用 [CQHTTP](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/README.md) 风格的命名和字段

## Event: `message`

+ **message.private**
Expand Down
2 changes: 2 additions & 0 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ async function getMsg(sync_flag = 0) {
}
if (rsp[4] !== 2)
getMsg.call(this, rsp[4]);
return true;
} catch (e) {
this.logger.debug("getMsg发生错误。");
this.logger.debug(e);
return false;
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ async function initFL() {
*/
async function initGL() {
this.gl = new Map;
const GetTroopListReqV2Simplify = jce.encodeStruct([
const GetTroopListReqV2 = jce.encodeStruct([
this.uin, 0, null, [], 1, 8, 0, 1, 1
]);
const extra = {
req_id: this.seq_id + 1,
service: "mqq.IMService.FriendListServiceServantObj",
method: "GetTroopListReqV2Simplify",
method: "GetTroopListReqV2",
};
const body = jce.encodeWrapper({GetTroopListReqV2Simplify}, extra);
const body = jce.encodeWrapper({GetTroopListReqV2}, extra);
try {
const blob = await this.sendUNI("friendlist.GetTroopListReqV2", body);
const nested = jce.decodeWrapper(blob);
Expand Down

0 comments on commit 3b03a3d

Please sign in to comment.