onebots 0.4.12 → 0.4.14

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
@@ -74,64 +74,71 @@ general: # 通用配置,在单个配置省略时的默认值
74
74
  use_ws: true # 是否启用 websocket
75
75
  webhook: [ ] # http 上报地址
76
76
  ws_reverse: [ ] # 反向ws连接地址
77
+ protocol:
78
+ platform: 2
79
+ sign_api_addr: '' #你的签名地址
80
+ password: '' # 账号密码,未配置则扫码登陆
81
+ # ...其他配置项参考icqq的Config配置
77
82
  # 每个账号的单独配置(用于覆盖通用配置)
78
83
  123456789:
79
84
  version: V11 # 使用的oneBot版本
80
- password: abcedfghi # 账号密码,未配置则扫码登陆
81
- # 。。。其他配置项参见上方对应oneBot版本的通用配置
82
-
85
+ # ...其他配置项参见上方对应oneBot版本的通用配置
86
+ protocol:
87
+ platform: 2
88
+ sign_api_addr: '' #你的签名地址
89
+ password: '' # 账号密码,未配置则扫码登陆
90
+ # ...其他配置项参考icqq的Config配置
83
91
  ```
84
92
  # 配置解释
85
93
  ## 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
+ | 配置项 | 类型 | 默认值 | desc |
95
+ |:---------|:-----------------------------|:--------|:-------|
96
+ | port | number | 6727 | 服务监听端口 |
97
+ | logLevel | string | info | 日志级别 |
98
+ | general | OneBotConfig | general | 通用配置 |
99
+ | [number] | OneBotConfig\|OneBotConfig[] | - | 机器人配置 |
94
100
  ## OneBotConfig
95
- | 配置项 | 类型 | 默认值 | desc |
96
- |:-----|:-------|:-----|:--------------------------------------------|
97
- | V11| ConfigV11| configV11| V11配置|
98
- | V12| ConfigV12| configV12| V12配置|
101
+ | 配置项 | 类型 | 默认值 | desc |
102
+ |:---------|:----------|:----------|:-------|
103
+ | V11 | ConfigV11 | configV11 | V11配置 |
104
+ | V12 | ConfigV12 | configV12 | V12配置 |
105
+ | protocol | Config | {} | icqq配置 |
99
106
  ## 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连接地址 |
107
+ | 配置项 | 类型 | 默认值 | desc |
108
+ |:--------------------|:---------|:-------|:-----------|
109
+ | heartbeat | number | 3 | 心跳间隔 单位:秒 |
110
+ | access_token | string | - | 访问令牌 |
111
+ | secret | string | - | 签名密钥 |
112
+ | rate_limit_interval | number | 4 | 限速间隔 单位:秒 |
113
+ | post_message_format | string | string | 消息格式化 |
114
+ | reconnect_interval | number | 3 | 重连间隔 单位:秒 |
115
+ | use_http | boolean | false | 是否使用http协议 |
116
+ | enable_cors | boolean | false | 是否允许跨域 |
117
+ | use_ws | boolean | false | 是否使用ws协议 |
118
+ | http_reverse_url | string[] | - | http上报地址地址 |
119
+ | ws_reverse_url | string[] | - | 反向ws连接地址 |
113
120
  ## 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连接地址 |
121
+ | 配置项 | 类型 | 默认值 | desc |
122
+ |:--------------------|:---------|:------|:------------|
123
+ | heartbeat | number | 3 | 心跳间隔 单位:秒 |
124
+ | access_token | string | - | 访问令牌 |
125
+ | request_timeout | number | 15 | 请求超时 单位:秒 |
126
+ | reconnect_interval | number | 3 | 重连间隔 单位:秒 |
127
+ | enable_cors | boolean | false | 是否允许跨域 |
128
+ | use_http | boolean | false | 是否使用http协议 |
129
+ | use_ws | boolean | false | 是否使用ws协议 |
130
+ | webhook_reverse_url | string[] | - | webhook上报地址 |
131
+ | ws_reverse_url | string[] | - | 反向ws连接地址 |
125
132
  # 使用API管理oneBot
126
133
 
127
134
  | url | method | params | desc |
128
- |:--------| :--- |:----------------|:-------------------------------|
129
- | /list | GET | | 获取当前运行的机器人列表 |
130
- | /detail | GET | uin | 获取指定机器人配置 |
131
- | /qrcode | GET | uin | 获取指定机器人登录二维码 |
132
- | /add | POST | {uin,...config} | 添加机器人 config 为机器人配置 |
133
- | /edit | POST | {uin,...config} | 修改机器人配置 config 为机器人配置 |
134
- | /remove | get | uin,force | 移除机器人,force为true时,将删除机器人data目录 |
135
+ |:--------|:-------|:----------------|:-------------------------------|
136
+ | /list | GET | | 获取当前运行的机器人列表 |
137
+ | /detail | GET | uin | 获取指定机器人配置 |
138
+ | /qrcode | GET | uin | 获取指定机器人登录二维码 |
139
+ | /add | POST | {uin,...config} | 添加机器人 config 为机器人配置 |
140
+ | /edit | POST | {uin,...config} | 修改机器人配置 config 为机器人配置 |
141
+ | /remove | get | uin,force | 移除机器人,force为true时,将删除机器人data目录 |
135
142
 
136
143
  # 鸣谢
137
144
  1. [icqqjs/icqq](https://github.com/icqqjs/icqq) 底层服务支持
@@ -26,8 +26,11 @@ general: # 通用配置,在单个配置省略时的默认值
26
26
  use_ws: true # 是否启用 websocket
27
27
  webhook: [ ] # http 上报地址
28
28
  ws_reverse: [ ] # 反向ws连接地址
29
+ protocol:
30
+ platform: 2
29
31
  # 每个账号的单独配置(用于覆盖通用配置)
30
32
  123456789:
31
33
  version: V11 # 使用的oneBot版本
32
- password: abcedfghi # 账号密码,未配置则扫码登陆
34
+ protocol: # 将会覆盖通用配置中的protocol
35
+ platform: 1
33
36
  # 。。。其他配置项参见上方对应oneBot版本的通用配置
package/lib/onebot.d.ts CHANGED
@@ -2,7 +2,8 @@
2
2
  import 'icqq-cq-enable';
3
3
  import { EventEmitter } from 'events';
4
4
  import { App } from "./server/app";
5
- import { Client, Platform } from "icqq";
5
+ import { Client } from "icqq";
6
+ import { Config as IcqqConfig } from 'icqq';
6
7
  import { V11 } from "./service/V11";
7
8
  import { V12 } from "./service/V12";
8
9
  import { MayBeArray } from "./types";
@@ -32,8 +33,7 @@ export declare namespace OneBot {
32
33
  type Version = 'V11' | 'V12';
33
34
  type Config<V extends Version = 'V11'> = ({
34
35
  version?: V;
35
- platform?: Platform;
36
- password?: string;
36
+ protocol?: IcqqConfig;
37
37
  } & (V extends 'V11' ? V11.Config : V12.Config));
38
38
  interface Base {
39
39
  start(path?: string): any;
package/lib/onebot.js CHANGED
@@ -47,15 +47,16 @@ class OneBot extends events_1.EventEmitter {
47
47
  this.app = app;
48
48
  this.uin = uin;
49
49
  config = [].concat(config);
50
- let platform = this.app.config.platform;
51
- let sign_api_addr = this.app.config.sign_api_addr;
50
+ const protocolConfig = {
51
+ data_dir: (0, path_1.join)(app_1.App.configDir, 'data'),
52
+ ...this.app.config.general.protocol
53
+ };
52
54
  this.config = config.map(c => {
53
- if (c.platform)
54
- platform = c.platform;
55
- if (c.password)
56
- this.password = c.password;
57
55
  if (!c.version)
58
56
  c.version = 'V11';
57
+ if (!c.protocol)
58
+ c.protocol = {};
59
+ Object.assign(protocolConfig, c.protocol);
59
60
  switch (c.version) {
60
61
  case 'V11':
61
62
  return (0, utils_1.deepMerge)((0, utils_1.deepClone)(this.app.config.general.V11), c);
@@ -65,13 +66,13 @@ class OneBot extends events_1.EventEmitter {
65
66
  throw new Error('不支持的oneBot版本:' + c.version);
66
67
  }
67
68
  });
68
- this.client = new icqq_1.Client({ platform, sign_api_addr, data_dir: (0, path_1.join)(app_1.App.configDir, 'data') });
69
+ this.client = new icqq_1.Client(protocolConfig);
69
70
  this.instances = this.config.map(c => {
70
71
  switch (c.version) {
71
72
  case 'V11':
72
- return new V11_1.V11(this, this.client, (0, utils_1.omit)(c, ['version', 'password']));
73
+ return new V11_1.V11(this, this.client, c);
73
74
  case 'V12':
74
- return new V12_1.V12(this, this.client, (0, utils_1.omit)(c, ['version', 'password']));
75
+ return new V12_1.V12(this, this.client, c);
75
76
  default:
76
77
  throw new Error('不支持的oneBot版本:' + c.version);
77
78
  }
@@ -3,12 +3,12 @@
3
3
  import Koa from 'koa';
4
4
  import { Logger } from "log4js";
5
5
  import { Server } from "http";
6
+ import { Config as IcqqConfig } from "icqq";
6
7
  import { OneBot } from "../onebot";
7
8
  import { Router } from "./router";
8
9
  import { V11 } from "../service/V11";
9
10
  import { V12 } from "../service/V12";
10
11
  import { LogLevel, MayBeArray } from "../types";
11
- import { Platform } from "icqq";
12
12
  export interface KoaOptions {
13
13
  env?: string;
14
14
  keys?: string[];
@@ -43,11 +43,10 @@ export declare namespace App {
43
43
  path?: string;
44
44
  timeout?: number;
45
45
  log_level?: LogLevel;
46
- sign_api_addr?: string;
47
- platform?: Platform;
48
46
  general?: {
49
47
  V11?: V11.Config;
50
48
  V12?: V12.Config;
49
+ protocol?: IcqqConfig;
51
50
  };
52
51
  } & KoaOptions & Record<`${number}`, MayBeArray<OneBot.Config<OneBot.Version>>>;
53
52
  const defaultConfig: Config;
package/lib/server/app.js CHANGED
@@ -47,7 +47,7 @@ class App extends koa_1.default {
47
47
  constructor(config = {}) {
48
48
  super(config);
49
49
  this.oneBots = [];
50
- this.config = (0, utils_1.deepMerge)((0, utils_1.deepClone)(App.defaultConfig), config);
50
+ this.config = (0, utils_1.deepMerge)((0, utils_1.deepClone)(_a.defaultConfig), config);
51
51
  this.logger = (0, log4js_1.getLogger)('[icqq-OneBot]');
52
52
  this.logger.level = this.config.log_level;
53
53
  this.router = new router_1.Router({ prefix: config.path });
@@ -86,7 +86,7 @@ class App extends koa_1.default {
86
86
  this.config[uin] = config;
87
87
  const oneBot = this.createOneBot(uin, config);
88
88
  oneBot.startListen();
89
- (0, fs_1.writeFileSync)(App.configPath, js_yaml_1.default.dump((0, utils_1.deepClone)(this.config)));
89
+ (0, fs_1.writeFileSync)(_a.configPath, js_yaml_1.default.dump((0, utils_1.deepClone)(this.config)));
90
90
  }
91
91
  updateAccount(uin, config) {
92
92
  if (typeof uin !== "number")
@@ -112,7 +112,7 @@ class App extends koa_1.default {
112
112
  oneBot.stop(force);
113
113
  delete this.config[uin];
114
114
  this.oneBots.splice(currentIdx, 1);
115
- (0, fs_1.writeFileSync)(App.configPath, js_yaml_1.default.dump(this.config));
115
+ (0, fs_1.writeFileSync)(_a.configPath, js_yaml_1.default.dump(this.config));
116
116
  }
117
117
  createOneBot(uin, config) {
118
118
  const oneBot = new onebot_1.OneBot(this, uin, config);
@@ -125,18 +125,18 @@ class App extends koa_1.default {
125
125
  ctx.body = this.oneBots.map(bot => {
126
126
  return {
127
127
  uin: bot.uin,
128
- config: bot.config.map(c => (0, utils_1.protectedFields)(c, 'password', "access_token")),
128
+ config: bot.config.map(c => (0, utils_1.protectedFields)(c, 'protocol', "access_token")),
129
129
  urls: bot.config.map(c => `/${c.version}/${bot.uin}`)
130
130
  };
131
131
  });
132
132
  });
133
133
  this.router.get('/qrcode', (ctx) => {
134
134
  const { uin } = ctx.query;
135
- const uinUrl = path.join(App.configDir, 'data', uin);
135
+ const uinUrl = path.join(_a.configDir, 'data', uin);
136
136
  if (!(0, fs_1.existsSync)(uinUrl)) {
137
137
  return ctx.res.writeHead(400).end('未登录');
138
138
  }
139
- const qrcodePath = path.join(App.configDir, 'data', uin, 'qrcode.png');
139
+ const qrcodePath = path.join(_a.configDir, 'data', uin, 'qrcode.png');
140
140
  let file = null;
141
141
  try {
142
142
  file = (0, fs_2.readFileSync)(qrcodePath); //读取文件
@@ -153,7 +153,7 @@ class App extends koa_1.default {
153
153
  const oneBot = this.oneBots.find(bot => bot.uin === Number(uin));
154
154
  ctx.body = {
155
155
  uin,
156
- config: oneBot.config.map(c => (0, utils_1.protectedFields)(c, 'password', "access_token")),
156
+ config: oneBot.config.map(c => (0, utils_1.protectedFields)(c, 'protocol', "access_token")),
157
157
  urls: oneBot.config.map(c => `/${uin}/${c.version}`)
158
158
  };
159
159
  });
@@ -234,10 +234,12 @@ exports.defineConfig = defineConfig;
234
234
  App.defaultConfig = {
235
235
  port: 6727,
236
236
  timeout: 30,
237
- platform: 5,
238
237
  general: {
239
238
  V11: V11_1.V11.defaultConfig,
240
- V12: V12_1.V12.defaultConfig
239
+ V12: V12_1.V12.defaultConfig,
240
+ protocol: {
241
+ platform: 2
242
+ }
241
243
  },
242
244
  log_level: 'info',
243
245
  };
@@ -17,9 +17,5 @@ export declare class GuildAction {
17
17
  * @param channel_id {string} 子频道id
18
18
  * @param message {import('icqq/lib/service').Sendable} 消息
19
19
  */
20
- sendGuildMsg(this: V12, guild_id: string, channel_id: string, message: V12.Sendable): Promise<{
21
- seq: number;
22
- rand: number;
23
- time: number;
24
- }>;
20
+ sendGuildMsg(this: V12, guild_id: string, channel_id: string, message: V12.Sendable): Promise<import("icqq/lib/internal").GuildMessageRet>;
25
21
  }
package/lib/utils.js CHANGED
@@ -153,10 +153,17 @@ function uuid() {
153
153
  }
154
154
  exports.uuid = uuid;
155
155
  function protectedFields(source, ...keys) {
156
+ const protocolValue = (value) => {
157
+ if (value && typeof value === 'object')
158
+ return Object.fromEntries(Object.entries(value).map(([key, value]) => {
159
+ return [key, protocolValue(value)];
160
+ }));
161
+ return `${value}`.split('').map(() => '*').join('');
162
+ };
156
163
  if (!source || typeof source !== 'object')
157
164
  throw new Error('source must is object');
158
165
  return Object.fromEntries(Object.entries(source).map(([key, value]) => {
159
- return [key, keys.includes(key) ? value.split('').map(c => '*').join('') : value];
166
+ return [key, keys.includes(key) ? protocolValue(value) : value];
160
167
  }));
161
168
  }
162
169
  exports.protectedFields = protectedFields;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onebots",
3
- "version": "0.4.12",
3
+ "version": "0.4.14",
4
4
  "description": "基于icqq的多例oneBot实现",
5
5
  "engines": {
6
6
  "node": ">=16"