onebots 0.4.23 → 0.4.26

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.
Files changed (77) hide show
  1. package/README.md +25 -3
  2. package/lib/adapter.d.ts +55 -0
  3. package/lib/adapter.js +60 -0
  4. package/lib/adapters/icqq/index.d.ts +36 -0
  5. package/lib/adapters/icqq/index.js +300 -0
  6. package/lib/adapters/qq/bot.d.ts +22 -0
  7. package/lib/adapters/qq/bot.js +20 -0
  8. package/lib/adapters/qq/constans.d.ts +69 -0
  9. package/lib/adapters/qq/constans.js +128 -0
  10. package/lib/adapters/qq/elements.d.ts +125 -0
  11. package/lib/adapters/qq/elements.js +8 -0
  12. package/lib/adapters/qq/entries/channel.d.ts +17 -0
  13. package/lib/adapters/qq/entries/channel.js +2 -0
  14. package/lib/adapters/qq/entries/friend.d.ts +8 -0
  15. package/lib/adapters/qq/entries/friend.js +2 -0
  16. package/lib/adapters/qq/entries/group.d.ts +6 -0
  17. package/lib/adapters/qq/entries/group.js +2 -0
  18. package/lib/adapters/qq/entries/groupMember.d.ts +7 -0
  19. package/lib/adapters/qq/entries/groupMember.js +2 -0
  20. package/lib/adapters/qq/entries/guild.d.ts +21 -0
  21. package/lib/adapters/qq/entries/guild.js +2 -0
  22. package/lib/adapters/qq/entries/guildMember.d.ts +9 -0
  23. package/lib/adapters/qq/entries/guildMember.js +2 -0
  24. package/lib/adapters/qq/entries/user.d.ts +9 -0
  25. package/lib/adapters/qq/entries/user.js +2 -0
  26. package/lib/adapters/qq/event.d.ts +28 -0
  27. package/lib/adapters/qq/event.js +24 -0
  28. package/lib/adapters/qq/index.d.ts +35 -0
  29. package/lib/adapters/qq/index.js +172 -0
  30. package/lib/adapters/qq/message.d.ts +84 -0
  31. package/lib/adapters/qq/message.js +272 -0
  32. package/lib/adapters/qq/qqBot.d.ts +122 -0
  33. package/lib/adapters/qq/qqBot.js +440 -0
  34. package/lib/adapters/qq/sessionManager.d.ts +33 -0
  35. package/lib/adapters/qq/sessionManager.js +257 -0
  36. package/lib/adapters/qq/types.d.ts +45 -0
  37. package/lib/adapters/qq/types.js +2 -0
  38. package/lib/adapters/qq/utils.d.ts +12 -0
  39. package/lib/adapters/qq/utils.js +86 -0
  40. package/lib/bin.js +17 -2
  41. package/lib/config.sample.yaml +23 -5
  42. package/lib/onebot.d.ts +32 -24
  43. package/lib/onebot.js +51 -188
  44. package/lib/server/app.d.ts +22 -12
  45. package/lib/server/app.js +97 -71
  46. package/lib/service/V11/action/common.d.ts +9 -11
  47. package/lib/service/V11/action/common.js +27 -64
  48. package/lib/service/V11/action/friend.d.ts +5 -13
  49. package/lib/service/V11/action/friend.js +6 -16
  50. package/lib/service/V11/action/group.d.ts +19 -22
  51. package/lib/service/V11/action/group.js +20 -30
  52. package/lib/service/V11/action/index.d.ts +1 -1
  53. package/lib/service/V11/db_entities.d.ts +1 -1
  54. package/lib/service/V11/db_entities.js +1 -1
  55. package/lib/service/V11/db_sqlite.d.ts +1 -1
  56. package/lib/service/V11/index.d.ts +47 -16
  57. package/lib/service/V11/index.js +143 -164
  58. package/lib/service/V12/action/common.d.ts +3 -67
  59. package/lib/service/V12/action/common.js +9 -63
  60. package/lib/service/V12/action/friend.d.ts +4 -10
  61. package/lib/service/V12/action/friend.js +4 -12
  62. package/lib/service/V12/action/group.d.ts +19 -21
  63. package/lib/service/V12/action/group.js +19 -27
  64. package/lib/service/V12/action/guild.d.ts +40 -13
  65. package/lib/service/V12/action/guild.js +99 -11
  66. package/lib/service/V12/action/index.d.ts +1 -1
  67. package/lib/service/V12/index.d.ts +37 -13
  68. package/lib/service/V12/index.js +44 -72
  69. package/lib/service.d.ts +7 -2
  70. package/lib/service.js +32 -30
  71. package/lib/utils.d.ts +7 -4
  72. package/lib/utils.js +33 -28
  73. package/package.json +5 -4
  74. package/lib/service/V12/utils.d.ts +0 -8
  75. package/lib/service/V12/utils.js +0 -47
  76. /package/lib/{service/V11 → adapters/icqq}/utils.d.ts +0 -0
  77. /package/lib/{service/V11 → adapters/icqq}/utils.js +0 -0
@@ -0,0 +1,257 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SessionManager = exports.MAX_RETRY = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const ws_1 = require("ws");
9
+ const utils_1 = require("./utils");
10
+ const events_1 = require("events");
11
+ const constans_1 = require("./constans");
12
+ exports.MAX_RETRY = 10;
13
+ class SessionManager extends events_1.EventEmitter {
14
+ get token() {
15
+ return this.bot.config.token;
16
+ }
17
+ constructor(bot) {
18
+ super();
19
+ this.bot = bot;
20
+ this.retry = 0;
21
+ this.sessionRecord = {
22
+ sessionID: "",
23
+ seq: 0
24
+ };
25
+ this.heartbeatParam = {
26
+ op: constans_1.OpCode.HEARTBEAT,
27
+ d: null // 心跳唯一值
28
+ };
29
+ this.on(constans_1.SessionEvents.EVENT_WS, (data) => {
30
+ switch (data.eventType) {
31
+ case constans_1.SessionEvents.RECONNECT:
32
+ this.bot.logger.mark("[CLIENT] 等待断线重连中...");
33
+ break;
34
+ case constans_1.SessionEvents.DISCONNECT:
35
+ if (this.retry < (this.bot.config.maxRetry || exports.MAX_RETRY)) {
36
+ this.bot.logger.mark("[CLIENT] 重新连接中,尝试次数:", this.retry + 1);
37
+ if (constans_1.WebsocketCloseReason.find((v) => v.code === data.code)?.resume) {
38
+ this.sessionRecord = data.eventMsg;
39
+ }
40
+ this.isReconnect = true;
41
+ this.start();
42
+ this.retry += 1;
43
+ }
44
+ else {
45
+ this.bot.logger.mark("[CLIENT] 超过重试次数,连接终止");
46
+ this.emit(constans_1.SessionEvents.DEAD, {
47
+ eventType: constans_1.SessionEvents.ERROR,
48
+ msg: "连接已死亡,请检查网络或重启"
49
+ });
50
+ }
51
+ break;
52
+ case constans_1.SessionEvents.READY:
53
+ this.bot.logger.mark("[CLIENT] 连接成功");
54
+ this.retry = 0;
55
+ break;
56
+ default:
57
+ }
58
+ });
59
+ }
60
+ async getAccessToken() {
61
+ let { secret, appid } = this.bot.config;
62
+ const getToken = () => {
63
+ return new Promise((resolve, reject) => {
64
+ axios_1.default.post("https://bots.qq.com/app/getAppAccessToken", {
65
+ appId: appid,
66
+ clientSecret: secret
67
+ }).then(res => {
68
+ if (res.status === 200 && res.data && typeof res.data === "object") {
69
+ resolve(res.data);
70
+ }
71
+ else {
72
+ reject(res);
73
+ }
74
+ });
75
+ });
76
+ };
77
+ const getNext = async (next_time) => {
78
+ return new Promise(resolve => {
79
+ setTimeout(async () => {
80
+ const token = await getToken();
81
+ this.bot.logger.debug("getAccessToken", token);
82
+ this.access_token = token.access_token;
83
+ getNext(token.expires_in - 1).catch(() => getNext(0));
84
+ resolve(token);
85
+ }, next_time * 1000);
86
+ });
87
+ };
88
+ return getNext(0);
89
+ }
90
+ async getWsUrl() {
91
+ return new Promise((resolve) => {
92
+ this.bot.request.get("/gateway/bot", {
93
+ headers: {
94
+ Accept: "*/*",
95
+ "Accept-Encoding": "utf-8",
96
+ "Accept-Language": "zh-CN,zh;q=0.8",
97
+ Connection: "keep-alive",
98
+ "User-Agent": "v1",
99
+ Authorization: ""
100
+ }
101
+ }).then(res => {
102
+ if (!res.data)
103
+ throw new Error("获取ws连接信息异常");
104
+ this.wsUrl = res.data.url;
105
+ resolve();
106
+ });
107
+ });
108
+ }
109
+ getValidIntends() {
110
+ return (this.bot.config.intents || []).reduce((result, item) => {
111
+ const value = constans_1.Intends[item];
112
+ if (value === undefined) {
113
+ this.bot.logger.warn(`Invalid intends(${item}),skip...`);
114
+ return result;
115
+ }
116
+ return constans_1.Intends[item] | result;
117
+ }, 0);
118
+ }
119
+ async start() {
120
+ await this.getAccessToken();
121
+ await this.getWsUrl();
122
+ this.connect();
123
+ this.startListen();
124
+ }
125
+ connect() {
126
+ this.bot.ws = new ws_1.WebSocket(this.wsUrl, {
127
+ headers: {
128
+ "Authorization": "QQBot " + this.access_token,
129
+ "X-Union-Appid": this.bot.config.appid
130
+ }
131
+ });
132
+ }
133
+ reconnectWs() {
134
+ const reconnectParam = {
135
+ op: constans_1.OpCode.RESUME,
136
+ d: {
137
+ // token: `Bot ${this.bot.appId}${this.token}`,
138
+ token: `QQBot ${this.access_token}`,
139
+ session_id: this.sessionRecord.sessionID,
140
+ seq: this.sessionRecord.seq
141
+ }
142
+ };
143
+ this.sendWs(reconnectParam);
144
+ }
145
+ // 发送websocket
146
+ sendWs(msg) {
147
+ try {
148
+ // 先将消息转为字符串
149
+ this.bot.ws.send(typeof msg === "string" ? msg : JSON.stringify(msg));
150
+ }
151
+ catch (e) {
152
+ this.bot.logger.error(e);
153
+ }
154
+ }
155
+ authWs() {
156
+ // 鉴权参数
157
+ const authOp = {
158
+ op: constans_1.OpCode.IDENTIFY,
159
+ d: {
160
+ // token: `Bot ${this.bot.appId}${this.token}`,
161
+ token: `QQBot ${this.access_token}`,
162
+ intents: this.getValidIntends(),
163
+ shard: [0, 1] // 分片信息,给一个默认值
164
+ }
165
+ };
166
+ // 发送鉴权请求
167
+ this.sendWs(authOp);
168
+ }
169
+ startListen() {
170
+ this.bot.ws.on("open", () => {
171
+ this.bot.logger.info("[CLIENT] 连接成功");
172
+ });
173
+ this.bot.ws.on("close", (code) => {
174
+ this.bot.logger.error(`[CLIENT] 连接关闭:${code}`);
175
+ this.emit(constans_1.SessionEvents.EVENT_WS, {
176
+ eventType: constans_1.SessionEvents.DISCONNECT,
177
+ code,
178
+ eventMsg: this.sessionRecord
179
+ });
180
+ if (code) {
181
+ constans_1.WebsocketCloseReason.forEach((e) => {
182
+ if (e.code === code) {
183
+ this.emit(constans_1.SessionEvents.ERROR, e.reason);
184
+ }
185
+ });
186
+ }
187
+ });
188
+ this.bot.ws.on("error", (e) => {
189
+ this.bot.logger.error("[CLIENT] 连接错误");
190
+ this.emit(constans_1.SessionEvents.CLOSED, { eventType: constans_1.SessionEvents.CLOSED });
191
+ });
192
+ this.bot.ws.on("message", (data) => {
193
+ this.bot.logger.debug(`[CLIENT] 收到消息: ${data}`);
194
+ // 先将消息解析
195
+ const wsRes = (0, utils_1.toObject)(data);
196
+ // 先判断websocket连接是否成功
197
+ if (wsRes?.op === constans_1.OpCode.HELLO && wsRes?.d?.heartbeat_interval) {
198
+ // websocket连接成功,拿到心跳周期
199
+ this.heartbeatInterval = wsRes?.d?.heartbeat_interval;
200
+ // 非断线重连时,需要鉴权
201
+ this.isReconnect ? this.reconnectWs() : this.authWs();
202
+ return;
203
+ }
204
+ // 鉴权通过
205
+ if (wsRes.t === constans_1.SessionEvents.READY) {
206
+ this.bot.logger.info(`[CLIENT] 鉴权通过`);
207
+ const { d, s } = wsRes;
208
+ const { session_id, user = {} } = d;
209
+ this.bot.self_id = user.id;
210
+ this.bot.nickname = user.username;
211
+ this.bot.status = user.status || 0;
212
+ // 获取当前会话参数
213
+ if (session_id && s) {
214
+ this.sessionRecord.sessionID = session_id;
215
+ this.sessionRecord.seq = s;
216
+ this.heartbeatParam.d = s;
217
+ }
218
+ this.bot.logger.info(`connect to ${user.username}(${user.id})`);
219
+ this.isReconnect = false;
220
+ this.emit(constans_1.SessionEvents.READY, { eventType: constans_1.SessionEvents.READY, msg: d || "" });
221
+ // 第一次发送心跳
222
+ this.bot.logger.debug(`[CLIENT] 发送第一次心跳`, this.heartbeatParam);
223
+ this.sendWs(this.heartbeatParam);
224
+ return;
225
+ }
226
+ // 心跳测试
227
+ if (wsRes.op === constans_1.OpCode.HEARTBEAT_ACK || wsRes.t === constans_1.SessionEvents.RESUMED) {
228
+ if (!this.alive) {
229
+ this.alive = true;
230
+ this.emit(constans_1.SessionEvents.EVENT_WS, { eventType: constans_1.SessionEvents.READY });
231
+ }
232
+ this.bot.logger.debug("[CLIENT] 心跳校验", this.heartbeatParam);
233
+ setTimeout(() => {
234
+ this.sendWs(this.heartbeatParam);
235
+ }, this.heartbeatInterval);
236
+ }
237
+ // 收到服务端重连的通知
238
+ if (wsRes.op === constans_1.OpCode.RECONNECT) {
239
+ // 通知会话,当前已断线
240
+ this.emit(constans_1.SessionEvents.EVENT_WS, { eventType: constans_1.SessionEvents.RECONNECT });
241
+ }
242
+ // 服务端主动推送的消息
243
+ if (wsRes.op === constans_1.OpCode.DISPATCH) {
244
+ // 更新心跳唯一值
245
+ const { s } = wsRes;
246
+ if (s)
247
+ this.sessionRecord.seq = this.heartbeatParam.d = s;
248
+ // OpenAPI事件分发
249
+ this.bot.dispatchEvent(wsRes.t, wsRes);
250
+ }
251
+ });
252
+ this.on(constans_1.SessionEvents.ERROR, (e) => {
253
+ this.bot.logger.error(`[CLIENT] 发生错误:${e}`);
254
+ });
255
+ }
256
+ }
257
+ exports.SessionManager = SessionManager;
@@ -0,0 +1,45 @@
1
+ import { ChannelSubType, ChannelType, PrivateType, SpeakPermission } from "./constans";
2
+ export type Dict<T = any> = Record<string, T>;
3
+ export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "mark" | "off";
4
+ export interface wsResData {
5
+ op: number;
6
+ d?: {
7
+ heartbeat_interval?: number;
8
+ session_id?: string;
9
+ user?: {
10
+ id?: string;
11
+ username?: string;
12
+ bot?: boolean;
13
+ status?: number;
14
+ };
15
+ };
16
+ s: number;
17
+ t: string;
18
+ id?: string;
19
+ }
20
+ export interface ChannelInfo {
21
+ id: string;
22
+ guild_id: string;
23
+ name: string;
24
+ type: ChannelType;
25
+ sub_type: ChannelSubType;
26
+ position: number;
27
+ parent_id?: string;
28
+ owner_id: string;
29
+ private_type: PrivateType;
30
+ speak_permission: SpeakPermission;
31
+ application_id?: string;
32
+ permissions?: string;
33
+ }
34
+ export type UpdatePermissionParams = {
35
+ add?: string;
36
+ remove?: string;
37
+ };
38
+ export type ApiBaseInfo = {
39
+ path: string;
40
+ method: "GET" | "POST" | "DELETE" | "PATCH" | "PUT";
41
+ };
42
+ export type RecommendInfo = {
43
+ channel_id: string;
44
+ introduce: string;
45
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ export declare const toObject: <T = any>(data: any) => T;
2
+ export declare function isEmpty<T>(data: T): boolean;
3
+ export declare function remove<T>(list: T[], item: T): void;
4
+ export declare function deepClone<T extends object>(obj: T): any;
5
+ /**
6
+ * 寻找数组中最后一个符合条件的元素下标
7
+ * @param list 数组
8
+ * @param predicate 条件
9
+ * @returns {number} 元素下标,未找到返回-1
10
+ */
11
+ export declare function findLastIndex<T>(list: T[], predicate: (item: T, index: number) => boolean): number;
12
+ export declare function trimQuote(str: string): string;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trimQuote = exports.findLastIndex = exports.deepClone = exports.remove = exports.isEmpty = exports.toObject = void 0;
4
+ const toObject = (data) => {
5
+ if (Buffer.isBuffer(data))
6
+ return JSON.parse(data.toString());
7
+ if (typeof data === 'object')
8
+ return data;
9
+ if (typeof data === 'string')
10
+ return JSON.parse(data);
11
+ // return String(data);
12
+ };
13
+ exports.toObject = toObject;
14
+ function isEmpty(data) {
15
+ if (!data)
16
+ return true;
17
+ if (typeof data !== "object")
18
+ return false;
19
+ return Reflect.ownKeys(data).length === 0;
20
+ }
21
+ exports.isEmpty = isEmpty;
22
+ function remove(list, item) {
23
+ const index = list.indexOf(item);
24
+ if (index !== -1)
25
+ list.splice(index, 1);
26
+ }
27
+ exports.remove = remove;
28
+ function deepClone(obj) {
29
+ if (typeof obj !== "object")
30
+ return obj;
31
+ if (Array.isArray(obj))
32
+ return obj.map(deepClone);
33
+ const Constructor = obj.constructor;
34
+ let newObj = Constructor();
35
+ for (let key in obj) {
36
+ newObj[key] = deepClone(obj[key]);
37
+ }
38
+ return newObj;
39
+ }
40
+ exports.deepClone = deepClone;
41
+ /**
42
+ * 寻找数组中最后一个符合条件的元素下标
43
+ * @param list 数组
44
+ * @param predicate 条件
45
+ * @returns {number} 元素下标,未找到返回-1
46
+ */
47
+ function findLastIndex(list, predicate) {
48
+ for (let i = list.length - 1; i >= 0; i--) {
49
+ if (predicate(list[i], i))
50
+ return i;
51
+ }
52
+ return -1;
53
+ }
54
+ exports.findLastIndex = findLastIndex;
55
+ function trimQuote(str) {
56
+ const quotes = [
57
+ [
58
+ '"',
59
+ '"',
60
+ ],
61
+ [
62
+ "'",
63
+ "'",
64
+ ],
65
+ [
66
+ '`',
67
+ '`',
68
+ ],
69
+ [
70
+ '“',
71
+ '”',
72
+ ],
73
+ [
74
+ '‘',
75
+ '’',
76
+ ]
77
+ ];
78
+ for (let i = 0; i < quotes.length; i++) {
79
+ const [start, end] = quotes[i];
80
+ if (str.startsWith(start) && str.endsWith(end)) {
81
+ return str.slice(1, -1);
82
+ }
83
+ }
84
+ return str;
85
+ }
86
+ exports.trimQuote = trimQuote;
package/lib/bin.js CHANGED
@@ -5,6 +5,21 @@ const app_1 = require("./server/app");
5
5
  const execArgv = process.argv.splice(2);
6
6
  const obj = {};
7
7
  for (let i = 0; i < execArgv.length; i += 2) {
8
- obj[execArgv[i]] = execArgv[i + 1];
8
+ const key = execArgv[i];
9
+ const value = execArgv[i + 1];
10
+ if (!obj[key])
11
+ obj[key] = value;
12
+ else {
13
+ if (Array.isArray(obj[key]))
14
+ obj[key].push(value);
15
+ else
16
+ obj[key] = [obj[key], value];
17
+ }
9
18
  }
10
- (0, app_1.createApp)(obj["-c"]).start();
19
+ if (obj['-r']) {
20
+ const adapters = [].concat(obj['-r']);
21
+ for (const adapter of adapters) {
22
+ app_1.App.registerAdapter(adapter);
23
+ }
24
+ }
25
+ (0, app_1.createOnebots)(obj['-c']).start();
@@ -1,6 +1,5 @@
1
1
  port: 6727 # 监听端口
2
2
  log_level: info # 日志等级
3
- platform: 5 # 机器人客户端协议(1:Android 2:APad 3:Watch 4:IMac 5:IPad)
4
3
  timeout: 30 #登录超时时间(秒)
5
4
  general: # 通用配置,在单个配置省略时的默认值
6
5
  V11: # oneBotV11的通用配置
@@ -29,10 +28,29 @@ general: # 通用配置,在单个配置省略时的默认值
29
28
  protocol:
30
29
  platform: 2
31
30
  # 每个账号的单独配置(用于覆盖通用配置)
32
- 123456789:
33
- version: V11 # 使用的oneBot版本
34
- password: '' # 账号密码,未配置则扫码登陆
35
- group_whitelist: [] # 群消息派发白名单,只有数组中的群号才派发,为空则全部派发
31
+ icqq.123456789: # `${适配器名称}:${账号}`
32
+ versions:
33
+ - version: V12
34
+ # 。。。其他配置项参见上方对应oneBot版本的通用配置
36
35
  protocol: # 将会覆盖通用配置中的protocol
37
36
  platform: 1
38
37
  # 。。。其他配置项参见上方对应oneBot版本的通用配置
38
+ qq.a: # `${适配器名称}:${账号}`
39
+ versions:
40
+ - version: V11
41
+ # 。。。其他配置项参见上方对应oneBot版本的通用配置
42
+ protocol: # 将会覆盖通用配置中的protocol
43
+ token: '' # qq机器人token
44
+ secret: '' # qq机器人secret
45
+ sandbox: false # 是否沙箱环境
46
+ intents: # 需要监听的intents
47
+ - 'GROUP_AT_MESSAGE_CREATE' # 群聊@事件 没有群聊权限请注释
48
+ - 'C2C_MESSAGE_CREATE' # 私聊事件 没有私聊权限请注释
49
+ - 'DIRECT_MESSAGE' # 频道私信事件
50
+ # - 'GUILD_MESSAGES' # 私域机器人频道消息事件,公域机器人请注释
51
+ - 'GUILDS' # 频道变更事件
52
+ - 'GUILD_MEMBERS' # 频道成员变更事件
53
+ - 'GUILD_MESSAGE_REACTIONS' # 频道消息表态事件
54
+ - 'INTERACTION' # 互动事件
55
+ - 'PUBLIC_GUILD_MESSAGES' # 公域机器人频道消息事件,私域机器人请注释
56
+ # 。。。其他配置项参见上方对应oneBot版本的通用配置
package/lib/onebot.d.ts CHANGED
@@ -1,50 +1,58 @@
1
1
  /// <reference types="node" />
2
- import "icqq-cq-enable";
3
- import { EventEmitter } from "events";
4
- import { App } from "./server/app";
5
- import { Client } from "icqq";
6
- import { Config as IcqqConfig } from "icqq";
2
+ import { EventEmitter } from 'events';
7
3
  import { V11 } from "./service/V11";
8
4
  import { V12 } from "./service/V12";
9
- import { MayBeArray } from "./types";
5
+ import { Adapter } from "./adapter";
10
6
  import { Service } from "./service";
7
+ import { Logger } from "log4js";
11
8
  export declare class NotFoundError extends Error {
12
9
  message: string;
13
10
  }
14
- export declare class OneBot<V extends OneBot.Version> extends EventEmitter {
15
- app: App;
16
- readonly uin: number;
17
- config: OneBotConfig[];
11
+ export declare class OneBot<V extends OneBot.Version = OneBot.Version> extends EventEmitter {
12
+ #private;
13
+ adapter: Adapter;
14
+ readonly uin: string;
15
+ config: OneBot.Config[];
18
16
  status: OneBotStatus;
19
17
  protected password: string;
20
- client: Client;
18
+ internal?: any;
21
19
  instances: (V11 | V12)[];
22
- constructor(app: App, uin: number, config: MayBeArray<OneBotConfig>);
23
- start(): Promise<[boolean, any]>;
24
- startListen(): void;
20
+ get app(): import(".").App;
21
+ get platform(): string;
22
+ get logger(): Logger;
23
+ constructor(adapter: Adapter, uin: string, version_configs: OneBot.Config[]);
24
+ start(): Promise<void>;
25
25
  stop(force?: boolean): Promise<void>;
26
- system_online(event: any, data: any): void;
26
+ getGroupList<V extends OneBot.Version>(version: V): Promise<OneBot.GroupInfo<V>[]>;
27
+ getFriendList<V extends OneBot.Version>(version: V): Promise<OneBot.UserInfo<V>[]>;
27
28
  dispatch(event: any, data: any): Promise<void>;
28
29
  }
29
30
  export declare enum OneBotStatus {
30
31
  Good = 0,
31
- Bad = 1
32
+ Bad = 1,
33
+ Online = "online"
32
34
  }
33
- export type OneBotConfig = OneBot.Config<OneBot.Version>;
34
35
  export declare namespace OneBot {
35
36
  type Filters = {};
36
- type Version = "V11" | "V12";
37
- type Config<V extends Version = "V11"> = {
37
+ type Version = 'V11' | 'V12';
38
+ type Config<V extends Version = Version> = {
38
39
  version?: V;
39
- password?: string;
40
- group_whitelist?: number[];
41
40
  filters?: Service.Filters;
42
- protocol?: IcqqConfig;
43
- } & (V extends "V11" ? V11.Config : V12.Config);
41
+ } & (V extends 'V11' ? V11.Config : V12.Config);
42
+ const UnsupportedMethodError: Error;
43
+ const UnsupportedVersionError: Error;
44
+ type Payload<V extends Version = Version> = V extends 'V11' ? V11.Payload : V12.Payload;
45
+ type Segment<V extends Version = Version> = V extends 'V11' ? V11.Segment : V12.Segment;
46
+ type SelfInfo<V extends Version = Version> = V extends 'V11' ? V11.SelfInfo : V12.SelfInfo;
47
+ type GroupInfo<V extends Version> = V extends 'V11' ? V11.GroupInfo : V12.GroupInfo;
48
+ type UserInfo<V extends Version> = V extends 'V11' ? V11.UserInfo : V12.UserInfo;
49
+ type Message<V extends Version> = V extends 'V11' ? V11.Message : V12.Message;
50
+ type MessageElement<V extends Version> = V extends 'V11' ? V11.MessageElement : V12.MessageElement;
51
+ type GroupMemberInfo<V extends Version> = V extends 'V11' ? V11.GroupMemberInfo : V12.GroupMemberInfo;
52
+ type MessageRet<V extends Version> = V extends 'V11' ? V11.MessageRet : V12.MessageRet;
44
53
  interface Base {
45
54
  start(path?: string): any;
46
55
  stop(): any;
47
- system_online(...args: any[]): any;
48
56
  dispatch(...args: any[]): any;
49
57
  apply(...args: any[]): any;
50
58
  }