@mrlingxd/koishi-plugin-adapter-onebot 0.1.0 → 0.2.2
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/bot/cqcode.d.ts +204 -5
- package/lib/bot/cqcode.js +1 -1
- package/lib/bot/index.d.ts +35 -19
- package/lib/bot/index.js +89 -53
- package/lib/bot/message.d.ts +4 -4
- package/lib/bot/message.js +58 -57
- package/lib/http.d.ts +5 -6
- package/lib/http.js +5 -7
- package/lib/index.d.ts +12 -8
- package/lib/index.js +2 -3
- package/lib/internal.d.ts +132 -0
- package/lib/{types.js → internal.js} +6 -57
- package/lib/types/device.d.ts +8 -0
- package/lib/types/device.js +1 -0
- package/lib/types/enum.d.ts +65 -0
- package/lib/types/enum.js +70 -0
- package/lib/types/event/base.d.ts +26 -0
- package/lib/types/event/base.js +20 -0
- package/lib/types/event/message.d.ts +44 -0
- package/lib/types/event/message.js +11 -0
- package/lib/types/event/meta.d.ts +34 -0
- package/lib/types/event/meta.js +1 -0
- package/lib/types/event/notice.d.ts +256 -0
- package/lib/types/event/notice.js +40 -0
- package/lib/types/event/request.d.ts +30 -0
- package/lib/types/event/request.js +11 -0
- package/lib/types/group.d.ts +43 -0
- package/lib/types/group.js +1 -0
- package/lib/types/index.d.ts +334 -0
- package/lib/types/index.js +10 -0
- package/lib/types/sender.d.ts +43 -0
- package/lib/types/sender.js +10 -0
- package/lib/types/user.d.ts +16 -0
- package/lib/types/user.js +1 -0
- package/lib/utils.d.ts +15 -11
- package/lib/utils.js +210 -200
- package/lib/ws.d.ts +9 -10
- package/lib/ws.js +2 -4
- package/package.json +6 -9
- package/lib/bot/base.d.ts +0 -36
- package/lib/bot/base.js +0 -66
- package/lib/bot/qqguild.d.ts +0 -31
- package/lib/bot/qqguild.js +0 -66
- package/lib/types.d.ts +0 -474
package/lib/bot/message.js
CHANGED
|
@@ -31,9 +31,8 @@ export class OneBotMessageEncoder extends MessageEncoder {
|
|
|
31
31
|
session.content = "";
|
|
32
32
|
session.messageId =
|
|
33
33
|
this.session.event.channel.type === 1 /* Universal.Channel.Type.DIRECT */
|
|
34
|
-
?
|
|
35
|
-
|
|
36
|
-
: "" + (await this.bot.internal.sendGroupForwardMsg(this.channelId, this.stack[0].children));
|
|
34
|
+
? (await this.bot.internal.sendPrivateForwardMsg(Number(this.channelId.slice(PRIVATE_PFX.length)), this.stack[0].children)).toString()
|
|
35
|
+
: (await this.bot.internal.sendGroupForwardMsg(Number(this.channelId), this.stack[0].children)).toString();
|
|
37
36
|
session.userId = this.bot.selfId;
|
|
38
37
|
session.channelId = this.session.channelId;
|
|
39
38
|
session.guildId = this.session.guildId;
|
|
@@ -67,35 +66,23 @@ export class OneBotMessageEncoder extends MessageEncoder {
|
|
|
67
66
|
if (!this.children.length && !author.messageId)
|
|
68
67
|
return;
|
|
69
68
|
if (type === "forward") {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
this.stack[1].children.push({
|
|
80
|
-
type: "node",
|
|
81
|
-
data: {
|
|
82
|
-
name: author.name || this.bot.user.name,
|
|
83
|
-
uin: author.id || this.bot.userId,
|
|
84
|
-
content: String(this.children),
|
|
85
|
-
time: `${Math.floor((+author.time || Date.now()) / 1000)}`
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
69
|
+
this.stack[1].children.push({
|
|
70
|
+
type: "node",
|
|
71
|
+
data: {
|
|
72
|
+
user_id: author.messageId,
|
|
73
|
+
nickname: author.nick || author.name,
|
|
74
|
+
content: []
|
|
75
|
+
}
|
|
76
|
+
});
|
|
89
77
|
this.children = [];
|
|
90
78
|
return;
|
|
91
79
|
}
|
|
92
80
|
const session = this.bot.session();
|
|
93
81
|
session.content = "";
|
|
94
|
-
session.messageId =
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
: "" + (await this.bot.internal.sendGroupMsg(this.channelId, this.children));
|
|
82
|
+
session.messageId =
|
|
83
|
+
this.session.event.channel.type === 1 /* Universal.Channel.Type.DIRECT */
|
|
84
|
+
? (await this.bot.internal.sendPrivateMsg(Number(this.channelId.slice(PRIVATE_PFX.length)), this.children)).toString()
|
|
85
|
+
: (await this.bot.internal.sendGroupMsg(Number(this.channelId), this.children)).toString();
|
|
99
86
|
session.userId = this.bot.selfId;
|
|
100
87
|
session.channelId = this.session.channelId;
|
|
101
88
|
session.guildId = this.session.guildId;
|
|
@@ -110,10 +97,10 @@ export class OneBotMessageEncoder extends MessageEncoder {
|
|
|
110
97
|
// 本地文件路径
|
|
111
98
|
const file = src.startsWith("file:") ? fileURLToPath(src) : await this.bot.internal.downloadFile(src);
|
|
112
99
|
if (this.session.event.channel.type === 1 /* Universal.Channel.Type.DIRECT */) {
|
|
113
|
-
await this.bot.internal.uploadPrivateFile(this.channelId.slice(PRIVATE_PFX.length), file, name);
|
|
100
|
+
await this.bot.internal.uploadPrivateFile(Number(this.channelId.slice(PRIVATE_PFX.length)), file, name);
|
|
114
101
|
}
|
|
115
102
|
else {
|
|
116
|
-
await this.bot.internal.uploadGroupFile(this.channelId, file, name);
|
|
103
|
+
await this.bot.internal.uploadGroupFile(Number(this.channelId), file, name);
|
|
117
104
|
}
|
|
118
105
|
const session = this.bot.session();
|
|
119
106
|
// 相关 API 没有返回 message_id
|
|
@@ -177,12 +164,16 @@ export class OneBotMessageEncoder extends MessageEncoder {
|
|
|
177
164
|
this.text(`(${attrs.href})`);
|
|
178
165
|
}
|
|
179
166
|
else if (["video", "audio", "image", "img"].includes(type)) {
|
|
180
|
-
|
|
167
|
+
let childrenType;
|
|
168
|
+
if (type === "video" || type === "audio") {
|
|
181
169
|
await this.flush();
|
|
170
|
+
}
|
|
171
|
+
if (type === "video")
|
|
172
|
+
childrenType = "video";
|
|
182
173
|
if (type === "audio")
|
|
183
|
-
|
|
174
|
+
childrenType = "record";
|
|
184
175
|
if (type === "img")
|
|
185
|
-
|
|
176
|
+
childrenType = "image";
|
|
186
177
|
attrs = { ...attrs };
|
|
187
178
|
attrs.file = attrs.src || attrs.url;
|
|
188
179
|
delete attrs.src;
|
|
@@ -198,7 +189,13 @@ export class OneBotMessageEncoder extends MessageEncoder {
|
|
|
198
189
|
const cap = /^data:([\w/.+-]+);base64,/.exec(attrs.file);
|
|
199
190
|
if (cap)
|
|
200
191
|
attrs.file = "base64://" + attrs.file.slice(cap[0].length);
|
|
201
|
-
this.children.push({
|
|
192
|
+
this.children.push({
|
|
193
|
+
type: childrenType,
|
|
194
|
+
data: {
|
|
195
|
+
...attrs,
|
|
196
|
+
file: attrs.file
|
|
197
|
+
}
|
|
198
|
+
});
|
|
202
199
|
}
|
|
203
200
|
else if (type === "file") {
|
|
204
201
|
await this.flush();
|
|
@@ -206,35 +203,34 @@ export class OneBotMessageEncoder extends MessageEncoder {
|
|
|
206
203
|
}
|
|
207
204
|
else if (type === "onebot:music") {
|
|
208
205
|
await this.flush();
|
|
209
|
-
this.children.push({
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
206
|
+
this.children.push({
|
|
207
|
+
type: "music",
|
|
208
|
+
data: {
|
|
209
|
+
type: attrs.type,
|
|
210
|
+
id: attrs.id,
|
|
211
|
+
...attrs
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
214
|
}
|
|
215
215
|
else if (type === "onebot:poke") {
|
|
216
216
|
await this.flush();
|
|
217
|
-
this.children.push({
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
this.children.push({ type: "share", data: attrs });
|
|
217
|
+
this.children.push({
|
|
218
|
+
type: "poke",
|
|
219
|
+
data: {
|
|
220
|
+
type: attrs.type || "poke",
|
|
221
|
+
id: attrs.id,
|
|
222
|
+
...attrs
|
|
223
|
+
}
|
|
224
|
+
});
|
|
226
225
|
}
|
|
227
226
|
else if (type === "onebot:json") {
|
|
228
227
|
await this.flush();
|
|
229
|
-
this.children.push({
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
else if (type === "onebot:cardimage") {
|
|
236
|
-
await this.flush();
|
|
237
|
-
this.children.push({ type: "cardimage", data: attrs });
|
|
228
|
+
this.children.push({
|
|
229
|
+
type: "json",
|
|
230
|
+
data: {
|
|
231
|
+
data: attrs.data
|
|
232
|
+
}
|
|
233
|
+
});
|
|
238
234
|
}
|
|
239
235
|
else if (type === "author") {
|
|
240
236
|
Object.assign(this.stack[0].author, attrs);
|
|
@@ -253,7 +249,12 @@ export class OneBotMessageEncoder extends MessageEncoder {
|
|
|
253
249
|
}
|
|
254
250
|
else if (type === "quote") {
|
|
255
251
|
await this.flush();
|
|
256
|
-
this.children.push({
|
|
252
|
+
this.children.push({
|
|
253
|
+
type: "reply",
|
|
254
|
+
data: {
|
|
255
|
+
id: attrs.id.toString()
|
|
256
|
+
}
|
|
257
|
+
});
|
|
257
258
|
}
|
|
258
259
|
else if (type === "message") {
|
|
259
260
|
await this.flush();
|
package/lib/http.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Adapter, Context, HTTP, Schema } from "koishi";
|
|
2
|
-
import {
|
|
3
|
-
export declare class HttpServer<C extends Context = Context> extends Adapter<C,
|
|
2
|
+
import { OneBot } from "./bot";
|
|
3
|
+
export declare class HttpServer<C extends Context = Context> extends Adapter<C, OneBot<C>> {
|
|
4
4
|
static inject: string[];
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
disconnect(bot: OneBotBot<C>): Promise<void>;
|
|
5
|
+
fork(ctx: C, bot: OneBot<C>): Promise<void>;
|
|
6
|
+
connect(bot: OneBot<C>): Promise<void>;
|
|
7
|
+
disconnect(bot: OneBot<C>): Promise<void>;
|
|
9
8
|
}
|
|
10
9
|
export declare namespace HttpServer {
|
|
11
10
|
interface Options extends HTTP.Config {
|
package/lib/http.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { createHmac } from "crypto";
|
|
2
2
|
import { Adapter, HTTP, Schema } from "koishi";
|
|
3
|
+
import { isBaseEvent } from "./types/event/base";
|
|
3
4
|
import { dispatchSession } from "./utils";
|
|
4
5
|
export class HttpServer extends Adapter {
|
|
5
6
|
static inject = ["server"];
|
|
6
7
|
async fork(ctx, bot) {
|
|
7
8
|
super.fork(ctx, bot);
|
|
8
9
|
const config = bot.config;
|
|
9
|
-
const {
|
|
10
|
-
if (!
|
|
10
|
+
const { baseURL, token } = config;
|
|
11
|
+
if (!baseURL)
|
|
11
12
|
return;
|
|
12
13
|
const http = ctx.http.extend({
|
|
13
14
|
...config,
|
|
@@ -35,11 +36,8 @@ export class HttpServer extends Adapter {
|
|
|
35
36
|
if (signature !== `sha1=${sig}`)
|
|
36
37
|
return (ctx.status = 403);
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (!bot)
|
|
41
|
-
return (ctx.status = 403);
|
|
42
|
-
bot.logger.debug("[receive] %o", ctx.request.response.body);
|
|
39
|
+
if (!isBaseEvent(ctx.request.response.body))
|
|
40
|
+
return (ctx.status = 400);
|
|
43
41
|
dispatchSession(bot, ctx.request.response.body);
|
|
44
42
|
});
|
|
45
43
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import { Session } from "koishi";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import { OneBot } from "./bot";
|
|
3
|
+
import { Internal } from "./internal";
|
|
4
4
|
export { OneBot };
|
|
5
5
|
export * from "./bot";
|
|
6
6
|
export * from "./http";
|
|
7
7
|
export * from "./ws";
|
|
8
|
-
export default
|
|
8
|
+
export default OneBot;
|
|
9
9
|
declare module "@satorijs/core" {
|
|
10
10
|
interface Session {
|
|
11
|
-
onebot?:
|
|
11
|
+
onebot?: Internal & {
|
|
12
|
+
targetId?: string;
|
|
13
|
+
duration?: number;
|
|
14
|
+
};
|
|
12
15
|
}
|
|
13
16
|
}
|
|
14
17
|
declare module "koishi" {
|
|
15
18
|
interface Events {
|
|
16
|
-
"onebot/
|
|
17
|
-
"onebot/
|
|
18
|
-
"onebot/
|
|
19
|
-
"onebot/
|
|
19
|
+
"onebot/notice-poke"(session: Session): void;
|
|
20
|
+
"onebot/notice-honor"(session: Session): void;
|
|
21
|
+
"onebot/notice-title"(session: Session): void;
|
|
22
|
+
"onebot/notice-lucky-king"(session: Session): void;
|
|
23
|
+
"onebot/group-essence"(session: Session): void;
|
|
20
24
|
}
|
|
21
25
|
}
|
package/lib/index.js
CHANGED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Dict } from "koishi";
|
|
2
|
+
import { OneBot } from "./bot";
|
|
3
|
+
import { CQCode } from "./bot/cqcode";
|
|
4
|
+
import { EssenceMessage, FriendInfo, GetCredentialsResponse, GroupAtAllRemain, GroupFileList, GroupFileSystemInfo, GroupHonorInfo, GroupNotice, GroupSystemMsgResponse, ImageOcrResult, LoginInfo, ModelVariant, UnidirectionalFriendInfo } from "./types";
|
|
5
|
+
import { Device } from "./types/device";
|
|
6
|
+
import { HonorType, SafetyLevel } from "./types/enum";
|
|
7
|
+
import { GroupMessageEvent, MessageEvent } from "./types/event/message";
|
|
8
|
+
import { GroupInfo, GroupMemberInfo } from "./types/group";
|
|
9
|
+
import { UserInfo } from "./types/user";
|
|
10
|
+
export declare class Internal {
|
|
11
|
+
readonly bot: OneBot;
|
|
12
|
+
_request: (action: string, params: Dict) => Promise<any>;
|
|
13
|
+
constructor(bot: OneBot);
|
|
14
|
+
private _get;
|
|
15
|
+
setGroupAnonymousBan(group_id: string, meta: string | object, duration?: number): Promise<void>;
|
|
16
|
+
setGroupAnonymousBanAsync(group_id: string, meta: string | object, duration?: number): Promise<void>;
|
|
17
|
+
sendPrivateMsg(user_id: number, message: string | readonly CQCode.CQCodeUnion[], auto_escape?: boolean): Promise<number>;
|
|
18
|
+
sendPrivateMsgAsync(user_id: number, message: string | readonly CQCode.CQCodeUnion[], auto_escape?: boolean): Promise<void>;
|
|
19
|
+
sendGroupMsg(group_id: number, message: string | readonly CQCode.CQCodeUnion[], auto_escape?: boolean): Promise<number>;
|
|
20
|
+
sendGroupMsgAsync(group_id: number, message: string | readonly CQCode.CQCodeUnion[], auto_escape?: boolean): Promise<void>;
|
|
21
|
+
sendGroupForwardMsg(group_id: number, messages: readonly CQCode.CQCodeUnion[]): Promise<number>;
|
|
22
|
+
sendGroupForwardMsgAsync(group_id: number, messages: readonly CQCode.CQCodeUnion[]): Promise<void>;
|
|
23
|
+
sendPrivateForwardMsg(user_id: number, messages: readonly CQCode.CQCodeUnion[]): Promise<number>;
|
|
24
|
+
sendPrivateForwardMsgAsync(user_id: number, messages: readonly CQCode.CQCodeUnion[]): Promise<void>;
|
|
25
|
+
deleteMsg(message_id: number): Promise<void>;
|
|
26
|
+
deleteMsgAsync(message_id: number): Promise<void>;
|
|
27
|
+
setEssenceMsg(message_id: number): Promise<void>;
|
|
28
|
+
setEssenceMsgAsync(message_id: number): Promise<void>;
|
|
29
|
+
deleteEssenceMsg(message_id: number): Promise<void>;
|
|
30
|
+
deleteEssenceMsgAsync(message_id: number): Promise<void>;
|
|
31
|
+
markMsgAsRead(message_id: number): Promise<void>;
|
|
32
|
+
sendLike(user_id: number, times?: number): Promise<void>;
|
|
33
|
+
sendLikeAsync(user_id: number, times?: number): Promise<void>;
|
|
34
|
+
sendGroupSign(group_id: number): Promise<void>;
|
|
35
|
+
sendGroupSignAsync(group_id: number): Promise<void>;
|
|
36
|
+
getMsg(message_id: number): Promise<MessageEvent>;
|
|
37
|
+
getForwardMsg(message_id: number): Promise<CQCode.MergeForward>;
|
|
38
|
+
getEssenceMsgList(group_id: number): Promise<EssenceMessage[]>;
|
|
39
|
+
getWordSlices(content: string): Promise<string[]>;
|
|
40
|
+
ocrImage(image: string): Promise<ImageOcrResult>;
|
|
41
|
+
getGroupMsgHistory(group_id: number, message_seq?: number): Promise<{
|
|
42
|
+
messages: GroupMessageEvent[];
|
|
43
|
+
}>;
|
|
44
|
+
deleteFriend(user_id: number): Promise<void>;
|
|
45
|
+
deleteFriendAsync(user_id: number): Promise<void>;
|
|
46
|
+
deleteUnidirectionalFriend(user_id: number): Promise<void>;
|
|
47
|
+
deleteUnidirectionalFriendAsync(user_id: number): Promise<void>;
|
|
48
|
+
setFriendAddRequest(flag: string, approve: boolean, remark?: string): Promise<void>;
|
|
49
|
+
setFriendAddRequestAsync(flag: string, approve: boolean, remark?: string): Promise<void>;
|
|
50
|
+
setGroupAddRequest(flag: string, subType: "add" | "invite", approve: boolean, reason?: string): Promise<void>;
|
|
51
|
+
setGroupAddRequestAsync(flag: string, subType: "add" | "invite", approve: boolean, reason?: string): Promise<void>;
|
|
52
|
+
setGroupKick(group_id: number, user_id: number, reject_add_request?: boolean): Promise<void>;
|
|
53
|
+
setGroupKickAsync(group_id: number, user_id: number, reject_add_request?: boolean): Promise<void>;
|
|
54
|
+
setGroupBan(group_id: number, user_id: number, duration?: number): Promise<void>;
|
|
55
|
+
setGroupBanAsync(group_id: number, user_id: number, duration?: number): Promise<void>;
|
|
56
|
+
setGroupWholeBan(group_id: number, enable?: boolean): Promise<void>;
|
|
57
|
+
setGroupWholeBanAsync(group_id: number, enable?: boolean): Promise<void>;
|
|
58
|
+
setGroupAdmin(group_id: number, user_id: number, enable?: boolean): Promise<void>;
|
|
59
|
+
setGroupAdminAsync(group_id: number, user_id: number, enable?: boolean): Promise<void>;
|
|
60
|
+
setGroupAnonymous(group_id: number, enable?: boolean): Promise<void>;
|
|
61
|
+
setGroupAnonymousAsync(group_id: number, enable?: boolean): Promise<void>;
|
|
62
|
+
setGroupCard(group_id: number, user_id: number, card?: string): Promise<void>;
|
|
63
|
+
setGroupCardAsync(group_id: number, user_id: number, card?: string): Promise<void>;
|
|
64
|
+
setGroupLeave(group_id: number, is_dismiss?: boolean): Promise<void>;
|
|
65
|
+
setGroupLeaveAsync(group_id: number, is_dismiss?: boolean): Promise<void>;
|
|
66
|
+
setGroupSpecialTitle(group_id: number, user_id: number, special_title?: string, duration?: number): Promise<void>;
|
|
67
|
+
setGroupSpecialTitleAsync(group_id: number, user_id: number, special_title?: string, duration?: number): Promise<void>;
|
|
68
|
+
setGroupName(group_id: number, name: string): Promise<void>;
|
|
69
|
+
setGroupNameAsync(group_id: number, name: string): Promise<void>;
|
|
70
|
+
setGroupPortrait(group_id: number, file: string, cache?: boolean): Promise<void>;
|
|
71
|
+
setGroupPortraitAsync(group_id: number, file: string, cache?: boolean): Promise<void>;
|
|
72
|
+
getGroupAtAllRemain(group_id: number): Promise<GroupAtAllRemain>;
|
|
73
|
+
sendGroupNotice(group_id: number, content: string, image?: string, pinned?: number, confirm_required?: number): Promise<void>;
|
|
74
|
+
sendGroupNoticeAsync(group_id: number, content: string, image?: string, pinned?: number, confirm_required?: number): Promise<void>;
|
|
75
|
+
getGroupNotice(group_id: number): Promise<GroupNotice[]>;
|
|
76
|
+
delGroupNotice(group_id: number, notice_id: number): Promise<void>;
|
|
77
|
+
getLoginInfo(): Promise<LoginInfo>;
|
|
78
|
+
setQqProfile(nickname: string, company: string, email: string, college: string, personal_note: string): Promise<void>;
|
|
79
|
+
setQqProfileAsync(nickname: string, company: string, email: string, college: string, personal_note: string): Promise<void>;
|
|
80
|
+
setQqAvatar(file: string): Promise<void>;
|
|
81
|
+
setOnlineStatus(status: string, extStatus: string, batteryStatus: string): Promise<void>;
|
|
82
|
+
getStrangerInfo(user_id: number, no_cache?: boolean): Promise<UserInfo>;
|
|
83
|
+
getFriendList(): Promise<FriendInfo[]>;
|
|
84
|
+
getUnidirectionalFriendList(): Promise<UnidirectionalFriendInfo[]>;
|
|
85
|
+
getGroupInfo(group_id: number, no_cache?: boolean): Promise<GroupInfo>;
|
|
86
|
+
getGroupList(no_cache?: boolean): Promise<GroupInfo[]>;
|
|
87
|
+
getGroupMemberInfo(group_id: number, user_id: number, no_cache?: boolean): Promise<GroupMemberInfo>;
|
|
88
|
+
getGroupMemberList(group_id: number, no_cache?: boolean): Promise<GroupMemberInfo[]>;
|
|
89
|
+
getGroupHonorInfo(group_id: number, type: HonorType | "all"): Promise<GroupHonorInfo>;
|
|
90
|
+
getGroupSystemMsg(): Promise<GroupSystemMsgResponse>;
|
|
91
|
+
getGroupFileSystemInfo(group_id: number): Promise<GroupFileSystemInfo>;
|
|
92
|
+
getGroupRootFiles(group_id: number): Promise<GroupFileList>;
|
|
93
|
+
getGroupFilesByFolder(group_id: number, folder_id: string): Promise<GroupFileList>;
|
|
94
|
+
getGroupFileUrl(group_id: number, file_id: string, busid: number): Promise<string>;
|
|
95
|
+
downloadFile(url: string, headers?: string | readonly string[], thread_count?: number): Promise<string>;
|
|
96
|
+
uploadPrivateFile(user_id: number, file: string, name: string): Promise<void>;
|
|
97
|
+
uploadGroupFile(group_id: number, file: string, name: string, folder?: string): Promise<void>;
|
|
98
|
+
createGroupFileFolder(group_id: number, folder_id: string, name: string): Promise<void>;
|
|
99
|
+
deleteGroupFolder(group_id: number, folder_id: string): Promise<void>;
|
|
100
|
+
deleteGroupFile(group_id: number, folder_id: string, file_id: string, busid: number): Promise<void>;
|
|
101
|
+
getOnlineClients(no_cache?: boolean): Promise<Device[]>;
|
|
102
|
+
checkUrlSafely(url: string): Promise<SafetyLevel>;
|
|
103
|
+
getModelShow(model: string): Promise<ModelVariant[]>;
|
|
104
|
+
setModelShow(model: string, model_show: string): Promise<void>;
|
|
105
|
+
getCookies(domain?: string): Promise<string>;
|
|
106
|
+
getCsrfToken(): Promise<number>;
|
|
107
|
+
getCredentials(domain?: string): Promise<GetCredentialsResponse>;
|
|
108
|
+
getRecord(file: string, out_format: "mp3" | "amr" | "wma" | "m4a" | "spx" | "ogg" | "wav" | "flac" | string, full_path?: boolean): Promise<{
|
|
109
|
+
/** 转换后的语音文件路径 */
|
|
110
|
+
file: string;
|
|
111
|
+
}>;
|
|
112
|
+
getImage(file: string): Promise<{
|
|
113
|
+
/** 图片源文件大小 */
|
|
114
|
+
size: number;
|
|
115
|
+
/** 图片文件原名 */
|
|
116
|
+
filename: string;
|
|
117
|
+
/** 图片下载地址 */
|
|
118
|
+
url: string;
|
|
119
|
+
}>;
|
|
120
|
+
canSendImage(): Promise<boolean>;
|
|
121
|
+
canSendRecord(): Promise<boolean>;
|
|
122
|
+
getStatus(): Promise<Dict<string>>;
|
|
123
|
+
getVersionInfo(): Promise<Dict<string>>;
|
|
124
|
+
setRestart(delay?: number): Promise<void>;
|
|
125
|
+
reloadEventFilter(): Promise<void>;
|
|
126
|
+
cleanCache(): Promise<void>;
|
|
127
|
+
uploadImage(file: string): Promise<string>;
|
|
128
|
+
getPrivateFileUrl(user_id: number, file_id: string, file_hash?: string): Promise<string>;
|
|
129
|
+
moveGroupFile(group_id: number, file_id: string, parent_directory: string, target_directory: string): Promise<void>;
|
|
130
|
+
deleteGroupFileFolder(group_id: number, folder_id: string): Promise<void>;
|
|
131
|
+
renameGroupFileFolder(group_id: number, folder_id: string, new_folder_name: string): Promise<void>;
|
|
132
|
+
}
|
|
@@ -1,30 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
(function (SafetyLevel) {
|
|
3
|
-
SafetyLevel[SafetyLevel["safe"] = 0] = "safe";
|
|
4
|
-
SafetyLevel[SafetyLevel["unknown"] = 1] = "unknown";
|
|
5
|
-
SafetyLevel[SafetyLevel["danger"] = 2] = "danger";
|
|
6
|
-
})(SafetyLevel || (SafetyLevel = {}));
|
|
7
|
-
export class TimeoutError extends Error {
|
|
8
|
-
constructor(args, url) {
|
|
9
|
-
super(`Timeout with request ${url}, args: ${JSON.stringify(args)}`);
|
|
10
|
-
Object.defineProperties(this, {
|
|
11
|
-
args: { value: args },
|
|
12
|
-
url: { value: url }
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
class SenderError extends Error {
|
|
17
|
-
constructor(args, url, retcode) {
|
|
18
|
-
super(`Error with request ${url}, args: ${JSON.stringify(args)}, retcode: ${retcode}`);
|
|
19
|
-
Object.defineProperties(this, {
|
|
20
|
-
code: { value: retcode },
|
|
21
|
-
args: { value: args },
|
|
22
|
-
url: { value: url }
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
1
|
+
import { SenderError } from "./types/sender";
|
|
26
2
|
export class Internal {
|
|
27
3
|
bot;
|
|
4
|
+
_request;
|
|
28
5
|
constructor(bot) {
|
|
29
6
|
this.bot = bot;
|
|
30
7
|
}
|
|
@@ -33,9 +10,10 @@ export class Internal {
|
|
|
33
10
|
const response = await this._request(action, params);
|
|
34
11
|
this.bot.logger.debug("[response] %o", response);
|
|
35
12
|
const { data, retcode } = response;
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
13
|
+
if (response.status === "failed" || retcode !== 0) {
|
|
14
|
+
throw new SenderError(params, action, retcode);
|
|
15
|
+
}
|
|
16
|
+
return data;
|
|
39
17
|
}
|
|
40
18
|
async setGroupAnonymousBan(group_id, meta, duration) {
|
|
41
19
|
const args = { group_id, duration };
|
|
@@ -233,9 +211,6 @@ export class Internal {
|
|
|
233
211
|
async getLoginInfo() {
|
|
234
212
|
return await this._get("get_login_info");
|
|
235
213
|
}
|
|
236
|
-
async qidianGetLoginInfo() {
|
|
237
|
-
return await this._get("qidian_get_login_info");
|
|
238
|
-
}
|
|
239
214
|
async setQqProfile(nickname, company, email, college, personal_note) {
|
|
240
215
|
await this._get("set_qq_profile", { nickname, company, email, college, personal_note });
|
|
241
216
|
}
|
|
@@ -248,9 +223,6 @@ export class Internal {
|
|
|
248
223
|
async setOnlineStatus(status, extStatus, batteryStatus) {
|
|
249
224
|
await this._get("set_online_status", { status, ext_status: extStatus, battery_status: batteryStatus });
|
|
250
225
|
}
|
|
251
|
-
async getVipInfo() {
|
|
252
|
-
return await this._get("_get_vip_info");
|
|
253
|
-
}
|
|
254
226
|
async getStrangerInfo(user_id, no_cache) {
|
|
255
227
|
return await this._get("get_stranger_info", { user_id, no_cache });
|
|
256
228
|
}
|
|
@@ -366,29 +338,6 @@ export class Internal {
|
|
|
366
338
|
async cleanCache() {
|
|
367
339
|
await this._get("clean_cache");
|
|
368
340
|
}
|
|
369
|
-
// Guild
|
|
370
|
-
async getGuildServiceProfile() {
|
|
371
|
-
return await this._get("get_guild_service_profile");
|
|
372
|
-
}
|
|
373
|
-
async getGuildList() {
|
|
374
|
-
return await this._get("get_guild_list");
|
|
375
|
-
}
|
|
376
|
-
async getGuildMetaByGuest(guild_id) {
|
|
377
|
-
return await this._get("get_guild_meta_by_guest", { guild_id });
|
|
378
|
-
}
|
|
379
|
-
async getGuildChannelList(guild_id, no_cache) {
|
|
380
|
-
return await this._get("get_guild_channel_list", { guild_id, no_cache });
|
|
381
|
-
}
|
|
382
|
-
async getGuildMemberList(guild_id, next_token) {
|
|
383
|
-
return await this._get("get_guild_member_list", { guild_id, next_token });
|
|
384
|
-
}
|
|
385
|
-
async getGuildMemberProfile(guild_id, user_id) {
|
|
386
|
-
return await this._get("get_guild_member_profile", { guild_id, user_id });
|
|
387
|
-
}
|
|
388
|
-
async sendGuildChannelMsg(guild_id, channel_id, message) {
|
|
389
|
-
const data = await this._get("send_guild_channel_msg", { guild_id, channel_id, message });
|
|
390
|
-
return data.message_id;
|
|
391
|
-
}
|
|
392
341
|
// Lagrange specific
|
|
393
342
|
async uploadImage(file) {
|
|
394
343
|
return await this._get("upload_image", { file });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 群荣誉类型枚举
|
|
3
|
+
*/
|
|
4
|
+
export declare enum HonorType {
|
|
5
|
+
/** 龙王 */
|
|
6
|
+
talkative = "talkative",
|
|
7
|
+
/** 群聊之火 */
|
|
8
|
+
performer = "performer",
|
|
9
|
+
/** 群聊炽焰 */
|
|
10
|
+
legend = "legend",
|
|
11
|
+
/** 新人王 */
|
|
12
|
+
strong_newbie = "strong_newbie",
|
|
13
|
+
/** 快乐源泉 */
|
|
14
|
+
emotion = "emotion"
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 安全等级
|
|
18
|
+
*/
|
|
19
|
+
export declare enum SafetyLevel {
|
|
20
|
+
/** 安全 */
|
|
21
|
+
Safe = 1,
|
|
22
|
+
/** 未知 */
|
|
23
|
+
Unknown = 2,
|
|
24
|
+
/** 危险 */
|
|
25
|
+
Dangerous = 3
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 用户性别枚举
|
|
29
|
+
*/
|
|
30
|
+
export declare enum UserSex {
|
|
31
|
+
/** 男性 */
|
|
32
|
+
male = "male",
|
|
33
|
+
/** 女性 */
|
|
34
|
+
female = "female",
|
|
35
|
+
/** 未知 */
|
|
36
|
+
unknown = "unknown"
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 群成员角色枚举
|
|
40
|
+
*/
|
|
41
|
+
export declare enum GroupMemberRole {
|
|
42
|
+
/** 群主 */
|
|
43
|
+
owner = "owner",
|
|
44
|
+
/** 管理员 */
|
|
45
|
+
admin = "admin",
|
|
46
|
+
/** 成员 */
|
|
47
|
+
member = "member"
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 消息事件类型枚举
|
|
51
|
+
*/
|
|
52
|
+
export declare enum EventType {
|
|
53
|
+
/** 元事件 */
|
|
54
|
+
META = "meta_event",
|
|
55
|
+
/** 请求类事件 */
|
|
56
|
+
REQUEST = "request",
|
|
57
|
+
/** 通知类事件 */
|
|
58
|
+
NOTICE = "notice",
|
|
59
|
+
/** 消息类事件 */
|
|
60
|
+
MESSAGE = "message",
|
|
61
|
+
/**
|
|
62
|
+
* 自身消息(go-cqhttp 扩展事件)
|
|
63
|
+
*/
|
|
64
|
+
MESSAGE_SENT = "message_sent"
|
|
65
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 群荣誉类型枚举
|
|
3
|
+
*/
|
|
4
|
+
export var HonorType;
|
|
5
|
+
(function (HonorType) {
|
|
6
|
+
/** 龙王 */
|
|
7
|
+
HonorType["talkative"] = "talkative";
|
|
8
|
+
/** 群聊之火 */
|
|
9
|
+
HonorType["performer"] = "performer";
|
|
10
|
+
/** 群聊炽焰 */
|
|
11
|
+
HonorType["legend"] = "legend";
|
|
12
|
+
/** 新人王 */
|
|
13
|
+
HonorType["strong_newbie"] = "strong_newbie";
|
|
14
|
+
/** 快乐源泉 */
|
|
15
|
+
HonorType["emotion"] = "emotion";
|
|
16
|
+
})(HonorType || (HonorType = {}));
|
|
17
|
+
/**
|
|
18
|
+
* 安全等级
|
|
19
|
+
*/
|
|
20
|
+
export var SafetyLevel;
|
|
21
|
+
(function (SafetyLevel) {
|
|
22
|
+
/** 安全 */
|
|
23
|
+
SafetyLevel[SafetyLevel["Safe"] = 1] = "Safe";
|
|
24
|
+
/** 未知 */
|
|
25
|
+
SafetyLevel[SafetyLevel["Unknown"] = 2] = "Unknown";
|
|
26
|
+
/** 危险 */
|
|
27
|
+
SafetyLevel[SafetyLevel["Dangerous"] = 3] = "Dangerous";
|
|
28
|
+
})(SafetyLevel || (SafetyLevel = {}));
|
|
29
|
+
/**
|
|
30
|
+
* 用户性别枚举
|
|
31
|
+
*/
|
|
32
|
+
export var UserSex;
|
|
33
|
+
(function (UserSex) {
|
|
34
|
+
/** 男性 */
|
|
35
|
+
UserSex["male"] = "male";
|
|
36
|
+
/** 女性 */
|
|
37
|
+
UserSex["female"] = "female";
|
|
38
|
+
/** 未知 */
|
|
39
|
+
UserSex["unknown"] = "unknown";
|
|
40
|
+
})(UserSex || (UserSex = {}));
|
|
41
|
+
/**
|
|
42
|
+
* 群成员角色枚举
|
|
43
|
+
*/
|
|
44
|
+
export var GroupMemberRole;
|
|
45
|
+
(function (GroupMemberRole) {
|
|
46
|
+
/** 群主 */
|
|
47
|
+
GroupMemberRole["owner"] = "owner";
|
|
48
|
+
/** 管理员 */
|
|
49
|
+
GroupMemberRole["admin"] = "admin";
|
|
50
|
+
/** 成员 */
|
|
51
|
+
GroupMemberRole["member"] = "member";
|
|
52
|
+
})(GroupMemberRole || (GroupMemberRole = {}));
|
|
53
|
+
/**
|
|
54
|
+
* 消息事件类型枚举
|
|
55
|
+
*/
|
|
56
|
+
export var EventType;
|
|
57
|
+
(function (EventType) {
|
|
58
|
+
/** 元事件 */
|
|
59
|
+
EventType["META"] = "meta_event";
|
|
60
|
+
/** 请求类事件 */
|
|
61
|
+
EventType["REQUEST"] = "request";
|
|
62
|
+
/** 通知类事件 */
|
|
63
|
+
EventType["NOTICE"] = "notice";
|
|
64
|
+
/** 消息类事件 */
|
|
65
|
+
EventType["MESSAGE"] = "message";
|
|
66
|
+
/**
|
|
67
|
+
* 自身消息(go-cqhttp 扩展事件)
|
|
68
|
+
*/
|
|
69
|
+
EventType["MESSAGE_SENT"] = "message_sent";
|
|
70
|
+
})(EventType || (EventType = {}));
|