onebots 0.4.21 → 0.4.23
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 +163 -62
- package/lib/bin.js +1 -1
- package/lib/config.sample.yaml +1 -1
- package/lib/db.js +6 -6
- package/lib/index.d.ts +5 -5
- package/lib/onebot.d.ts +9 -6
- package/lib/onebot.js +63 -49
- package/lib/service/V11/action/common.d.ts +3 -2
- package/lib/service/V11/action/common.js +34 -38
- package/lib/service/V11/action/friend.d.ts +7 -7
- package/lib/service/V11/action/friend.js +6 -6
- package/lib/service/V11/action/group.d.ts +3 -3
- package/lib/service/V11/action/group.js +6 -6
- package/lib/service/V11/db_sqlite.js +7 -9
- package/lib/service/V11/index.d.ts +11 -12
- package/lib/service/V11/index.js +223 -172
- package/lib/service/V11/utils.d.ts +1 -4
- package/lib/service/V11/utils.js +11 -16
- package/lib/service/V12/index.d.ts +3 -5
- package/lib/service/V12/index.js +24 -26
- package/lib/service/shareMusicCustom.js +2 -2
- package/lib/service.d.ts +29 -0
- package/lib/service.js +85 -0
- package/lib/types.d.ts +2 -2
- package/lib/types.js +3 -3
- package/lib/utils.js +27 -15
- package/package.json +73 -70
package/README.md
CHANGED
|
@@ -2,51 +2,61 @@
|
|
|
2
2
|
<h1>基于icqq的oneBot实现</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
53
|
npx onebots
|
|
47
54
|
```
|
|
55
|
+
|
|
48
56
|
## 4. 更改生成的默认配置文件成你想要的配置配置后再次运行上面的指令,启动项目
|
|
57
|
+
|
|
49
58
|
# 默认配置文件
|
|
59
|
+
|
|
50
60
|
```yaml
|
|
51
61
|
port: 6727 # 监听端口
|
|
52
62
|
log_level: info # 日志等级
|
|
@@ -55,96 +65,187 @@ timeout: 30 #登录超时时间(秒)
|
|
|
55
65
|
general: # 通用配置,在单个配置省略时的默认值
|
|
56
66
|
V11: # oneBotV11的通用配置
|
|
57
67
|
heartbeat: 3 # 心跳间隔 (秒)
|
|
58
|
-
access_token:
|
|
68
|
+
access_token: "" # 访问api的token
|
|
59
69
|
post_timeout: 15 # 上报超时时间,(秒)
|
|
60
|
-
secret:
|
|
70
|
+
secret: "" # 上报数据的sha1签名密钥
|
|
61
71
|
rate_limit_interval: 4 # ws心跳间隔(秒)
|
|
62
72
|
post_message_format: string # "string"或"array"
|
|
63
73
|
reconnect_interval: 3 # 重连间隔 (秒)
|
|
64
74
|
use_http: true # 是否使用 http
|
|
65
75
|
enable_cors: true # 是否允许跨域
|
|
76
|
+
filters: {} # 过滤器配置
|
|
66
77
|
use_ws: true # 是否使用websocket
|
|
67
|
-
http_reverse: [
|
|
68
|
-
ws_reverse: [
|
|
78
|
+
http_reverse: [] # http上报地址
|
|
79
|
+
ws_reverse: [] # 反向ws连接地址
|
|
69
80
|
V12: # oneBotV12的通用配置
|
|
70
81
|
heartbeat: 3 # 心跳间隔 (秒)
|
|
71
|
-
access_token:
|
|
82
|
+
access_token: "" # 访问api的token
|
|
72
83
|
request_timeout: 15 # 上报超时时间 (秒)
|
|
73
84
|
reconnect_interval: 3 # 重连间隔 (秒)
|
|
74
85
|
enable_cors: true # 是否允许跨域
|
|
75
86
|
use_http: true # 是否启用http
|
|
76
87
|
use_ws: true # 是否启用 websocket
|
|
77
|
-
|
|
78
|
-
|
|
88
|
+
filters: {} # 过滤器配置
|
|
89
|
+
webhook: [] # http 上报地址
|
|
90
|
+
ws_reverse: [] # 反向ws连接地址
|
|
79
91
|
protocol:
|
|
80
92
|
platform: 2
|
|
81
|
-
sign_api_addr:
|
|
82
|
-
password:
|
|
93
|
+
sign_api_addr: "" #你的签名地址
|
|
94
|
+
password: "" # 账号密码,未配置则扫码登陆
|
|
83
95
|
# ...其他配置项参考icqq的Config配置
|
|
84
96
|
# 每个账号的单独配置(用于覆盖通用配置)
|
|
85
97
|
123456789:
|
|
86
|
-
password:
|
|
98
|
+
password: "" # 账号密码,未配置则扫码登陆
|
|
87
99
|
version: V11 # 使用的oneBot版本
|
|
88
100
|
# ...其他配置项参见上方对应oneBot版本的通用配置
|
|
89
101
|
protocol:
|
|
90
102
|
platform: 2
|
|
91
|
-
sign_api_addr:
|
|
103
|
+
sign_api_addr: "" #你的签名地址
|
|
92
104
|
# ...其他配置项参考icqq的Config配置
|
|
93
105
|
```
|
|
94
106
|
|
|
95
107
|
# 配置解释
|
|
96
108
|
|
|
97
109
|
## Config
|
|
98
|
-
|
|
99
|
-
|
|
110
|
+
|
|
111
|
+
| 配置项 | 类型 | 默认值 | desc |
|
|
112
|
+
| :------- | :--------------------------- | :------ | :----------- |
|
|
100
113
|
| port | number | 6727 | 服务监听端口 |
|
|
101
|
-
| logLevel | string | info | 日志级别
|
|
102
|
-
| general | OneBotConfig | general | 通用配置
|
|
103
|
-
| [number] | OneBotConfig\|OneBotConfig[] | - | 机器人配置
|
|
114
|
+
| logLevel | string | info | 日志级别 |
|
|
115
|
+
| general | OneBotConfig | general | 通用配置 |
|
|
116
|
+
| [number] | OneBotConfig\|OneBotConfig[] | - | 机器人配置 |
|
|
117
|
+
|
|
104
118
|
## OneBotConfig
|
|
105
|
-
|
|
106
|
-
|
|
119
|
+
|
|
120
|
+
| 配置项 | 类型 | 默认值 | desc |
|
|
121
|
+
| :------- | :-------- | :-------- | :---------------------------------- |
|
|
107
122
|
| password | string | - | 账号密码 未填写或填写为空则扫码登陆 |
|
|
108
|
-
| V11 | ConfigV11 | configV11 | V11配置
|
|
109
|
-
| V12 | ConfigV12 | configV12 | V12配置
|
|
110
|
-
| protocol | Config | {} | icqq配置
|
|
123
|
+
| V11 | ConfigV11 | configV11 | V11配置 |
|
|
124
|
+
| V12 | ConfigV12 | configV12 | V12配置 |
|
|
125
|
+
| protocol | Config | {} | icqq配置 |
|
|
126
|
+
|
|
111
127
|
## ConfigV11
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
|
115
|
-
|
|
|
116
|
-
|
|
|
117
|
-
|
|
|
118
|
-
|
|
|
119
|
-
|
|
|
120
|
-
|
|
|
121
|
-
|
|
|
122
|
-
|
|
|
123
|
-
|
|
|
124
|
-
|
|
|
128
|
+
|
|
129
|
+
| 配置项 | 类型 | 默认值 | desc |
|
|
130
|
+
| :------------------ | :------- | :----- | :---------------- |
|
|
131
|
+
| heartbeat | number | 3 | 心跳间隔 单位:秒 |
|
|
132
|
+
| access_token | string | - | 访问令牌 |
|
|
133
|
+
| secret | string | - | 签名密钥 |
|
|
134
|
+
| rate_limit_interval | number | 4 | 限速间隔 单位:秒 |
|
|
135
|
+
| post_message_format | string | string | 消息格式化 |
|
|
136
|
+
| reconnect_interval | number | 3 | 重连间隔 单位:秒 |
|
|
137
|
+
| use_http | boolean | false | 是否使用http协议 |
|
|
138
|
+
| enable_cors | boolean | false | 是否允许跨域 |
|
|
139
|
+
| filters | Filters | {} | 事件过滤器配置 |
|
|
140
|
+
| use_ws | boolean | false | 是否使用ws协议 |
|
|
141
|
+
| http_reverse_url | string[] | - | http上报地址地址 |
|
|
142
|
+
| ws_reverse_url | string[] | - | 反向ws连接地址 |
|
|
143
|
+
|
|
125
144
|
## ConfigV12
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
|
129
|
-
|
|
|
130
|
-
|
|
|
131
|
-
|
|
|
132
|
-
|
|
|
133
|
-
|
|
|
134
|
-
|
|
|
135
|
-
|
|
|
136
|
-
|
|
|
145
|
+
|
|
146
|
+
| 配置项 | 类型 | 默认值 | desc |
|
|
147
|
+
| :------------------ | :------- | :----- | :---------------- |
|
|
148
|
+
| heartbeat | number | 3 | 心跳间隔 单位:秒 |
|
|
149
|
+
| access_token | string | - | 访问令牌 |
|
|
150
|
+
| request_timeout | number | 15 | 请求超时 单位:秒 |
|
|
151
|
+
| reconnect_interval | number | 3 | 重连间隔 单位:秒 |
|
|
152
|
+
| enable_cors | boolean | false | 是否允许跨域 |
|
|
153
|
+
| filters | Filters | {} | 事件过滤器配置 |
|
|
154
|
+
| use_http | boolean | false | 是否使用http协议 |
|
|
155
|
+
| use_ws | boolean | false | 是否使用ws协议 |
|
|
156
|
+
| webhook_reverse_url | string[] | - | webhook上报地址 |
|
|
157
|
+
| ws_reverse_url | string[] | - | 反向ws连接地址 |
|
|
158
|
+
|
|
159
|
+
# 事件过滤器
|
|
160
|
+
|
|
161
|
+
## 语法说明
|
|
162
|
+
|
|
163
|
+
- `onebots` 的事件过滤器最外层是一个JSON对象,其中的键是键如果是运算法,则值作为运算符的参数,如果不是运算符,则表示对事件数据对象相应 `key` 进行过滤。
|
|
164
|
+
- 过滤规则中任何一个对象, 只有在它的所有项都匹配的情况下, 才会让事件通过(等价于一个 and 运算),如果值为一个数组,则表示事件对应 `key` 值需满足其中一个。
|
|
165
|
+
- 可用逻辑运算符有:`$and` (逻辑与) 、`$or` (逻辑或) 、 `$not` (逻辑非)、`$nor` (逻辑异或)、`$regexp` (文本正则匹配)、`$like` (文本模糊匹配)、`$gt` (数值大于比较)、`$gte` (数值大于等于比较)、`$lt` (数值小于比较)、`$lte` (数值小于等于比较)、`$between` (数值范围比较)
|
|
166
|
+
|
|
167
|
+
## 示例
|
|
168
|
+
|
|
169
|
+
### 1. 仅上报私聊事件
|
|
170
|
+
|
|
171
|
+
```yaml
|
|
172
|
+
filters:
|
|
173
|
+
message_type: private
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 2. 私聊或指定群聊
|
|
177
|
+
|
|
178
|
+
```yaml
|
|
179
|
+
filters:
|
|
180
|
+
$or:
|
|
181
|
+
message_type: private
|
|
182
|
+
group_id:
|
|
183
|
+
- 123456789 987654321
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### 3. 私聊事件且不是指定用户
|
|
187
|
+
|
|
188
|
+
```yaml
|
|
189
|
+
filters:
|
|
190
|
+
message_type: private
|
|
191
|
+
$not:
|
|
192
|
+
user_id:
|
|
193
|
+
- 123456789 987654321
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### 4. 私聊事件(排除指定用户的事件)或指定群聊事件
|
|
197
|
+
|
|
198
|
+
```yaml
|
|
199
|
+
filters:
|
|
200
|
+
$or:
|
|
201
|
+
- message_type: private
|
|
202
|
+
$not:
|
|
203
|
+
user_id: 123456789
|
|
204
|
+
- message_type: group
|
|
205
|
+
group_id: 987654321
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### 5. 仅上报消息事件且用户年龄大于18岁
|
|
209
|
+
|
|
210
|
+
```yaml
|
|
211
|
+
filters:
|
|
212
|
+
type: message
|
|
213
|
+
sender:
|
|
214
|
+
age:
|
|
215
|
+
$gt: 18
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### 6. 仅上报消息事件且消息内容以!开头的消息
|
|
219
|
+
|
|
220
|
+
```yaml
|
|
221
|
+
filters:
|
|
222
|
+
type: message
|
|
223
|
+
raw_message:
|
|
224
|
+
.regexp: '^!|\!'
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### 7. 不上报消息内容包含`cnm`的消息
|
|
228
|
+
|
|
229
|
+
```yaml
|
|
230
|
+
filters:
|
|
231
|
+
$not:
|
|
232
|
+
type: message
|
|
233
|
+
raw_message:
|
|
234
|
+
$like: cnm
|
|
235
|
+
```
|
|
236
|
+
|
|
137
237
|
# 使用API管理oneBot
|
|
138
238
|
|
|
139
|
-
| url | method | params | desc
|
|
140
|
-
|
|
141
|
-
| /list | GET | | 获取当前运行的机器人列表
|
|
142
|
-
| /detail | GET | uin | 获取指定机器人配置
|
|
143
|
-
| /qrcode | GET | uin | 获取指定机器人登录二维码
|
|
144
|
-
| /add | POST | {uin,...config} | 添加机器人 config 为机器人配置
|
|
145
|
-
| /edit | POST | {uin,...config} | 修改机器人配置 config 为机器人配置
|
|
239
|
+
| url | method | params | desc |
|
|
240
|
+
| :------ | :----- | :-------------- | :--------------------------------------------- |
|
|
241
|
+
| /list | GET | | 获取当前运行的机器人列表 |
|
|
242
|
+
| /detail | GET | uin | 获取指定机器人配置 |
|
|
243
|
+
| /qrcode | GET | uin | 获取指定机器人登录二维码 |
|
|
244
|
+
| /add | POST | {uin,...config} | 添加机器人 config 为机器人配置 |
|
|
245
|
+
| /edit | POST | {uin,...config} | 修改机器人配置 config 为机器人配置 |
|
|
146
246
|
| /remove | get | uin,force | 移除机器人,force为true时,将删除机器人data目录 |
|
|
147
247
|
|
|
148
248
|
# 鸣谢
|
|
249
|
+
|
|
149
250
|
1. [icqqjs/icqq](https://github.com/icqqjs/icqq) 底层服务支持
|
|
150
251
|
2. [takayama-lily/onebot](https://github.com/takayama-lily/node-onebot) oneBot V11 原先版本
|
package/lib/bin.js
CHANGED
package/lib/config.sample.yaml
CHANGED
|
@@ -31,7 +31,7 @@ general: # 通用配置,在单个配置省略时的默认值
|
|
|
31
31
|
# 每个账号的单独配置(用于覆盖通用配置)
|
|
32
32
|
123456789:
|
|
33
33
|
version: V11 # 使用的oneBot版本
|
|
34
|
-
password:'' # 账号密码,未配置则扫码登陆
|
|
34
|
+
password: '' # 账号密码,未配置则扫码登陆
|
|
35
35
|
group_whitelist: [] # 群消息派发白名单,只有数组中的群号才派发,为空则全部派发
|
|
36
36
|
protocol: # 将会覆盖通用配置中的protocol
|
|
37
37
|
platform: 1
|
package/lib/db.js
CHANGED
|
@@ -7,15 +7,15 @@ class Database {
|
|
|
7
7
|
constructor(path) {
|
|
8
8
|
this.path = path;
|
|
9
9
|
this.data = {};
|
|
10
|
-
if (!this.path.toLowerCase().endsWith(
|
|
11
|
-
this.path = this.path +
|
|
10
|
+
if (!this.path.toLowerCase().endsWith(".json"))
|
|
11
|
+
this.path = this.path + ".json";
|
|
12
12
|
if (!(0, fs_1.existsSync)(this.path)) {
|
|
13
13
|
(0, fs_1.writeFileSync)(this.path, "", "utf-8");
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
sync(defaultValue) {
|
|
17
17
|
try {
|
|
18
|
-
this.data = JSON.parse((0, fs_1.readFileSync)(this.path,
|
|
18
|
+
this.data = JSON.parse((0, fs_1.readFileSync)(this.path, "utf-8"));
|
|
19
19
|
}
|
|
20
20
|
catch {
|
|
21
21
|
this.data = defaultValue;
|
|
@@ -24,7 +24,7 @@ class Database {
|
|
|
24
24
|
}
|
|
25
25
|
get(key) {
|
|
26
26
|
const value = (0, shared_1.getValue)(this.data, key);
|
|
27
|
-
if (typeof value !==
|
|
27
|
+
if (typeof value !== "object")
|
|
28
28
|
return value;
|
|
29
29
|
const saveValue = () => {
|
|
30
30
|
this.set(key, value);
|
|
@@ -44,7 +44,7 @@ class Database {
|
|
|
44
44
|
const res = Reflect.defineProperty(target, p, r);
|
|
45
45
|
saveValue();
|
|
46
46
|
return res;
|
|
47
|
-
}
|
|
47
|
+
},
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
delete(key) {
|
|
@@ -52,7 +52,7 @@ class Database {
|
|
|
52
52
|
}
|
|
53
53
|
set(key, value) {
|
|
54
54
|
(0, shared_1.setValue)(this.data, key, value);
|
|
55
|
-
return (0, fs_1.writeFileSync)(this.path, JSON.stringify(this.data, null, 2),
|
|
55
|
+
return (0, fs_1.writeFileSync)(this.path, JSON.stringify(this.data, null, 2), "utf-8");
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
exports.Database = Database;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from "./server/app";
|
|
2
|
+
export * from "./server/router";
|
|
3
|
+
export * from "./onebot";
|
|
4
|
+
export * from "./types";
|
|
5
|
+
export * from "./utils";
|
package/lib/onebot.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import
|
|
3
|
-
import { EventEmitter } from
|
|
2
|
+
import "icqq-cq-enable";
|
|
3
|
+
import { EventEmitter } from "events";
|
|
4
4
|
import { App } from "./server/app";
|
|
5
5
|
import { Client } from "icqq";
|
|
6
|
-
import { Config as IcqqConfig } from
|
|
6
|
+
import { Config as IcqqConfig } from "icqq";
|
|
7
7
|
import { V11 } from "./service/V11";
|
|
8
8
|
import { V12 } from "./service/V12";
|
|
9
9
|
import { MayBeArray } from "./types";
|
|
10
|
+
import { Service } from "./service";
|
|
10
11
|
export declare class NotFoundError extends Error {
|
|
11
12
|
message: string;
|
|
12
13
|
}
|
|
@@ -31,13 +32,15 @@ export declare enum OneBotStatus {
|
|
|
31
32
|
}
|
|
32
33
|
export type OneBotConfig = OneBot.Config<OneBot.Version>;
|
|
33
34
|
export declare namespace OneBot {
|
|
34
|
-
type
|
|
35
|
-
type
|
|
35
|
+
type Filters = {};
|
|
36
|
+
type Version = "V11" | "V12";
|
|
37
|
+
type Config<V extends Version = "V11"> = {
|
|
36
38
|
version?: V;
|
|
37
39
|
password?: string;
|
|
38
40
|
group_whitelist?: number[];
|
|
41
|
+
filters?: Service.Filters;
|
|
39
42
|
protocol?: IcqqConfig;
|
|
40
|
-
} & (V extends
|
|
43
|
+
} & (V extends "V11" ? V11.Config : V12.Config);
|
|
41
44
|
interface Base {
|
|
42
45
|
start(path?: string): any;
|
|
43
46
|
stop(): any;
|