onebots 0.4.23 → 0.4.25
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 +25 -3
- package/lib/adapter.d.ts +55 -0
- package/lib/adapter.js +60 -0
- package/lib/adapters/icqq/index.d.ts +36 -0
- package/lib/adapters/icqq/index.js +300 -0
- package/lib/adapters/qq/bot.d.ts +24 -0
- package/lib/adapters/qq/bot.js +20 -0
- package/lib/adapters/qq/constans.d.ts +69 -0
- package/lib/adapters/qq/constans.js +128 -0
- package/lib/adapters/qq/elements.d.ts +125 -0
- package/lib/adapters/qq/elements.js +8 -0
- package/lib/adapters/qq/entries/channel.d.ts +17 -0
- package/lib/adapters/qq/entries/channel.js +2 -0
- package/lib/adapters/qq/entries/friend.d.ts +8 -0
- package/lib/adapters/qq/entries/friend.js +2 -0
- package/lib/adapters/qq/entries/group.d.ts +6 -0
- package/lib/adapters/qq/entries/group.js +2 -0
- package/lib/adapters/qq/entries/groupMember.d.ts +7 -0
- package/lib/adapters/qq/entries/groupMember.js +2 -0
- package/lib/adapters/qq/entries/guild.d.ts +21 -0
- package/lib/adapters/qq/entries/guild.js +2 -0
- package/lib/adapters/qq/entries/guildMember.d.ts +9 -0
- package/lib/adapters/qq/entries/guildMember.js +2 -0
- package/lib/adapters/qq/entries/user.d.ts +9 -0
- package/lib/adapters/qq/entries/user.js +2 -0
- package/lib/adapters/qq/event.d.ts +28 -0
- package/lib/adapters/qq/event.js +24 -0
- package/lib/adapters/qq/index.d.ts +35 -0
- package/lib/adapters/qq/index.js +170 -0
- package/lib/adapters/qq/message.d.ts +83 -0
- package/lib/adapters/qq/message.js +272 -0
- package/lib/adapters/qq/qqBot.d.ts +122 -0
- package/lib/adapters/qq/qqBot.js +438 -0
- package/lib/adapters/qq/sessionManager.d.ts +33 -0
- package/lib/adapters/qq/sessionManager.js +257 -0
- package/lib/adapters/qq/types.d.ts +45 -0
- package/lib/adapters/qq/types.js +2 -0
- package/lib/adapters/qq/utils.d.ts +12 -0
- package/lib/adapters/qq/utils.js +86 -0
- package/lib/bin.js +17 -2
- package/lib/config.sample.yaml +11 -5
- package/lib/onebot.d.ts +32 -24
- package/lib/onebot.js +51 -188
- package/lib/server/app.d.ts +22 -12
- package/lib/server/app.js +97 -71
- package/lib/service/V11/action/common.d.ts +9 -11
- package/lib/service/V11/action/common.js +27 -64
- package/lib/service/V11/action/friend.d.ts +5 -13
- package/lib/service/V11/action/friend.js +6 -16
- package/lib/service/V11/action/group.d.ts +19 -22
- package/lib/service/V11/action/group.js +20 -30
- package/lib/service/V11/action/index.d.ts +1 -1
- package/lib/service/V11/db_entities.d.ts +1 -1
- package/lib/service/V11/db_entities.js +1 -1
- package/lib/service/V11/db_sqlite.d.ts +1 -1
- package/lib/service/V11/index.d.ts +47 -16
- package/lib/service/V11/index.js +142 -164
- package/lib/service/V12/action/common.d.ts +3 -67
- package/lib/service/V12/action/common.js +9 -63
- package/lib/service/V12/action/friend.d.ts +4 -10
- package/lib/service/V12/action/friend.js +4 -12
- package/lib/service/V12/action/group.d.ts +19 -21
- package/lib/service/V12/action/group.js +19 -27
- package/lib/service/V12/action/guild.d.ts +40 -13
- package/lib/service/V12/action/guild.js +99 -11
- package/lib/service/V12/action/index.d.ts +1 -1
- package/lib/service/V12/index.d.ts +37 -13
- package/lib/service/V12/index.js +44 -72
- package/lib/service.d.ts +7 -2
- package/lib/service.js +32 -30
- package/lib/utils.d.ts +7 -4
- package/lib/utils.js +33 -28
- package/package.json +5 -4
- package/lib/service/V12/utils.d.ts +0 -8
- package/lib/service/V12/utils.js +0 -47
- /package/lib/{service/V11 → adapters/icqq}/utils.d.ts +0 -0
- /package/lib/{service/V11 → adapters/icqq}/utils.js +0 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SpeakPermission = exports.PrivateType = exports.ChannelSubType = exports.ChannelType = exports.Intends = exports.WebsocketCloseReason = exports.SessionEvents = exports.OpCode = void 0;
|
|
4
|
+
// 心跳参数
|
|
5
|
+
var OpCode;
|
|
6
|
+
(function (OpCode) {
|
|
7
|
+
OpCode[OpCode["DISPATCH"] = 0] = "DISPATCH";
|
|
8
|
+
OpCode[OpCode["HEARTBEAT"] = 1] = "HEARTBEAT";
|
|
9
|
+
OpCode[OpCode["IDENTIFY"] = 2] = "IDENTIFY";
|
|
10
|
+
OpCode[OpCode["RESUME"] = 6] = "RESUME";
|
|
11
|
+
OpCode[OpCode["RECONNECT"] = 7] = "RECONNECT";
|
|
12
|
+
OpCode[OpCode["INVALID_SESSION"] = 9] = "INVALID_SESSION";
|
|
13
|
+
OpCode[OpCode["HELLO"] = 10] = "HELLO";
|
|
14
|
+
OpCode[OpCode["HEARTBEAT_ACK"] = 11] = "HEARTBEAT_ACK";
|
|
15
|
+
})(OpCode || (exports.OpCode = OpCode = {}));
|
|
16
|
+
exports.SessionEvents = {
|
|
17
|
+
CLOSED: "CLOSED",
|
|
18
|
+
READY: "READY",
|
|
19
|
+
ERROR: "ERROR",
|
|
20
|
+
INVALID_SESSION: "INVALID_SESSION",
|
|
21
|
+
RECONNECT: "RECONNECT",
|
|
22
|
+
DISCONNECT: "DISCONNECT",
|
|
23
|
+
EVENT_WS: "EVENT_WS",
|
|
24
|
+
RESUMED: "RESUMED",
|
|
25
|
+
DEAD: "DEAD" // 连接已死亡,请检查网络或重启
|
|
26
|
+
};
|
|
27
|
+
// websocket错误原因
|
|
28
|
+
exports.WebsocketCloseReason = [
|
|
29
|
+
{
|
|
30
|
+
code: 4001,
|
|
31
|
+
reason: "无效的opcode"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
code: 4002,
|
|
35
|
+
reason: "无效的payload"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
code: 4007,
|
|
39
|
+
reason: "seq错误"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
code: 4008,
|
|
43
|
+
reason: "发送 payload 过快,请重新连接,并遵守连接后返回的频控信息",
|
|
44
|
+
resume: true
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
code: 4009,
|
|
48
|
+
reason: "连接过期,请重连",
|
|
49
|
+
resume: true
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
code: 4010,
|
|
53
|
+
reason: "无效的shard"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
code: 4011,
|
|
57
|
+
reason: "连接需要处理的guild过多,请进行合理分片"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
code: 4012,
|
|
61
|
+
reason: "无效的version"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
code: 4013,
|
|
65
|
+
reason: "无效的intent"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
code: 4014,
|
|
69
|
+
reason: "intent无权限"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
code: 4900,
|
|
73
|
+
reason: "内部错误,请重连"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
code: 4914,
|
|
77
|
+
reason: "机器人已下架,只允许连接沙箱环境,请断开连接,检验当前连接环境"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
code: 4915,
|
|
81
|
+
reason: "机器人已封禁,不允许连接,请断开连接,申请解封后再连接"
|
|
82
|
+
}
|
|
83
|
+
];
|
|
84
|
+
var Intends;
|
|
85
|
+
(function (Intends) {
|
|
86
|
+
Intends[Intends["GUILDS"] = 1] = "GUILDS";
|
|
87
|
+
Intends[Intends["GUILD_MEMBERS"] = 2] = "GUILD_MEMBERS";
|
|
88
|
+
Intends[Intends["GUILD_MESSAGES"] = 512] = "GUILD_MESSAGES";
|
|
89
|
+
Intends[Intends["GUILD_MESSAGE_REACTIONS"] = 1024] = "GUILD_MESSAGE_REACTIONS";
|
|
90
|
+
Intends[Intends["DIRECT_MESSAGE"] = 4096] = "DIRECT_MESSAGE";
|
|
91
|
+
Intends[Intends["OPEN_FORUMS_EVENTS"] = 262144] = "OPEN_FORUMS_EVENTS";
|
|
92
|
+
Intends[Intends["AUDIO_OR_LIVE_CHANNEL_MEMBERS"] = 524288] = "AUDIO_OR_LIVE_CHANNEL_MEMBERS";
|
|
93
|
+
// GROUP_MESSAGE_CREATE = 1 << 24, // 群聊消息事件
|
|
94
|
+
Intends[Intends["C2C_MESSAGE_CREATE"] = 33554432] = "C2C_MESSAGE_CREATE";
|
|
95
|
+
Intends[Intends["GROUP_AT_MESSAGE_CREATE"] = 33554432] = "GROUP_AT_MESSAGE_CREATE";
|
|
96
|
+
Intends[Intends["INTERACTION"] = 67108864] = "INTERACTION";
|
|
97
|
+
Intends[Intends["MESSAGE_AUDIT"] = 134217728] = "MESSAGE_AUDIT";
|
|
98
|
+
Intends[Intends["FORUMS_EVENTS"] = 268435456] = "FORUMS_EVENTS";
|
|
99
|
+
Intends[Intends["AUDIO_ACTIONS"] = 536870912] = "AUDIO_ACTIONS";
|
|
100
|
+
Intends[Intends["PUBLIC_GUILD_MESSAGES"] = 1073741824] = "PUBLIC_GUILD_MESSAGES";
|
|
101
|
+
})(Intends || (exports.Intends = Intends = {}));
|
|
102
|
+
var ChannelType;
|
|
103
|
+
(function (ChannelType) {
|
|
104
|
+
ChannelType[ChannelType["Content"] = 0] = "Content";
|
|
105
|
+
ChannelType[ChannelType["Record"] = 2] = "Record";
|
|
106
|
+
ChannelType[ChannelType["ChannelGroup"] = 4] = "ChannelGroup";
|
|
107
|
+
ChannelType[ChannelType["Live"] = 10005] = "Live";
|
|
108
|
+
ChannelType[ChannelType["App"] = 10006] = "App";
|
|
109
|
+
ChannelType[ChannelType["Forms"] = 10007] = "Forms";
|
|
110
|
+
})(ChannelType || (exports.ChannelType = ChannelType = {}));
|
|
111
|
+
var ChannelSubType;
|
|
112
|
+
(function (ChannelSubType) {
|
|
113
|
+
ChannelSubType[ChannelSubType["Chat"] = 0] = "Chat";
|
|
114
|
+
ChannelSubType[ChannelSubType["Announces"] = 1] = "Announces";
|
|
115
|
+
ChannelSubType[ChannelSubType["Strategy"] = 2] = "Strategy";
|
|
116
|
+
ChannelSubType[ChannelSubType["Black"] = 3] = "Black";
|
|
117
|
+
})(ChannelSubType || (exports.ChannelSubType = ChannelSubType = {}));
|
|
118
|
+
var PrivateType;
|
|
119
|
+
(function (PrivateType) {
|
|
120
|
+
PrivateType[PrivateType["Public"] = 0] = "Public";
|
|
121
|
+
PrivateType[PrivateType["Admin"] = 1] = "Admin";
|
|
122
|
+
PrivateType[PrivateType["Some"] = 2] = "Some";
|
|
123
|
+
})(PrivateType || (exports.PrivateType = PrivateType = {}));
|
|
124
|
+
var SpeakPermission;
|
|
125
|
+
(function (SpeakPermission) {
|
|
126
|
+
SpeakPermission[SpeakPermission["All"] = 1] = "All";
|
|
127
|
+
SpeakPermission[SpeakPermission["Some"] = 2] = "Some";
|
|
128
|
+
})(SpeakPermission || (exports.SpeakPermission = SpeakPermission = {}));
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Dict } from './types';
|
|
3
|
+
export declare enum MusicPlatform {
|
|
4
|
+
qq = "qq",
|
|
5
|
+
netease = "163"
|
|
6
|
+
}
|
|
7
|
+
export interface Quotable {
|
|
8
|
+
event_id?: string;
|
|
9
|
+
message_id?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface MessageElemMap {
|
|
12
|
+
text: {
|
|
13
|
+
text: string;
|
|
14
|
+
};
|
|
15
|
+
at: {
|
|
16
|
+
/** 在频道消息中该值为0 */
|
|
17
|
+
qq: number | "all";
|
|
18
|
+
/** 频道中的`tiny_id` */
|
|
19
|
+
id?: string | "all";
|
|
20
|
+
/** AT后跟的字符串,接收消息时有效 */
|
|
21
|
+
text?: string;
|
|
22
|
+
/** 假AT */
|
|
23
|
+
dummy?: boolean;
|
|
24
|
+
};
|
|
25
|
+
face: {
|
|
26
|
+
/** face为0~348,sface不明 */
|
|
27
|
+
id: number;
|
|
28
|
+
/** 表情说明,接收消息时有效 */
|
|
29
|
+
text?: string;
|
|
30
|
+
/** 大表情 */
|
|
31
|
+
qlottie?: string;
|
|
32
|
+
};
|
|
33
|
+
image: {
|
|
34
|
+
/**
|
|
35
|
+
* @type {string} 本地图片文件路径,例如`"/tmp/1.jpg"`
|
|
36
|
+
* @type {Buffer} 图片`Buffer`
|
|
37
|
+
*/
|
|
38
|
+
file: string | Buffer;
|
|
39
|
+
/** 网络图片是否使用缓存 */
|
|
40
|
+
cache?: boolean;
|
|
41
|
+
/** 流的超时时间,默认60(秒) */
|
|
42
|
+
timeout?: number;
|
|
43
|
+
headers?: import("http").OutgoingHttpHeaders;
|
|
44
|
+
/** 图片url地址,接收时有效 */
|
|
45
|
+
url?: string;
|
|
46
|
+
/** 是否作为表情发送 */
|
|
47
|
+
asface?: boolean;
|
|
48
|
+
/** 是否显示下载原图按钮 */
|
|
49
|
+
origin?: boolean;
|
|
50
|
+
};
|
|
51
|
+
video: {
|
|
52
|
+
/**
|
|
53
|
+
* 需要`ffmpeg`和`ffprobe`
|
|
54
|
+
* @type {string} 本地视频文件路径,例如`"/tmp/1.mp4"`
|
|
55
|
+
*/
|
|
56
|
+
file: string;
|
|
57
|
+
/** 视频名,接收时有效 */
|
|
58
|
+
name?: string;
|
|
59
|
+
/** 作为文件的文件id,接收时有效 */
|
|
60
|
+
fid?: string;
|
|
61
|
+
md5?: string;
|
|
62
|
+
/** 文件大小,接收时有效 */
|
|
63
|
+
size?: number;
|
|
64
|
+
/** 视频时长(秒),接收时有效 */
|
|
65
|
+
seconds?: number;
|
|
66
|
+
};
|
|
67
|
+
audio: {
|
|
68
|
+
/**
|
|
69
|
+
* 支持`raw silk`和`amr`文件
|
|
70
|
+
* @type {string} 本地语音文件路径,例如`"/tmp/1.slk"`
|
|
71
|
+
* @type {Buffer} ptt buffer (silk or amr)
|
|
72
|
+
*/
|
|
73
|
+
file: string | Buffer;
|
|
74
|
+
/** 语言url地址,接收时有效 */
|
|
75
|
+
url?: string;
|
|
76
|
+
md5?: string;
|
|
77
|
+
/** 文件大小,接收时有效 */
|
|
78
|
+
size?: number;
|
|
79
|
+
/** 语音时长(秒),接收时有效 */
|
|
80
|
+
seconds?: number;
|
|
81
|
+
};
|
|
82
|
+
xml: {
|
|
83
|
+
id?: number;
|
|
84
|
+
data: string;
|
|
85
|
+
};
|
|
86
|
+
json: {
|
|
87
|
+
res_id?: string;
|
|
88
|
+
data: string | Record<string, any>;
|
|
89
|
+
};
|
|
90
|
+
markdown: {
|
|
91
|
+
content: string;
|
|
92
|
+
};
|
|
93
|
+
music: {
|
|
94
|
+
id: number;
|
|
95
|
+
platform: MusicPlatform;
|
|
96
|
+
};
|
|
97
|
+
reply: Quotable;
|
|
98
|
+
link: {
|
|
99
|
+
channel_id: string;
|
|
100
|
+
};
|
|
101
|
+
button: {
|
|
102
|
+
data: Dict;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export type MessageElemType = keyof MessageElemMap;
|
|
106
|
+
export type MessageElem<T extends MessageElemType = MessageElemType> = {
|
|
107
|
+
type: T;
|
|
108
|
+
} & MessageElemMap[T];
|
|
109
|
+
export type TextElem = MessageElem<"text">;
|
|
110
|
+
export type AtElem = MessageElem<"at">;
|
|
111
|
+
export type FaceElem = MessageElem<"face">;
|
|
112
|
+
export type ImageElem = MessageElem<"image">;
|
|
113
|
+
export type VideoElem = MessageElem<"video">;
|
|
114
|
+
export type AudioElem = MessageElem<"audio">;
|
|
115
|
+
export type LinkElem = MessageElem<'link'>;
|
|
116
|
+
export type XmlElem = MessageElem<"xml">;
|
|
117
|
+
export type JsonElem = MessageElem<"json">;
|
|
118
|
+
export type MDElem = MessageElem<'markdown'>;
|
|
119
|
+
export type MusicElem = MessageElem<"music">;
|
|
120
|
+
export type ButtonElem = MessageElem<'button'>;
|
|
121
|
+
export type ReplyElem = MessageElem<"reply">;
|
|
122
|
+
type RepeatableCombineElem = TextElem | FaceElem | ImageElem | AtElem | ButtonElem;
|
|
123
|
+
type WithReply<T extends MessageElem> = T | [T] | [ReplyElem, T] | [ReplyElem, ...RepeatableCombineElem[]];
|
|
124
|
+
export type Sendable = string | RepeatableCombineElem | (RepeatableCombineElem | string)[] | WithReply<MDElem | LinkElem | VideoElem | AudioElem | XmlElem | MusicElem | JsonElem>;
|
|
125
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MusicPlatform = void 0;
|
|
4
|
+
var MusicPlatform;
|
|
5
|
+
(function (MusicPlatform) {
|
|
6
|
+
MusicPlatform["qq"] = "qq";
|
|
7
|
+
MusicPlatform["netease"] = "163";
|
|
8
|
+
})(MusicPlatform || (exports.MusicPlatform = MusicPlatform = {}));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ChannelSubType, ChannelType, PrivateType, SpeakPermission } from "../constans";
|
|
2
|
+
export declare namespace Channel {
|
|
3
|
+
interface Info {
|
|
4
|
+
id: string;
|
|
5
|
+
guild_id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
type: ChannelType;
|
|
8
|
+
sub_type: ChannelSubType;
|
|
9
|
+
position: number;
|
|
10
|
+
parent_id?: string;
|
|
11
|
+
owner_id: string;
|
|
12
|
+
private_type: PrivateType;
|
|
13
|
+
speak_permission: SpeakPermission;
|
|
14
|
+
application_id?: string;
|
|
15
|
+
permissions?: string;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare namespace Guild {
|
|
2
|
+
interface Info {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
icon: string;
|
|
6
|
+
owner_id: string;
|
|
7
|
+
owner: boolean;
|
|
8
|
+
join_time: number;
|
|
9
|
+
member_count: number;
|
|
10
|
+
max_members: number;
|
|
11
|
+
description: string;
|
|
12
|
+
}
|
|
13
|
+
interface Role {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
color: string;
|
|
17
|
+
hoist: boolean;
|
|
18
|
+
number: number;
|
|
19
|
+
member_limit: number;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DirectMessageEvent, GroupMessageEvent, GuildMessageEvent, PrivateMessageEvent } from "./message";
|
|
2
|
+
export declare enum QQEvent {
|
|
3
|
+
DIRECT_MESSAGE_CREATE = "message.direct",
|
|
4
|
+
AT_MESSAGE_CREATE = "message.guild",
|
|
5
|
+
MESSAGE_CREATE = "message.guild",
|
|
6
|
+
GUILD_CREATE = "notice.guild.increase",
|
|
7
|
+
GUILD_UPDATE = "notice.guild.update",
|
|
8
|
+
GUILD_DELETE = "notice.guild.decrease",
|
|
9
|
+
CHANNEL_CREATE = "notice.channel.increase",
|
|
10
|
+
CHANNEL_UPDATE = "notice.channel.update",
|
|
11
|
+
CHANNEL_DELETE = "notice.channel.decrease",
|
|
12
|
+
GUILD_MEMBER_ADD = "notice.guild.member.increase",
|
|
13
|
+
GUILD_MEMBER_UPDATE = "notice.guild.member.update",
|
|
14
|
+
GUILD_MEMBER_REMOVE = "notice.guild.member.decrease",
|
|
15
|
+
GROUP_ADD_ROBOT = "notice.group.increase",
|
|
16
|
+
GROUP_DEL_ROBOT = "notice.group.decrease",
|
|
17
|
+
FRIEND_ADD = "notice.friend.add",
|
|
18
|
+
FRIEND_DEL = "notice.friend.del",
|
|
19
|
+
C2C_MESSAGE_CREATE = "message.private",
|
|
20
|
+
GROUP_AT_MESSAGE_CREATE = "message.group"
|
|
21
|
+
}
|
|
22
|
+
export interface EventMap {
|
|
23
|
+
'message'(e: PrivateMessageEvent | GroupMessageEvent | GuildMessageEvent | DirectMessageEvent): void;
|
|
24
|
+
'message.direct'(e: DirectMessageEvent): void;
|
|
25
|
+
'message.group'(e: GroupMessageEvent): void;
|
|
26
|
+
'message.private'(e: PrivateMessageEvent): void;
|
|
27
|
+
'message.guild'(e: GuildMessageEvent): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QQEvent = void 0;
|
|
4
|
+
var QQEvent;
|
|
5
|
+
(function (QQEvent) {
|
|
6
|
+
QQEvent["DIRECT_MESSAGE_CREATE"] = "message.direct";
|
|
7
|
+
QQEvent["AT_MESSAGE_CREATE"] = "message.guild";
|
|
8
|
+
QQEvent["MESSAGE_CREATE"] = "message.guild";
|
|
9
|
+
QQEvent["GUILD_CREATE"] = "notice.guild.increase";
|
|
10
|
+
QQEvent["GUILD_UPDATE"] = "notice.guild.update";
|
|
11
|
+
QQEvent["GUILD_DELETE"] = "notice.guild.decrease";
|
|
12
|
+
QQEvent["CHANNEL_CREATE"] = "notice.channel.increase";
|
|
13
|
+
QQEvent["CHANNEL_UPDATE"] = "notice.channel.update";
|
|
14
|
+
QQEvent["CHANNEL_DELETE"] = "notice.channel.decrease";
|
|
15
|
+
QQEvent["GUILD_MEMBER_ADD"] = "notice.guild.member.increase";
|
|
16
|
+
QQEvent["GUILD_MEMBER_UPDATE"] = "notice.guild.member.update";
|
|
17
|
+
QQEvent["GUILD_MEMBER_REMOVE"] = "notice.guild.member.decrease";
|
|
18
|
+
QQEvent["GROUP_ADD_ROBOT"] = "notice.group.increase";
|
|
19
|
+
QQEvent["GROUP_DEL_ROBOT"] = "notice.group.decrease";
|
|
20
|
+
QQEvent["FRIEND_ADD"] = "notice.friend.add";
|
|
21
|
+
QQEvent["FRIEND_DEL"] = "notice.friend.del";
|
|
22
|
+
QQEvent["C2C_MESSAGE_CREATE"] = "message.private";
|
|
23
|
+
QQEvent["GROUP_AT_MESSAGE_CREATE"] = "message.group";
|
|
24
|
+
})(QQEvent || (exports.QQEvent = QQEvent = {}));
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Adapter } from "../../adapter";
|
|
2
|
+
import { App } from "../../server/app";
|
|
3
|
+
import { OneBot } from "../../onebot";
|
|
4
|
+
export default class QQAdapter extends Adapter<'qq'> {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(app: App, config: QQAdapter.Config);
|
|
7
|
+
startOneBot(oneBot: OneBot): Promise<() => void>;
|
|
8
|
+
call(uin: string, version: string, method: string, args?: any[]): Promise<any>;
|
|
9
|
+
fromSegment<V extends OneBot.Version>(version: V, segment: OneBot.Segment<V> | OneBot.Segment<V>[]): OneBot.MessageElement<V>[];
|
|
10
|
+
toSegment<V extends OneBot.Version>(version: V, message: OneBot.MessageElement<V>[]): OneBot.Segment<V>[];
|
|
11
|
+
fromCqcode<V extends OneBot.Version>(version: V, message: string): OneBot.MessageElement<V>[];
|
|
12
|
+
toCqcode<V extends OneBot.Version>(version: V, messageArr: OneBot.MessageElement<V>[]): string;
|
|
13
|
+
formatEventPayload<V extends OneBot.Version>(version: V, event: string, data: any): OneBot.Payload<V>;
|
|
14
|
+
start(uin: string): Promise<void>;
|
|
15
|
+
stop(uin?: string): Promise<void>;
|
|
16
|
+
getSelfInfo<V extends OneBot.Version>(uin: string, version: V): OneBot.SelfInfo<V>;
|
|
17
|
+
}
|
|
18
|
+
declare module '../../adapter' {
|
|
19
|
+
namespace Adapter {
|
|
20
|
+
interface Configs {
|
|
21
|
+
qq: QQAdapter.Config;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export declare namespace QQAdapter {
|
|
26
|
+
interface Config extends Adapter.Config<'qq'> {
|
|
27
|
+
protocol: {
|
|
28
|
+
secret: string;
|
|
29
|
+
token: string;
|
|
30
|
+
sandbox?: boolean;
|
|
31
|
+
maxRetry?: number;
|
|
32
|
+
intents?: string[];
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _QQAdapter_disposes;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const adapter_1 = require("../../adapter");
|
|
10
|
+
const onebot_1 = require("../../onebot");
|
|
11
|
+
const bot_1 = require("../../adapters/qq/bot");
|
|
12
|
+
var UnsupportedMethodError = onebot_1.OneBot.UnsupportedMethodError;
|
|
13
|
+
class QQAdapter extends adapter_1.Adapter {
|
|
14
|
+
constructor(app, config) {
|
|
15
|
+
super(app, 'qq', config);
|
|
16
|
+
_QQAdapter_disposes.set(this, new Map());
|
|
17
|
+
}
|
|
18
|
+
async startOneBot(oneBot) {
|
|
19
|
+
const config = this.app.config[`qq.${oneBot.uin}`].protocol;
|
|
20
|
+
const qqBot = oneBot.internal = new bot_1.Bot(oneBot, oneBot.uin, config);
|
|
21
|
+
await qqBot.init();
|
|
22
|
+
const disposeArr = [];
|
|
23
|
+
const clean = () => {
|
|
24
|
+
while (disposeArr.length > 0) {
|
|
25
|
+
disposeArr.pop()();
|
|
26
|
+
}
|
|
27
|
+
qqBot.stop();
|
|
28
|
+
};
|
|
29
|
+
const _this = this;
|
|
30
|
+
const messageHandler = (event) => {
|
|
31
|
+
this.emit('message.receive', oneBot.uin, event);
|
|
32
|
+
};
|
|
33
|
+
qqBot.on('message', messageHandler);
|
|
34
|
+
disposeArr.push(() => {
|
|
35
|
+
qqBot.off('message', messageHandler);
|
|
36
|
+
});
|
|
37
|
+
return clean;
|
|
38
|
+
}
|
|
39
|
+
call(uin, version, method, args) {
|
|
40
|
+
const oneBot = this.oneBots.get(uin);
|
|
41
|
+
if (!oneBot) {
|
|
42
|
+
throw new Error(`未找到账号${uin}`);
|
|
43
|
+
}
|
|
44
|
+
if (typeof this[method] === 'function')
|
|
45
|
+
return this[method](uin, version, args);
|
|
46
|
+
if (typeof oneBot.internal[method] !== 'function')
|
|
47
|
+
throw UnsupportedMethodError;
|
|
48
|
+
try {
|
|
49
|
+
return oneBot.internal[method](...(args || []));
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
throw new Error(`call internal method error:${e.message}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
fromSegment(version, segment) {
|
|
56
|
+
return [].concat(segment).map(item => {
|
|
57
|
+
if (typeof item === "string")
|
|
58
|
+
return {
|
|
59
|
+
type: 'text',
|
|
60
|
+
data: {
|
|
61
|
+
text: item
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return item;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
toSegment(version, message) {
|
|
68
|
+
return [].concat(message).map(item => {
|
|
69
|
+
if (!item || typeof item !== "object")
|
|
70
|
+
return {
|
|
71
|
+
type: 'text',
|
|
72
|
+
data: {
|
|
73
|
+
text: item
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const { type, ...data } = item;
|
|
77
|
+
return {
|
|
78
|
+
type,
|
|
79
|
+
data
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
fromCqcode(version, message) {
|
|
84
|
+
const regExpMatchArray = message.match(/\[CQ:([a-z]+),(!])+]/g);
|
|
85
|
+
if (!regExpMatchArray)
|
|
86
|
+
return [
|
|
87
|
+
{
|
|
88
|
+
type: 'text',
|
|
89
|
+
data: {
|
|
90
|
+
text: message
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
];
|
|
94
|
+
const result = [];
|
|
95
|
+
for (const match of regExpMatchArray) {
|
|
96
|
+
const [type, ...valueArr] = match.substring(1, match.length - 1).split(',');
|
|
97
|
+
result.push({
|
|
98
|
+
type: type,
|
|
99
|
+
data: Object.fromEntries(valueArr.map(item => {
|
|
100
|
+
const [key, value] = item.split('=');
|
|
101
|
+
return [key, value];
|
|
102
|
+
}))
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
toCqcode(version, messageArr) {
|
|
108
|
+
return [].concat(messageArr).map(item => {
|
|
109
|
+
const dataStr = Object.entries(item.data).map(([key, value]) => {
|
|
110
|
+
// is Buffer
|
|
111
|
+
if (value instanceof Buffer)
|
|
112
|
+
return `${key}=${value.toString('base64')}`;
|
|
113
|
+
// is Object
|
|
114
|
+
if (value instanceof Object)
|
|
115
|
+
return `${key}=${JSON.stringify(value)}`;
|
|
116
|
+
// is Array
|
|
117
|
+
if (value instanceof Array)
|
|
118
|
+
return `${key}=${value.map(v => JSON.stringify(v)).join(',')}`;
|
|
119
|
+
// is String
|
|
120
|
+
return `${key}=${item.data[key]}`;
|
|
121
|
+
});
|
|
122
|
+
return `[CQ:${item.type},${dataStr.join(',')}]`;
|
|
123
|
+
}).join('');
|
|
124
|
+
}
|
|
125
|
+
formatEventPayload(version, event, data) {
|
|
126
|
+
return {
|
|
127
|
+
id: data.id,
|
|
128
|
+
type: event,
|
|
129
|
+
version: version,
|
|
130
|
+
self: {
|
|
131
|
+
platform: 'qq',
|
|
132
|
+
user_id: data.self_id
|
|
133
|
+
},
|
|
134
|
+
detail_type: data.message_type || data.notice_type || data.request_type,
|
|
135
|
+
platform: 'qq',
|
|
136
|
+
...data,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
async start(uin) {
|
|
140
|
+
const startOneBots = [...this.oneBots.values()].filter(oneBot => {
|
|
141
|
+
return uin ? oneBot.uin === uin : true;
|
|
142
|
+
});
|
|
143
|
+
for (const oneBot of startOneBots) {
|
|
144
|
+
__classPrivateFieldGet(this, _QQAdapter_disposes, "f").set(oneBot.uin, await this.startOneBot(oneBot));
|
|
145
|
+
}
|
|
146
|
+
const { protocol } = this.config;
|
|
147
|
+
await super.start();
|
|
148
|
+
}
|
|
149
|
+
async stop(uin) {
|
|
150
|
+
const stopOneBots = [...this.oneBots.values()].filter(oneBot => {
|
|
151
|
+
return uin ? oneBot.uin === uin : true;
|
|
152
|
+
});
|
|
153
|
+
for (const oneBot of stopOneBots) {
|
|
154
|
+
const dispose = __classPrivateFieldGet(this, _QQAdapter_disposes, "f").get(oneBot.uin);
|
|
155
|
+
if (dispose) {
|
|
156
|
+
dispose();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
await super.stop();
|
|
160
|
+
}
|
|
161
|
+
getSelfInfo(uin, version) {
|
|
162
|
+
const oneBot = this.oneBots.get(uin);
|
|
163
|
+
return {
|
|
164
|
+
nickname: oneBot?.internal?.nickname,
|
|
165
|
+
status: onebot_1.OneBotStatus.Online,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
_QQAdapter_disposes = new WeakMap();
|
|
170
|
+
exports.default = QQAdapter;
|