onebots 0.1.5 → 0.1.6
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 +12 -2
- 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
|
@@ -369,7 +369,6 @@ class V12 extends events_1.EventEmitter {
|
|
|
369
369
|
params[k] = (0, utils_2.toBool)(params[k]);
|
|
370
370
|
if (k === 'message') {
|
|
371
371
|
params[k] = V12.fromSegment(params[k]);
|
|
372
|
-
params['message_id'] = params[k].find(e => e.type === 'reply')?.message_id;
|
|
373
372
|
}
|
|
374
373
|
args.push(params[k]);
|
|
375
374
|
}
|
|
@@ -565,6 +564,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
565
564
|
}
|
|
566
565
|
exports.V12 = V12;
|
|
567
566
|
(function (V12) {
|
|
567
|
+
const fileTypes = ['image', "file", 'record', 'video', 'flash'];
|
|
568
568
|
function fromSegment(msgList) {
|
|
569
569
|
msgList = [].concat(msgList);
|
|
570
570
|
return msgList.map((msg) => {
|
|
@@ -573,9 +573,17 @@ exports.V12 = V12;
|
|
|
573
573
|
if (typeof msg === 'string') {
|
|
574
574
|
return { type: 'text', text: msg };
|
|
575
575
|
}
|
|
576
|
-
const { type, data, ...other } = msg;
|
|
576
|
+
const { type, data = {}, ...other } = msg;
|
|
577
|
+
Object.assign(data, other);
|
|
578
|
+
if (type === 'music' && !data['platform']) {
|
|
579
|
+
data['platform'] = data['type'];
|
|
580
|
+
delete data['type'];
|
|
581
|
+
}
|
|
577
582
|
if (type === 'mention')
|
|
578
583
|
data['qq'] = Number(data['user_id']);
|
|
584
|
+
if (fileTypes.includes(type) && !data['file']) {
|
|
585
|
+
data['file'] = data['file_id'];
|
|
586
|
+
}
|
|
579
587
|
return {
|
|
580
588
|
type: type.replace('mention', 'at').replace('at_all', 'at'),
|
|
581
589
|
...other,
|
|
@@ -590,6 +598,8 @@ exports.V12 = V12;
|
|
|
590
598
|
if (typeof msg === 'string')
|
|
591
599
|
return { type: 'text', data: { text: msg } };
|
|
592
600
|
let { type, ...other } = msg;
|
|
601
|
+
if (fileTypes.includes(type))
|
|
602
|
+
other['file_id'] = other['file'];
|
|
593
603
|
return {
|
|
594
604
|
type: type === 'at' ? other['qq'] ? 'mention' : "mention_all" : type,
|
|
595
605
|
data: {
|