onebots 0.4.22 → 0.4.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -72
- package/lib/adapter.d.ts +55 -0
- package/lib/adapter.js +60 -0
- package/lib/adapters/icqq/index.d.ts +36 -0
- package/lib/adapters/icqq/index.js +300 -0
- package/lib/adapters/icqq/utils.d.ts +6 -0
- package/lib/adapters/icqq/utils.js +26 -0
- package/lib/adapters/qq/bot.d.ts +24 -0
- package/lib/adapters/qq/bot.js +20 -0
- package/lib/adapters/qq/constans.d.ts +69 -0
- package/lib/adapters/qq/constans.js +128 -0
- package/lib/adapters/qq/elements.d.ts +125 -0
- package/lib/adapters/qq/elements.js +8 -0
- package/lib/adapters/qq/entries/channel.d.ts +17 -0
- package/lib/adapters/qq/entries/channel.js +2 -0
- package/lib/adapters/qq/entries/friend.d.ts +8 -0
- package/lib/adapters/qq/entries/friend.js +2 -0
- package/lib/adapters/qq/entries/group.d.ts +6 -0
- package/lib/adapters/qq/entries/group.js +2 -0
- package/lib/adapters/qq/entries/groupMember.d.ts +7 -0
- package/lib/adapters/qq/entries/groupMember.js +2 -0
- package/lib/adapters/qq/entries/guild.d.ts +21 -0
- package/lib/adapters/qq/entries/guild.js +2 -0
- package/lib/adapters/qq/entries/guildMember.d.ts +9 -0
- package/lib/adapters/qq/entries/guildMember.js +2 -0
- package/lib/adapters/qq/entries/user.d.ts +9 -0
- package/lib/adapters/qq/entries/user.js +2 -0
- package/lib/adapters/qq/event.d.ts +28 -0
- package/lib/adapters/qq/event.js +24 -0
- package/lib/adapters/qq/index.d.ts +35 -0
- package/lib/adapters/qq/index.js +170 -0
- package/lib/adapters/qq/message.d.ts +83 -0
- package/lib/adapters/qq/message.js +272 -0
- package/lib/adapters/qq/qqBot.d.ts +122 -0
- package/lib/adapters/qq/qqBot.js +438 -0
- package/lib/adapters/qq/sessionManager.d.ts +33 -0
- package/lib/adapters/qq/sessionManager.js +257 -0
- package/lib/adapters/qq/types.d.ts +45 -0
- package/lib/adapters/qq/types.js +2 -0
- package/lib/adapters/qq/utils.d.ts +12 -0
- package/lib/adapters/qq/utils.js +86 -0
- package/lib/bin.js +17 -2
- package/lib/config.sample.yaml +11 -5
- package/lib/db.js +6 -6
- package/lib/index.d.ts +5 -5
- package/lib/onebot.d.ts +30 -22
- package/lib/onebot.js +42 -165
- package/lib/server/app.d.ts +22 -12
- package/lib/server/app.js +97 -71
- package/lib/service/V11/action/common.d.ts +11 -12
- package/lib/service/V11/action/common.js +19 -65
- package/lib/service/V11/action/friend.d.ts +6 -14
- package/lib/service/V11/action/friend.js +6 -16
- package/lib/service/V11/action/group.d.ts +20 -23
- package/lib/service/V11/action/group.js +20 -30
- package/lib/service/V11/action/index.d.ts +1 -1
- package/lib/service/V11/db_entities.d.ts +1 -1
- package/lib/service/V11/db_entities.js +1 -1
- package/lib/service/V11/db_sqlite.d.ts +1 -1
- package/lib/service/V11/db_sqlite.js +5 -7
- package/lib/service/V11/index.d.ts +46 -14
- package/lib/service/V11/index.js +163 -134
- package/lib/service/V12/action/common.d.ts +3 -67
- package/lib/service/V12/action/common.js +9 -63
- package/lib/service/V12/action/friend.d.ts +4 -10
- package/lib/service/V12/action/friend.js +4 -12
- package/lib/service/V12/action/group.d.ts +19 -21
- package/lib/service/V12/action/group.js +19 -27
- package/lib/service/V12/action/guild.d.ts +40 -13
- package/lib/service/V12/action/guild.js +99 -11
- package/lib/service/V12/action/index.d.ts +1 -1
- package/lib/service/V12/index.d.ts +37 -13
- package/lib/service/V12/index.js +63 -94
- package/lib/service.d.ts +7 -2
- package/lib/service.js +5 -1
- package/lib/types.d.ts +2 -2
- package/lib/types.js +3 -3
- package/lib/utils.d.ts +7 -4
- package/lib/utils.js +18 -1
- package/package.json +74 -70
- package/lib/service/V11/utils.d.ts +0 -9
- package/lib/service/V11/utils.js +0 -31
- package/lib/service/V12/utils.d.ts +0 -8
- package/lib/service/V12/utils.js +0 -47
package/README.md
CHANGED
|
@@ -1,52 +1,63 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<h1
|
|
2
|
+
<h1>使用ts实现的oneBot应用启动器,支持icqq和qq官方机器人</h1>
|
|
3
3
|
<p>
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/onebots)
|
|
6
|
-
[](https://www.npmjs.com/package/onebots)
|
|
8
|
-
[](https://onebot.dev/)
|
|
9
|
-
[](https://12.onebot.dev/)
|
|
10
|
-
[](https://nodejs.org)
|
|
5
|
+
[](https://www.npmjs.com/package/onebots) [](https://github.com/icqqjs/onebots/actions/workflows/release.yml) [](https://www.npmjs.com/package/onebots) [](https://onebot.dev/)
|
|
6
|
+
[](https://12.onebot.dev/) [](https://nodejs.org)
|
|
11
7
|
[](https://jq.qq.com/?_wv=1027&k=B22VGXov)
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
[Type Docs](https://lc-cn.github.io/onebots)
|
|
16
|
-
|
|
9
|
+
[Type Docs](https://lc-cn.github.io/onebots)
|
|
17
10
|
|
|
18
11
|
</p>
|
|
19
12
|
</div>
|
|
20
13
|
|
|
21
14
|
# 使用示例
|
|
15
|
+
|
|
22
16
|
## 全局安装(0.4.8以后不推荐)
|
|
17
|
+
|
|
23
18
|
### 1 安装依赖
|
|
19
|
+
|
|
24
20
|
```shell
|
|
25
21
|
npm install -g onebots
|
|
26
22
|
# 0.4.8以上版本需要安装icqq
|
|
27
23
|
npm install -g icqq
|
|
28
24
|
```
|
|
25
|
+
|
|
29
26
|
### 2 初始化配置文件
|
|
27
|
+
|
|
30
28
|
在你想存放配置文件的目录执行如下命令
|
|
29
|
+
|
|
31
30
|
```shell
|
|
32
31
|
onebots
|
|
33
32
|
```
|
|
33
|
+
|
|
34
34
|
### 3 更改生成的默认配置文件成你想要的配置配置后再次运行上面的指令,启动项目
|
|
35
|
+
|
|
35
36
|
## 局部安装
|
|
37
|
+
|
|
36
38
|
## 1 初始化node项目
|
|
39
|
+
|
|
37
40
|
```shell
|
|
38
41
|
npm init -y
|
|
39
42
|
```
|
|
43
|
+
|
|
40
44
|
## 2. 安装onebots和icqq
|
|
45
|
+
|
|
41
46
|
```shell
|
|
42
47
|
npm install onebots icqq
|
|
43
48
|
```
|
|
49
|
+
|
|
44
50
|
## 3. 执行如下命令生成配置文件
|
|
51
|
+
|
|
45
52
|
```shell
|
|
46
|
-
npx onebots
|
|
53
|
+
npx onebots -r icqq #注册icqq适配器并启动onebots
|
|
54
|
+
npx onebots -r qq #注册qq官方适配器并启动onebots
|
|
47
55
|
```
|
|
56
|
+
|
|
48
57
|
## 4. 更改生成的默认配置文件成你想要的配置配置后再次运行上面的指令,启动项目
|
|
58
|
+
|
|
49
59
|
# 默认配置文件
|
|
60
|
+
|
|
50
61
|
```yaml
|
|
51
62
|
port: 6727 # 监听端口
|
|
52
63
|
log_level: info # 日志等级
|
|
@@ -55,9 +66,9 @@ timeout: 30 #登录超时时间(秒)
|
|
|
55
66
|
general: # 通用配置,在单个配置省略时的默认值
|
|
56
67
|
V11: # oneBotV11的通用配置
|
|
57
68
|
heartbeat: 3 # 心跳间隔 (秒)
|
|
58
|
-
access_token:
|
|
69
|
+
access_token: "" # 访问api的token
|
|
59
70
|
post_timeout: 15 # 上报超时时间,(秒)
|
|
60
|
-
secret:
|
|
71
|
+
secret: "" # 上报数据的sha1签名密钥
|
|
61
72
|
rate_limit_interval: 4 # ws心跳间隔(秒)
|
|
62
73
|
post_message_format: string # "string"或"array"
|
|
63
74
|
reconnect_interval: 3 # 重连间隔 (秒)
|
|
@@ -65,120 +76,159 @@ general: # 通用配置,在单个配置省略时的默认值
|
|
|
65
76
|
enable_cors: true # 是否允许跨域
|
|
66
77
|
filters: {} # 过滤器配置
|
|
67
78
|
use_ws: true # 是否使用websocket
|
|
68
|
-
http_reverse: [
|
|
69
|
-
ws_reverse: [
|
|
79
|
+
http_reverse: [] # http上报地址
|
|
80
|
+
ws_reverse: [] # 反向ws连接地址
|
|
70
81
|
V12: # oneBotV12的通用配置
|
|
71
82
|
heartbeat: 3 # 心跳间隔 (秒)
|
|
72
|
-
access_token:
|
|
83
|
+
access_token: "" # 访问api的token
|
|
73
84
|
request_timeout: 15 # 上报超时时间 (秒)
|
|
74
85
|
reconnect_interval: 3 # 重连间隔 (秒)
|
|
75
86
|
enable_cors: true # 是否允许跨域
|
|
76
87
|
use_http: true # 是否启用http
|
|
77
88
|
use_ws: true # 是否启用 websocket
|
|
78
89
|
filters: {} # 过滤器配置
|
|
79
|
-
webhook: [
|
|
80
|
-
ws_reverse: [
|
|
90
|
+
webhook: [] # http 上报地址
|
|
91
|
+
ws_reverse: [] # 反向ws连接地址
|
|
81
92
|
protocol:
|
|
82
93
|
platform: 2
|
|
83
|
-
sign_api_addr:
|
|
84
|
-
password:
|
|
94
|
+
sign_api_addr: "" #你的签名地址
|
|
95
|
+
password: "" # 账号密码,未配置则扫码登陆
|
|
85
96
|
# ...其他配置项参考icqq的Config配置
|
|
86
97
|
# 每个账号的单独配置(用于覆盖通用配置)
|
|
87
|
-
123456789:
|
|
88
|
-
password:
|
|
98
|
+
icqq.123456789:
|
|
99
|
+
password: "" # 账号密码,未配置则扫码登陆
|
|
89
100
|
version: V11 # 使用的oneBot版本
|
|
90
101
|
# ...其他配置项参见上方对应oneBot版本的通用配置
|
|
91
102
|
protocol:
|
|
92
103
|
platform: 2
|
|
93
|
-
sign_api_addr:
|
|
104
|
+
sign_api_addr: "" #你的签名地址
|
|
94
105
|
# ...其他配置项参考icqq的Config配置
|
|
106
|
+
|
|
107
|
+
qq.123456789: # `${适配器名称}:${appId}`
|
|
108
|
+
versions:
|
|
109
|
+
- version: V11
|
|
110
|
+
# 。。。其他配置项参见上方对应oneBot版本的通用配置
|
|
111
|
+
protocol: # 将会覆盖通用配置中的protocol
|
|
112
|
+
token: '' # qq机器人token
|
|
113
|
+
secret: '' # qq机器人secret
|
|
114
|
+
sandbox: false # 是否沙箱环境
|
|
115
|
+
intents: # 需要监听的intents
|
|
116
|
+
- 'GROUP_AT_MESSAGE_CREATE' # 群聊@事件 没有群聊权限请注释
|
|
117
|
+
- 'C2C_MESSAGE_CREATE' # 私聊事件 没有私聊权限请注释
|
|
118
|
+
- 'DIRECT_MESSAGE' # 频道私信事件
|
|
119
|
+
# - 'GUILD_MESSAGES' # 私域机器人频道消息事件,公域机器人请注释
|
|
120
|
+
- 'GUILDS' # 频道变更事件
|
|
121
|
+
- 'GUILD_MEMBERS' # 频道成员变更事件
|
|
122
|
+
- 'GUILD_MESSAGE_REACTIONS' # 频道消息表态事件
|
|
123
|
+
- 'INTERACTION' # 互动事件
|
|
124
|
+
- 'PUBLIC_GUILD_MESSAGES' # 公域机器人频道消息事件,私域机器人请注释
|
|
125
|
+
# 。。。其他配置项参见上方对应oneBot版本的通用配置
|
|
126
|
+
|
|
95
127
|
```
|
|
96
128
|
|
|
97
129
|
# 配置解释
|
|
98
130
|
|
|
99
131
|
## Config
|
|
100
|
-
|
|
101
|
-
|
|
132
|
+
|
|
133
|
+
| 配置项 | 类型 | 默认值 | desc |
|
|
134
|
+
| :------- | :--------------------------- | :------ | :----------- |
|
|
102
135
|
| port | number | 6727 | 服务监听端口 |
|
|
103
|
-
| logLevel | string | info | 日志级别
|
|
104
|
-
| general | OneBotConfig | general | 通用配置
|
|
105
|
-
| [number] | OneBotConfig\|OneBotConfig[] | - | 机器人配置
|
|
136
|
+
| logLevel | string | info | 日志级别 |
|
|
137
|
+
| general | OneBotConfig | general | 通用配置 |
|
|
138
|
+
| [number] | OneBotConfig\|OneBotConfig[] | - | 机器人配置 |
|
|
139
|
+
|
|
106
140
|
## OneBotConfig
|
|
107
|
-
|
|
108
|
-
|
|
141
|
+
|
|
142
|
+
| 配置项 | 类型 | 默认值 | desc |
|
|
143
|
+
| :------- | :-------- | :-------- | :---------------------------------- |
|
|
109
144
|
| password | string | - | 账号密码 未填写或填写为空则扫码登陆 |
|
|
110
|
-
| V11 | ConfigV11 | configV11 | V11配置
|
|
111
|
-
| V12 | ConfigV12 | configV12 | V12配置
|
|
112
|
-
| protocol | Config | {} | icqq配置
|
|
145
|
+
| V11 | ConfigV11 | configV11 | V11配置 |
|
|
146
|
+
| V12 | ConfigV12 | configV12 | V12配置 |
|
|
147
|
+
| protocol | Config | {} | icqq配置 |
|
|
148
|
+
|
|
113
149
|
## ConfigV11
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
|
117
|
-
|
|
|
118
|
-
|
|
|
119
|
-
|
|
|
120
|
-
|
|
|
121
|
-
|
|
|
122
|
-
|
|
|
123
|
-
|
|
|
150
|
+
|
|
151
|
+
| 配置项 | 类型 | 默认值 | desc |
|
|
152
|
+
| :------------------ | :------- | :----- | :---------------- |
|
|
153
|
+
| heartbeat | number | 3 | 心跳间隔 单位:秒 |
|
|
154
|
+
| access_token | string | - | 访问令牌 |
|
|
155
|
+
| secret | string | - | 签名密钥 |
|
|
156
|
+
| rate_limit_interval | number | 4 | 限速间隔 单位:秒 |
|
|
157
|
+
| post_message_format | string | string | 消息格式化 |
|
|
158
|
+
| reconnect_interval | number | 3 | 重连间隔 单位:秒 |
|
|
159
|
+
| use_http | boolean | false | 是否使用http协议 |
|
|
160
|
+
| enable_cors | boolean | false | 是否允许跨域 |
|
|
124
161
|
| filters | Filters | {} | 事件过滤器配置 |
|
|
125
|
-
| use_ws | boolean | false | 是否使用ws协议
|
|
126
|
-
| http_reverse_url | string[] | - | http上报地址地址
|
|
127
|
-
| ws_reverse_url | string[] | - | 反向ws连接地址
|
|
162
|
+
| use_ws | boolean | false | 是否使用ws协议 |
|
|
163
|
+
| http_reverse_url | string[] | - | http上报地址地址 |
|
|
164
|
+
| ws_reverse_url | string[] | - | 反向ws连接地址 |
|
|
165
|
+
|
|
128
166
|
## ConfigV12
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
|
132
|
-
|
|
|
133
|
-
|
|
|
134
|
-
|
|
|
135
|
-
|
|
|
167
|
+
|
|
168
|
+
| 配置项 | 类型 | 默认值 | desc |
|
|
169
|
+
| :------------------ | :------- | :----- | :---------------- |
|
|
170
|
+
| heartbeat | number | 3 | 心跳间隔 单位:秒 |
|
|
171
|
+
| access_token | string | - | 访问令牌 |
|
|
172
|
+
| request_timeout | number | 15 | 请求超时 单位:秒 |
|
|
173
|
+
| reconnect_interval | number | 3 | 重连间隔 单位:秒 |
|
|
174
|
+
| enable_cors | boolean | false | 是否允许跨域 |
|
|
136
175
|
| filters | Filters | {} | 事件过滤器配置 |
|
|
137
|
-
| use_http | boolean | false
|
|
138
|
-
| use_ws | boolean | false
|
|
139
|
-
| webhook_reverse_url | string[] | -
|
|
140
|
-
| ws_reverse_url | string[] | -
|
|
176
|
+
| use_http | boolean | false | 是否使用http协议 |
|
|
177
|
+
| use_ws | boolean | false | 是否使用ws协议 |
|
|
178
|
+
| webhook_reverse_url | string[] | - | webhook上报地址 |
|
|
179
|
+
| ws_reverse_url | string[] | - | 反向ws连接地址 |
|
|
180
|
+
|
|
141
181
|
# 事件过滤器
|
|
182
|
+
|
|
142
183
|
## 语法说明
|
|
184
|
+
|
|
143
185
|
- `onebots` 的事件过滤器最外层是一个JSON对象,其中的键是键如果是运算法,则值作为运算符的参数,如果不是运算符,则表示对事件数据对象相应 `key` 进行过滤。
|
|
144
186
|
- 过滤规则中任何一个对象, 只有在它的所有项都匹配的情况下, 才会让事件通过(等价于一个 and 运算),如果值为一个数组,则表示事件对应 `key` 值需满足其中一个。
|
|
145
187
|
- 可用逻辑运算符有:`$and` (逻辑与) 、`$or` (逻辑或) 、 `$not` (逻辑非)、`$nor` (逻辑异或)、`$regexp` (文本正则匹配)、`$like` (文本模糊匹配)、`$gt` (数值大于比较)、`$gte` (数值大于等于比较)、`$lt` (数值小于比较)、`$lte` (数值小于等于比较)、`$between` (数值范围比较)
|
|
188
|
+
|
|
146
189
|
## 示例
|
|
190
|
+
|
|
147
191
|
### 1. 仅上报私聊事件
|
|
192
|
+
|
|
148
193
|
```yaml
|
|
149
194
|
filters:
|
|
150
195
|
message_type: private
|
|
151
196
|
```
|
|
197
|
+
|
|
152
198
|
### 2. 私聊或指定群聊
|
|
199
|
+
|
|
153
200
|
```yaml
|
|
154
201
|
filters:
|
|
155
202
|
$or:
|
|
156
203
|
message_type: private
|
|
157
|
-
group_id:
|
|
158
|
-
- 123456789
|
|
159
|
-
987654321
|
|
204
|
+
group_id:
|
|
205
|
+
- 123456789 987654321
|
|
160
206
|
```
|
|
207
|
+
|
|
161
208
|
### 3. 私聊事件且不是指定用户
|
|
209
|
+
|
|
162
210
|
```yaml
|
|
163
211
|
filters:
|
|
164
212
|
message_type: private
|
|
165
213
|
$not:
|
|
166
214
|
user_id:
|
|
167
|
-
- 123456789
|
|
168
|
-
987654321
|
|
215
|
+
- 123456789 987654321
|
|
169
216
|
```
|
|
217
|
+
|
|
170
218
|
### 4. 私聊事件(排除指定用户的事件)或指定群聊事件
|
|
219
|
+
|
|
171
220
|
```yaml
|
|
172
221
|
filters:
|
|
173
222
|
$or:
|
|
174
223
|
- message_type: private
|
|
175
224
|
$not:
|
|
176
225
|
user_id: 123456789
|
|
177
|
-
-
|
|
178
|
-
message_type: group
|
|
226
|
+
- message_type: group
|
|
179
227
|
group_id: 987654321
|
|
180
228
|
```
|
|
229
|
+
|
|
181
230
|
### 5. 仅上报消息事件且用户年龄大于18岁
|
|
231
|
+
|
|
182
232
|
```yaml
|
|
183
233
|
filters:
|
|
184
234
|
type: message
|
|
@@ -186,14 +236,18 @@ filters:
|
|
|
186
236
|
age:
|
|
187
237
|
$gt: 18
|
|
188
238
|
```
|
|
239
|
+
|
|
189
240
|
### 6. 仅上报消息事件且消息内容以!开头的消息
|
|
241
|
+
|
|
190
242
|
```yaml
|
|
191
243
|
filters:
|
|
192
244
|
type: message
|
|
193
245
|
raw_message:
|
|
194
246
|
.regexp: '^!|\!'
|
|
195
247
|
```
|
|
248
|
+
|
|
196
249
|
### 7. 不上报消息内容包含`cnm`的消息
|
|
250
|
+
|
|
197
251
|
```yaml
|
|
198
252
|
filters:
|
|
199
253
|
$not:
|
|
@@ -201,16 +255,19 @@ filters:
|
|
|
201
255
|
raw_message:
|
|
202
256
|
$like: cnm
|
|
203
257
|
```
|
|
258
|
+
|
|
204
259
|
# 使用API管理oneBot
|
|
205
260
|
|
|
206
|
-
| url | method | params | desc
|
|
207
|
-
|
|
208
|
-
| /list | GET | | 获取当前运行的机器人列表
|
|
209
|
-
| /detail | GET | uin | 获取指定机器人配置
|
|
210
|
-
| /qrcode | GET | uin | 获取指定机器人登录二维码
|
|
211
|
-
| /add | POST | {uin,...config} | 添加机器人 config 为机器人配置
|
|
212
|
-
| /edit | POST | {uin,...config} | 修改机器人配置 config 为机器人配置
|
|
261
|
+
| url | method | params | desc |
|
|
262
|
+
| :------ | :----- | :-------------- | :--------------------------------------------- |
|
|
263
|
+
| /list | GET | | 获取当前运行的机器人列表 |
|
|
264
|
+
| /detail | GET | uin | 获取指定机器人配置 |
|
|
265
|
+
| /qrcode | GET | uin | 获取指定机器人登录二维码 |
|
|
266
|
+
| /add | POST | {uin,...config} | 添加机器人 config 为机器人配置 |
|
|
267
|
+
| /edit | POST | {uin,...config} | 修改机器人配置 config 为机器人配置 |
|
|
213
268
|
| /remove | get | uin,force | 移除机器人,force为true时,将删除机器人data目录 |
|
|
269
|
+
|
|
214
270
|
# 鸣谢
|
|
271
|
+
|
|
215
272
|
1. [icqqjs/icqq](https://github.com/icqqjs/icqq) 底层服务支持
|
|
216
273
|
2. [takayama-lily/onebot](https://github.com/takayama-lily/node-onebot) oneBot V11 原先版本
|
package/lib/adapter.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import { App } from "./server/app";
|
|
4
|
+
import { OneBot } from "./onebot";
|
|
5
|
+
import { Dict } from "@zhinjs/shared";
|
|
6
|
+
import { Logger } from "log4js";
|
|
7
|
+
export declare abstract class Adapter<T extends string = string> extends EventEmitter {
|
|
8
|
+
#private;
|
|
9
|
+
app: App;
|
|
10
|
+
platform: T;
|
|
11
|
+
config: Adapter.Configs[T];
|
|
12
|
+
oneBots: Map<string, OneBot>;
|
|
13
|
+
protected constructor(app: App, platform: T, config: Adapter.Configs[T]);
|
|
14
|
+
get logger(): Logger;
|
|
15
|
+
getLogger(uin: string, version?: string): Logger;
|
|
16
|
+
createOneBot(uin: string, protocol: Dict, versions: OneBot.Config[]): OneBot;
|
|
17
|
+
start(uin?: string): Promise<any>;
|
|
18
|
+
stop(uin?: string, force?: boolean): Promise<any>;
|
|
19
|
+
}
|
|
20
|
+
export interface Adapter extends Adapter.Base {
|
|
21
|
+
call<V extends OneBot.Version>(uin: string, version: V, method: string, args?: any[]): Promise<any>;
|
|
22
|
+
}
|
|
23
|
+
export declare namespace Adapter {
|
|
24
|
+
interface Base {
|
|
25
|
+
toSegment<V extends OneBot.Version>(version: V, message: OneBot.MessageElement<V>[]): OneBot.Segment<V>[];
|
|
26
|
+
fromSegment<V extends OneBot.Version>(version: V, segment: OneBot.Segment<V>): OneBot.MessageElement<V>[];
|
|
27
|
+
toCqcode<V extends OneBot.Version>(version: V, message: OneBot.MessageElement<V>[]): string;
|
|
28
|
+
fromCqcode<V extends OneBot.Version>(version: V, message: string): OneBot.MessageElement<V>[];
|
|
29
|
+
getSelfInfo<V extends OneBot.Version>(uin: string, version: V): OneBot.SelfInfo<V>;
|
|
30
|
+
/** 格式化事件 */
|
|
31
|
+
formatEventPayload<V extends OneBot.Version>(version: V, event: string, payload: Dict): OneBot.Payload<V>;
|
|
32
|
+
/** 解析消息事件的消息 */
|
|
33
|
+
parseMessage<V extends OneBot.Version>(version: V, payload: Dict): OneBot.Message<V>[];
|
|
34
|
+
/** 获取群列表 */
|
|
35
|
+
getGroupList<V extends OneBot.Version>(uin: string, version: V): Promise<OneBot.GroupInfo<V>[]>;
|
|
36
|
+
/** 获取好友列表 */
|
|
37
|
+
getFriendList<V extends OneBot.Version>(uin: string, version: V): Promise<OneBot.UserInfo<V>[]>;
|
|
38
|
+
getGroupMemberList<V extends OneBot.Version>(uin: string, version: V, args: [string]): Promise<OneBot.GroupMemberInfo<V>[]>;
|
|
39
|
+
/** 发送群消息 */
|
|
40
|
+
sendGroupMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[]]): Promise<OneBot.MessageRet<V>>;
|
|
41
|
+
/** 发送私聊消息 */
|
|
42
|
+
sendPrivateMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[]]): Promise<OneBot.MessageRet<V>>;
|
|
43
|
+
/** 获取消息 */
|
|
44
|
+
getMessage<V extends OneBot.Version>(uin: string, version: V): Promise<OneBot.Message<V>>;
|
|
45
|
+
deleteMessage<V extends OneBot.Version>(uin: string, version: V, args: [string]): Promise<boolean>;
|
|
46
|
+
}
|
|
47
|
+
interface Configs {
|
|
48
|
+
[key: string]: Adapter.Config;
|
|
49
|
+
}
|
|
50
|
+
type Config<T extends string = string> = {
|
|
51
|
+
platform?: T;
|
|
52
|
+
versions: OneBot.Config<OneBot.Version>[];
|
|
53
|
+
protocol?: Dict;
|
|
54
|
+
} & Record<string, any>;
|
|
55
|
+
}
|
package/lib/adapter.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
+
};
|
|
13
|
+
var _Adapter_logger;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Adapter = void 0;
|
|
16
|
+
const events_1 = require("events");
|
|
17
|
+
const onebot_1 = require("./onebot");
|
|
18
|
+
class Adapter extends events_1.EventEmitter {
|
|
19
|
+
constructor(app, platform, config) {
|
|
20
|
+
super();
|
|
21
|
+
this.app = app;
|
|
22
|
+
this.platform = platform;
|
|
23
|
+
this.config = config;
|
|
24
|
+
this.oneBots = new Map();
|
|
25
|
+
_Adapter_logger.set(this, void 0);
|
|
26
|
+
}
|
|
27
|
+
get logger() {
|
|
28
|
+
return __classPrivateFieldSet(this, _Adapter_logger, __classPrivateFieldGet(this, _Adapter_logger, "f") || this.app.getLogger(this.platform), "f");
|
|
29
|
+
}
|
|
30
|
+
getLogger(uin, version) {
|
|
31
|
+
if (!version)
|
|
32
|
+
return this.app.getLogger(`${this.platform}-${uin}`);
|
|
33
|
+
return this.app.getLogger(`${this.platform}-${version}(${uin})`);
|
|
34
|
+
}
|
|
35
|
+
createOneBot(uin, protocol, versions) {
|
|
36
|
+
const oneBot = new onebot_1.OneBot(this, uin, versions);
|
|
37
|
+
this.oneBots.set(uin, oneBot);
|
|
38
|
+
return oneBot;
|
|
39
|
+
}
|
|
40
|
+
async start(uin) {
|
|
41
|
+
const startOneBots = [...this.oneBots.values()].filter(oneBot => {
|
|
42
|
+
return uin ? oneBot.uin === uin : true;
|
|
43
|
+
});
|
|
44
|
+
for (const oneBot of startOneBots) {
|
|
45
|
+
await oneBot.start();
|
|
46
|
+
}
|
|
47
|
+
this.app.emit('adapter.start', this.platform);
|
|
48
|
+
}
|
|
49
|
+
async stop(uin, force) {
|
|
50
|
+
const stopOneBots = [...this.oneBots.values()].filter(oneBot => {
|
|
51
|
+
return uin ? oneBot.uin === uin : true;
|
|
52
|
+
});
|
|
53
|
+
for (const oneBot of stopOneBots) {
|
|
54
|
+
await oneBot.stop(force);
|
|
55
|
+
}
|
|
56
|
+
this.app.emit('adapter.stop', this.platform);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Adapter = Adapter;
|
|
60
|
+
_Adapter_logger = new WeakMap();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Adapter } from "../../adapter";
|
|
2
|
+
import { App } from "../../server/app";
|
|
3
|
+
import { Config as IcqqConfig } from "icqq/lib/client";
|
|
4
|
+
import { Dict } from "@zhinjs/shared";
|
|
5
|
+
import { OneBot } from "../../onebot";
|
|
6
|
+
export default class IcqqAdapter extends Adapter<'icqq'> {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(app: App, config: IcqqAdapter.Config);
|
|
9
|
+
createOneBot(uin: string, protocol: Dict, versions: OneBot.Config[]): OneBot;
|
|
10
|
+
formatEventPayload<V extends OneBot.Version>(version: V, event: string, data: any): OneBot.Payload<V>;
|
|
11
|
+
toMessageElement<V extends OneBot.Version>(event: any): OneBot.MessageElement<V>[];
|
|
12
|
+
sendPrivateMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[]]): Promise<OneBot.MessageRet<V>>;
|
|
13
|
+
sendGroupMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[]]): Promise<OneBot.MessageRet<V>>;
|
|
14
|
+
call<V extends OneBot.Version>(uin: string, version: V, method: string, args?: any[]): Promise<any>;
|
|
15
|
+
fromSegment<V extends OneBot.Version>(version: V, segment: OneBot.Segment<V> | OneBot.Segment<V>[]): OneBot.MessageElement<V>[];
|
|
16
|
+
toSegment<V extends OneBot.Version>(version: V, message: OneBot.MessageElement<V>[]): OneBot.Segment<V>[];
|
|
17
|
+
fromCqcode<V extends OneBot.Version>(version: V, message: string): OneBot.MessageElement<V>[];
|
|
18
|
+
toCqcode<V extends OneBot.Version>(version: V, messageArr: OneBot.MessageElement<V>[]): string;
|
|
19
|
+
getSelfInfo<V extends OneBot.Version>(uin: string, version: V): OneBot.SelfInfo<V>;
|
|
20
|
+
startOneBot(oneBot: OneBot): Promise<Function>;
|
|
21
|
+
start(uin?: string): Promise<void>;
|
|
22
|
+
stop(uin?: string, force?: boolean): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
declare module '../../adapter' {
|
|
25
|
+
namespace Adapter {
|
|
26
|
+
interface Configs {
|
|
27
|
+
icqq: IcqqAdapter.Config;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export declare namespace IcqqAdapter {
|
|
32
|
+
interface Config extends Adapter.Config<'icqq'> {
|
|
33
|
+
protocol?: IcqqConfig;
|
|
34
|
+
password?: string;
|
|
35
|
+
}
|
|
36
|
+
}
|