onebots 0.4.9 → 0.4.11

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 CHANGED
@@ -17,57 +17,112 @@
17
17
  </div>
18
18
 
19
19
  # 使用示例
20
- ## 全局安装
20
+ ## 全局安装(0.4.8以后不推荐)
21
21
  ### 1 安装依赖
22
22
  ```shell
23
23
  npm install -g onebots
24
+ # 0.4.8以上版本需要安装icqq
25
+ npm install -g icqq
24
26
  ```
25
27
  ### 2 初始化配置文件
26
- (1) 配置文件存到(用户目录/.onebots/config.yaml)
28
+ 在你想存放配置文件的目录执行如下命令
27
29
  ```shell
28
30
  onebots
29
31
  ```
30
- (2) 配置文件存到(当前目录/config.yaml)
31
- ```shell
32
- onebots -c config.yaml
33
- ```
34
- 二选一即可
35
- ### 3 更改配置文件后,启动项目
36
-
37
- (1) 使用全局配置文件(用户目录/.onebots/config.yaml)
38
- ```shell
39
- onebots
40
- ```
41
- (2) 使用指定配置文件(当前目录/config.yaml)
42
- ```shell
43
- onebots -c config.yaml
44
- ```
45
- # 2 在NodeJS项目中启动
32
+ ### 3 更改生成的默认配置文件成你想要的配置配置后再次运行上面的指令,启动项目
33
+ ## 局部安装
46
34
  ## 1 初始化node项目
47
35
  ```shell
48
36
  npm init -y
49
37
  ```
50
- ## 2. 安装onebots
38
+ ## 2. 安装onebots和icqq
51
39
  ```shell
52
- npm install onebots
53
- ```
54
- ## 3. 在项目跟目录添加配置文件config.yaml
55
- ```yaml
56
- port: 6727 # 项目onebots监听的端口(默认:6727)
57
- 1472258369: # 你的机器人账户
58
- version: V11 # oneBot版本(V11 或 V12)
59
- ```
60
- ## 4. 新建入口文件`index.js`并输入一下内容
61
- ```javascript
62
- const {createApp}=require('onebots')
63
- createApp('config.yaml')
64
- .start()
40
+ npm install onebots icqq
65
41
  ```
66
- ## 5. 启动项目
42
+ ## 3. 执行如下命令生成配置文件
67
43
  ```shell
68
- node ./index.js
44
+ npx onebots
45
+ ```
46
+ ## 4. 更改生成的默认配置文件成你想要的配置配置后再次运行上面的指令,启动项目
47
+ # 默认配置文件
48
+ ```yaml
49
+ port: 6727 # 监听端口
50
+ log_level: info # 日志等级
51
+ platform: 5 # 机器人客户端协议(1:Android 2:APad 3:Watch 4:IMac 5:IPad)
52
+ timeout: 30 #登录超时时间(秒)
53
+ general: # 通用配置,在单个配置省略时的默认值
54
+ V11: # oneBotV11的通用配置
55
+ heartbeat: 3 # 心跳间隔 (秒)
56
+ access_token: '' # 访问api的token
57
+ post_timeout: 15 # 上报超时时间,(秒)
58
+ secret: '' # 上报数据的sha1签名密钥
59
+ rate_limit_interval: 4 # ws心跳间隔(秒)
60
+ post_message_format: string # "string"或"array"
61
+ reconnect_interval: 3 # 重连间隔 (秒)
62
+ use_http: true # 是否使用 http
63
+ enable_cors: true # 是否允许跨域
64
+ use_ws: true # 是否使用websocket
65
+ http_reverse: [ ] # http上报地址
66
+ ws_reverse: [ ] # 反向ws连接地址
67
+ V12: # oneBotV12的通用配置
68
+ heartbeat: 3 # 心跳间隔 (秒)
69
+ access_token: '' # 访问api的token
70
+ request_timeout: 15 # 上报超时时间 (秒)
71
+ reconnect_interval: 3 # 重连间隔 (秒)
72
+ enable_cors: true # 是否允许跨域
73
+ use_http: true # 是否启用http
74
+ use_ws: true # 是否启用 websocket
75
+ webhook: [ ] # http 上报地址
76
+ ws_reverse: [ ] # 反向ws连接地址
77
+ # 每个账号的单独配置(用于覆盖通用配置)
78
+ 123456789:
79
+ version: V11 # 使用的oneBot版本
80
+ password: abcedfghi # 账号密码,未配置则扫码登陆
81
+ # 。。。其他配置项参见上方对应oneBot版本的通用配置
82
+
69
83
  ```
70
- # 使用接口管理oneBot
84
+ # 配置解释
85
+ ## Config
86
+ | 配置项 | 类型 | 默认值 | desc |
87
+ |:-----|:-------|:-----|:--------------------------------------------|
88
+ | port | number | 6727 | 服务监听端口 |
89
+ | logLevel| string | info | 日志级别 |
90
+ | platform | number | 5 | 机器人平台,1:android 2:aPid 3:watch 4:mac 5:iPad |
91
+ | sign_api_addr| string | - | 签名API地址|
92
+ | general | OneBotConfig | general | 通用配置|
93
+ | [number] | OneBotConfig\|OneBotConfig[] | - | 机器人配置|
94
+ ## OneBotConfig
95
+ | 配置项 | 类型 | 默认值 | desc |
96
+ |:-----|:-------|:-----|:--------------------------------------------|
97
+ | V11| ConfigV11| configV11| V11配置|
98
+ | V12| ConfigV12| configV12| V12配置|
99
+ ## ConfigV11
100
+ | 配置项 | 类型 | 默认值 | desc |
101
+ |:-----|:---------|:----|:-----------|
102
+ | heartbeat| number | 3 | 心跳间隔 单位:秒 |
103
+ | access_token| string | - | 访问令牌 |
104
+ | secret| string | - | 签名密钥 |
105
+ |rate_limit_interval| number | 4 | 限速间隔 单位:秒 |
106
+ | post_message_format| string | string | 消息格式化 |
107
+ |reconnect_interval| number | 3 | 重连间隔 单位:秒 |
108
+ | use_http| boolean | false | 是否使用http协议 |
109
+ | enable_cors| boolean | false | 是否允许跨域 |
110
+ | use_ws| boolean | false | 是否使用ws协议 |
111
+ |http_reverse_url| string[] | - | http上报地址地址 |
112
+ | ws_reverse_url| string[] | - | 反向ws连接地址 |
113
+ ## ConfigV12
114
+ | 配置项 | 类型 | 默认值 | desc |
115
+ |:-----|:---------|:----|:------------|
116
+ | heartbeat| number | 3 | 心跳间隔 单位:秒 |
117
+ | access_token| string | - | 访问令牌 |
118
+ | request_timeout| number | 15 | 请求超时 单位:秒 |
119
+ | reconnect_interval| number | 3 | 重连间隔 单位:秒 |
120
+ |enable_cors| boolean | false | 是否允许跨域 |
121
+ |use_http| boolean | false | 是否使用http协议 |
122
+ |use_ws| boolean | false | 是否使用ws协议 |
123
+ |webhook_reverse_url| string[] | - | webhook上报地址 |
124
+ |ws_reverse_url| string[] | - | 反向ws连接地址 |
125
+ # 使用API管理oneBot
71
126
 
72
127
  | url | method | params | desc |
73
128
  |:--------| :--- |:----------------|:-------------------------------|
@@ -16,7 +16,7 @@ export declare class CommonAction {
16
16
  * 获取消息
17
17
  * @param message_id {string} 消息id
18
18
  */
19
- getMsg(this: V11, message_id: string): Promise<import("icqq").GroupMessage | import("icqq").PrivateMessage>;
19
+ getMsg(this: V11, message_id: number): Promise<import("icqq").GroupMessage | import("icqq").PrivateMessage>;
20
20
  /**
21
21
  * 获取合并消息
22
22
  * @param id {string} 合并id
@@ -25,7 +25,8 @@ class CommonAction {
25
25
  * @param message_id {string} 消息id
26
26
  */
27
27
  getMsg(message_id) {
28
- return this.client.getMsg(message_id);
28
+ const messageId = this.db.get(`KVMap.${message_id}`);
29
+ return this.client.getMsg(messageId);
29
30
  }
30
31
  /**
31
32
  * 获取合并消息
@@ -8,6 +8,8 @@ import { Logger } from "log4js";
8
8
  import { WebSocket, WebSocketServer } from "ws";
9
9
  import { Dispose } from "../../types";
10
10
  import { EventEmitter } from "events";
11
+ import { Database } from "../../db";
12
+ import { V12 } from "../../service/V12";
11
13
  export declare class V11 extends EventEmitter implements OneBot.Base {
12
14
  oneBot: OneBot<'V11'>;
13
15
  client: Client;
@@ -17,6 +19,11 @@ export declare class V11 extends EventEmitter implements OneBot.Base {
17
19
  protected timestamp: number;
18
20
  protected heartbeat?: NodeJS.Timeout;
19
21
  private path;
22
+ db: Database<{
23
+ eventBuffer: V12.Payload<keyof Action>[];
24
+ KVMap: Record<number, string>;
25
+ files: Record<string, V12.FileInfo>;
26
+ }>;
20
27
  disposes: Dispose[];
21
28
  protected _queue: Array<{
22
29
  method: keyof Action;
@@ -68,7 +75,7 @@ export declare namespace V11 {
68
75
  function error(error: string, retcode?: number): Result<any>;
69
76
  const defaultConfig: Config;
70
77
  function genMetaEvent(uin: number, type: string): {
71
- self_id: string;
78
+ self_id: number;
72
79
  time: number;
73
80
  post_type: string;
74
81
  meta_event_type: string;
@@ -16,6 +16,9 @@ const http_1 = __importDefault(require("http"));
16
16
  const https_1 = __importDefault(require("https"));
17
17
  const events_1 = require("events");
18
18
  const fs_1 = require("fs");
19
+ const db_1 = require("../../db");
20
+ const path_1 = require("path");
21
+ const app_1 = require("../../server/app");
19
22
  class V11 extends events_1.EventEmitter {
20
23
  constructor(oneBot, client, config) {
21
24
  super();
@@ -28,6 +31,8 @@ class V11 extends events_1.EventEmitter {
28
31
  this.queue_running = false;
29
32
  this.wsr = new Set();
30
33
  this.action = new action_1.Action();
34
+ this.db = new db_1.Database((0, path_1.join)(app_1.App.configDir, 'data', this.oneBot.uin + '.json'));
35
+ this.db.sync({ eventBuffer: [], KVMap: {}, files: {} });
31
36
  this.logger = this.oneBot.app.getLogger(this.oneBot.uin, this.version);
32
37
  }
33
38
  start(path) {
@@ -61,7 +66,7 @@ class V11 extends events_1.EventEmitter {
61
66
  if (this.config.heartbeat) {
62
67
  this.heartbeat = setInterval(() => {
63
68
  this.dispatch({
64
- self_id: this.oneBot.uin + '',
69
+ self_id: this.oneBot.uin,
65
70
  status: {
66
71
  online: this.client.status === icqq_1.OnlineStatus.Online,
67
72
  good: this.oneBot.status === onebot_1.OneBotStatus.Good
@@ -193,12 +198,20 @@ class V11 extends events_1.EventEmitter {
193
198
  if (data.message && data.post_type === 'message') {
194
199
  data.message = this.config.post_message_format === 'array' ? (0, icqq_cq_enable_1.toSegment)(data.message) : (0, icqq_cq_enable_1.toCqcode)(data);
195
200
  }
201
+ if (data.message_id) {
202
+ this.db.set(`KVMap.${data.seq}`, data.message_id);
203
+ data.message_id = data.seq;
204
+ }
205
+ if (data.font) {
206
+ const fontNo = Buffer.from(data.font).readUInt32BE();
207
+ this.db.set(`KVMap.${data.fontNo}`, data.font);
208
+ data.font = fontNo;
209
+ }
196
210
  data.time = Math.floor(Date.now() / 1000);
197
- data = (0, utils_1.transformObj)(data, (key, value) => {
198
- if (!['user_id', 'group_id', 'discuss_id', 'member_id', 'channel_id', 'guild_id'].includes(key))
199
- return value;
200
- return value + '';
201
- });
211
+ // data = transformObj(data, (key, value) => {
212
+ // if (!['user_id', 'group_id', 'discuss_id', 'member_id', 'channel_id', 'guild_id'].includes(key)) return value
213
+ // return value + ''
214
+ // })
202
215
  this.emit('dispatch', JSON.stringify(data));
203
216
  }
204
217
  async _httpRequestHandler(ctx) {
@@ -498,7 +511,7 @@ exports.V11 = V11;
498
511
  };
499
512
  function genMetaEvent(uin, type) {
500
513
  return {
501
- self_id: uin + '',
514
+ self_id: uin,
502
515
  time: Math.floor(Date.now() / 1000),
503
516
  post_type: "meta_event",
504
517
  meta_event_type: "lifecycle",
@@ -8,9 +8,9 @@ export declare class GuildAction {
8
8
  guild_id: string;
9
9
  channel_id: string;
10
10
  channel_name: string;
11
- channel_type: import("icqq/lib/channel").ChannelType;
11
+ channel_type: import("icqq").ChannelType;
12
12
  }[];
13
- getGuildMemberList(this: V12, guild_id: string): never[] | Promise<import("icqq/lib/guild").GuildMember[]>;
13
+ getGuildMemberList(this: V12, guild_id: string): never[] | Promise<import("icqq").GuildMember[]>;
14
14
  /**
15
15
  * 发送群聊消息
16
16
  * @param guild_id {number} 频道id
@@ -44,7 +44,7 @@ export declare class V12 extends EventEmitter implements OneBot.Base {
44
44
  sub_type: string;
45
45
  } & Omit<V12.BotEventMap[E], E> & {
46
46
  group: any;
47
- frind: any;
47
+ friend: any;
48
48
  member: any;
49
49
  };
50
50
  dispatch(data: Record<string, any>): void;
@@ -229,7 +229,7 @@ export declare namespace V12 {
229
229
  sub_type: string;
230
230
  } & Omit<BotEventMap[K], K> & {
231
231
  group: any;
232
- frind: any;
232
+ friend: any;
233
233
  member: any;
234
234
  };
235
235
  type RequestAction = {
@@ -29,7 +29,7 @@ class V12 extends events_1.EventEmitter {
29
29
  this.timestamp = Date.now();
30
30
  this.wsr = new Set();
31
31
  this.db = new db_1.Database((0, path_1.join)(app_1.App.configDir, 'data', this.oneBot.uin + '.json'));
32
- this.db.sync({ eventBuffer: [], files: {} });
32
+ this.db.sync({ eventBuffer: [], msgIdMap: {}, files: {} });
33
33
  this.action = new action_1.Action();
34
34
  this.logger = this.oneBot.app.getLogger(this.oneBot.uin, this.version);
35
35
  }
@@ -570,7 +570,7 @@ class V12 extends events_1.EventEmitter {
570
570
  setTimeout(() => {
571
571
  if (timestmap < this.timestamp)
572
572
  return;
573
- this.startWsReverse(config);
573
+ this._createWsr(url, config);
574
574
  }, this.config.reconnect_interval * 1000);
575
575
  });
576
576
  }
@@ -723,7 +723,7 @@ exports.V12 = V12;
723
723
  sub_type: '',
724
724
  ...data,
725
725
  group: data['group']?.info,
726
- frind: data['friend']?.info,
726
+ friend: data['friend']?.info,
727
727
  member: data['member']?.info,
728
728
  };
729
729
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onebots",
3
- "version": "0.4.9",
3
+ "version": "0.4.11",
4
4
  "description": "基于icqq的多例oneBot实现",
5
5
  "engines": {
6
6
  "node": ">=16"