onebots 0.1.5 → 0.1.7
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/lib/server/app.js +6 -0
- package/lib/service/V12/action/friend.js +6 -21
- package/lib/service/V12/action/group.js +6 -21
- package/lib/service/V12/action/guild.js +4 -18
- package/lib/service/V12/action/utils.d.ts +7 -0
- package/lib/service/V12/action/utils.js +43 -0
- package/lib/service/V12/index.d.ts +13 -0
- package/lib/service/V12/index.js +15 -6
- package/package.json +1 -1
package/lib/server/app.js
CHANGED
|
@@ -123,6 +123,12 @@ class App extends koa_1.default {
|
|
|
123
123
|
for (const oneBot of this.oneBots) {
|
|
124
124
|
oneBot.start();
|
|
125
125
|
}
|
|
126
|
+
process.on('uncaughtException', (e) => {
|
|
127
|
+
console.error('uncaughtException', e);
|
|
128
|
+
});
|
|
129
|
+
process.on('unhandledRejection', (e) => {
|
|
130
|
+
console.error('unhandledRejection', e);
|
|
131
|
+
});
|
|
126
132
|
this.httpServer.listen(this.config.port);
|
|
127
133
|
this.router.get('/list', (ctx) => {
|
|
128
134
|
ctx.body = this.oneBots.map(bot => {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FriendAction = void 0;
|
|
4
|
-
const
|
|
5
|
-
const utils_1 = require("../../../utils");
|
|
4
|
+
const utils_1 = require("../../../service/V12/action/utils");
|
|
6
5
|
class FriendAction {
|
|
7
6
|
getUserInfo(user_id) {
|
|
8
7
|
return this.client.getStrangerInfo(user_id);
|
|
@@ -17,25 +16,11 @@ class FriendAction {
|
|
|
17
16
|
* @param message_id {string} 引用的消息ID
|
|
18
17
|
*/
|
|
19
18
|
async sendPrivateMsg(user_id, message, message_id) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
(0, utils_1.remove)(message, quote);
|
|
26
|
-
const element = index_1.V12.fromSegment(message);
|
|
27
|
-
if (forward)
|
|
28
|
-
element.unshift(await this.client.makeForwardMsg(forward.data.message.map(segment => {
|
|
29
|
-
return {
|
|
30
|
-
message: index_1.V12.fromSegment([segment]),
|
|
31
|
-
user_id: forward.data.user_id,
|
|
32
|
-
nickname: forward.data.user_name,
|
|
33
|
-
time: forward.data.time
|
|
34
|
-
};
|
|
35
|
-
})));
|
|
36
|
-
if (quote && !message_id)
|
|
37
|
-
message_id = quote.data.message_id;
|
|
38
|
-
return await this.client.sendPrivateMsg(user_id, element, message_id ? await this.client.getMsg(message_id) : undefined);
|
|
19
|
+
let { element, quote_id } = await utils_1.processMessage.apply(this.client, [message, message_id]);
|
|
20
|
+
element = await utils_1.processMusic.apply(this.client, ['friend', user_id, element]);
|
|
21
|
+
if (!element.length)
|
|
22
|
+
return;
|
|
23
|
+
return await this.client.sendPrivateMsg(user_id, element, quote_id ? await this.client.getMsg(quote_id) : undefined);
|
|
39
24
|
}
|
|
40
25
|
}
|
|
41
26
|
exports.FriendAction = FriendAction;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GroupAction = void 0;
|
|
4
|
-
const
|
|
5
|
-
const utils_1 = require("../../../utils");
|
|
4
|
+
const utils_1 = require("../../../service/V12/action/utils");
|
|
6
5
|
class GroupAction {
|
|
7
6
|
/**
|
|
8
7
|
* 发送群聊消息
|
|
@@ -11,25 +10,11 @@ class GroupAction {
|
|
|
11
10
|
* @param message_id {string} 引用的消息ID
|
|
12
11
|
*/
|
|
13
12
|
async sendGroupMsg(group_id, message, message_id) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
(0, utils_1.remove)(message, quote);
|
|
20
|
-
const element = index_1.V12.fromSegment(message);
|
|
21
|
-
if (forward)
|
|
22
|
-
element.unshift(await this.client.makeForwardMsg(forward.data.message.map(segment => {
|
|
23
|
-
return {
|
|
24
|
-
message: index_1.V12.fromSegment([segment]),
|
|
25
|
-
user_id: forward.data.user_id,
|
|
26
|
-
nickname: forward.data.user_name,
|
|
27
|
-
time: forward.data.time
|
|
28
|
-
};
|
|
29
|
-
})));
|
|
30
|
-
if (quote && !message_id)
|
|
31
|
-
message_id = quote.data.message_id;
|
|
32
|
-
return await this.client.sendGroupMsg(group_id, element, message_id ? await this.client.getMsg(message_id) : undefined);
|
|
13
|
+
let { element, quote_id } = await utils_1.processMessage.apply(this.client, [message, message_id]);
|
|
14
|
+
element = await utils_1.processMusic.apply(this.client, ['group', group_id, element]);
|
|
15
|
+
if (!element.length)
|
|
16
|
+
return;
|
|
17
|
+
return await this.client.sendGroupMsg(group_id, element, quote_id ? await this.client.getMsg(quote_id) : undefined);
|
|
33
18
|
}
|
|
34
19
|
/**
|
|
35
20
|
* 群组踢人
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GuildAction = void 0;
|
|
4
|
-
const
|
|
5
|
-
const utils_1 = require("../../../utils");
|
|
4
|
+
const utils_1 = require("../../../service/V12/action/utils");
|
|
6
5
|
class GuildAction {
|
|
7
6
|
getGuildList() {
|
|
8
7
|
return this.client.getGuildList();
|
|
@@ -14,22 +13,9 @@ class GuildAction {
|
|
|
14
13
|
return this.client.getGuildMemberList(guild_id);
|
|
15
14
|
}
|
|
16
15
|
async sendGuildMsg(guild_id, channel_id, message) {
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
let quote = message.find(e => e.type === 'reply');
|
|
21
|
-
if (quote)
|
|
22
|
-
(0, utils_1.remove)(message, quote);
|
|
23
|
-
const element = V12_1.V12.fromSegment(message);
|
|
24
|
-
// if(forward) element.unshift(await this.client.makeForwardMsg(forward.data.message.map(segment=>{
|
|
25
|
-
// return {
|
|
26
|
-
// message:V12.fromSegment([segment]),
|
|
27
|
-
// user_id:forward.data.user_id,
|
|
28
|
-
// nickname:forward.data.user_name,
|
|
29
|
-
// time:forward.data.time
|
|
30
|
-
// }
|
|
31
|
-
// })))
|
|
32
|
-
// if(quote && !message_id) message_id=quote.data.message_id
|
|
16
|
+
const { element } = await utils_1.processMessage.apply(this.client, [message]);
|
|
17
|
+
if (!element.length)
|
|
18
|
+
return;
|
|
33
19
|
return await this.client.sendGuildMsg(guild_id, channel_id, element);
|
|
34
20
|
}
|
|
35
21
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Client, MessageElem } from "icqq";
|
|
2
|
+
import { V12 } from "../../../service/V12";
|
|
3
|
+
export declare function processMusic(this: Client, target_type: 'group' | 'friend', target_id: number, element: any): Promise<any>;
|
|
4
|
+
export declare function processMessage(this: Client, message: V12.SegmentElem[], quote_id?: string): Promise<{
|
|
5
|
+
element: MessageElem[];
|
|
6
|
+
quote_id?: string;
|
|
7
|
+
}>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processMessage = exports.processMusic = void 0;
|
|
4
|
+
const V12_1 = require("../../../service/V12");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
|
+
async function processMusic(target_type, target_id, element) {
|
|
7
|
+
const musicList = element.filter(e => e.type === 'music');
|
|
8
|
+
element = element.filter(e => !musicList.includes(e));
|
|
9
|
+
const target = target_type === 'group' ? this.pickGroup(target_id) : this.pickFriend(target_id);
|
|
10
|
+
if (musicList.length)
|
|
11
|
+
await Promise.all(musicList.map(async (music) => {
|
|
12
|
+
return await target.shareMusic(music.platform, music.id);
|
|
13
|
+
}));
|
|
14
|
+
return element;
|
|
15
|
+
}
|
|
16
|
+
exports.processMusic = processMusic;
|
|
17
|
+
async function processMessage(message, quote_id) {
|
|
18
|
+
const forward = message.find(e => e.type === 'node');
|
|
19
|
+
if (forward)
|
|
20
|
+
(0, utils_1.remove)(message, forward);
|
|
21
|
+
let quote = message.find(e => e.type === 'reply');
|
|
22
|
+
if (quote)
|
|
23
|
+
(0, utils_1.remove)(message, quote);
|
|
24
|
+
const element = V12_1.V12.fromSegment(message);
|
|
25
|
+
if (forward)
|
|
26
|
+
element.unshift(
|
|
27
|
+
// 构造抓发消息
|
|
28
|
+
await this.makeForwardMsg(await Promise.all(
|
|
29
|
+
// 处理转发消息段
|
|
30
|
+
forward.data.message.map(async (segment) => {
|
|
31
|
+
return {
|
|
32
|
+
// 转发套转发处理
|
|
33
|
+
message: (await processMessage.apply(this, [V12_1.V12.fromSegment([segment])])).element,
|
|
34
|
+
user_id: forward.data.user_id,
|
|
35
|
+
nickname: forward.data.user_name,
|
|
36
|
+
time: forward.data.time
|
|
37
|
+
};
|
|
38
|
+
}))));
|
|
39
|
+
if (quote && !quote_id)
|
|
40
|
+
quote_id = quote.data.message_id;
|
|
41
|
+
return { element, quote_id };
|
|
42
|
+
}
|
|
43
|
+
exports.processMessage = processMessage;
|
|
@@ -81,6 +81,13 @@ export declare namespace V12 {
|
|
|
81
81
|
file: {
|
|
82
82
|
file_id: string;
|
|
83
83
|
};
|
|
84
|
+
music: {
|
|
85
|
+
type: "163" | 'qq' | 'xm' | 'custom';
|
|
86
|
+
id?: string;
|
|
87
|
+
url?: string;
|
|
88
|
+
audio?: string;
|
|
89
|
+
title?: string;
|
|
90
|
+
};
|
|
84
91
|
location: {
|
|
85
92
|
latitude: number;
|
|
86
93
|
longitude: number;
|
|
@@ -93,6 +100,12 @@ export declare namespace V12 {
|
|
|
93
100
|
user_name?: string;
|
|
94
101
|
message: SegmentElem[];
|
|
95
102
|
};
|
|
103
|
+
share: {
|
|
104
|
+
url: string;
|
|
105
|
+
title: string;
|
|
106
|
+
content?: string;
|
|
107
|
+
image?: string;
|
|
108
|
+
};
|
|
96
109
|
reply: {
|
|
97
110
|
message_id: string;
|
|
98
111
|
};
|
package/lib/service/V12/index.js
CHANGED
|
@@ -367,10 +367,6 @@ class V12 extends events_1.EventEmitter {
|
|
|
367
367
|
if (Reflect.has(params, k)) {
|
|
368
368
|
if (onebot_1.BOOLS.includes(k))
|
|
369
369
|
params[k] = (0, utils_2.toBool)(params[k]);
|
|
370
|
-
if (k === 'message') {
|
|
371
|
-
params[k] = V12.fromSegment(params[k]);
|
|
372
|
-
params['message_id'] = params[k].find(e => e.type === 'reply')?.message_id;
|
|
373
|
-
}
|
|
374
370
|
args.push(params[k]);
|
|
375
371
|
}
|
|
376
372
|
}
|
|
@@ -461,7 +457,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
461
457
|
return;
|
|
462
458
|
const action = event.detail_type === "private" ? "sendPrivateMsg" : "sendGroupMsg";
|
|
463
459
|
const id = event.detail_type === "private" ? event.user_id : event.group_id;
|
|
464
|
-
this.
|
|
460
|
+
this.action[action].apply(this, [id, res.reply]);
|
|
465
461
|
}
|
|
466
462
|
if (event.detail_type === "group") {
|
|
467
463
|
if (res.delete)
|
|
@@ -546,6 +542,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
546
542
|
}
|
|
547
543
|
else {
|
|
548
544
|
code = 10003;
|
|
545
|
+
this.logger.debug(e);
|
|
549
546
|
message = "请求格式错误";
|
|
550
547
|
}
|
|
551
548
|
ws.send(JSON.stringify({
|
|
@@ -565,6 +562,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
565
562
|
}
|
|
566
563
|
exports.V12 = V12;
|
|
567
564
|
(function (V12) {
|
|
565
|
+
const fileTypes = ['image', "file", 'record', 'video', 'flash'];
|
|
568
566
|
function fromSegment(msgList) {
|
|
569
567
|
msgList = [].concat(msgList);
|
|
570
568
|
return msgList.map((msg) => {
|
|
@@ -573,9 +571,18 @@ exports.V12 = V12;
|
|
|
573
571
|
if (typeof msg === 'string') {
|
|
574
572
|
return { type: 'text', text: msg };
|
|
575
573
|
}
|
|
576
|
-
const { type, data, ...other } = msg;
|
|
574
|
+
const { type, data = {}, ...other } = msg;
|
|
575
|
+
Object.assign(data, other);
|
|
576
|
+
if (type === 'music' && !data['platform']) {
|
|
577
|
+
data['platform'] = data['type'];
|
|
578
|
+
delete data['type'];
|
|
579
|
+
}
|
|
577
580
|
if (type === 'mention')
|
|
578
581
|
data['qq'] = Number(data['user_id']);
|
|
582
|
+
if (fileTypes.includes(type) && !data['file']) {
|
|
583
|
+
data['file'] = data['file_id'];
|
|
584
|
+
delete data['file_id'];
|
|
585
|
+
}
|
|
579
586
|
return {
|
|
580
587
|
type: type.replace('mention', 'at').replace('at_all', 'at'),
|
|
581
588
|
...other,
|
|
@@ -590,6 +597,8 @@ exports.V12 = V12;
|
|
|
590
597
|
if (typeof msg === 'string')
|
|
591
598
|
return { type: 'text', data: { text: msg } };
|
|
592
599
|
let { type, ...other } = msg;
|
|
600
|
+
if (fileTypes.includes(type))
|
|
601
|
+
other['file_id'] = other['file'];
|
|
593
602
|
return {
|
|
594
603
|
type: type === 'at' ? other['qq'] ? 'mention' : "mention_all" : type,
|
|
595
604
|
data: {
|