Skip to content

Commit 89107d9

Browse files
author
MomoCow
committed
docs: update API docs [skip ci]
1 parent a706662 commit 89107d9

12 files changed

+497
-556
lines changed

Diff for: README.md

+9-55
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
88

99

10-
## 分支狀態
10+
## 🚧 分支狀態
1111
- 主線
1212
- [![Build Status](https://travis-ci.org/momocow/node-cq-websocket.svg?branch=master)](https://travis-ci.org/momocow/node-cq-websocket)
1313
- [![Coverage Status](https://coveralls.io/repos/github/momocow/node-cq-websocket/badge.svg?branch=master)](https://coveralls.io/github/momocow/node-cq-websocket?branch=master)
1414
- dev
1515
- [![Build Status](https://travis-ci.org/momocow/node-cq-websocket.svg?branch=dev)](https://travis-ci.org/momocow/node-cq-websocket)
1616
- [![Coverage Status](https://coveralls.io/repos/github/momocow/node-cq-websocket/badge.svg?branch=dev)](https://coveralls.io/github/momocow/node-cq-websocket?branch=dev)
1717

18-
## 關於 Node CQWebSocket SDK
18+
## 🗯️ 關於此 SDK
1919
依賴 CQHTTP API 插件的 websocket 接口, 為 NodeJs 開發者提供一個搭建 QQ 聊天機器人的 SDK。
2020

2121
關於 CQHTTP API 插件,見 [richardchien/coolq-http-api](https://github.com/richardchien/coolq-http-api#readme)
@@ -24,62 +24,16 @@
2424
2525
> 由於付費問題,本 SDK 目前僅針對酷Q Air做測試。
2626
27-
### 功能特色
27+
## 🎉 功能/特色
2828
- 輕鬆配置, 快速搭建 QQ 聊天機器人。
2929
- 自動維護底層連線, 開發者只需專注在聊天應用的開發。若斷線, 可依照配置[重新連線](#自動重新連線說明)
3030
- 支持消息監聽器內, [快速響應](#快速響應)
3131
- 連線建立時, 可[自動獲取機器人QQ號](#自動獲取機器人qq號)
32-
- 兼容 CQHTTP API 插件 `v3.x``v4.x` 兩個大版本。
3332

34-
## 使用方式
35-
### CDN
33+
## 🗎 SDK 文件
34+
[閱讀更多 ➡️](https://github.com/momocow/node-cq-websocket/tree/master/docs/README.md)
3635

37-
如果你在網頁前端上使用,可以通過 CDN 引入。
38-
39-
- 最新版
40-
```html
41-
<script src="https://cdn.jsdelivr.net/npm/cq-websocket/dist/cq-websocket.min.js"></script>
42-
```
43-
44-
- 指定版本 (以 `v2.0.0` 為例, 可依照實際需求版本自行替換版號)
45-
> CDN 引入方式僅提供 v1.8.1 以上的版本使用
46-
```html
47-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cq-websocket.min.js"></script>
48-
```
49-
50-
在你的 js 代碼中, 使用全局變數 `CQWebSocketSDK` 獲取 SDK。
51-
52-
```js
53-
// 全局變數 CQWebSocketSDK 存在於 window 對象下
54-
const { CQWebSocket } = window.CQWebSocketSDK
55-
const bot = new CQWebSocket()
56-
```
57-
58-
### NPM
59-
60-
如果你使用打包工具(如 webpack, browserify...)或 NodeJS,可以通過 NPM 安裝。
61-
62-
```
63-
npm install cq-websocket
64-
```
65-
66-
將 SDK 導入代碼
67-
```js
68-
const { CQWebSocket } = require('cq-websocket')
69-
```
70-
71-
或是使用 ES6 import
72-
```js
73-
import { CQWebSocket } from 'cq-websocket'
74-
```
75-
76-
## 快速開始
77-
[閱讀更多...](docs/get-started/README.md)
78-
79-
## API 文件
80-
[閱讀更多...](docs/api/README.md)
81-
82-
## 開發者看板
36+
## 🛠️ 開發者看板
8337
本 SDK 採用 [ava](https://github.com/avajs/ava) 框架執行測試。
8438

8539
### 打包 CQWebSocket 至 browser 環境
@@ -95,7 +49,7 @@ npm run build-demo
9549
打包 `/demo/webpack/app.js` 內容, 在 `/demo/webpack/www` 目錄下產生一個 `bundle.js`
9650

9751
### 開發日誌
98-
[<點擊前往>](./docs/CHANGELOG.md)
52+
[閱讀更多 ➡️](https://github.com/momocow/node-cq-websocket/tree/master/docs/CHANGELOG.md)
9953

10054
### Known Issues
10155
- CQHTTP API 插件尚未支援收發 Fragmant, 暫時禁用
@@ -116,7 +70,7 @@ RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be
11670
at W3CWebSocket.send (/***/node-cq-websocket/node_modules/websocket/lib/W3CWebSocket.js:116:26)
11771
```
11872

119-
## 歡迎餵食 ☕
120-
請勿拍打 🤜 無限期掙飯中 🍙
73+
## 🍙 歡迎餵食
74+
請勿拍打 🤜 無限期掙飯中
12175

12276
<a href="https://www.buymeacoffee.com/momocow" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>

Diff for: docs/README.md

+26-444
Large diffs are not rendered by default.

Diff for: docs/api/ArrayMessage.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ArrayMessage
2+
```ts
3+
type ArrayMessage = (CQTag | CQHTTPMessage)[]
4+
```
5+
6+
- `CQTag` 見 [CQTag](message/README.md#CQTag)。
7+
- `CQHTTPMessage` 見 [CQHTTPMessage](CQHTTPMessage.md)。
8+
9+
此結構可作為**快速響應**或是 **API 調用發送訊息**之消息格式,亦可使用 `string` 發送消息。
10+
11+
可見 CQHTTP API 之[消息格式](https://cqhttp.cc/docs/#/Message)說明。

Diff for: docs/api/CQEvent.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# CQEvents
2+
3+
- [CQEvents](#cqevents)
4+
- [stopPropagation](#stoppropagation)
5+
- [getMessage](#getmessage)
6+
- [setMessage](#setmessage)
7+
- [appendMessage](#appendmessage)
8+
- [hasMessage](#hasmessage)
9+
- [onResponse](#onresponse)
10+
- [onError](#onerror)
11+
12+
此類別無法自行創建實例。
13+
此類別的實例於 `message` 事件監聽器,作為第一個參數傳入。
14+
15+
## stopPropagation
16+
```js
17+
e.stopPropagation()
18+
```
19+
- 返回值: `void`
20+
21+
<!-- TODO -->
22+
截獲事件並停止[事件傳播](#事件傳播)
23+
24+
## getMessage
25+
```js
26+
e.getMessage()
27+
```
28+
- 返回值: `string` | [`ArrayMessage`](ArrayMessage.md)
29+
30+
取得目前的響應訊息。
31+
32+
## setMessage
33+
```js
34+
e.setMessage(msg)
35+
```
36+
- `msg` string | [`ArrayMessage`](ArrayMessage.md)
37+
- 返回值: `void`
38+
39+
設置響應訊息。
40+
41+
## appendMessage
42+
```js
43+
e.appendMessage(msg)
44+
```
45+
- `msg` string | [CQTag](message/README.md) | [CQHTTPMessage](CQHTTPMessage.md)
46+
- 返回值: `void`
47+
48+
串接響應訊息。
49+
50+
## hasMessage
51+
```js
52+
e.hasMessage()
53+
```
54+
55+
- 返回值: `boolean`
56+
57+
是否有響應訊息。
58+
59+
## onResponse
60+
```js
61+
e.onResponse(handler[, options])
62+
e.onResponse(options)
63+
```
64+
- `handler` (res: ResObj) => void
65+
- `options` object 同[API 調用](CQWebSocket.md#api-call)之 options
66+
67+
設置響應結果的處理器, 用以追蹤訊息是否傳送成功。
68+
69+
`ResObj` 對象, 此為 CQHttp API 的[回應對象](https://cqhttp.cc/docs/#/WebSocketAPI?id=api-%E6%8E%A5%E5%8F%A3)
70+
71+
## onError
72+
```js
73+
e.onError(handler)
74+
```
75+
- `handler` (err: ApiTimeoutError) => void
76+
77+
設置錯誤處理器, 可能的錯誤已知有響應超時。

Diff for: docs/api/CQHTTPMessage.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# CQHTTPMessage
2+
```ts
3+
interface CQHTTPMessage {
4+
type: string
5+
data: null | {
6+
[key: string]: string
7+
}
8+
}
9+
```
10+
11+
見 CQHTTP API 之[消息段](https://cqhttp.cc/docs/#/Message?id=%E6%B6%88%E6%81%AF%E6%AE%B5%EF%BC%88%E5%B9%BF%E4%B9%89-cq-%E7%A0%81%EF%BC%89)說明。

0 commit comments

Comments
 (0)