onebots 0.2.3 → 0.2.4
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 +41 -4
- package/lib/service/V11/action/friend.d.ts +1 -1
- package/lib/service/V11/action/friend.js +9 -9
- package/lib/service/V11/action/group.d.ts +1 -1
- package/lib/service/V11/action/group.js +9 -9
- package/lib/service/V11/action/utils.d.ts +9 -0
- package/lib/service/V11/action/utils.js +19 -0
- package/lib/service/V12/action/friend.d.ts +1 -4
- package/lib/service/V12/action/friend.js +6 -13
- package/lib/service/V12/action/group.d.ts +1 -4
- package/lib/service/V12/action/group.js +6 -13
- package/lib/service/V12/action/utils.d.ts +0 -1
- package/lib/service/V12/action/utils.js +7 -44
- package/package.json +1 -1
package/lib/onebot.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.BOOLS = exports.OneBotStatus = exports.OneBot = exports.NotFoundError = void 0;
|
|
4
27
|
require("icqq-cq-enable");
|
|
@@ -10,6 +33,7 @@ const icqq_1 = require("icqq");
|
|
|
10
33
|
const message_1 = require("icqq/lib/message");
|
|
11
34
|
const V11_1 = require("./service/V11");
|
|
12
35
|
const V12_1 = require("./service/V12");
|
|
36
|
+
const process = __importStar(require("process"));
|
|
13
37
|
class NotFoundError extends Error {
|
|
14
38
|
constructor() {
|
|
15
39
|
super(...arguments);
|
|
@@ -66,11 +90,24 @@ class OneBot extends events_1.EventEmitter {
|
|
|
66
90
|
this.off('system.login.qrcode', qrcodeHelper);
|
|
67
91
|
});
|
|
68
92
|
});
|
|
69
|
-
this.client.trap('system.login.device', function deviceHelper() {
|
|
70
|
-
console.log('
|
|
93
|
+
this.client.trap('system.login.device', function deviceHelper(e) {
|
|
94
|
+
console.log('请选择验证方式:1.短信验证 2.url验证');
|
|
71
95
|
this.sendSmsCode();
|
|
72
|
-
process.stdin.once('data', (
|
|
73
|
-
|
|
96
|
+
process.stdin.once('data', (buf) => {
|
|
97
|
+
const input = e.toString().trim();
|
|
98
|
+
if (input === '1') {
|
|
99
|
+
this.sendSmsCode();
|
|
100
|
+
console.log('请输入短信验证码:');
|
|
101
|
+
process.stdin.once('data', buf => {
|
|
102
|
+
this.submitSmsCode(buf.toString().trim());
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
console.log(`请前往:${e.url} 完成验证后回车继续`);
|
|
107
|
+
process.stdin.once('data', buf => {
|
|
108
|
+
this.login();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
74
111
|
});
|
|
75
112
|
disposeArr.push(() => {
|
|
76
113
|
this.off('system.login.device', deviceHelper);
|
|
@@ -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[], message_id?: string): Promise<import("icqq").MessageRet>;
|
|
11
|
+
sendPrivateMsg(this: V11, user_id: number, message: string | SegmentElem | SegmentElem[], message_id?: string): Promise<import("icqq").MessageRet>;
|
|
12
12
|
/**
|
|
13
13
|
* 获取好友列表
|
|
14
14
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FriendAction = void 0;
|
|
4
|
-
const
|
|
4
|
+
const utils_1 = require("../../../service/V11/action/utils");
|
|
5
5
|
class FriendAction {
|
|
6
6
|
/**
|
|
7
7
|
* 发送私聊消息
|
|
@@ -10,15 +10,15 @@ class FriendAction {
|
|
|
10
10
|
* @param message_id {string} 引用的消息ID
|
|
11
11
|
*/
|
|
12
12
|
async sendPrivateMsg(user_id, message, message_id) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const msg = message ? await this.client.getMsg(message_id) : undefined;
|
|
14
|
+
const { element, quote, music, share } = await utils_1.processMessage.apply(this.client, [message, msg]);
|
|
15
|
+
if (music)
|
|
16
|
+
await this.client.pickUser(user_id).shareMusic(music.data.platform, music.data.id);
|
|
17
|
+
if (share)
|
|
18
|
+
await this.client.pickUser(user_id).shareUrl(music.data);
|
|
19
|
+
if (element.length) {
|
|
20
|
+
return await this.client.sendPrivateMsg(user_id, element, quote ? await this.client.getMsg(quote.data.message_id) : undefined);
|
|
18
21
|
}
|
|
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);
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* 获取好友列表
|
|
@@ -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[], message_id?: string): Promise<import("icqq").MessageRet>;
|
|
10
|
+
sendGroupMsg(this: V11, group_id: number, message: string | SegmentElem | SegmentElem[], message_id?: string): Promise<import("icqq").MessageRet>;
|
|
11
11
|
/**
|
|
12
12
|
* 群组踢人
|
|
13
13
|
* @param group_id {number} 群id
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GroupAction = void 0;
|
|
4
|
-
const
|
|
4
|
+
const utils_1 = require("../../../service/V11/action/utils");
|
|
5
5
|
class GroupAction {
|
|
6
6
|
/**
|
|
7
7
|
* 发送群聊消息
|
|
@@ -10,15 +10,15 @@ class GroupAction {
|
|
|
10
10
|
* @param message_id {string} 引用的消息ID
|
|
11
11
|
*/
|
|
12
12
|
async sendGroupMsg(group_id, message, message_id) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const msg = message ? await this.client.getMsg(message_id) : undefined;
|
|
14
|
+
const { element, quote, music, share } = await utils_1.processMessage.apply(this.client, [message, msg]);
|
|
15
|
+
if (music)
|
|
16
|
+
await this.client.pickGroup(group_id).shareMusic(music.data.platform, music.data.id);
|
|
17
|
+
if (share)
|
|
18
|
+
await this.client.pickGroup(group_id).shareUrl(music.data);
|
|
19
|
+
if (element.length) {
|
|
20
|
+
return await this.client.sendGroupMsg(group_id, element, quote ? await this.client.getMsg(quote.data.message_id) : undefined);
|
|
18
21
|
}
|
|
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);
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* 群组踢人
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Client, MessageElem, ShareElem } from "icqq";
|
|
2
|
+
import { SegmentElem } from "icqq-cq-enable/lib/utils";
|
|
3
|
+
import { QuoteElem } from "icqq/lib/message";
|
|
4
|
+
export declare function processMessage(this: Client, message: string | SegmentElem | SegmentElem[], source?: QuoteElem): Promise<{
|
|
5
|
+
element: MessageElem[];
|
|
6
|
+
music?: MessageElem;
|
|
7
|
+
share?: ShareElem;
|
|
8
|
+
quote?: QuoteElem;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processMessage = void 0;
|
|
4
|
+
const utils_1 = require("../../../utils");
|
|
5
|
+
const utils_2 = require("icqq-cq-enable/lib/utils");
|
|
6
|
+
async function processMessage(message, source) {
|
|
7
|
+
const element = typeof message === 'string' ? (0, utils_2.fromCqcode)(message) : (0, utils_2.fromSegment)(message);
|
|
8
|
+
let quote = element.find(e => e.type === 'reply');
|
|
9
|
+
if (quote)
|
|
10
|
+
(0, utils_1.remove)(element, quote);
|
|
11
|
+
let music = element.find(e => e.type === 'music');
|
|
12
|
+
if (music)
|
|
13
|
+
(0, utils_1.remove)(element, music);
|
|
14
|
+
let share = element.find(e => e.type === 'share');
|
|
15
|
+
if (share)
|
|
16
|
+
(0, utils_1.remove)(element, share);
|
|
17
|
+
return { element, quote: quote || source, share, music };
|
|
18
|
+
}
|
|
19
|
+
exports.processMessage = processMessage;
|
|
@@ -14,10 +14,7 @@ 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
|
|
18
|
-
message_id: string;
|
|
19
|
-
message: V12.Sendable;
|
|
20
|
-
}>;
|
|
17
|
+
sendPrivateMsg(this: V12, user_id: number, message: V12.Sendable, source?: V12.SegmentElem<'reply'>): Promise<import("icqq").MessageRet>;
|
|
21
18
|
/**
|
|
22
19
|
* 为指定用户点赞
|
|
23
20
|
* @param user_id {number} 用户id
|
|
@@ -17,20 +17,13 @@ class FriendAction {
|
|
|
17
17
|
*/
|
|
18
18
|
async sendPrivateMsg(user_id, message, source) {
|
|
19
19
|
let { element, quote, music, share } = await utils_1.processMessage.apply(this.client, [message, source]);
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (share)
|
|
27
|
-
await target.shareUrl(share.data);
|
|
28
|
-
return {
|
|
29
|
-
message_id: '',
|
|
30
|
-
message
|
|
31
|
-
};
|
|
20
|
+
if (music)
|
|
21
|
+
await this.client.pickUser(user_id).shareMusic(music.data.platform, music.data.id);
|
|
22
|
+
if (share)
|
|
23
|
+
await this.client.pickUser(user_id).shareUrl(music.data);
|
|
24
|
+
if (element.length) {
|
|
25
|
+
return await this.client.sendPrivateMsg(user_id, element, quote ? await this.client.getMsg(quote.data.message_id) : undefined);
|
|
32
26
|
}
|
|
33
|
-
return await this.client.sendPrivateMsg(user_id, element, quote ? await this.client.getMsg(quote.data.message_id) : undefined);
|
|
34
27
|
}
|
|
35
28
|
/**
|
|
36
29
|
* 为指定用户点赞
|
|
@@ -6,10 +6,7 @@ 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
|
|
10
|
-
message_id: string;
|
|
11
|
-
message: V12.Sendable;
|
|
12
|
-
}>;
|
|
9
|
+
sendGroupMsg(this: V12, group_id: number, message: V12.Sendable, source?: V12.SegmentElem<'reply'>): Promise<import("icqq").MessageRet>;
|
|
13
10
|
/**
|
|
14
11
|
* 群组踢人
|
|
15
12
|
* @param group_id {number} 群id
|
|
@@ -11,20 +11,13 @@ class GroupAction {
|
|
|
11
11
|
*/
|
|
12
12
|
async sendGroupMsg(group_id, message, source) {
|
|
13
13
|
let { element, quote, music, share } = await utils_1.processMessage.apply(this.client, [message, source]);
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (share)
|
|
21
|
-
await target.shareUrl(share.data);
|
|
22
|
-
return {
|
|
23
|
-
message_id: '',
|
|
24
|
-
message
|
|
25
|
-
};
|
|
14
|
+
if (music)
|
|
15
|
+
await this.client.pickGroup(group_id).shareMusic(music.data.platform, music.data.id);
|
|
16
|
+
if (share)
|
|
17
|
+
await this.client.pickGroup(group_id).shareUrl(music.data);
|
|
18
|
+
if (element.length) {
|
|
19
|
+
return await this.client.sendGroupMsg(group_id, element, quote ? await this.client.getMsg(quote.data.message_id) : undefined);
|
|
26
20
|
}
|
|
27
|
-
return await this.client.sendGroupMsg(group_id, element, quote ? await this.client.getMsg(quote.data.message_id) : undefined);
|
|
28
21
|
}
|
|
29
22
|
/**
|
|
30
23
|
* 群组踢人
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Client, MessageElem } from "icqq";
|
|
2
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
3
|
export declare function processMessage(this: Client, message: V12.Sendable, source?: V12.SegmentElem<'reply'>): Promise<{
|
|
5
4
|
element: MessageElem[];
|
|
6
5
|
music?: V12.SegmentElem<'music'>;
|
|
@@ -1,46 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.processMessage =
|
|
3
|
+
exports.processMessage = void 0;
|
|
4
4
|
const V12_1 = require("../../../service/V12");
|
|
5
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
6
|
async function processMessage(message, source) {
|
|
18
7
|
let segments = [].concat(message).map(m => {
|
|
19
8
|
if (typeof m === 'string')
|
|
20
9
|
return { type: 'text', data: { text: m } };
|
|
21
10
|
return m;
|
|
22
11
|
});
|
|
23
|
-
|
|
12
|
+
let quote = segments.find(e => e.type === 'reply');
|
|
13
|
+
if (quote)
|
|
14
|
+
(0, utils_1.remove)(segments, quote);
|
|
15
|
+
let music = segments.find(e => e.type === 'music');
|
|
24
16
|
if (music)
|
|
25
17
|
(0, utils_1.remove)(segments, music);
|
|
26
|
-
|
|
27
|
-
throw new Error('一次只能发送一个音乐元素');
|
|
28
|
-
if (segments.length && music)
|
|
29
|
-
throw new Error('音乐元素只能单独发送');
|
|
30
|
-
const share = segments.find(e => e.type === 'share');
|
|
18
|
+
let share = segments.find(e => e.type === 'share');
|
|
31
19
|
if (share)
|
|
32
20
|
(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('只能单独发送转发节点');
|
|
41
|
-
let quote = segments.find(e => e.type === 'reply');
|
|
42
|
-
if (quote)
|
|
43
|
-
(0, utils_1.remove)(segments, quote);
|
|
44
21
|
segments = segments.filter(n => [
|
|
45
22
|
'face', 'text', 'image',
|
|
46
23
|
'rpx', 'dice', 'poke', 'mention', 'mention_all',
|
|
@@ -49,20 +26,6 @@ async function processMessage(message, source) {
|
|
|
49
26
|
'music', 'share', 'xml', 'json', 'location', // 分享类
|
|
50
27
|
].includes(n.type));
|
|
51
28
|
const element = V12_1.V12.fromSegment(segments);
|
|
52
|
-
|
|
53
|
-
element.unshift(
|
|
54
|
-
// 构造抓发消息
|
|
55
|
-
await this.makeForwardMsg(await Promise.all(
|
|
56
|
-
// 处理转发消息段
|
|
57
|
-
forwardNodes.map(async (forwardNode) => {
|
|
58
|
-
return {
|
|
59
|
-
// 转发套转发处理
|
|
60
|
-
message: (await processMessage.apply(this, [forwardNode.data.message])).element,
|
|
61
|
-
user_id: Number(forwardNode.data.user_id),
|
|
62
|
-
nickname: forwardNode.data.user_name,
|
|
63
|
-
time: forwardNode.data.time
|
|
64
|
-
};
|
|
65
|
-
}))));
|
|
66
|
-
return { element, quote: quote || source, music, share };
|
|
29
|
+
return { element, quote: quote || source, share, music };
|
|
67
30
|
}
|
|
68
31
|
exports.processMessage = processMessage;
|