onebots 0.2.3 → 0.2.5
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/README.md +2 -2
- package/lib/onebot.js +41 -6
- 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/utils.d.ts +9 -0
- package/lib/service/V11/utils.js +19 -0
- package/lib/service/V12/action/friend.d.ts +1 -4
- package/lib/service/V12/action/friend.js +7 -14
- package/lib/service/V12/action/group.d.ts +1 -4
- package/lib/service/V12/action/group.js +7 -14
- package/lib/service/V12/action/guild.js +1 -1
- package/lib/service/V12/index.d.ts +6 -1
- package/lib/service/V12/{action/utils.d.ts → utils.d.ts} +1 -2
- package/lib/service/V12/utils.js +31 -0
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +5 -5
- package/package.json +7 -3
- package/lib/service/V12/action/utils.js +0 -68
package/README.md
CHANGED
|
@@ -79,5 +79,5 @@ node ./index.js
|
|
|
79
79
|
| /remove | get | uin,force | 移除机器人,force为true时,将删除机器人data目录 |
|
|
80
80
|
|
|
81
81
|
# 鸣谢
|
|
82
|
-
1. [
|
|
83
|
-
2. [takayama-lily/onebot](https://github.com/takayama-lily/node-onebot)
|
|
82
|
+
1. [icqqjs/icqq](https://github.com/icqqjs/icqq) 底层服务支持
|
|
83
|
+
2. [takayama-lily/onebot](https://github.com/takayama-lily/node-onebot) oneBot V11 原先版本
|
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,23 @@ 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('
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
93
|
+
this.client.trap('system.login.device', function deviceHelper(e) {
|
|
94
|
+
console.log('请选择验证方式:1.短信验证 2.url验证');
|
|
95
|
+
process.stdin.once('data', (buf) => {
|
|
96
|
+
const input = e.toString().trim();
|
|
97
|
+
if (input === '1') {
|
|
98
|
+
this.sendSmsCode();
|
|
99
|
+
console.log('请输入短信验证码:');
|
|
100
|
+
process.stdin.once('data', buf => {
|
|
101
|
+
this.submitSmsCode(buf.toString().trim());
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
console.log(`请前往:${e.url} 完成验证后回车继续`);
|
|
106
|
+
process.stdin.once('data', () => {
|
|
107
|
+
this.login();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
74
110
|
});
|
|
75
111
|
disposeArr.push(() => {
|
|
76
112
|
this.off('system.login.device', deviceHelper);
|
|
@@ -88,7 +124,6 @@ class OneBot extends events_1.EventEmitter {
|
|
|
88
124
|
this.off('system.login.error', errorHandler);
|
|
89
125
|
});
|
|
90
126
|
this.client.trap('system.login.slider', function sliderHelper(e) {
|
|
91
|
-
console.log('滑块验证地址:' + e.url);
|
|
92
127
|
console.log('请输入滑块验证返回的ticket');
|
|
93
128
|
process.stdin.once('data', (e) => {
|
|
94
129
|
this.submitSlider(e.toString().trim());
|
|
@@ -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/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_id ? 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.pickFriend(user_id).shareMusic(music.data.platform, music.data.id);
|
|
17
|
+
if (share)
|
|
18
|
+
await this.client.pickFriend(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/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_id ? 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
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FriendAction = void 0;
|
|
4
|
-
const utils_1 = require("../../../service/V12/
|
|
4
|
+
const utils_1 = require("../../../service/V12/utils");
|
|
5
5
|
class FriendAction {
|
|
6
6
|
getUserInfo(user_id) {
|
|
7
7
|
return this.client.getStrangerInfo(user_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.pickFriend(user_id).shareMusic(music.data.platform, music.data.id);
|
|
22
|
+
if (share)
|
|
23
|
+
await this.client.pickFriend(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
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GroupAction = void 0;
|
|
4
|
-
const utils_1 = require("../../../service/V12/
|
|
4
|
+
const utils_1 = require("../../../service/V12/utils");
|
|
5
5
|
class GroupAction {
|
|
6
6
|
/**
|
|
7
7
|
* 发送群聊消息
|
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GuildAction = void 0;
|
|
4
|
-
const utils_1 = require("../../../service/V12/
|
|
4
|
+
const utils_1 = require("../../../service/V12/utils");
|
|
5
5
|
class GuildAction {
|
|
6
6
|
getGuildList() {
|
|
7
7
|
return this.client.getGuildList();
|
|
@@ -38,7 +38,7 @@ export declare class V12 extends EventEmitter implements OneBot.Base {
|
|
|
38
38
|
sub_type: string;
|
|
39
39
|
} & Omit<V12.BotEventMap[E], E>;
|
|
40
40
|
dispatch(data: Record<string, any>): void;
|
|
41
|
-
apply(req:
|
|
41
|
+
apply(req: V12.RequestAction): Promise<string>;
|
|
42
42
|
private _httpRequestHandler;
|
|
43
43
|
/**
|
|
44
44
|
* 快速操作
|
|
@@ -215,4 +215,9 @@ export declare namespace V12 {
|
|
|
215
215
|
type: string;
|
|
216
216
|
sub_type: string;
|
|
217
217
|
} & Omit<BotEventMap[K], K>;
|
|
218
|
+
type RequestAction = {
|
|
219
|
+
action: string;
|
|
220
|
+
params: Record<string, any>;
|
|
221
|
+
echo?: number;
|
|
222
|
+
};
|
|
218
223
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Client, MessageElem } from "icqq";
|
|
2
|
-
import { V12 } from "
|
|
3
|
-
export declare function processMusic(this: Client, target_type: 'group' | 'friend', target_id: number, element: any[]): Promise<any[]>;
|
|
2
|
+
import { V12 } from "../../service/V12";
|
|
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'>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processMessage = void 0;
|
|
4
|
+
const V12_1 = require("../../service/V12");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
async function processMessage(message, source) {
|
|
7
|
+
let segments = [].concat(message).map(m => {
|
|
8
|
+
if (typeof m === 'string')
|
|
9
|
+
return { type: 'text', data: { text: m } };
|
|
10
|
+
return m;
|
|
11
|
+
});
|
|
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');
|
|
16
|
+
if (music)
|
|
17
|
+
(0, utils_1.remove)(segments, music);
|
|
18
|
+
let share = segments.find(e => e.type === 'share');
|
|
19
|
+
if (share)
|
|
20
|
+
(0, utils_1.remove)(segments, share);
|
|
21
|
+
segments = segments.filter(n => [
|
|
22
|
+
'face', 'text', 'image',
|
|
23
|
+
'rpx', 'dice', 'poke', 'mention', 'mention_all',
|
|
24
|
+
'voice', 'file', 'record',
|
|
25
|
+
'forward', 'node',
|
|
26
|
+
'music', 'share', 'xml', 'json', 'location', // 分享类
|
|
27
|
+
].includes(n.type));
|
|
28
|
+
const element = V12_1.V12.fromSegment(segments);
|
|
29
|
+
return { element, quote: quote || source, share, music };
|
|
30
|
+
}
|
|
31
|
+
exports.processMessage = processMessage;
|
package/lib/utils.d.ts
CHANGED
|
@@ -4,13 +4,13 @@ export declare function transformObj(obj: any, callback: any): any;
|
|
|
4
4
|
export declare function deepClone<T extends any>(obj: T): T;
|
|
5
5
|
export declare function pick<T extends object, K extends keyof T>(source: T, keys?: Iterable<K>, forced?: boolean): Pick<T, K>;
|
|
6
6
|
export declare function omit<T, K extends keyof T>(source: T, keys?: Iterable<K>): Omit<T, K>;
|
|
7
|
+
export declare function toLine<T extends string>(name: T): string;
|
|
7
8
|
export interface Class {
|
|
8
9
|
new (...args: any[]): any;
|
|
9
10
|
}
|
|
10
11
|
export declare function Mixin(base: Class, ...classes: Class[]): Class;
|
|
11
12
|
export declare function toHump(action: string): string;
|
|
12
13
|
export declare function remove<T>(list: T[], item: T): void;
|
|
13
|
-
export declare function toLine(name: string): string;
|
|
14
14
|
export declare function toBool(v: any): boolean;
|
|
15
15
|
export declare function uuid(): string;
|
|
16
16
|
export declare function protectedFields<T>(source: T, ...keys: (keyof T)[]): T;
|
package/lib/utils.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getProperties = exports.protectedFields = exports.uuid = exports.toBool = exports.
|
|
26
|
+
exports.getProperties = exports.protectedFields = exports.uuid = exports.toBool = exports.remove = exports.toHump = exports.Mixin = exports.toLine = exports.omit = exports.pick = exports.deepClone = exports.transformObj = exports.deepMerge = exports.version = void 0;
|
|
27
27
|
const crypto = __importStar(require("crypto"));
|
|
28
28
|
const packageJson = require('../package.json');
|
|
29
29
|
exports.version = packageJson.version;
|
|
@@ -114,6 +114,10 @@ function omit(source, keys) {
|
|
|
114
114
|
return result;
|
|
115
115
|
}
|
|
116
116
|
exports.omit = omit;
|
|
117
|
+
function toLine(name) {
|
|
118
|
+
return name.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
119
|
+
}
|
|
120
|
+
exports.toLine = toLine;
|
|
117
121
|
function Mixin(base, ...classes) {
|
|
118
122
|
classes.forEach(ctr => {
|
|
119
123
|
Object.getOwnPropertyNames(ctr.prototype).forEach(name => {
|
|
@@ -137,10 +141,6 @@ function remove(list, item) {
|
|
|
137
141
|
list.splice(idx, 1);
|
|
138
142
|
}
|
|
139
143
|
exports.remove = remove;
|
|
140
|
-
function toLine(name) {
|
|
141
|
-
return name.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
142
|
-
}
|
|
143
|
-
exports.toLine = toLine;
|
|
144
144
|
function toBool(v) {
|
|
145
145
|
if (v === "0" || v === "false")
|
|
146
146
|
v = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onebots",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "基于icqq的多例oneBot实现",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16"
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
|
|
15
15
|
"dev": "ts-node-dev -r tsconfig-paths/register ./src/bin.ts -c config.yaml",
|
|
16
16
|
"pub": "npm publish --access public",
|
|
17
|
+
"docs:dev": "vitepress dev docs --port 8989",
|
|
18
|
+
"docs:build": "vitepress build docs",
|
|
19
|
+
"docs:preview": "vitepress preview docs",
|
|
17
20
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
18
21
|
},
|
|
19
22
|
"repository": {
|
|
@@ -40,7 +43,8 @@
|
|
|
40
43
|
"ts-node-dev": "latest",
|
|
41
44
|
"tsc-alias": "latest",
|
|
42
45
|
"tsconfig-paths": "latest",
|
|
43
|
-
"typescript": "latest"
|
|
46
|
+
"typescript": "latest",
|
|
47
|
+
"vitepress": "^1.0.0-alpha.72"
|
|
44
48
|
},
|
|
45
49
|
"files": [
|
|
46
50
|
"/lib/**/*.js",
|
|
@@ -50,7 +54,7 @@
|
|
|
50
54
|
],
|
|
51
55
|
"dependencies": {
|
|
52
56
|
"@koa/router": "^10.1.1",
|
|
53
|
-
"icqq": "^0.
|
|
57
|
+
"icqq": "^0.3.6",
|
|
54
58
|
"icqq-cq-enable": "^1.0.0",
|
|
55
59
|
"js-yaml": "^4.1.0",
|
|
56
60
|
"koa": "^2.13.4",
|
|
@@ -1,68 +0,0 @@
|
|
|
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, source) {
|
|
18
|
-
let segments = [].concat(message).map(m => {
|
|
19
|
-
if (typeof m === 'string')
|
|
20
|
-
return { type: 'text', data: { text: m } };
|
|
21
|
-
return m;
|
|
22
|
-
});
|
|
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('只能单独发送转发节点');
|
|
41
|
-
let quote = segments.find(e => e.type === 'reply');
|
|
42
|
-
if (quote)
|
|
43
|
-
(0, utils_1.remove)(segments, quote);
|
|
44
|
-
segments = segments.filter(n => [
|
|
45
|
-
'face', 'text', 'image',
|
|
46
|
-
'rpx', 'dice', 'poke', 'mention', 'mention_all',
|
|
47
|
-
'voice', 'file', 'record',
|
|
48
|
-
'forward', 'node',
|
|
49
|
-
'music', 'share', 'xml', 'json', 'location', // 分享类
|
|
50
|
-
].includes(n.type));
|
|
51
|
-
const element = V12_1.V12.fromSegment(segments);
|
|
52
|
-
if (forwardNodes.length)
|
|
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 };
|
|
67
|
-
}
|
|
68
|
-
exports.processMessage = processMessage;
|