onebots 0.4.12 → 0.4.13

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,12 +74,20 @@ 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
@@ -87,8 +95,6 @@ general: # 通用配置,在单个配置省略时的默认值
87
95
  |:-----|:-------|:-----|:--------------------------------------------|
88
96
  | port | number | 6727 | 服务监听端口 |
89
97
  | logLevel| string | info | 日志级别 |
90
- | platform | number | 5 | 机器人平台,1:android 2:aPid 3:watch 4:mac 5:iPad |
91
- | sign_api_addr| string | - | 签名API地址|
92
98
  | general | OneBotConfig | general | 通用配置|
93
99
  | [number] | OneBotConfig\|OneBotConfig[] | - | 机器人配置|
94
100
  ## OneBotConfig
@@ -26,8 +26,9 @@ 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 # 账号密码,未配置则扫码登陆
33
34
  # 。。。其他配置项参见上方对应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
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
@@ -125,7 +125,7 @@ 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
  });
@@ -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.13",
4
4
  "description": "基于icqq的多例oneBot实现",
5
5
  "engines": {
6
6
  "node": ">=16"