Skip to content

Commit

Permalink
[*] 更新依赖
Browse files Browse the repository at this point in the history
[*] 修改自行编写 `events` 来替换 `mitt` @YunYouJun
[*] 更新接口
[*] 优化 `bun` 兼容性
  • Loading branch information
huankong233 committed Sep 27, 2024
1 parent 5e553d9 commit d7d1767
Show file tree
Hide file tree
Showing 8 changed files with 573 additions and 308 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## 2024

### 09-27 v0.3.0

- [*] 更新依赖
- [*] 修改自行编写 `events` 来替换 `mitt` @YunYouJun
- [*] 更新接口
- [*] 优化 `bun` 兼容性

### 09-25 v0.2.22

- [*] 使用 `mitt` 替换 `node:events` 来尝试兼容 `bun` 或其他引擎
Expand Down
98 changes: 10 additions & 88 deletions docs/src/guide/bind-event.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function handler(context) {
console.log(context.message)
}

// ↓ 还能单独导入SocketHandlers等
import type { AllHandlers } from 'node-napcat-ts'
// ↓ 手动加上,这样就可以拥有完整的类型检查和提词器
function handler(context: AllHandlers['message']) {
Expand All @@ -43,95 +44,16 @@ function handler(context: AllHandlers['message']) {

## 事件名大全

### 总类型
::: tip 注意
如有缺少或类型错误请提交 [pr](https://github.com/huankong233/node-napcat-ts/compare)
:::

接口类: `AllHandlers`
[NapCatQQ文档](https://napneko.github.io/zh-CN/develop/compatibility/event) 为准

### socket 事件
::: tip 注意
使用父类可以被子类触发

接口类: `SocketHandler`
比如:

| 事件名 | 说明 | 类型 |
| ------------------- | ------------------------ | -------------- |
| `socket` | 以下子事件都会触发该事件 | |
| `socket.connecting` | 连接中 | `WSConnecting` |
| `socket.open` | 连接成功 | `WSOpenRes` |
| `socket.close` | 连接关闭 | `WSCloseRes` |
| `socket.error` | 连接出错 | `WSErrorRes` |

### api 事件

接口类: `ApiHandler`

| 事件名 | 说明 | 类型 |
| ---------------------- | ------------------------ | ---------------------------------------- |
| `api` | 以下子事件都会触发该事件 | |
| `api.preSend` | 请求发送前 | `APIRequest<keyof WSSendParam>` |
| `api.response` | | |
| `api.response.success` | 请求成功 | `APISuccessResponse<keyof WSSendReturn>` |
| `api.response.failure` | 请求失败 | `APIErrorResponse` |

### meta_event 事件

接口类: `MetaEventHandler`

| 事件名 | 说明 | 类型 |
| ---------------------- | ------------------------ | ----------- |
| `meta_event` | 以下子事件都会触发该事件 | |
| `meta_event.lifecycle` | 生命周期 | `LifeCycle` |
| `meta_event.heartbeat` | 心跳 | `HeartBeat` |

### message 事件

接口类: `MessageHandler`

| 事件名 | 说明 | 类型 |
| ----------------- | ------------------------ | ---------------- |
| `message` | 以下子事件都会触发该事件 | |
| `message.private` | 私聊消息 | `PrivateMessage` |
| `message.group` | 群聊消息 | `GroupMessage` |

### message_sent 事件

接口类: `MessageSentHandler`

| 事件名 | 说明 | 类型 |
| ---------------------- | ------------------------ | -------------------- |
| `message_sent` | 以下子事件都会触发该事件 | |
| `message_sent.private` | 私聊消息 | `PrivateMessageSelf` |
| `message_sent.group` | 群聊消息 | `GroupMessageSelf` |

### request 事件

接口类: `RequestHandler`

| 事件名 | 说明 | 类型 |
| ---------------- | ------------------------ | --------------- |
| `request` | 以下子事件都会触发该事件 | |
| `request.friend` | 加好友请求 | `RequestFriend` |
| `request.group` | 加群请求 | `RequestGroup` |

### notice 事件

接口类: `NoticeHandler`

| 事件名 | 说明 | 类型 |
| ----------------------------------- | ------------------------ | ------------------------- |
| `notice` | 以下子事件都会触发该事件 | |
| `notice.friend_recall` | 私聊消息撤回 | `FriendRecall` |
| `notice.group_recall` | 群聊消息撤回 | `GroupRecall` |
| `notice.group_increase` | 群聊成员增加 | `GroupIncrease` |
| `notice.group_decrease` | 群聊成员减少 | `GroupDecrease` |
| `notice.group_admin` | 群聊管理员变动 | `GroupAdmin` |
| `notice.group_upload` | 群聊文件上传 | `GroupUpload` |
| `notice.group_ban` | 群聊禁言 | `GroupBan` |
| `notice.friend_add` | 好友添加 | `FriendAdd` |
| `notice.notify` | | |
| `notice.notify.input_status` | 输入状态 | |
| `notice.notify.input_status.friend` | 私聊输入状态 | `NotifyInputStatusFriend` |
| `notice.notify.input_status.group` | 群聊输入状态 | `NotifyInputStatusGroup` |
| `notice.notify.poke` | 戳一戳 | |
| `notice.notify.poke.friend` | 私聊戳一戳 | `NotifyPokeFriend` |
| `notice.notify.poke.group` | 群聊戳一戳 | `NotifyPokeGroup` |
| `notice.essence` | 群聊设精(设置精华) | `Essence` |
| `notice.group_msg_emoji_like` | 群聊表情回应 | `GroupMsgEmojiLike` |
`message` 可以被 `message.private` 触发
:::
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-napcat-ts",
"version": "0.2.22",
"version": "0.3.0",
"description": "napcat SDK for Node",
"license": "MIT",
"type": "module",
Expand Down Expand Up @@ -35,26 +35,29 @@
"url": "https://github.com/YunYouJun"
}
],
"repository": "https://github.com/huankong233/node-napcat-ts.git",
"repository": {
"type": "git",
"url": "git+https://github.com/huankong233/node-napcat-ts.git"
},
"scripts": {
"build": "tsc",
"dev": "nodemon",
"test": "tsx test/index.ts",
"typecheck": "tsc --noEmit",
"docs:dev": "pnpm -C docs run dev",
"docs:build": "pnpm -C docs run build",
"typecheck": "tsc --noEmit"
"docs:build": "pnpm -C docs run build"
},
"dependencies": {
"isomorphic-ws": "^5.0.0",
"nanoid": "^5.0.7",
"ws": "^8.18.0"
},
"devDependencies": {
"@types/node": "^22.5.1",
"@types/node": "^22.7.3",
"@types/ws": "^8.5.12",
"dotenv": "^16.4.5",
"nodemon": "^3.1.4",
"tsx": "^4.19.0",
"typescript": "^5.5.4"
"nodemon": "^3.1.7",
"tsx": "^4.19.1",
"typescript": "^5.6.2"
}
}
Loading

0 comments on commit d7d1767

Please sign in to comment.