onebots 0.1.14 → 0.1.16
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/bin.js +0 -0
- package/lib/config.sample.yaml +5 -5
- package/lib/onebot.d.ts +1 -1
- package/lib/service/V12/action/friend.d.ts +4 -1
- package/lib/service/V12/action/friend.js +14 -4
- package/lib/service/V12/action/group.d.ts +4 -1
- package/lib/service/V12/action/group.js +14 -4
- package/lib/service/V12/action/utils.d.ts +3 -1
- package/lib/service/V12/action/utils.js +22 -7
- package/lib/types.d.ts +3 -3
- package/package.json +2 -2
package/lib/bin.js
CHANGED
|
File without changes
|
package/lib/config.sample.yaml
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
port: 6727 # 监听端口
|
|
2
|
+
log_level: info # 日志等级
|
|
2
3
|
general: # 通用配置,在单个配置省略时的默认值
|
|
3
4
|
V11: # oneBotV11的通用配置
|
|
4
5
|
heartbeat: 3 # 心跳间隔 (秒)
|
|
@@ -11,8 +12,8 @@ general: # 通用配置,在单个配置省略时的默认值
|
|
|
11
12
|
use_http: true # 是否使用 http
|
|
12
13
|
enable_cors: true # 是否允许跨域
|
|
13
14
|
use_ws: true # 是否使用websocket
|
|
14
|
-
http_reverse: [] # http上报地址
|
|
15
|
-
ws_reverse: [] # 反向ws连接地址
|
|
15
|
+
http_reverse: [ ] # http上报地址
|
|
16
|
+
ws_reverse: [ ] # 反向ws连接地址
|
|
16
17
|
V12: # oneBotV12的通用配置
|
|
17
18
|
heartbeat: 3 # 心跳间隔 (秒)
|
|
18
19
|
access_token: '' # 访问api的token
|
|
@@ -21,9 +22,8 @@ general: # 通用配置,在单个配置省略时的默认值
|
|
|
21
22
|
enable_cors: true # 是否允许跨域
|
|
22
23
|
use_http: true # 是否启用http
|
|
23
24
|
use_ws: true # 是否启用 websocket
|
|
24
|
-
webhook: [] # http 上报地址
|
|
25
|
-
ws_reverse: [] # 反向ws连接地址
|
|
26
|
-
log_level: info # 日志等级
|
|
25
|
+
webhook: [ ] # http 上报地址
|
|
26
|
+
ws_reverse: [ ] # 反向ws连接地址
|
|
27
27
|
# 每个账号的单独配置(用于覆盖通用配置)
|
|
28
28
|
123456789:
|
|
29
29
|
version: V11 # 使用的oneBot版本
|
package/lib/onebot.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare enum OneBotStatus {
|
|
|
27
27
|
Good = 0,
|
|
28
28
|
Bad = 1
|
|
29
29
|
}
|
|
30
|
-
export
|
|
30
|
+
export type OneBotConfig = OneBot.Config<OneBot.Version>;
|
|
31
31
|
export declare namespace OneBot {
|
|
32
32
|
type Version = 'V11' | 'V12';
|
|
33
33
|
type Config<V extends Version = 'V11'> = ({
|
|
@@ -14,5 +14,8 @@ export declare class FriendAction {
|
|
|
14
14
|
* @param message {import('onebots/lib/service/v12').Sendable} 消息
|
|
15
15
|
* @param source {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
|
|
16
16
|
*/
|
|
17
|
-
sendPrivateMsg(this: V12, user_id: number, message: V12.Sendable, source?: V12.SegmentElem<'reply'>): Promise<import("icqq").MessageRet
|
|
17
|
+
sendPrivateMsg(this: V12, user_id: number, message: V12.Sendable, source?: V12.SegmentElem<'reply'>): Promise<import("icqq").MessageRet | {
|
|
18
|
+
message_id: string;
|
|
19
|
+
message: V12.Sendable;
|
|
20
|
+
}>;
|
|
18
21
|
}
|
|
@@ -16,10 +16,20 @@ class FriendAction {
|
|
|
16
16
|
* @param source {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
|
|
17
17
|
*/
|
|
18
18
|
async sendPrivateMsg(user_id, message, source) {
|
|
19
|
-
let { element, quote } = await utils_1.processMessage.apply(this.client, [message, source]);
|
|
20
|
-
element
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
let { element, quote, music, share } = await utils_1.processMessage.apply(this.client, [message, source]);
|
|
20
|
+
if (!element.length && (!music || !share))
|
|
21
|
+
throw new Error('发送消息不受支持');
|
|
22
|
+
if (music || share) {
|
|
23
|
+
const target = this.client.pickFriend(user_id);
|
|
24
|
+
if (music)
|
|
25
|
+
await target.shareMusic(music.data.type, music.data.id);
|
|
26
|
+
if (share)
|
|
27
|
+
await target.shareUrl(share.data);
|
|
28
|
+
return {
|
|
29
|
+
message_id: '',
|
|
30
|
+
message
|
|
31
|
+
};
|
|
32
|
+
}
|
|
23
33
|
return await this.client.sendPrivateMsg(user_id, element, quote ? await this.client.getMsg(quote.data.message_id) : undefined);
|
|
24
34
|
}
|
|
25
35
|
}
|
|
@@ -6,7 +6,10 @@ export declare class GroupAction {
|
|
|
6
6
|
* @param message {import('icqq/lib/service').Sendable} 消息
|
|
7
7
|
* @param source {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
|
|
8
8
|
*/
|
|
9
|
-
sendGroupMsg(this: V12, group_id: number, message: V12.Sendable, source?: V12.SegmentElem<'reply'>): Promise<import("icqq").MessageRet
|
|
9
|
+
sendGroupMsg(this: V12, group_id: number, message: V12.Sendable, source?: V12.SegmentElem<'reply'>): Promise<import("icqq").MessageRet | {
|
|
10
|
+
message_id: string;
|
|
11
|
+
message: V12.Sendable;
|
|
12
|
+
}>;
|
|
10
13
|
/**
|
|
11
14
|
* 群组踢人
|
|
12
15
|
* @param group_id {number} 群id
|
|
@@ -10,10 +10,20 @@ class GroupAction {
|
|
|
10
10
|
* @param source {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
|
|
11
11
|
*/
|
|
12
12
|
async sendGroupMsg(group_id, message, source) {
|
|
13
|
-
let { element, quote } = await utils_1.processMessage.apply(this.client, [message, source]);
|
|
14
|
-
element
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
let { element, quote, music, share } = await utils_1.processMessage.apply(this.client, [message, source]);
|
|
14
|
+
if (!element.length && (!music || !share))
|
|
15
|
+
throw new Error('发送消息不受支持');
|
|
16
|
+
if (music || share) {
|
|
17
|
+
const target = this.client.pickGroup(group_id);
|
|
18
|
+
if (music)
|
|
19
|
+
await target.shareMusic(music.data.type, music.data.id);
|
|
20
|
+
if (share)
|
|
21
|
+
await target.shareUrl(share.data);
|
|
22
|
+
return {
|
|
23
|
+
message_id: '',
|
|
24
|
+
message
|
|
25
|
+
};
|
|
26
|
+
}
|
|
17
27
|
return await this.client.sendGroupMsg(group_id, element, quote ? await this.client.getMsg(quote.data.message_id) : undefined);
|
|
18
28
|
}
|
|
19
29
|
/**
|
|
@@ -3,5 +3,7 @@ import { V12 } from "../../../service/V12";
|
|
|
3
3
|
export declare function processMusic(this: Client, target_type: 'group' | 'friend', target_id: number, element: any[]): Promise<any[]>;
|
|
4
4
|
export declare function processMessage(this: Client, message: V12.Sendable, source?: V12.SegmentElem<'reply'>): Promise<{
|
|
5
5
|
element: MessageElem[];
|
|
6
|
-
|
|
6
|
+
music?: V12.SegmentElem<'music'>;
|
|
7
|
+
share?: V12.SegmentElem<'share'>;
|
|
8
|
+
quote?: V12.SegmentElem<'reply'>;
|
|
7
9
|
}>;
|
|
@@ -20,26 +20,41 @@ async function processMessage(message, source) {
|
|
|
20
20
|
return { type: 'text', data: { text: m } };
|
|
21
21
|
return m;
|
|
22
22
|
});
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
(0, utils_1.remove)(segments,
|
|
23
|
+
const music = segments.find(e => e.type === 'music');
|
|
24
|
+
if (music)
|
|
25
|
+
(0, utils_1.remove)(segments, music);
|
|
26
|
+
if (segments.find(e => e.type === 'music'))
|
|
27
|
+
throw new Error('一次只能发送一个音乐元素');
|
|
28
|
+
if (segments.length && music)
|
|
29
|
+
throw new Error('音乐元素只能单独发送');
|
|
30
|
+
const share = segments.find(e => e.type === 'share');
|
|
31
|
+
if (share)
|
|
32
|
+
(0, utils_1.remove)(segments, share);
|
|
33
|
+
if (segments.find(e => e.type === 'share'))
|
|
34
|
+
throw new Error('一次只能发送一个分享元素');
|
|
35
|
+
if (segments.length && share)
|
|
36
|
+
throw new Error('分享元素只能单独发送');
|
|
37
|
+
const forwardNodes = segments.filter(e => e.type === 'node');
|
|
38
|
+
segments = segments.filter(s => !forwardNodes.includes(s));
|
|
39
|
+
if (forwardNodes.length && segments.length)
|
|
40
|
+
throw new Error('只能单独发送转发节点');
|
|
26
41
|
let quote = segments.find(e => e.type === 'reply');
|
|
27
42
|
if (quote)
|
|
28
43
|
(0, utils_1.remove)(segments, quote);
|
|
29
44
|
segments = segments.filter(n => [
|
|
30
45
|
'face', 'text', 'image',
|
|
31
46
|
'rpx', 'dice', 'poke', 'mention', 'mention_all',
|
|
32
|
-
'voice', 'file', '
|
|
47
|
+
'voice', 'file', 'record',
|
|
33
48
|
'forward', 'node',
|
|
34
49
|
'music', 'share', 'xml', 'json', 'location', // 分享类
|
|
35
50
|
].includes(n.type));
|
|
36
51
|
const element = V12_1.V12.fromSegment(segments);
|
|
37
|
-
if (
|
|
52
|
+
if (forwardNodes.length)
|
|
38
53
|
element.unshift(
|
|
39
54
|
// 构造抓发消息
|
|
40
55
|
await this.makeForwardMsg(await Promise.all(
|
|
41
56
|
// 处理转发消息段
|
|
42
|
-
|
|
57
|
+
forwardNodes.map(async (forwardNode) => {
|
|
43
58
|
return {
|
|
44
59
|
// 转发套转发处理
|
|
45
60
|
message: (await processMessage.apply(this, [forwardNode.data.message])).element,
|
|
@@ -48,6 +63,6 @@ async function processMessage(message, source) {
|
|
|
48
63
|
time: forwardNode.data.time
|
|
49
64
|
};
|
|
50
65
|
}))));
|
|
51
|
-
return { element, quote: quote || source };
|
|
66
|
+
return { element, quote: quote || source, music, share };
|
|
52
67
|
}
|
|
53
68
|
exports.processMessage = processMessage;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "mark" | "off";
|
|
2
|
+
export type Dispose = () => any;
|
|
3
|
+
export type MayBeArray<T extends any> = T | T[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onebots",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "基于icqq的多例oneBot实现",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16"
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@koa/router": "^10.1.1",
|
|
53
|
-
"icqq": "^0.0.
|
|
53
|
+
"icqq": "^0.0.21",
|
|
54
54
|
"icqq-cq-enable": "^1.0.0",
|
|
55
55
|
"js-yaml": "^4.1.0",
|
|
56
56
|
"koa": "^2.13.4",
|