onebots 0.4.15 → 0.4.17
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 +2 -0
- package/lib/onebot.js +1 -1
- package/lib/server/app.js +6 -6
- package/lib/server/router.d.ts +1 -1
- package/lib/service/V11/action/common.d.ts +1 -1
- package/lib/service/V11/action/common.js +1 -2
- package/lib/service/V11/action/friend.d.ts +1 -1
- package/lib/service/V11/action/friend.js +2 -2
- package/lib/service/V11/action/group.d.ts +1 -1
- package/lib/service/V11/action/group.js +2 -2
- package/lib/service/V11/index.d.ts +1 -0
- package/lib/service/V11/index.js +67 -2
- package/lib/service/V12/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
<h1>基于icqq的oneBot实现</h1>
|
|
3
3
|
<p>
|
|
4
4
|
|
|
5
|
+
[](https://www.npmjs.com/package/onebots)
|
|
6
|
+
[](https://github.com/icqqjs/onebots/actions/workflows/release.yml)
|
|
5
7
|
[](https://www.npmjs.com/package/onebots)
|
|
6
8
|
[](https://onebot.dev/)
|
|
7
9
|
[](https://12.onebot.dev/)
|
package/lib/onebot.js
CHANGED
|
@@ -202,5 +202,5 @@ var OneBotStatus;
|
|
|
202
202
|
(function (OneBotStatus) {
|
|
203
203
|
OneBotStatus[OneBotStatus["Good"] = 0] = "Good";
|
|
204
204
|
OneBotStatus[OneBotStatus["Bad"] = 1] = "Bad";
|
|
205
|
-
})(OneBotStatus
|
|
205
|
+
})(OneBotStatus = exports.OneBotStatus || (exports.OneBotStatus = {}));
|
|
206
206
|
exports.BOOLS = ["no_cache", "auto_escape", "as_long", "enable", "reject_add_request", "is_dismiss", "approve", "block"];
|
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)(
|
|
50
|
+
this.config = (0, utils_1.deepMerge)((0, utils_1.deepClone)(App.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)(
|
|
89
|
+
(0, fs_1.writeFileSync)(App.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)(
|
|
115
|
+
(0, fs_1.writeFileSync)(App.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);
|
|
@@ -132,11 +132,11 @@ class App extends koa_1.default {
|
|
|
132
132
|
});
|
|
133
133
|
this.router.get('/qrcode', (ctx) => {
|
|
134
134
|
const { uin } = ctx.query;
|
|
135
|
-
const uinUrl = path.join(
|
|
135
|
+
const uinUrl = path.join(App.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(
|
|
139
|
+
const qrcodePath = path.join(App.configDir, 'data', uin, 'qrcode.png');
|
|
140
140
|
let file = null;
|
|
141
141
|
try {
|
|
142
142
|
file = (0, fs_2.readFileSync)(qrcodePath); //读取文件
|
|
@@ -243,4 +243,4 @@ exports.defineConfig = defineConfig;
|
|
|
243
243
|
},
|
|
244
244
|
log_level: 'info',
|
|
245
245
|
};
|
|
246
|
-
})(App
|
|
246
|
+
})(App = exports.App || (exports.App = {}));
|
package/lib/server/router.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ import { WebSocketServer } from "ws";
|
|
|
5
5
|
import http from "http";
|
|
6
6
|
export declare class Router extends KoaRouter {
|
|
7
7
|
wsStack: WebSocketServer[];
|
|
8
|
-
ws(path: string, server: http.Server): import("ws").Server<
|
|
8
|
+
ws(path: string, server: http.Server): import("ws").Server<import("ws").WebSocket>;
|
|
9
9
|
}
|
|
@@ -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:
|
|
19
|
+
getMsg(this: V11, message_id: string): Promise<import("icqq").GroupMessage | import("icqq").PrivateMessage>;
|
|
20
20
|
/**
|
|
21
21
|
* 获取合并消息
|
|
22
22
|
* @param id {string} 合并id
|
|
@@ -8,7 +8,7 @@ export declare class FriendAction {
|
|
|
8
8
|
* @param message {import('icqq').Sendable} 发送的消息
|
|
9
9
|
* @param message_id {string} 引用的消息ID
|
|
10
10
|
*/
|
|
11
|
-
sendPrivateMsg(this: V11, user_id: number, message: string | SegmentElem | SegmentElem[], message_id?: string): Promise<import("icqq").MessageRet>;
|
|
11
|
+
sendPrivateMsg(this: V11, user_id: number, message: string | SegmentElem | SegmentElem[], message_id?: string): Promise<void | import("icqq").MessageRet>;
|
|
12
12
|
/**
|
|
13
13
|
* 获取好友列表
|
|
14
14
|
*/
|
|
@@ -13,9 +13,9 @@ class FriendAction {
|
|
|
13
13
|
const msg = message_id ? await this.client.getMsg(message_id) : undefined;
|
|
14
14
|
const { element, quote, music, share } = await utils_1.processMessage.apply(this.client, [message, msg]);
|
|
15
15
|
if (music)
|
|
16
|
-
await this.client.pickFriend(user_id).shareMusic(music.
|
|
16
|
+
return await this.client.pickFriend(user_id).shareMusic(music.platform, music.id);
|
|
17
17
|
if (share)
|
|
18
|
-
await this.client.pickFriend(user_id).shareUrl(music.data);
|
|
18
|
+
return await this.client.pickFriend(user_id).shareUrl(music.data);
|
|
19
19
|
if (element.length) {
|
|
20
20
|
return await this.client.sendPrivateMsg(user_id, element, quote ? await this.client.getMsg(quote.data.message_id) : undefined);
|
|
21
21
|
}
|
|
@@ -7,7 +7,7 @@ export declare class GroupAction {
|
|
|
7
7
|
* @param message {import('icqq').Sendable} 消息
|
|
8
8
|
* @param message_id {string} 引用的消息ID
|
|
9
9
|
*/
|
|
10
|
-
sendGroupMsg(this: V11, group_id: number, message: string | SegmentElem | SegmentElem[], message_id?: string): Promise<import("icqq").MessageRet>;
|
|
10
|
+
sendGroupMsg(this: V11, group_id: number, message: string | SegmentElem | SegmentElem[], message_id?: string): Promise<void | import("icqq").MessageRet>;
|
|
11
11
|
/**
|
|
12
12
|
* 群组踢人
|
|
13
13
|
* @param group_id {number} 群id
|
|
@@ -13,9 +13,9 @@ class GroupAction {
|
|
|
13
13
|
const msg = message_id ? await this.client.getMsg(message_id) : undefined;
|
|
14
14
|
const { element, quote, music, share } = await utils_1.processMessage.apply(this.client, [message, msg]);
|
|
15
15
|
if (music)
|
|
16
|
-
await this.client.pickGroup(group_id).shareMusic(music.
|
|
16
|
+
return await this.client.pickGroup(group_id).shareMusic(music.platform, music.id);
|
|
17
17
|
if (share)
|
|
18
|
-
await this.client.pickGroup(group_id).shareUrl(music.data);
|
|
18
|
+
return await this.client.pickGroup(group_id).shareUrl(music.data);
|
|
19
19
|
if (element.length) {
|
|
20
20
|
return await this.client.sendGroupMsg(group_id, element, quote ? await this.client.getMsg(quote.data.message_id) : undefined);
|
|
21
21
|
}
|
package/lib/service/V11/index.js
CHANGED
|
@@ -224,7 +224,63 @@ class V11 extends events_1.EventEmitter {
|
|
|
224
224
|
// if (!['user_id', 'group_id', 'discuss_id', 'member_id', 'channel_id', 'guild_id'].includes(key)) return value
|
|
225
225
|
// return value + ''
|
|
226
226
|
// })
|
|
227
|
-
this.emit('dispatch',
|
|
227
|
+
this.emit('dispatch', this._formatEvent(data));
|
|
228
|
+
}
|
|
229
|
+
_formatEvent(data) {
|
|
230
|
+
if (data.post_type === 'notice') {
|
|
231
|
+
// console.log(JSON.stringify(data))
|
|
232
|
+
const data1 = { ...data };
|
|
233
|
+
if (data.notice_type === 'group') {
|
|
234
|
+
delete data1.group;
|
|
235
|
+
delete data1.member;
|
|
236
|
+
switch (data.sub_type) {
|
|
237
|
+
case 'decrease':
|
|
238
|
+
data1.sub_type = data.operator_id === data.user_id ? 'leave' : data.user_id === this.client.uin ? 'kick_me' : 'kick';
|
|
239
|
+
data1.notice_type = `${data.notice_type}_${data.sub_type}`;
|
|
240
|
+
break;
|
|
241
|
+
case 'increase':
|
|
242
|
+
data1.notice_type = `${data.notice_type}_${data.sub_type}`;
|
|
243
|
+
data1.sub_type = 'approve'; // todo 尚未实现
|
|
244
|
+
data1.operator_id = data1.user_id; // todo 尚未实现
|
|
245
|
+
break;
|
|
246
|
+
case 'ban':
|
|
247
|
+
data1.notice_type = `${data.notice_type}_${data.sub_type}`;
|
|
248
|
+
data1.subtype = data.duration ? 'ban' : 'lift_ban';
|
|
249
|
+
break;
|
|
250
|
+
case 'recall':
|
|
251
|
+
data1.notice_type = `${data.notice_type}_${data.sub_type}`;
|
|
252
|
+
delete data1.sub_type;
|
|
253
|
+
break;
|
|
254
|
+
case 'admin':
|
|
255
|
+
data1.notice_type = `${data.notice_type}_${data.sub_type}`;
|
|
256
|
+
data1.sub_type = data.set ? 'set' : 'unset';
|
|
257
|
+
break;
|
|
258
|
+
case 'poke':
|
|
259
|
+
data1.notice_type = 'notify';
|
|
260
|
+
data1.user_id = data.operator_id;
|
|
261
|
+
break;
|
|
262
|
+
default:
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
delete data1.friend;
|
|
268
|
+
switch (data.sub_type) {
|
|
269
|
+
case 'increase':
|
|
270
|
+
data1.notice_type = `friend_add`;
|
|
271
|
+
break;
|
|
272
|
+
case 'recall':
|
|
273
|
+
data1.notice_type = `friend_recall`;
|
|
274
|
+
break;
|
|
275
|
+
default:
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return JSON.stringify(data1);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
return JSON.stringify(data);
|
|
283
|
+
}
|
|
228
284
|
}
|
|
229
285
|
async _httpRequestHandler(ctx) {
|
|
230
286
|
if (ctx.method === 'OPTIONS') {
|
|
@@ -412,6 +468,8 @@ class V11 extends events_1.EventEmitter {
|
|
|
412
468
|
else
|
|
413
469
|
throw new Error('required message_type or input (user_id/group_id)');
|
|
414
470
|
}
|
|
471
|
+
if (action === 'send_like')
|
|
472
|
+
action = 'send_user_like';
|
|
415
473
|
const method = (0, utils_1.toHump)(action);
|
|
416
474
|
if (Reflect.has(this.action, method)) {
|
|
417
475
|
const ARGS = String(Reflect.get(this.action, method)).match(/\(.*\)/)?.[0]
|
|
@@ -426,9 +484,16 @@ class V11 extends events_1.EventEmitter {
|
|
|
426
484
|
params[k] = (0, utils_1.toBool)(params[k]);
|
|
427
485
|
if (k === 'message') {
|
|
428
486
|
if (typeof params[k] === 'string') {
|
|
487
|
+
if (/[CQ:music,type=.+,id=.+]/.test(params[k])) {
|
|
488
|
+
params[k] = params[k].replace(',type=', ',platform=');
|
|
489
|
+
}
|
|
429
490
|
params[k] = (0, icqq_cq_enable_1.fromCqcode)(params[k]);
|
|
430
491
|
}
|
|
431
492
|
else {
|
|
493
|
+
if (params[k][0].type == 'music' && params[k][0]?.data?.type) {
|
|
494
|
+
params[k][0].data.platform = params[k][0].data.type;
|
|
495
|
+
delete params[k][0].data.type;
|
|
496
|
+
}
|
|
432
497
|
params[k] = (0, icqq_cq_enable_1.fromSegment)(params[k]);
|
|
433
498
|
}
|
|
434
499
|
params['message_id'] = params[k].find(e => e.type === 'reply')?.message_id;
|
|
@@ -540,4 +605,4 @@ exports.V11 = V11;
|
|
|
540
605
|
};
|
|
541
606
|
}
|
|
542
607
|
V11.genMetaEvent = genMetaEvent;
|
|
543
|
-
})(V11
|
|
608
|
+
})(V11 = exports.V11 || (exports.V11 = {}));
|
package/lib/service/V12/index.js
CHANGED