onebots 0.0.19 → 0.0.20
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/onebot.js +17 -0
- package/lib/service/V11/action/friend.d.ts +4 -2
- package/lib/service/V11/action/friend.js +12 -2
- package/lib/service/V11/action/group.d.ts +3 -2
- package/lib/service/V11/action/group.js +13 -3
- package/lib/service/V11/index.js +1 -0
- package/lib/service/V12/action/common.d.ts +1 -1
- package/lib/service/V12/action/common.js +1 -1
- package/lib/service/V12/action/friend.d.ts +7 -2
- package/lib/service/V12/action/friend.js +17 -2
- package/lib/service/V12/action/group.d.ts +2 -2
- package/lib/service/V12/action/group.js +13 -3
- package/lib/service/V12/index.js +1 -0
- package/package.json +1 -1
package/lib/onebot.js
CHANGED
|
@@ -7,6 +7,7 @@ const app_1 = require("./server/app");
|
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const oicq_1 = require("oicq");
|
|
10
|
+
const message_1 = require("oicq/lib/message");
|
|
10
11
|
const V11_1 = require("./service/V11");
|
|
11
12
|
const V12_1 = require("./service/V12");
|
|
12
13
|
class NotFoundError extends Error {
|
|
@@ -118,6 +119,22 @@ class OneBot extends events_1.EventEmitter {
|
|
|
118
119
|
dispatch(event, data) {
|
|
119
120
|
for (const instance of this.instances) {
|
|
120
121
|
const result = instance.format(event, data);
|
|
122
|
+
if (data.source) {
|
|
123
|
+
switch (data.message_type) {
|
|
124
|
+
case 'group':
|
|
125
|
+
data.message.shift({
|
|
126
|
+
type: 'reply',
|
|
127
|
+
message_id: (0, message_1.genGroupMessageId)(data.group_id, data.source.user_id, data.source.seq, data.source.rand, data.source.rand, data.source.time)
|
|
128
|
+
});
|
|
129
|
+
break;
|
|
130
|
+
case 'private':
|
|
131
|
+
data.message.shift({
|
|
132
|
+
type: 'reply',
|
|
133
|
+
message_id: (0, message_1.genDmMessageId)(data.source.user_id, data.source.seq, data.source.rand, data.source.rand, data.source.time)
|
|
134
|
+
});
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
121
138
|
instance.dispatch(result);
|
|
122
139
|
}
|
|
123
140
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { OneBot } from "../../../onebot";
|
|
2
|
-
import {
|
|
2
|
+
import { V11 } from "../../../service/V11";
|
|
3
|
+
import { SegmentElem } from "oicq2-cq-enable/lib/utils";
|
|
3
4
|
export declare class FriendAction {
|
|
4
5
|
/**
|
|
5
6
|
* 发送私聊消息
|
|
6
7
|
* @param user_id {number} 用户id
|
|
7
8
|
* @param message {import('oicq').Sendable} 发送的消息
|
|
9
|
+
* @param message_id {string} 引用的消息ID
|
|
8
10
|
*/
|
|
9
|
-
sendPrivateMsg(this:
|
|
11
|
+
sendPrivateMsg(this: V11, user_id: number, message: string | SegmentElem[], message_id?: string): Promise<import("oicq").MessageRet>;
|
|
10
12
|
/**
|
|
11
13
|
* 获取好友列表
|
|
12
14
|
*/
|
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FriendAction = void 0;
|
|
4
|
+
const oicq2_cq_enable_1 = require("oicq2-cq-enable");
|
|
4
5
|
class FriendAction {
|
|
5
6
|
/**
|
|
6
7
|
* 发送私聊消息
|
|
7
8
|
* @param user_id {number} 用户id
|
|
8
9
|
* @param message {import('oicq').Sendable} 发送的消息
|
|
10
|
+
* @param message_id {string} 引用的消息ID
|
|
9
11
|
*/
|
|
10
|
-
sendPrivateMsg(user_id, message) {
|
|
11
|
-
|
|
12
|
+
async sendPrivateMsg(user_id, message, message_id) {
|
|
13
|
+
const element = typeof message === 'string' ? (0, oicq2_cq_enable_1.fromCqcode)(message) : (0, oicq2_cq_enable_1.fromSegment)(message);
|
|
14
|
+
let quote, quoteIdx = element.findIndex(e => e.type === 'reply');
|
|
15
|
+
if (quoteIdx !== -1) {
|
|
16
|
+
quote = element[quoteIdx];
|
|
17
|
+
element.splice(quoteIdx, 1);
|
|
18
|
+
}
|
|
19
|
+
if (quote && !message_id)
|
|
20
|
+
message_id = quote.message_id;
|
|
21
|
+
return await this.client.sendPrivateMsg(user_id, element, message_id ? await this.client.getMsg(message_id) : undefined);
|
|
12
22
|
}
|
|
13
23
|
/**
|
|
14
24
|
* 获取好友列表
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Sendable } from "oicq";
|
|
2
1
|
import { V11 } from "../../../service/V11";
|
|
2
|
+
import { SegmentElem } from "oicq2-cq-enable/lib/utils";
|
|
3
3
|
export declare class GroupAction {
|
|
4
4
|
/**
|
|
5
5
|
* 发送群聊消息
|
|
6
6
|
* @param group_id {number} 群id
|
|
7
7
|
* @param message {import('oicq').Sendable} 消息
|
|
8
|
+
* @param message_id {string} 引用的消息ID
|
|
8
9
|
*/
|
|
9
|
-
sendGroupMsg(this: V11, group_id: number, message:
|
|
10
|
+
sendGroupMsg(this: V11, group_id: number, message: string | SegmentElem[], message_id?: string): Promise<import("oicq").MessageRet>;
|
|
10
11
|
/**
|
|
11
12
|
* 群组踢人
|
|
12
13
|
* @param group_id {number} 群id
|
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GroupAction = void 0;
|
|
4
|
+
const oicq2_cq_enable_1 = require("oicq2-cq-enable");
|
|
4
5
|
class GroupAction {
|
|
5
6
|
/**
|
|
6
7
|
* 发送群聊消息
|
|
7
8
|
* @param group_id {number} 群id
|
|
8
9
|
* @param message {import('oicq').Sendable} 消息
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
* @param message_id {string} 引用的消息ID
|
|
11
|
+
*/
|
|
12
|
+
async sendGroupMsg(group_id, message, message_id) {
|
|
13
|
+
const element = typeof message === 'string' ? (0, oicq2_cq_enable_1.fromCqcode)(message) : (0, oicq2_cq_enable_1.fromSegment)(message);
|
|
14
|
+
let quote, quoteIdx = element.findIndex(e => e.type === 'reply');
|
|
15
|
+
if (quoteIdx !== -1) {
|
|
16
|
+
quote = element[quoteIdx];
|
|
17
|
+
element.splice(quoteIdx, 1);
|
|
18
|
+
}
|
|
19
|
+
if (quote && !message_id)
|
|
20
|
+
message_id = quote.message_id;
|
|
21
|
+
return await this.client.sendGroupMsg(group_id, element, message_id ? await this.client.getMsg(message_id) : undefined);
|
|
12
22
|
}
|
|
13
23
|
/**
|
|
14
24
|
* 群组踢人
|
package/lib/service/V11/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { V12 } from "../index";
|
|
2
|
-
import { Sendable } from "oicq";
|
|
3
2
|
export declare class FriendAction {
|
|
4
3
|
getUserInfo(this: V12, user_id: number): Promise<{
|
|
5
4
|
user_id: number;
|
|
@@ -9,5 +8,11 @@ export declare class FriendAction {
|
|
|
9
8
|
area: string;
|
|
10
9
|
}>;
|
|
11
10
|
getFriendList(this: V12): Map<number, import("oicq").FriendInfo>;
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* 发送私聊消息
|
|
13
|
+
* @param user_id {number} 用户id
|
|
14
|
+
* @param message {import('oicq').Sendable} 发送的消息
|
|
15
|
+
* @param message_id {string} 引用的消息ID
|
|
16
|
+
*/
|
|
17
|
+
sendPrivateMsg(this: V12, user_id: number, message: V12.SegmentElem[], message_id?: string): Promise<import("oicq").MessageRet>;
|
|
13
18
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FriendAction = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
4
5
|
class FriendAction {
|
|
5
6
|
getUserInfo(user_id) {
|
|
6
7
|
return this.client.getStrangerInfo(user_id);
|
|
@@ -8,8 +9,22 @@ class FriendAction {
|
|
|
8
9
|
getFriendList() {
|
|
9
10
|
return this.client.getFriendList();
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* 发送私聊消息
|
|
14
|
+
* @param user_id {number} 用户id
|
|
15
|
+
* @param message {import('oicq').Sendable} 发送的消息
|
|
16
|
+
* @param message_id {string} 引用的消息ID
|
|
17
|
+
*/
|
|
18
|
+
async sendPrivateMsg(user_id, message, message_id) {
|
|
19
|
+
const element = index_1.V12.fromSegment(message);
|
|
20
|
+
let quote, quoteIdx = element.findIndex(e => e.type === 'reply');
|
|
21
|
+
if (quoteIdx !== -1) {
|
|
22
|
+
quote = element[quoteIdx];
|
|
23
|
+
element.splice(quoteIdx, 1);
|
|
24
|
+
}
|
|
25
|
+
if (quote && !message_id)
|
|
26
|
+
message_id = quote.message_id;
|
|
27
|
+
return await this.client.sendPrivateMsg(user_id, element, message_id ? await this.client.getMsg(message_id) : undefined);
|
|
13
28
|
}
|
|
14
29
|
}
|
|
15
30
|
exports.FriendAction = FriendAction;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { V12 } from "../index";
|
|
2
|
-
import { Sendable } from "oicq";
|
|
3
2
|
export declare class GroupAction {
|
|
4
3
|
/**
|
|
5
4
|
* 发送群聊消息
|
|
6
5
|
* @param group_id {number} 群id
|
|
7
6
|
* @param message {import('oicq').Sendable} 消息
|
|
7
|
+
* @param message_id {string} 引用的消息ID
|
|
8
8
|
*/
|
|
9
|
-
sendGroupMsg(this: V12, group_id: number, message:
|
|
9
|
+
sendGroupMsg(this: V12, group_id: number, message: V12.SegmentElem[], message_id?: string): Promise<import("oicq").MessageRet>;
|
|
10
10
|
/**
|
|
11
11
|
* 群组踢人
|
|
12
12
|
* @param group_id {number} 群id
|
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GroupAction = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
4
5
|
class GroupAction {
|
|
5
6
|
/**
|
|
6
7
|
* 发送群聊消息
|
|
7
8
|
* @param group_id {number} 群id
|
|
8
9
|
* @param message {import('oicq').Sendable} 消息
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
* @param message_id {string} 引用的消息ID
|
|
11
|
+
*/
|
|
12
|
+
async sendGroupMsg(group_id, message, message_id) {
|
|
13
|
+
const element = index_1.V12.fromSegment(message);
|
|
14
|
+
let quote, quoteIdx = element.findIndex(e => e.type === 'reply');
|
|
15
|
+
if (quoteIdx !== -1) {
|
|
16
|
+
quote = element[quoteIdx];
|
|
17
|
+
element.splice(quoteIdx, 1);
|
|
18
|
+
}
|
|
19
|
+
if (quote && !message_id)
|
|
20
|
+
message_id = quote.message_id;
|
|
21
|
+
return await this.client.sendGroupMsg(group_id, element, message_id ? await this.client.getMsg(message_id) : undefined);
|
|
12
22
|
}
|
|
13
23
|
/**
|
|
14
24
|
* 群组踢人
|
package/lib/service/V12/index.js
CHANGED
|
@@ -300,6 +300,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
300
300
|
params[k] = (0, utils_1.toBool)(params[k]);
|
|
301
301
|
if (k === 'message') {
|
|
302
302
|
params[k] = V12.fromSegment(params[k]);
|
|
303
|
+
params['message_id'] = params[k].find(e => e.type === 'reply')?.message_id;
|
|
303
304
|
}
|
|
304
305
|
args.push(params[k]);
|
|
305
306
|
}
|