onebots 0.4.35 → 0.4.37
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/dist/assets/index-Lg7SiZ8I.js +2 -0
- package/dist/assets/index-Q4D7Uqbk.css +1 -0
- package/dist/index.html +2 -10
- package/lib/adapter.d.ts +19 -1
- package/lib/adapter.js +19 -0
- package/lib/adapters/icqq/index.d.ts +3 -1
- package/lib/adapters/icqq/index.js +34 -6
- package/lib/adapters/qq/index.d.ts +6 -4
- package/lib/adapters/qq/index.js +56 -9
- package/lib/adapters/qq/utils.d.ts +0 -2
- package/lib/adapters/qq/utils.js +1 -19
- package/lib/onebot.d.ts +13 -2
- package/lib/onebot.js +14 -0
- package/lib/server/app.d.ts +22 -2
- package/lib/server/app.js +45 -22
- package/lib/service/V11/index.d.ts +2 -2
- package/lib/service/V12/action/group.d.ts +1 -1
- package/lib/service/V12/action/group.js +1 -1
- package/lib/service/V12/index.d.ts +2 -2
- package/package.json +8 -3
- package/dist/assets/index--pKafL3b.js +0 -2
- package/dist/assets/index-H3-fKIdb.css +0 -1
- package/lib/adapters/qq/bot.d.ts +0 -22
- package/lib/adapters/qq/bot.js +0 -21
- package/lib/adapters/qq/constans.d.ts +0 -69
- package/lib/adapters/qq/constans.js +0 -128
- package/lib/adapters/qq/elements.d.ts +0 -131
- package/lib/adapters/qq/elements.js +0 -8
- package/lib/adapters/qq/entries/channel.d.ts +0 -17
- package/lib/adapters/qq/entries/channel.js +0 -2
- package/lib/adapters/qq/entries/friend.d.ts +0 -8
- package/lib/adapters/qq/entries/friend.js +0 -2
- package/lib/adapters/qq/entries/group.d.ts +0 -6
- package/lib/adapters/qq/entries/group.js +0 -2
- package/lib/adapters/qq/entries/groupMember.d.ts +0 -7
- package/lib/adapters/qq/entries/groupMember.js +0 -2
- package/lib/adapters/qq/entries/guild.d.ts +0 -21
- package/lib/adapters/qq/entries/guild.js +0 -2
- package/lib/adapters/qq/entries/guildMember.d.ts +0 -9
- package/lib/adapters/qq/entries/guildMember.js +0 -2
- package/lib/adapters/qq/entries/user.d.ts +0 -9
- package/lib/adapters/qq/entries/user.js +0 -2
- package/lib/adapters/qq/event.d.ts +0 -28
- package/lib/adapters/qq/event.js +0 -24
- package/lib/adapters/qq/message.d.ts +0 -84
- package/lib/adapters/qq/message.js +0 -294
- package/lib/adapters/qq/qqBot.d.ts +0 -122
- package/lib/adapters/qq/qqBot.js +0 -448
- package/lib/adapters/qq/sessionManager.d.ts +0 -33
- package/lib/adapters/qq/sessionManager.js +0 -256
- package/lib/adapters/qq/types.d.ts +0 -45
- package/lib/adapters/qq/types.js +0 -2
package/lib/adapter.js
CHANGED
|
@@ -24,9 +24,26 @@ class Adapter extends events_1.EventEmitter {
|
|
|
24
24
|
this.oneBots = new Map();
|
|
25
25
|
_Adapter_logger.set(this, void 0);
|
|
26
26
|
}
|
|
27
|
+
getOneBot(uin) {
|
|
28
|
+
return this.oneBots.get(uin);
|
|
29
|
+
}
|
|
27
30
|
get logger() {
|
|
28
31
|
return __classPrivateFieldSet(this, _Adapter_logger, __classPrivateFieldGet(this, _Adapter_logger, "f") || this.app.getLogger(this.platform), "f");
|
|
29
32
|
}
|
|
33
|
+
get info() {
|
|
34
|
+
return {
|
|
35
|
+
platform: this.platform,
|
|
36
|
+
config: this.config,
|
|
37
|
+
icon: this.icon,
|
|
38
|
+
bots: [...this.oneBots.values()].map(bot => {
|
|
39
|
+
return bot.info;
|
|
40
|
+
})
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async setOnline(uin) {
|
|
44
|
+
}
|
|
45
|
+
async setOffline(uin) {
|
|
46
|
+
}
|
|
30
47
|
getLogger(uin, version) {
|
|
31
48
|
if (!version)
|
|
32
49
|
return this.app.getLogger(`${this.platform}-${uin}`);
|
|
@@ -42,6 +59,7 @@ class Adapter extends events_1.EventEmitter {
|
|
|
42
59
|
return uin ? oneBot.uin === uin : true;
|
|
43
60
|
});
|
|
44
61
|
for (const oneBot of startOneBots) {
|
|
62
|
+
await this.setOnline(oneBot.uin);
|
|
45
63
|
await oneBot.start();
|
|
46
64
|
}
|
|
47
65
|
this.app.emit('adapter.start', this.platform);
|
|
@@ -52,6 +70,7 @@ class Adapter extends events_1.EventEmitter {
|
|
|
52
70
|
});
|
|
53
71
|
for (const oneBot of stopOneBots) {
|
|
54
72
|
await oneBot.stop(force);
|
|
73
|
+
await this.setOffline(oneBot.uin);
|
|
55
74
|
}
|
|
56
75
|
this.app.emit('adapter.stop', this.platform);
|
|
57
76
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Adapter } from "../../adapter";
|
|
2
2
|
import { App } from "../../server/app";
|
|
3
|
-
import { Config as IcqqConfig } from "icqq
|
|
3
|
+
import { Config as IcqqConfig } from "icqq";
|
|
4
4
|
import { OneBot } from "../../onebot";
|
|
5
5
|
export default class IcqqAdapter extends Adapter<'icqq'> {
|
|
6
6
|
#private;
|
|
7
7
|
constructor(app: App, config: IcqqAdapter.Config);
|
|
8
|
+
setOnline(uin: string): Promise<void>;
|
|
9
|
+
setOffline(uin: string): Promise<void>;
|
|
8
10
|
createOneBot(uin: string, protocol: IcqqConfig, versions: OneBot.Config[]): OneBot;
|
|
9
11
|
formatEventPayload<V extends OneBot.Version>(version: V, event: string, data: any): OneBot.Payload<V>;
|
|
10
12
|
sendPrivateMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[]]): Promise<OneBot.MessageRet<V>>;
|
|
@@ -22,17 +22,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
26
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
27
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
28
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
29
|
+
};
|
|
25
30
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
26
31
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
27
32
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
28
33
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
29
34
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
30
35
|
};
|
|
31
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
32
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
33
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
34
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
35
|
-
};
|
|
36
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
38
|
};
|
|
@@ -92,10 +92,28 @@ class IcqqAdapter extends adapter_1.Adapter {
|
|
|
92
92
|
super(app, 'icqq', config);
|
|
93
93
|
_IcqqAdapter_password.set(this, void 0);
|
|
94
94
|
_IcqqAdapter_disposes.set(this, new Map());
|
|
95
|
+
this.icon = `https://qzonestyle.gtimg.cn/qzone/qzact/act/external/tiqq/logo.png`;
|
|
96
|
+
}
|
|
97
|
+
async setOnline(uin) {
|
|
98
|
+
const oneBot = this.getOneBot(uin);
|
|
99
|
+
if (!oneBot)
|
|
100
|
+
throw new Error('No one');
|
|
101
|
+
await oneBot.internal.login(parseInt(uin), __classPrivateFieldGet(this, _IcqqAdapter_password, "f"));
|
|
102
|
+
}
|
|
103
|
+
async setOffline(uin) {
|
|
104
|
+
const oneBot = this.getOneBot(uin);
|
|
105
|
+
if (!oneBot)
|
|
106
|
+
throw new Error('No one');
|
|
107
|
+
await oneBot.internal.logout();
|
|
108
|
+
oneBot.status = onebot_1.OneBotStatus.Bad;
|
|
95
109
|
}
|
|
96
110
|
createOneBot(uin, protocol, versions) {
|
|
97
111
|
const oneBot = super.createOneBot(uin, protocol, versions);
|
|
98
112
|
__classPrivateFieldSet(this, _IcqqAdapter_password, this.app.config[`icqq.${uin}`].password, "f");
|
|
113
|
+
oneBot.avatar = `https://q1.qlogo.cn/g?b=qq&s=100&nk=` + uin;
|
|
114
|
+
const pkg = require(path.resolve(path.dirname(require.resolve('icqq')), '../package.json'));
|
|
115
|
+
oneBot.dependency = `icqq v${pkg.version}`;
|
|
116
|
+
oneBot.status = onebot_1.OneBotStatus.Online;
|
|
99
117
|
oneBot.internal = new icqq_1.Client((0, utils_1.deepMerge)(protocol, (0, utils_1.deepClone)({
|
|
100
118
|
...exports.defaultIcqqConfig,
|
|
101
119
|
log_level: this.app.config.log_level
|
|
@@ -289,7 +307,7 @@ class IcqqAdapter extends adapter_1.Adapter {
|
|
|
289
307
|
disposeArr.push(client.on('request', (event) => {
|
|
290
308
|
this.emit('request.receive', oneBot.uin, event);
|
|
291
309
|
}));
|
|
292
|
-
|
|
310
|
+
this.setOnline(oneBot.uin);
|
|
293
311
|
return new Promise((resolve, reject) => {
|
|
294
312
|
client.trap('system.login.error', function errorHandler(e) {
|
|
295
313
|
if (e.message.includes('密码错误')) {
|
|
@@ -299,6 +317,7 @@ class IcqqAdapter extends adapter_1.Adapter {
|
|
|
299
317
|
}
|
|
300
318
|
else {
|
|
301
319
|
_this.logger.error(e.message);
|
|
320
|
+
oneBot.status = onebot_1.OneBotStatus.Bad;
|
|
302
321
|
clean();
|
|
303
322
|
}
|
|
304
323
|
this.off('system.login.error', errorHandler);
|
|
@@ -310,10 +329,19 @@ class IcqqAdapter extends adapter_1.Adapter {
|
|
|
310
329
|
}
|
|
311
330
|
};
|
|
312
331
|
client.trap('system.online', () => {
|
|
332
|
+
oneBot.nickname = client.nickname;
|
|
333
|
+
oneBot.status = onebot_1.OneBotStatus.Good;
|
|
334
|
+
this.app.ws.clients.forEach(client => {
|
|
335
|
+
client.send(JSON.stringify({
|
|
336
|
+
event: 'bot.change',
|
|
337
|
+
data: oneBot.info
|
|
338
|
+
}));
|
|
339
|
+
});
|
|
313
340
|
clearTimeout(timer);
|
|
314
341
|
resolve(clean);
|
|
315
342
|
});
|
|
316
343
|
const timer = setTimeout(() => {
|
|
344
|
+
oneBot.status = onebot_1.OneBotStatus.Bad;
|
|
317
345
|
clean();
|
|
318
346
|
reject('登录超时');
|
|
319
347
|
}, this.app.config.timeout * 1000);
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Adapter } from "../../adapter";
|
|
2
2
|
import { App } from "../../server/app";
|
|
3
3
|
import { OneBot } from "../../onebot";
|
|
4
|
-
import {
|
|
5
|
-
import { Sendable } from "../../adapters/qq/elements";
|
|
4
|
+
import { Bot, Sendable } from "qq-group-bot";
|
|
6
5
|
export default class QQAdapter extends Adapter<'qq'> {
|
|
7
6
|
#private;
|
|
8
7
|
constructor(app: App, config: QQAdapter.Config);
|
|
9
|
-
startOneBot(oneBot: OneBot): Promise<() => void>;
|
|
8
|
+
startOneBot(oneBot: OneBot<Bot>): Promise<() => void>;
|
|
9
|
+
setOnline(uin: string): Promise<void>;
|
|
10
|
+
setOffline(uin: string): Promise<void>;
|
|
11
|
+
createOneBot(uin: string, protocol: Bot.Config, versions: OneBot.Config[]): OneBot;
|
|
10
12
|
call(uin: string, version: string, method: string, args?: any[]): Promise<any>;
|
|
11
13
|
fromSegment<V extends OneBot.Version>(version: V, segment: OneBot.Segment<V> | OneBot.Segment<V>[]): OneBot.MessageElement<V>[];
|
|
12
14
|
toSegment<V extends OneBot.Version, M = Sendable>(version: V, message: M): OneBot.Segment<V>[];
|
|
@@ -26,6 +28,6 @@ declare module '../../adapter' {
|
|
|
26
28
|
}
|
|
27
29
|
export declare namespace QQAdapter {
|
|
28
30
|
interface Config extends Adapter.Config<'qq'> {
|
|
29
|
-
protocol: Omit<
|
|
31
|
+
protocol: Omit<Bot.Config, 'appid'>;
|
|
30
32
|
}
|
|
31
33
|
}
|
package/lib/adapters/qq/index.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
26
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
27
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
@@ -8,33 +31,57 @@ var _QQAdapter_disposes;
|
|
|
8
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
32
|
const adapter_1 = require("../../adapter");
|
|
10
33
|
const onebot_1 = require("../../onebot");
|
|
11
|
-
const
|
|
12
|
-
|
|
34
|
+
const qq_group_bot_1 = require("qq-group-bot");
|
|
35
|
+
const path = __importStar(require("path"));
|
|
13
36
|
class QQAdapter extends adapter_1.Adapter {
|
|
14
37
|
constructor(app, config) {
|
|
15
38
|
super(app, 'qq', config);
|
|
16
39
|
_QQAdapter_disposes.set(this, new Map());
|
|
40
|
+
this.icon = `https://qzonestyle.gtimg.cn/qzone/qzact/act/external/tiqq/logo.png`;
|
|
17
41
|
}
|
|
18
42
|
async startOneBot(oneBot) {
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
43
|
+
await this.setOnline(oneBot.uin);
|
|
44
|
+
const selfInfo = await oneBot.internal.getSelfInfo();
|
|
45
|
+
oneBot.avatar = selfInfo.avatar;
|
|
46
|
+
oneBot.nickname = selfInfo.username;
|
|
47
|
+
const pkg = require(path.resolve(path.dirname(require.resolve('qq-group-bot')), '../package.json'));
|
|
48
|
+
oneBot.dependency = `qq-group-bot v${pkg.version}`;
|
|
22
49
|
const disposeArr = [];
|
|
23
50
|
const clean = () => {
|
|
24
51
|
while (disposeArr.length > 0) {
|
|
25
52
|
disposeArr.pop()();
|
|
26
53
|
}
|
|
27
|
-
|
|
54
|
+
oneBot.internal.stop();
|
|
28
55
|
};
|
|
29
56
|
const messageHandler = (event) => {
|
|
30
57
|
this.emit('message.receive', oneBot.uin, event);
|
|
31
58
|
};
|
|
32
|
-
|
|
59
|
+
oneBot.internal.on('message', messageHandler);
|
|
33
60
|
disposeArr.push(() => {
|
|
34
|
-
|
|
61
|
+
oneBot.internal.off('message', messageHandler);
|
|
35
62
|
});
|
|
36
63
|
return clean;
|
|
37
64
|
}
|
|
65
|
+
async setOnline(uin) {
|
|
66
|
+
const oneBot = this.getOneBot(uin);
|
|
67
|
+
await oneBot?.internal.start();
|
|
68
|
+
oneBot.status = onebot_1.OneBotStatus.Good;
|
|
69
|
+
}
|
|
70
|
+
async setOffline(uin) {
|
|
71
|
+
const oneBot = this.getOneBot(uin);
|
|
72
|
+
await oneBot?.internal.stop();
|
|
73
|
+
oneBot.status = onebot_1.OneBotStatus.Bad;
|
|
74
|
+
}
|
|
75
|
+
createOneBot(uin, protocol, versions) {
|
|
76
|
+
const oneBot = super.createOneBot(uin, protocol, versions);
|
|
77
|
+
oneBot.internal = new qq_group_bot_1.Bot({
|
|
78
|
+
appid: oneBot.uin,
|
|
79
|
+
logLevel: this.app.config.log_level,
|
|
80
|
+
...protocol
|
|
81
|
+
});
|
|
82
|
+
oneBot.status = onebot_1.OneBotStatus.Online;
|
|
83
|
+
return oneBot;
|
|
84
|
+
}
|
|
38
85
|
call(uin, version, method, args) {
|
|
39
86
|
const oneBot = this.oneBots.get(uin);
|
|
40
87
|
if (!oneBot) {
|
|
@@ -43,7 +90,7 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
43
90
|
if (typeof this[method] === 'function')
|
|
44
91
|
return this[method](uin, version, args);
|
|
45
92
|
if (typeof oneBot.internal[method] !== 'function')
|
|
46
|
-
throw UnsupportedMethodError;
|
|
93
|
+
throw onebot_1.OneBot.UnsupportedMethodError;
|
|
47
94
|
try {
|
|
48
95
|
return oneBot.internal[method](...(args || []));
|
|
49
96
|
}
|
package/lib/adapters/qq/utils.js
CHANGED
|
@@ -1,24 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.trimQuote = exports.findLastIndex = exports.deepClone = exports.remove =
|
|
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;
|
|
3
|
+
exports.trimQuote = exports.findLastIndex = exports.deepClone = exports.remove = void 0;
|
|
22
4
|
function remove(list, item) {
|
|
23
5
|
const index = list.indexOf(item);
|
|
24
6
|
if (index !== -1)
|
package/lib/onebot.d.ts
CHANGED
|
@@ -8,19 +8,30 @@ import { Logger } from "log4js";
|
|
|
8
8
|
export declare class NotFoundError extends Error {
|
|
9
9
|
message: string;
|
|
10
10
|
}
|
|
11
|
-
export declare class OneBot<
|
|
11
|
+
export declare class OneBot<T = any> extends EventEmitter {
|
|
12
12
|
#private;
|
|
13
13
|
adapter: Adapter;
|
|
14
14
|
readonly uin: string;
|
|
15
15
|
config: OneBot.Config[];
|
|
16
16
|
status: OneBotStatus;
|
|
17
17
|
avatar: string;
|
|
18
|
+
nickname: string;
|
|
19
|
+
dependency: string;
|
|
18
20
|
protected password: string;
|
|
19
|
-
internal
|
|
21
|
+
internal: T;
|
|
20
22
|
instances: (V11 | V12)[];
|
|
21
23
|
get app(): import(".").App;
|
|
22
24
|
get platform(): string;
|
|
23
25
|
get logger(): Logger;
|
|
26
|
+
get info(): {
|
|
27
|
+
uin: string;
|
|
28
|
+
status: OneBotStatus;
|
|
29
|
+
platform: string;
|
|
30
|
+
avatar: string;
|
|
31
|
+
nickname: string;
|
|
32
|
+
dependency: string;
|
|
33
|
+
urls: string[];
|
|
34
|
+
};
|
|
24
35
|
constructor(adapter: Adapter, uin: string, version_configs: OneBot.Config[]);
|
|
25
36
|
start(): Promise<void>;
|
|
26
37
|
stop(force?: boolean): Promise<void>;
|
package/lib/onebot.js
CHANGED
|
@@ -34,6 +34,19 @@ class OneBot extends events_1.EventEmitter {
|
|
|
34
34
|
get logger() {
|
|
35
35
|
return __classPrivateFieldSet(this, _OneBot_logger, __classPrivateFieldGet(this, _OneBot_logger, "f") || this.adapter.getLogger(this.uin), "f");
|
|
36
36
|
}
|
|
37
|
+
get info() {
|
|
38
|
+
return {
|
|
39
|
+
uin: this.uin,
|
|
40
|
+
status: this.status,
|
|
41
|
+
platform: this.platform,
|
|
42
|
+
avatar: this.avatar,
|
|
43
|
+
nickname: this.nickname,
|
|
44
|
+
dependency: this.dependency,
|
|
45
|
+
urls: this.instances.map(ins => {
|
|
46
|
+
return `/${this.platform}/${this.uin}/${ins.version}`;
|
|
47
|
+
})
|
|
48
|
+
};
|
|
49
|
+
}
|
|
37
50
|
constructor(adapter, uin, version_configs) {
|
|
38
51
|
super();
|
|
39
52
|
this.adapter = adapter;
|
|
@@ -72,6 +85,7 @@ class OneBot extends events_1.EventEmitter {
|
|
|
72
85
|
for (const instance of this.instances) {
|
|
73
86
|
await instance.stop(force);
|
|
74
87
|
}
|
|
88
|
+
this.emit('stop');
|
|
75
89
|
}
|
|
76
90
|
getGroupList(version) {
|
|
77
91
|
return this.adapter.getGroupList(this.uin, version);
|
package/lib/server/app.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
2
4
|
/// <reference types="koa-bodyparser" />
|
|
3
5
|
/// <reference types="node" />
|
|
4
6
|
import Koa from 'koa';
|
|
7
|
+
import * as os from 'os';
|
|
5
8
|
import "reflect-metadata";
|
|
6
9
|
import { Logger } from "log4js";
|
|
7
10
|
import { Server } from "http";
|
|
@@ -31,6 +34,23 @@ export declare class App extends Koa {
|
|
|
31
34
|
ws: WsServer;
|
|
32
35
|
router: Router;
|
|
33
36
|
static logFile: string;
|
|
37
|
+
get info(): {
|
|
38
|
+
system_platform: NodeJS.Platform;
|
|
39
|
+
system_arch: NodeJS.Architecture;
|
|
40
|
+
system_cpus: os.CpuInfo[];
|
|
41
|
+
system_version: string;
|
|
42
|
+
system_uptime: number;
|
|
43
|
+
username: string;
|
|
44
|
+
total_memory: number;
|
|
45
|
+
free_memory: number;
|
|
46
|
+
process_id: number;
|
|
47
|
+
process_parent_id: number;
|
|
48
|
+
process_cwd: string;
|
|
49
|
+
process_use_memory: number;
|
|
50
|
+
node_version: string;
|
|
51
|
+
sdk_version: any;
|
|
52
|
+
uptime: number;
|
|
53
|
+
};
|
|
34
54
|
constructor(config?: App.Config);
|
|
35
55
|
init(): void;
|
|
36
56
|
getLogger(patform: string): Logger;
|
|
@@ -39,8 +59,8 @@ export declare class App extends Koa {
|
|
|
39
59
|
addAccount<P extends string>(platform: P, uin: string, config: Adapter.Configs[P]): void;
|
|
40
60
|
updateAccount<P extends string>(platform: P, uin: string, config: Adapter.Configs[P]): void;
|
|
41
61
|
removeAccount(platform: string, uin: string, force?: boolean): void;
|
|
42
|
-
createOneBot<P extends string>(platform: P, uin: string, config: Adapter.Config): import("..").OneBot<
|
|
43
|
-
get oneBots(): import("..").OneBot<
|
|
62
|
+
createOneBot<P extends string>(platform: P, uin: string, config: Adapter.Config): import("..").OneBot<any>;
|
|
63
|
+
get oneBots(): import("..").OneBot<any>[];
|
|
44
64
|
findOrCreateAdapter<P extends string>(platform: P, config?: Adapter.Config): void | Adapter<string>;
|
|
45
65
|
start(): Promise<void>;
|
|
46
66
|
reload(config: App.Config): Promise<void>;
|
package/lib/server/app.js
CHANGED
|
@@ -46,6 +46,28 @@ const path = __importStar(require("path"));
|
|
|
46
46
|
const process_1 = __importDefault(require("process"));
|
|
47
47
|
const fs = __importStar(require("fs"));
|
|
48
48
|
class App extends koa_1.default {
|
|
49
|
+
get info() {
|
|
50
|
+
const pkg = require(path.resolve(__dirname, '../../package.json'));
|
|
51
|
+
const free_memory = os.freemem();
|
|
52
|
+
const total_memory = os.totalmem();
|
|
53
|
+
return {
|
|
54
|
+
system_platform: process_1.default.platform,
|
|
55
|
+
system_arch: process_1.default.arch,
|
|
56
|
+
system_cpus: os.cpus(),
|
|
57
|
+
system_version: os.version(),
|
|
58
|
+
system_uptime: os.uptime() * 1000,
|
|
59
|
+
username: os.userInfo().username,
|
|
60
|
+
total_memory,
|
|
61
|
+
free_memory,
|
|
62
|
+
process_id: process_1.default.pid,
|
|
63
|
+
process_parent_id: process_1.default.ppid,
|
|
64
|
+
process_cwd: process_1.default.cwd(),
|
|
65
|
+
process_use_memory: process_1.default.memoryUsage.rss(),
|
|
66
|
+
node_version: process_1.default.version,
|
|
67
|
+
sdk_version: pkg.version,
|
|
68
|
+
uptime: process_1.default.uptime() * 1000
|
|
69
|
+
};
|
|
70
|
+
}
|
|
49
71
|
constructor(config = {}) {
|
|
50
72
|
super(config);
|
|
51
73
|
this.adapters = new Map();
|
|
@@ -164,24 +186,13 @@ class App extends koa_1.default {
|
|
|
164
186
|
data: {
|
|
165
187
|
config: fs.readFileSync(App.configPath, 'utf8'),
|
|
166
188
|
adapters: [...this.adapters.values()].map(adapter => {
|
|
167
|
-
return
|
|
168
|
-
platform: adapter.platform,
|
|
169
|
-
config: adapter.config,
|
|
170
|
-
bots: [...adapter.oneBots.values()].map(bot => {
|
|
171
|
-
return {
|
|
172
|
-
uin: bot.uin,
|
|
173
|
-
status: bot.status,
|
|
174
|
-
urls: bot.instances.map(ins => {
|
|
175
|
-
return `/${adapter.platform}/${bot.uin}/${ins.version}`;
|
|
176
|
-
})
|
|
177
|
-
};
|
|
178
|
-
})
|
|
179
|
-
};
|
|
189
|
+
return adapter.info;
|
|
180
190
|
}),
|
|
191
|
+
app: this.info,
|
|
181
192
|
logs: fs.existsSync(App.logFile) ? fs.readFileSync(App.logFile, 'utf8') : ''
|
|
182
193
|
}
|
|
183
194
|
}));
|
|
184
|
-
client.on('message', (raw) => {
|
|
195
|
+
client.on('message', async (raw) => {
|
|
185
196
|
let payload = {};
|
|
186
197
|
try {
|
|
187
198
|
payload = JSON.parse(raw.toString());
|
|
@@ -197,18 +208,28 @@ class App extends koa_1.default {
|
|
|
197
208
|
case 'system.reload':
|
|
198
209
|
const config = js_yaml_1.default.load(fs.readFileSync(App.configPath, 'utf8'));
|
|
199
210
|
return this.reload(config);
|
|
211
|
+
case 'bot.start': {
|
|
212
|
+
const { platform, uin } = JSON.parse(payload.data);
|
|
213
|
+
await this.adapters.get(platform)?.setOnline(uin);
|
|
214
|
+
return client.send(JSON.stringify({
|
|
215
|
+
event: 'bot.change',
|
|
216
|
+
data: this.adapters.get(platform).getOneBot(uin).info
|
|
217
|
+
}));
|
|
218
|
+
}
|
|
219
|
+
case 'bot.stop': {
|
|
220
|
+
const { platform, uin } = JSON.parse(payload.data);
|
|
221
|
+
await this.adapters.get(platform)?.setOffline(uin);
|
|
222
|
+
return client.send(JSON.stringify({
|
|
223
|
+
event: 'bot.change',
|
|
224
|
+
data: this.adapters.get(platform).getOneBot(uin).info
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
200
227
|
}
|
|
201
228
|
});
|
|
202
229
|
});
|
|
203
230
|
this.router.get('/list', (ctx) => {
|
|
204
231
|
ctx.body = this.oneBots.map(bot => {
|
|
205
|
-
return
|
|
206
|
-
uin: bot.uin,
|
|
207
|
-
platform: bot.platform,
|
|
208
|
-
status: bot.status,
|
|
209
|
-
config: bot.config.map(c => (0, utils_1.protectedFields)(c, 'password', 'sign_api_addr', "access_token")),
|
|
210
|
-
urls: bot.config.map(c => `/${bot.platform}/${c.version}/${bot.uin}`)
|
|
211
|
-
};
|
|
232
|
+
return bot.info;
|
|
212
233
|
});
|
|
213
234
|
});
|
|
214
235
|
this.router.post('/add', (ctx, next) => {
|
|
@@ -256,12 +277,14 @@ class App extends koa_1.default {
|
|
|
256
277
|
async reload(config) {
|
|
257
278
|
await this.stop();
|
|
258
279
|
this.config = (0, utils_1.deepMerge)((0, utils_1.deepClone)(App.defaultConfig), config);
|
|
259
|
-
this.
|
|
280
|
+
this.createOneBots();
|
|
281
|
+
await this.start();
|
|
260
282
|
}
|
|
261
283
|
async stop() {
|
|
262
284
|
for (const [_, adapter] of this.adapters) {
|
|
263
285
|
await adapter.stop();
|
|
264
286
|
}
|
|
287
|
+
this.adapters.clear();
|
|
265
288
|
// this.ws.close()
|
|
266
289
|
this.httpServer.close();
|
|
267
290
|
this.emit('close');
|
|
@@ -9,7 +9,7 @@ import { Service } from "../../service";
|
|
|
9
9
|
import { Dict } from "@zhinjs/shared";
|
|
10
10
|
import { JsonDB } from "../../db";
|
|
11
11
|
export declare class V11 extends Service<"V11"> implements OneBot.Base {
|
|
12
|
-
oneBot: OneBot
|
|
12
|
+
oneBot: OneBot;
|
|
13
13
|
config: OneBot.Config<"V11">;
|
|
14
14
|
action: Action;
|
|
15
15
|
version: OneBot.Version;
|
|
@@ -25,7 +25,7 @@ export declare class V11 extends Service<"V11"> implements OneBot.Base {
|
|
|
25
25
|
logger: Logger;
|
|
26
26
|
wss?: WebSocketServer;
|
|
27
27
|
wsr: Set<WebSocket>;
|
|
28
|
-
constructor(oneBot: OneBot
|
|
28
|
+
constructor(oneBot: OneBot, config: OneBot.Config<"V11">);
|
|
29
29
|
start(): void;
|
|
30
30
|
private startHttp;
|
|
31
31
|
private startHttpReverse;
|
|
@@ -3,7 +3,7 @@ export declare class GroupAction {
|
|
|
3
3
|
/**
|
|
4
4
|
* 发送群聊消息
|
|
5
5
|
* @param group_id {number} 群id
|
|
6
|
-
* @param message {import('
|
|
6
|
+
* @param message {import('onebots/lib/service/v12').Sendable} 消息
|
|
7
7
|
* @param source {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
|
|
8
8
|
*/
|
|
9
9
|
sendGroupMsg(this: V12, group_id: number, message: V12.Sendable, source?: V12.SegmentElem<'reply'>): Promise<any>;
|
|
@@ -5,7 +5,7 @@ class GroupAction {
|
|
|
5
5
|
/**
|
|
6
6
|
* 发送群聊消息
|
|
7
7
|
* @param group_id {number} 群id
|
|
8
|
-
* @param message {import('
|
|
8
|
+
* @param message {import('onebots/lib/service/v12').Sendable} 消息
|
|
9
9
|
* @param source {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
|
|
10
10
|
*/
|
|
11
11
|
async sendGroupMsg(group_id, message, source) {
|
|
@@ -8,7 +8,7 @@ import { WebSocket, WebSocketServer } from "ws";
|
|
|
8
8
|
import { Service } from "../../service";
|
|
9
9
|
import { Dict } from "@zhinjs/shared";
|
|
10
10
|
export declare class V12 extends Service<'V12'> implements OneBot.Base {
|
|
11
|
-
oneBot: OneBot
|
|
11
|
+
oneBot: OneBot;
|
|
12
12
|
config: OneBot.Config<'V12'>;
|
|
13
13
|
version: OneBot.Version;
|
|
14
14
|
action: Action;
|
|
@@ -18,7 +18,7 @@ export declare class V12 extends Service<'V12'> implements OneBot.Base {
|
|
|
18
18
|
wss?: WebSocketServer;
|
|
19
19
|
wsr: Set<WebSocket>;
|
|
20
20
|
private db;
|
|
21
|
-
constructor(oneBot: OneBot
|
|
21
|
+
constructor(oneBot: OneBot, config: OneBot.Config<'V12'>);
|
|
22
22
|
addHistory(payload: V12.Payload<keyof Action>): number;
|
|
23
23
|
shiftHistory(): unknown;
|
|
24
24
|
get history(): V12.Payload<keyof Action>[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onebots",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.37",
|
|
4
4
|
"description": "基于icqq的多例oneBot实现",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16"
|
|
@@ -38,19 +38,23 @@
|
|
|
38
38
|
"homepage": "https://github.com/liucl-cn/onebots#readme",
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/koa": "^2.13.4",
|
|
41
|
+
"@types/koa__router": "^8.0.11",
|
|
41
42
|
"@types/koa-basic-auth": "^2.0.6",
|
|
42
43
|
"@types/koa-bodyparser": "^4.3.7",
|
|
43
44
|
"@types/koa-static": "^4.0.4",
|
|
44
|
-
"@types/koa__router": "^8.0.11",
|
|
45
45
|
"@types/node": "latest",
|
|
46
46
|
"@types/ws": "^8.5.3",
|
|
47
47
|
"@vitejs/plugin-vue": "^5.0.0",
|
|
48
|
+
"dayjs": "^1.11.10",
|
|
49
|
+
"element-plus": "^2.4.4",
|
|
48
50
|
"prettier": "^3.0.0",
|
|
49
51
|
"sass": "^1.69.6",
|
|
50
52
|
"ts-node-dev": "latest",
|
|
51
53
|
"tsc-alias": "latest",
|
|
52
54
|
"tsconfig-paths": "latest",
|
|
53
55
|
"typescript": "latest",
|
|
56
|
+
"unplugin-auto-import": "^0.17.3",
|
|
57
|
+
"unplugin-vue-components": "^0.26.0",
|
|
54
58
|
"vite": "^5.0.10",
|
|
55
59
|
"vitepress": "^1.0.0-rc.33",
|
|
56
60
|
"vue": "^3.4.0",
|
|
@@ -64,7 +68,8 @@
|
|
|
64
68
|
"/**/LICENSE"
|
|
65
69
|
],
|
|
66
70
|
"peerDependencies": {
|
|
67
|
-
"icqq": "latest"
|
|
71
|
+
"icqq": "latest",
|
|
72
|
+
"qq-group-bot": "^1.0.7"
|
|
68
73
|
},
|
|
69
74
|
"dependencies": {
|
|
70
75
|
"@koa/router": "^10.1.1",
|