@mrlingxd/koishi-plugin-adapter-onebot 0.2.5 → 0.2.7
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 +7 -1
- package/lib/bot/cqcode.js +3 -1
- package/lib/bot/index.d.ts +3 -1
- package/lib/bot/index.js +13 -4
- package/lib/bot/message.d.ts +4 -3
- package/lib/bot/message.js +21 -14
- package/lib/http.d.ts +3 -2
- package/lib/http.js +5 -4
- package/lib/index.d.ts +2 -3
- package/lib/internal.d.ts +13 -40
- package/lib/internal.js +108 -105
- package/lib/types/event/base.d.ts +1 -1
- package/lib/types/event/message.d.ts +3 -3
- package/lib/types/event/meta.d.ts +2 -2
- package/lib/types/event/notice.d.ts +2 -2
- package/lib/types/event/request.d.ts +1 -1
- package/lib/types/group.d.ts +2 -2
- package/lib/types/index.d.ts +2 -2
- package/lib/types/sender.d.ts +2 -2
- package/lib/types/user.d.ts +1 -1
- package/lib/utils.d.ts +5 -5
- package/lib/utils.js +21 -21
- package/lib/ws.d.ts +4 -3
- package/lib/ws.js +9 -9
- package/package.json +56 -58
package/lib/bot/cqcode.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { Dict
|
|
1
|
+
import type { Dict } from "koishi";
|
|
2
|
+
import { h } from "koishi";
|
|
2
3
|
export declare function CQCode(type: string, attrs: Dict<string>): string;
|
|
4
|
+
/** CQ 码接口 */
|
|
3
5
|
export interface CQCode<T extends string = string, D = Dict<string>> {
|
|
6
|
+
/**
|
|
7
|
+
* 消息类型
|
|
8
|
+
*/
|
|
4
9
|
type: T;
|
|
10
|
+
/** 消息数据 */
|
|
5
11
|
data: D;
|
|
6
12
|
}
|
|
7
13
|
export declare namespace CQCode {
|
package/lib/bot/cqcode.js
CHANGED
|
@@ -47,7 +47,9 @@ export function CQCode(type, attrs) {
|
|
|
47
47
|
while ((result = from(source))) {
|
|
48
48
|
const { type, data, capture } = result;
|
|
49
49
|
if (capture.index) {
|
|
50
|
-
elements.push(h("text", {
|
|
50
|
+
elements.push(h("text", {
|
|
51
|
+
content: unescape(source.slice(0, capture.index))
|
|
52
|
+
}));
|
|
51
53
|
}
|
|
52
54
|
elements.push(h(type, data));
|
|
53
55
|
source = source.slice(capture.index + capture[0].length);
|
package/lib/bot/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Context } from "koishi";
|
|
2
|
+
import { Bot, Schema, type Session, Universal } from "koishi";
|
|
2
3
|
import { HttpServer } from "../http";
|
|
3
4
|
import { Internal } from "../internal";
|
|
4
5
|
import { WsClient, WsServer } from "../ws";
|
|
5
6
|
import { OneBotMessageEncoder } from "./message";
|
|
7
|
+
export { CQCode } from "./cqcode";
|
|
6
8
|
export declare class OneBot<C extends Context = Context> extends Bot<C> {
|
|
7
9
|
static MessageEncoder: typeof OneBotMessageEncoder;
|
|
8
10
|
static inject: string[];
|
package/lib/bot/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { Bot, Schema } from "koishi";
|
|
1
|
+
import { Bot, Schema, Universal } from "koishi";
|
|
2
2
|
import { HttpServer } from "../http";
|
|
3
3
|
import { Internal } from "../internal";
|
|
4
|
+
import {} from "../types/event/message";
|
|
4
5
|
import { adaptChannel, adaptGuild, convertUser, decodeGuildMember, decodeMessage } from "../utils";
|
|
5
6
|
import { WsClient, WsServer } from "../ws";
|
|
6
7
|
import { OneBotMessageEncoder, PRIVATE_PFX } from "./message";
|
|
8
|
+
export { CQCode } from "./cqcode";
|
|
7
9
|
export class OneBot extends Bot {
|
|
8
10
|
static MessageEncoder = OneBotMessageEncoder;
|
|
9
11
|
static inject = ["http"];
|
|
@@ -30,7 +32,10 @@ export class OneBot extends Bot {
|
|
|
30
32
|
await Promise.all([this.getLogin()]).then(() => this.online(), (error) => this.offline(error));
|
|
31
33
|
}
|
|
32
34
|
async createDirectChannel(userId) {
|
|
33
|
-
return {
|
|
35
|
+
return {
|
|
36
|
+
id: `${PRIVATE_PFX}${userId}`,
|
|
37
|
+
type: Universal.Channel.Type.DIRECT
|
|
38
|
+
};
|
|
34
39
|
}
|
|
35
40
|
async getMessage(channelId, messageId) {
|
|
36
41
|
const data = await this.internal.getMsg(Number(messageId));
|
|
@@ -55,7 +60,9 @@ export class OneBot extends Bot {
|
|
|
55
60
|
}
|
|
56
61
|
async getFriendList() {
|
|
57
62
|
const data = await this.internal.getFriendList();
|
|
58
|
-
return {
|
|
63
|
+
return {
|
|
64
|
+
data: data.map((item) => convertUser(item, this.selfId === item.user_id.toString()))
|
|
65
|
+
};
|
|
59
66
|
}
|
|
60
67
|
async handleFriendRequest(messageId, approve, comment) {
|
|
61
68
|
await this.internal.setFriendAddRequest(messageId, approve, comment);
|
|
@@ -84,7 +91,9 @@ export class OneBot extends Bot {
|
|
|
84
91
|
list = (await this.internal.getGroupMsgHistory(Number(channelId))).messages;
|
|
85
92
|
}
|
|
86
93
|
// 从旧到新
|
|
87
|
-
return {
|
|
94
|
+
return {
|
|
95
|
+
data: await Promise.all(list.map((item) => decodeMessage(this, item)))
|
|
96
|
+
};
|
|
88
97
|
}
|
|
89
98
|
async getChannel(channelId) {
|
|
90
99
|
const data = await this.internal.getGroupInfo(Number(channelId));
|
package/lib/bot/message.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Context, h
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { Context, h } from "koishi";
|
|
2
|
+
import { MessageEncoder, Universal } from "koishi";
|
|
3
|
+
import type { OneBot } from ".";
|
|
4
|
+
import type { CQCode } from "./cqcode";
|
|
4
5
|
export interface Author extends Universal.User {
|
|
5
6
|
time?: string | number;
|
|
6
7
|
messageId?: string;
|
package/lib/bot/message.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MessageEncoder, pick } from "koishi";
|
|
1
|
+
import { MessageEncoder, pick, Universal } from "koishi";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
class State {
|
|
4
4
|
type;
|
|
@@ -13,24 +13,24 @@ export class OneBotMessageEncoder extends MessageEncoder {
|
|
|
13
13
|
stack = [new State("message")];
|
|
14
14
|
children = [];
|
|
15
15
|
async prepare() {
|
|
16
|
-
super.prepare();
|
|
16
|
+
await super.prepare();
|
|
17
17
|
const { event: { channel } } = this.session;
|
|
18
|
-
if (!channel.type) {
|
|
18
|
+
if (channel && !channel.type) {
|
|
19
19
|
channel.type = channel.id.startsWith(PRIVATE_PFX)
|
|
20
|
-
?
|
|
21
|
-
:
|
|
20
|
+
? Universal.Channel.Type.DIRECT
|
|
21
|
+
: Universal.Channel.Type.TEXT;
|
|
22
22
|
}
|
|
23
23
|
if (!this.session.isDirect) {
|
|
24
24
|
this.session.guildId ??= this.channelId;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
async forward() {
|
|
28
|
-
if (!this.stack[0].children.length)
|
|
28
|
+
if (!this.stack[0] || !this.stack[0].children.length)
|
|
29
29
|
return;
|
|
30
30
|
const session = this.bot.session();
|
|
31
31
|
session.content = "";
|
|
32
32
|
session.messageId =
|
|
33
|
-
this.session.event.channel
|
|
33
|
+
this.session.event.channel?.type === Universal.Channel.Type.DIRECT
|
|
34
34
|
? (await this.bot.internal.sendPrivateForwardMsg(Number(this.channelId.slice(PRIVATE_PFX.length)), this.stack[0].children)).toString()
|
|
35
35
|
: (await this.bot.internal.sendGroupForwardMsg(Number(this.channelId), this.stack[0].children)).toString();
|
|
36
36
|
session.userId = this.bot.selfId;
|
|
@@ -69,9 +69,9 @@ export class OneBotMessageEncoder extends MessageEncoder {
|
|
|
69
69
|
this.stack[1].children.push({
|
|
70
70
|
type: "node",
|
|
71
71
|
data: {
|
|
72
|
-
user_id: author.
|
|
72
|
+
user_id: author.id,
|
|
73
73
|
nickname: author.nick || author.name,
|
|
74
|
-
content:
|
|
74
|
+
content: this.children
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
77
|
this.children = [];
|
|
@@ -80,7 +80,7 @@ export class OneBotMessageEncoder extends MessageEncoder {
|
|
|
80
80
|
const session = this.bot.session();
|
|
81
81
|
session.content = "";
|
|
82
82
|
session.messageId =
|
|
83
|
-
this.session.event.channel.type ===
|
|
83
|
+
this.session.event.channel.type === Universal.Channel.Type.DIRECT
|
|
84
84
|
? (await this.bot.internal.sendPrivateMsg(Number(this.channelId.slice(PRIVATE_PFX.length)), this.children)).toString()
|
|
85
85
|
: (await this.bot.internal.sendGroupMsg(Number(this.channelId), this.children)).toString();
|
|
86
86
|
session.userId = this.bot.selfId;
|
|
@@ -96,7 +96,7 @@ export class OneBotMessageEncoder extends MessageEncoder {
|
|
|
96
96
|
const name = attrs.title || (await this.bot.ctx.http.file(src)).filename;
|
|
97
97
|
// 本地文件路径
|
|
98
98
|
const file = src.startsWith("file:") ? fileURLToPath(src) : await this.bot.internal.downloadFile(src);
|
|
99
|
-
if (this.session.event.channel.type ===
|
|
99
|
+
if (this.session.event.channel.type === Universal.Channel.Type.DIRECT) {
|
|
100
100
|
await this.bot.internal.uploadPrivateFile(Number(this.channelId.slice(PRIVATE_PFX.length)), file, name);
|
|
101
101
|
}
|
|
102
102
|
else {
|
|
@@ -142,7 +142,10 @@ export class OneBotMessageEncoder extends MessageEncoder {
|
|
|
142
142
|
this.children.push({ type: "at", data: { qq: "all" } });
|
|
143
143
|
}
|
|
144
144
|
else {
|
|
145
|
-
this.children.push({
|
|
145
|
+
this.children.push({
|
|
146
|
+
type: "at",
|
|
147
|
+
data: { qq: attrs.id, name: attrs.name }
|
|
148
|
+
});
|
|
146
149
|
}
|
|
147
150
|
}
|
|
148
151
|
else if (type === "sharp") {
|
|
@@ -164,7 +167,12 @@ export class OneBotMessageEncoder extends MessageEncoder {
|
|
|
164
167
|
this.text(`(${attrs.href})`);
|
|
165
168
|
}
|
|
166
169
|
else if (["video", "audio", "image", "img"].includes(type)) {
|
|
167
|
-
const typeMap = {
|
|
170
|
+
const typeMap = {
|
|
171
|
+
video: "video",
|
|
172
|
+
audio: "record",
|
|
173
|
+
img: "image",
|
|
174
|
+
image: "image"
|
|
175
|
+
};
|
|
168
176
|
const childrenType = typeMap[type];
|
|
169
177
|
if (type === "video" || type === "audio") {
|
|
170
178
|
await this.flush();
|
|
@@ -246,7 +254,6 @@ export class OneBotMessageEncoder extends MessageEncoder {
|
|
|
246
254
|
}
|
|
247
255
|
else if (type === "message") {
|
|
248
256
|
await this.flush();
|
|
249
|
-
// qqguild does not support forward messages
|
|
250
257
|
if ("forward" in attrs && !this.bot.parent) {
|
|
251
258
|
this.stack.unshift(new State("forward"));
|
|
252
259
|
await this.render(children);
|
package/lib/http.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { Context } from "koishi";
|
|
2
|
+
import { Adapter, HTTP, Schema } from "koishi";
|
|
3
|
+
import type { OneBot } from "./bot";
|
|
3
4
|
export declare class HttpServer<C extends Context = Context> extends Adapter<C, OneBot<C>> {
|
|
4
5
|
static inject: string[];
|
|
5
6
|
fork(ctx: C, bot: OneBot<C>): Promise<void>;
|
package/lib/http.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import {} from "@koishijs/plugin-server";
|
|
1
2
|
import { createHmac } from "crypto";
|
|
2
|
-
import { Adapter, HTTP, Schema } from "koishi";
|
|
3
|
+
import { Adapter, HTTP, Schema, Universal } from "koishi";
|
|
3
4
|
import { isBaseEvent } from "./types/event/base";
|
|
4
5
|
import { dispatchSession } from "./utils";
|
|
5
6
|
export class HttpServer extends Adapter {
|
|
@@ -23,7 +24,7 @@ export class HttpServer extends Adapter {
|
|
|
23
24
|
}
|
|
24
25
|
async connect(bot) {
|
|
25
26
|
const { secret, path = "/onebot" } = bot.config;
|
|
26
|
-
this.ctx.server.post(path, (ctx) => {
|
|
27
|
+
this.ctx.server.post(path, async (ctx) => {
|
|
27
28
|
if (secret) {
|
|
28
29
|
// no signature
|
|
29
30
|
const signature = ctx.headers["x-signature"];
|
|
@@ -41,11 +42,11 @@ export class HttpServer extends Adapter {
|
|
|
41
42
|
return (ctx.status = 403);
|
|
42
43
|
if (!isBaseEvent(ctx.request.response.body))
|
|
43
44
|
return (ctx.status = 400);
|
|
44
|
-
dispatchSession(bot, ctx.request.response.body);
|
|
45
|
+
void dispatchSession(bot, ctx.request.response.body);
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
async disconnect(bot) {
|
|
48
|
-
bot.status =
|
|
49
|
+
bot.status = Universal.Status.RECONNECT;
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
(function (HttpServer) {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Session } from "koishi";
|
|
2
1
|
import { OneBot } from "./bot";
|
|
3
|
-
import { Internal } from "./internal";
|
|
2
|
+
import type { Internal } from "./internal";
|
|
4
3
|
export { OneBot };
|
|
5
4
|
export * from "./bot";
|
|
6
5
|
export * from "./http";
|
|
7
6
|
export * from "./ws";
|
|
8
7
|
export default OneBot;
|
|
9
|
-
declare module "
|
|
8
|
+
declare module "koishi" {
|
|
10
9
|
interface Session {
|
|
11
10
|
onebot?: Internal & {
|
|
12
11
|
targetId?: string;
|
package/lib/internal.d.ts
CHANGED
|
@@ -1,38 +1,27 @@
|
|
|
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";
|
|
1
|
+
import { type Dict } from "koishi";
|
|
2
|
+
import type { OneBot } from "./bot";
|
|
3
|
+
import type { CQCode } from "./bot/cqcode";
|
|
4
|
+
import type { EssenceMessage, FriendInfo, GetCredentialsResponse, GroupAtAllRemain, GroupFileList, GroupFileSystemInfo, GroupHonorInfo, GroupNotice, GroupSystemMsgResponse, ImageOcrResult, LoginInfo, ModelVariant, UnidirectionalFriendInfo } from "./types";
|
|
5
|
+
import type { Device } from "./types/device";
|
|
6
|
+
import type { HonorType, SafetyLevel } from "./types/enum";
|
|
7
|
+
import type { GroupMessageEvent, MessageEvent } from "./types/event/message";
|
|
8
|
+
import type { GroupInfo, GroupMemberInfo } from "./types/group";
|
|
9
|
+
import type { UserInfo } from "./types/user";
|
|
10
10
|
export declare class Internal {
|
|
11
11
|
readonly bot: OneBot;
|
|
12
|
-
_request
|
|
12
|
+
_request?: (action: string, params: Dict) => Promise<any>;
|
|
13
13
|
constructor(bot: OneBot);
|
|
14
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
15
|
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
16
|
sendGroupMsg(group_id: number, message: string | readonly CQCode.CQCodeUnion[], auto_escape?: boolean): Promise<number>;
|
|
20
|
-
|
|
21
|
-
|
|
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>;
|
|
17
|
+
sendGroupForwardMsg(group_id: number, messages: readonly CQCode.MergeForward[] | CQCode.Forward): Promise<number>;
|
|
18
|
+
sendPrivateForwardMsg(user_id: number, messages: readonly CQCode.MergeForward[] | CQCode.Forward): Promise<number>;
|
|
25
19
|
deleteMsg(message_id: number): Promise<void>;
|
|
26
|
-
deleteMsgAsync(message_id: number): Promise<void>;
|
|
27
20
|
setEssenceMsg(message_id: number): Promise<void>;
|
|
28
|
-
setEssenceMsgAsync(message_id: number): Promise<void>;
|
|
29
21
|
deleteEssenceMsg(message_id: number): Promise<void>;
|
|
30
|
-
deleteEssenceMsgAsync(message_id: number): Promise<void>;
|
|
31
22
|
markMsgAsRead(message_id: number): Promise<void>;
|
|
32
23
|
sendLike(user_id: number, times?: number): Promise<void>;
|
|
33
|
-
sendLikeAsync(user_id: number, times?: number): Promise<void>;
|
|
34
24
|
sendGroupSign(group_id: number): Promise<void>;
|
|
35
|
-
sendGroupSignAsync(group_id: number): Promise<void>;
|
|
36
25
|
getMsg(message_id: number): Promise<MessageEvent>;
|
|
37
26
|
getForwardMsg(message_id: number): Promise<CQCode.MergeForward>;
|
|
38
27
|
getEssenceMsgList(group_id: number): Promise<EssenceMessage[]>;
|
|
@@ -42,41 +31,25 @@ export declare class Internal {
|
|
|
42
31
|
messages: GroupMessageEvent[];
|
|
43
32
|
}>;
|
|
44
33
|
deleteFriend(user_id: number): Promise<void>;
|
|
45
|
-
deleteFriendAsync(user_id: number): Promise<void>;
|
|
46
34
|
deleteUnidirectionalFriend(user_id: number): Promise<void>;
|
|
47
|
-
deleteUnidirectionalFriendAsync(user_id: number): Promise<void>;
|
|
48
35
|
setFriendAddRequest(flag: string, approve: boolean, remark?: string): Promise<void>;
|
|
49
|
-
setFriendAddRequestAsync(flag: string, approve: boolean, remark?: string): Promise<void>;
|
|
50
36
|
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
37
|
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
38
|
setGroupBan(group_id: number, user_id: number, duration?: number): Promise<void>;
|
|
55
|
-
setGroupBanAsync(group_id: number, user_id: number, duration?: number): Promise<void>;
|
|
56
39
|
setGroupWholeBan(group_id: number, enable?: boolean): Promise<void>;
|
|
57
|
-
setGroupWholeBanAsync(group_id: number, enable?: boolean): Promise<void>;
|
|
58
40
|
setGroupAdmin(group_id: number, user_id: number, enable?: boolean): Promise<void>;
|
|
59
|
-
setGroupAdminAsync(group_id: number, user_id: number, enable?: boolean): Promise<void>;
|
|
60
41
|
setGroupAnonymous(group_id: number, enable?: boolean): Promise<void>;
|
|
61
|
-
setGroupAnonymousAsync(group_id: number, enable?: boolean): Promise<void>;
|
|
62
42
|
setGroupCard(group_id: number, user_id: number, card?: string): Promise<void>;
|
|
63
|
-
setGroupCardAsync(group_id: number, user_id: number, card?: string): Promise<void>;
|
|
64
43
|
setGroupLeave(group_id: number, is_dismiss?: boolean): Promise<void>;
|
|
65
|
-
setGroupLeaveAsync(group_id: number, is_dismiss?: boolean): Promise<void>;
|
|
66
44
|
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
45
|
setGroupName(group_id: number, name: string): Promise<void>;
|
|
69
|
-
setGroupNameAsync(group_id: number, name: string): Promise<void>;
|
|
70
46
|
setGroupPortrait(group_id: number, file: string, cache?: boolean): Promise<void>;
|
|
71
|
-
setGroupPortraitAsync(group_id: number, file: string, cache?: boolean): Promise<void>;
|
|
72
47
|
getGroupAtAllRemain(group_id: number): Promise<GroupAtAllRemain>;
|
|
73
48
|
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
49
|
getGroupNotice(group_id: number): Promise<GroupNotice[]>;
|
|
76
50
|
delGroupNotice(group_id: number, notice_id: number): Promise<void>;
|
|
77
51
|
getLoginInfo(): Promise<LoginInfo>;
|
|
78
52
|
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
53
|
setQqAvatar(file: string): Promise<void>;
|
|
81
54
|
setOnlineStatus(status: string, extStatus: string, batteryStatus: string): Promise<void>;
|
|
82
55
|
getStrangerInfo(user_id: number, no_cache?: boolean): Promise<UserInfo>;
|
|
@@ -105,7 +78,7 @@ export declare class Internal {
|
|
|
105
78
|
getCookies(domain?: string): Promise<string>;
|
|
106
79
|
getCsrfToken(): Promise<number>;
|
|
107
80
|
getCredentials(domain?: string): Promise<GetCredentialsResponse>;
|
|
108
|
-
getRecord(file: string, out_format:
|
|
81
|
+
getRecord(file: string, out_format: string, full_path?: boolean): Promise<{
|
|
109
82
|
/** 转换后的语音文件路径 */
|
|
110
83
|
file: string;
|
|
111
84
|
}>;
|
package/lib/internal.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {} from "koishi";
|
|
1
2
|
import { SenderError } from "./types/sender";
|
|
2
3
|
export class Internal {
|
|
3
4
|
bot;
|
|
@@ -7,6 +8,9 @@ export class Internal {
|
|
|
7
8
|
}
|
|
8
9
|
async _get(action, params = {}) {
|
|
9
10
|
this.bot.logger.debug("[request] %s %o", action, params);
|
|
11
|
+
if (!this._request) {
|
|
12
|
+
throw new Error("适配器未连接");
|
|
13
|
+
}
|
|
10
14
|
const response = await this._request(action, params);
|
|
11
15
|
this.bot.logger.debug("[response] %o", response);
|
|
12
16
|
const { data, retcode } = response;
|
|
@@ -15,78 +19,55 @@ export class Internal {
|
|
|
15
19
|
}
|
|
16
20
|
return data;
|
|
17
21
|
}
|
|
18
|
-
async setGroupAnonymousBan(group_id, meta, duration) {
|
|
19
|
-
const args = { group_id, duration };
|
|
20
|
-
args[typeof meta === "string" ? "flag" : "anonymous"] = meta;
|
|
21
|
-
await this._get("set_group_anonymous_ban", args);
|
|
22
|
-
}
|
|
23
|
-
async setGroupAnonymousBanAsync(group_id, meta, duration) {
|
|
24
|
-
const args = { group_id, duration };
|
|
25
|
-
args[typeof meta === "string" ? "flag" : "anonymous"] = meta;
|
|
26
|
-
await this._get("set_group_anonymous_ban_async", args);
|
|
27
|
-
}
|
|
28
22
|
// Messages
|
|
29
23
|
async sendPrivateMsg(user_id, message, auto_escape) {
|
|
30
|
-
const data = await this._get("send_private_msg", {
|
|
24
|
+
const data = await this._get("send_private_msg", {
|
|
25
|
+
user_id,
|
|
26
|
+
message,
|
|
27
|
+
auto_escape
|
|
28
|
+
});
|
|
31
29
|
return data.message_id;
|
|
32
30
|
}
|
|
33
|
-
async sendPrivateMsgAsync(user_id, message, auto_escape) {
|
|
34
|
-
await this._get("send_private_msg_async", { user_id, message, auto_escape });
|
|
35
|
-
}
|
|
36
31
|
async sendGroupMsg(group_id, message, auto_escape) {
|
|
37
|
-
const data = await this._get("send_group_msg", {
|
|
32
|
+
const data = await this._get("send_group_msg", {
|
|
33
|
+
group_id,
|
|
34
|
+
message,
|
|
35
|
+
auto_escape
|
|
36
|
+
});
|
|
38
37
|
return data.message_id;
|
|
39
38
|
}
|
|
40
|
-
async sendGroupMsgAsync(group_id, message, auto_escape) {
|
|
41
|
-
await this._get("send_group_msg_async", { group_id, message, auto_escape });
|
|
42
|
-
}
|
|
43
39
|
async sendGroupForwardMsg(group_id, messages) {
|
|
44
|
-
const data = await this._get("send_group_forward_msg", {
|
|
40
|
+
const data = await this._get("send_group_forward_msg", {
|
|
41
|
+
group_id,
|
|
42
|
+
messages
|
|
43
|
+
});
|
|
45
44
|
return data.message_id;
|
|
46
45
|
}
|
|
47
|
-
async sendGroupForwardMsgAsync(group_id, messages) {
|
|
48
|
-
await this._get("send_group_forward_msg_async", { group_id, messages });
|
|
49
|
-
}
|
|
50
46
|
async sendPrivateForwardMsg(user_id, messages) {
|
|
51
|
-
const data = await this._get("send_private_forward_msg", {
|
|
47
|
+
const data = await this._get("send_private_forward_msg", {
|
|
48
|
+
user_id,
|
|
49
|
+
messages
|
|
50
|
+
});
|
|
52
51
|
return data.message_id;
|
|
53
52
|
}
|
|
54
|
-
async sendPrivateForwardMsgAsync(user_id, messages) {
|
|
55
|
-
await this._get("send_private_forward_msg_async", { user_id, messages });
|
|
56
|
-
}
|
|
57
53
|
async deleteMsg(message_id) {
|
|
58
54
|
await this._get("delete_msg", { message_id });
|
|
59
55
|
}
|
|
60
|
-
async deleteMsgAsync(message_id) {
|
|
61
|
-
await this._get("delete_msg_async", { message_id });
|
|
62
|
-
}
|
|
63
56
|
async setEssenceMsg(message_id) {
|
|
64
57
|
await this._get("set_essence_msg", { message_id });
|
|
65
58
|
}
|
|
66
|
-
async setEssenceMsgAsync(message_id) {
|
|
67
|
-
await this._get("set_essence_msg_async", { message_id });
|
|
68
|
-
}
|
|
69
59
|
async deleteEssenceMsg(message_id) {
|
|
70
60
|
await this._get("delete_essence_msg", { message_id });
|
|
71
61
|
}
|
|
72
|
-
async deleteEssenceMsgAsync(message_id) {
|
|
73
|
-
await this._get("delete_essence_msg_async", { message_id });
|
|
74
|
-
}
|
|
75
62
|
async markMsgAsRead(message_id) {
|
|
76
63
|
await this._get("mark_msg_as_read", { message_id });
|
|
77
64
|
}
|
|
78
65
|
async sendLike(user_id, times) {
|
|
79
66
|
await this._get("send_like", { user_id, times });
|
|
80
67
|
}
|
|
81
|
-
async sendLikeAsync(user_id, times) {
|
|
82
|
-
await this._get("send_like_async", { user_id, times });
|
|
83
|
-
}
|
|
84
68
|
async sendGroupSign(group_id) {
|
|
85
69
|
await this._get("send_group_sign", { group_id });
|
|
86
70
|
}
|
|
87
|
-
async sendGroupSignAsync(group_id) {
|
|
88
|
-
await this._get("send_group_sign_async", { group_id });
|
|
89
|
-
}
|
|
90
71
|
async getMsg(message_id) {
|
|
91
72
|
return await this._get("get_msg", { message_id });
|
|
92
73
|
}
|
|
@@ -105,101 +86,79 @@ export class Internal {
|
|
|
105
86
|
return await this._get("ocr_image", { image });
|
|
106
87
|
}
|
|
107
88
|
async getGroupMsgHistory(group_id, message_seq) {
|
|
108
|
-
return await this._get("get_group_msg_history", {
|
|
89
|
+
return await this._get("get_group_msg_history", {
|
|
90
|
+
group_id,
|
|
91
|
+
message_seq
|
|
92
|
+
});
|
|
109
93
|
}
|
|
110
94
|
async deleteFriend(user_id) {
|
|
111
95
|
await this._get("delete_friend", { user_id });
|
|
112
96
|
}
|
|
113
|
-
async deleteFriendAsync(user_id) {
|
|
114
|
-
await this._get("delete_friend_async", { user_id });
|
|
115
|
-
}
|
|
116
97
|
async deleteUnidirectionalFriend(user_id) {
|
|
117
98
|
await this._get("delete_unidirectional_friend", { user_id });
|
|
118
99
|
}
|
|
119
|
-
async deleteUnidirectionalFriendAsync(user_id) {
|
|
120
|
-
await this._get("delete_unidirectional_friend_async", { user_id });
|
|
121
|
-
}
|
|
122
100
|
async setFriendAddRequest(flag, approve, remark) {
|
|
123
101
|
await this._get("set_friend_add_request", { flag, approve, remark });
|
|
124
102
|
}
|
|
125
|
-
async setFriendAddRequestAsync(flag, approve, remark) {
|
|
126
|
-
await this._get("set_friend_add_request_async", { flag, approve, remark });
|
|
127
|
-
}
|
|
128
103
|
async setGroupAddRequest(flag, subType, approve, reason) {
|
|
129
|
-
await this._get("set_group_add_request", {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
104
|
+
await this._get("set_group_add_request", {
|
|
105
|
+
flag,
|
|
106
|
+
sub_type: subType,
|
|
107
|
+
approve,
|
|
108
|
+
reason
|
|
109
|
+
});
|
|
133
110
|
}
|
|
134
111
|
// Group operations
|
|
135
112
|
async setGroupKick(group_id, user_id, reject_add_request) {
|
|
136
|
-
await this._get("set_group_kick", {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
113
|
+
await this._get("set_group_kick", {
|
|
114
|
+
group_id,
|
|
115
|
+
user_id,
|
|
116
|
+
reject_add_request
|
|
117
|
+
});
|
|
140
118
|
}
|
|
141
119
|
async setGroupBan(group_id, user_id, duration) {
|
|
142
120
|
await this._get("set_group_ban", { group_id, user_id, duration });
|
|
143
121
|
}
|
|
144
|
-
async setGroupBanAsync(group_id, user_id, duration) {
|
|
145
|
-
await this._get("set_group_ban_async", { group_id, user_id, duration });
|
|
146
|
-
}
|
|
147
122
|
async setGroupWholeBan(group_id, enable) {
|
|
148
123
|
await this._get("set_group_whole_ban", { group_id, enable });
|
|
149
124
|
}
|
|
150
|
-
async setGroupWholeBanAsync(group_id, enable) {
|
|
151
|
-
await this._get("set_group_whole_ban_async", { group_id, enable });
|
|
152
|
-
}
|
|
153
125
|
async setGroupAdmin(group_id, user_id, enable) {
|
|
154
126
|
await this._get("set_group_admin", { group_id, user_id, enable });
|
|
155
127
|
}
|
|
156
|
-
async setGroupAdminAsync(group_id, user_id, enable) {
|
|
157
|
-
await this._get("set_group_admin_async", { group_id, user_id, enable });
|
|
158
|
-
}
|
|
159
128
|
async setGroupAnonymous(group_id, enable) {
|
|
160
129
|
await this._get("set_group_anonymous", { group_id, enable });
|
|
161
130
|
}
|
|
162
|
-
async setGroupAnonymousAsync(group_id, enable) {
|
|
163
|
-
await this._get("set_group_anonymous_async", { group_id, enable });
|
|
164
|
-
}
|
|
165
131
|
async setGroupCard(group_id, user_id, card) {
|
|
166
132
|
await this._get("set_group_card", { group_id, user_id, card });
|
|
167
133
|
}
|
|
168
|
-
async setGroupCardAsync(group_id, user_id, card) {
|
|
169
|
-
await this._get("set_group_card_async", { group_id, user_id, card });
|
|
170
|
-
}
|
|
171
134
|
async setGroupLeave(group_id, is_dismiss) {
|
|
172
135
|
await this._get("set_group_leave", { group_id, is_dismiss });
|
|
173
136
|
}
|
|
174
|
-
async setGroupLeaveAsync(group_id, is_dismiss) {
|
|
175
|
-
await this._get("set_group_leave_async", { group_id, is_dismiss });
|
|
176
|
-
}
|
|
177
137
|
async setGroupSpecialTitle(group_id, user_id, special_title, duration) {
|
|
178
|
-
await this._get("set_group_special_title", {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
138
|
+
await this._get("set_group_special_title", {
|
|
139
|
+
group_id,
|
|
140
|
+
user_id,
|
|
141
|
+
special_title,
|
|
142
|
+
duration
|
|
143
|
+
});
|
|
182
144
|
}
|
|
183
145
|
async setGroupName(group_id, name) {
|
|
184
146
|
await this._get("set_group_name", { group_id, group_name: name });
|
|
185
147
|
}
|
|
186
|
-
async setGroupNameAsync(group_id, name) {
|
|
187
|
-
await this._get("set_group_name_async", { group_id, group_name: name });
|
|
188
|
-
}
|
|
189
148
|
async setGroupPortrait(group_id, file, cache) {
|
|
190
149
|
await this._get("set_group_portrait", { group_id, file, cache });
|
|
191
150
|
}
|
|
192
|
-
async setGroupPortraitAsync(group_id, file, cache) {
|
|
193
|
-
await this._get("set_group_portrait_async", { group_id, file, cache });
|
|
194
|
-
}
|
|
195
151
|
async getGroupAtAllRemain(group_id) {
|
|
196
152
|
return await this._get("get_group_at_all_remain", { group_id });
|
|
197
153
|
}
|
|
198
154
|
async sendGroupNotice(group_id, content, image, pinned, confirm_required) {
|
|
199
|
-
await this._get("_send_group_notice", {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
155
|
+
await this._get("_send_group_notice", {
|
|
156
|
+
group_id,
|
|
157
|
+
content,
|
|
158
|
+
image,
|
|
159
|
+
pinned,
|
|
160
|
+
confirm_required
|
|
161
|
+
});
|
|
203
162
|
}
|
|
204
163
|
async getGroupNotice(group_id) {
|
|
205
164
|
return await this._get("_get_group_notice", { group_id });
|
|
@@ -212,16 +171,23 @@ export class Internal {
|
|
|
212
171
|
return await this._get("get_login_info");
|
|
213
172
|
}
|
|
214
173
|
async setQqProfile(nickname, company, email, college, personal_note) {
|
|
215
|
-
await this._get("set_qq_profile", {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
174
|
+
await this._get("set_qq_profile", {
|
|
175
|
+
nickname,
|
|
176
|
+
company,
|
|
177
|
+
email,
|
|
178
|
+
college,
|
|
179
|
+
personal_note
|
|
180
|
+
});
|
|
219
181
|
}
|
|
220
182
|
async setQqAvatar(file) {
|
|
221
183
|
await this._get("set_qq_avatar", { file });
|
|
222
184
|
}
|
|
223
185
|
async setOnlineStatus(status, extStatus, batteryStatus) {
|
|
224
|
-
await this._get("set_online_status", {
|
|
186
|
+
await this._get("set_online_status", {
|
|
187
|
+
status,
|
|
188
|
+
ext_status: extStatus,
|
|
189
|
+
battery_status: batteryStatus
|
|
190
|
+
});
|
|
225
191
|
}
|
|
226
192
|
async getStrangerInfo(user_id, no_cache) {
|
|
227
193
|
return await this._get("get_stranger_info", { user_id, no_cache });
|
|
@@ -239,7 +205,11 @@ export class Internal {
|
|
|
239
205
|
return await this._get("get_group_list", { no_cache });
|
|
240
206
|
}
|
|
241
207
|
async getGroupMemberInfo(group_id, user_id, no_cache) {
|
|
242
|
-
return await this._get("get_group_member_info", {
|
|
208
|
+
return await this._get("get_group_member_info", {
|
|
209
|
+
group_id,
|
|
210
|
+
user_id,
|
|
211
|
+
no_cache
|
|
212
|
+
});
|
|
243
213
|
}
|
|
244
214
|
async getGroupMemberList(group_id, no_cache) {
|
|
245
215
|
return await this._get("get_group_member_list", { group_id, no_cache });
|
|
@@ -258,14 +228,25 @@ export class Internal {
|
|
|
258
228
|
return await this._get("get_group_root_files", { group_id });
|
|
259
229
|
}
|
|
260
230
|
async getGroupFilesByFolder(group_id, folder_id) {
|
|
261
|
-
return await this._get("get_group_files_by_folder", {
|
|
231
|
+
return await this._get("get_group_files_by_folder", {
|
|
232
|
+
group_id,
|
|
233
|
+
folder_id
|
|
234
|
+
});
|
|
262
235
|
}
|
|
263
236
|
async getGroupFileUrl(group_id, file_id, busid) {
|
|
264
|
-
const data = await this._get("get_group_file_url", {
|
|
237
|
+
const data = await this._get("get_group_file_url", {
|
|
238
|
+
group_id,
|
|
239
|
+
file_id,
|
|
240
|
+
busid
|
|
241
|
+
});
|
|
265
242
|
return data.url;
|
|
266
243
|
}
|
|
267
244
|
async downloadFile(url, headers, thread_count) {
|
|
268
|
-
const data = await this._get("download_file", {
|
|
245
|
+
const data = await this._get("download_file", {
|
|
246
|
+
url,
|
|
247
|
+
headers,
|
|
248
|
+
thread_count
|
|
249
|
+
});
|
|
269
250
|
return data.file;
|
|
270
251
|
}
|
|
271
252
|
async uploadPrivateFile(user_id, file, name) {
|
|
@@ -275,13 +256,22 @@ export class Internal {
|
|
|
275
256
|
await this._get("upload_group_file", { group_id, file, name, folder });
|
|
276
257
|
}
|
|
277
258
|
async createGroupFileFolder(group_id, folder_id, name) {
|
|
278
|
-
await this._get("create_group_file_folder", {
|
|
259
|
+
await this._get("create_group_file_folder", {
|
|
260
|
+
group_id,
|
|
261
|
+
folder_id,
|
|
262
|
+
name
|
|
263
|
+
});
|
|
279
264
|
}
|
|
280
265
|
async deleteGroupFolder(group_id, folder_id) {
|
|
281
266
|
await this._get("delete_group_folder", { group_id, folder_id });
|
|
282
267
|
}
|
|
283
268
|
async deleteGroupFile(group_id, folder_id, file_id, busid) {
|
|
284
|
-
await this._get("delete_group_file", {
|
|
269
|
+
await this._get("delete_group_file", {
|
|
270
|
+
group_id,
|
|
271
|
+
folder_id,
|
|
272
|
+
file_id,
|
|
273
|
+
busid
|
|
274
|
+
});
|
|
285
275
|
}
|
|
286
276
|
async getOnlineClients(no_cache) {
|
|
287
277
|
const data = await this._get("get_online_clients", { no_cache });
|
|
@@ -343,16 +333,29 @@ export class Internal {
|
|
|
343
333
|
return await this._get("upload_image", { file });
|
|
344
334
|
}
|
|
345
335
|
async getPrivateFileUrl(user_id, file_id, file_hash) {
|
|
346
|
-
const data = await this._get("get_private_file_url", {
|
|
336
|
+
const data = await this._get("get_private_file_url", {
|
|
337
|
+
user_id,
|
|
338
|
+
file_id,
|
|
339
|
+
file_hash
|
|
340
|
+
});
|
|
347
341
|
return data.url;
|
|
348
342
|
}
|
|
349
343
|
async moveGroupFile(group_id, file_id, parent_directory, target_directory) {
|
|
350
|
-
await this._get("move_group_file", {
|
|
344
|
+
await this._get("move_group_file", {
|
|
345
|
+
group_id,
|
|
346
|
+
file_id,
|
|
347
|
+
parent_directory,
|
|
348
|
+
target_directory
|
|
349
|
+
});
|
|
351
350
|
}
|
|
352
351
|
async deleteGroupFileFolder(group_id, folder_id) {
|
|
353
352
|
await this._get("delete_group_file_folder", { group_id, folder_id });
|
|
354
353
|
}
|
|
355
354
|
async renameGroupFileFolder(group_id, folder_id, new_folder_name) {
|
|
356
|
-
await this._get("rename_group_file_folder", {
|
|
355
|
+
await this._get("rename_group_file_folder", {
|
|
356
|
+
group_id,
|
|
357
|
+
folder_id,
|
|
358
|
+
new_folder_name
|
|
359
|
+
});
|
|
357
360
|
}
|
|
358
361
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CQCode } from "../../bot/cqcode";
|
|
1
|
+
import type { CQCode } from "../../bot/cqcode";
|
|
2
2
|
import { EventType } from "../enum";
|
|
3
|
-
import { Anonymous, GroupSender, Sender } from "../sender";
|
|
4
|
-
import { BaseEvent, SubType } from "./base";
|
|
3
|
+
import type { Anonymous, GroupSender, Sender } from "../sender";
|
|
4
|
+
import type { BaseEvent, SubType } from "./base";
|
|
5
5
|
/** 消息事件接口 */
|
|
6
6
|
interface BaseMessageEvent<S extends Sender | GroupSender, M extends "private" | "group"> extends BaseEvent<EventType.MESSAGE | EventType.MESSAGE_SENT> {
|
|
7
7
|
/** 消息类型 */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EventType } from "../enum";
|
|
2
|
-
import { BaseEvent } from "./base";
|
|
1
|
+
import type { EventType } from "../enum";
|
|
2
|
+
import type { BaseEvent } from "./base";
|
|
3
3
|
/** 元事件 */
|
|
4
4
|
interface MetaEvent<meta_event_type extends "lifecycle" | "heartbeat"> extends BaseEvent<EventType.META> {
|
|
5
5
|
/** 元事件类型 */
|
package/lib/types/group.d.ts
CHANGED
package/lib/types/index.d.ts
CHANGED
package/lib/types/sender.d.ts
CHANGED
package/lib/types/user.d.ts
CHANGED
package/lib/utils.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Universal } from "koishi";
|
|
2
|
-
import { OneBot } from "./bot";
|
|
2
|
+
import type { OneBot } from "./bot";
|
|
3
3
|
import { EventType } from "./types/enum";
|
|
4
|
-
import { BaseEvent } from "./types/event/base";
|
|
5
|
-
import { MessageEvent } from "./types/event/message";
|
|
6
|
-
import { GroupInfo, GroupMemberInfo } from "./types/group";
|
|
7
|
-
import { UserInfo } from "./types/user";
|
|
4
|
+
import type { BaseEvent } from "./types/event/base";
|
|
5
|
+
import { type MessageEvent } from "./types/event/message";
|
|
6
|
+
import type { GroupInfo, GroupMemberInfo } from "./types/group";
|
|
7
|
+
import type { UserInfo } from "./types/user";
|
|
8
8
|
export * from "./types";
|
|
9
9
|
export declare const convertUser: (user: UserInfo, isBot?: boolean) => Universal.User;
|
|
10
10
|
export declare const decodeUser: (event: MessageEvent, isBot?: boolean) => Universal.User;
|
package/lib/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h, omit } from "koishi";
|
|
1
|
+
import { h, omit, Universal } from "koishi";
|
|
2
2
|
import * as qface from "qface";
|
|
3
3
|
import { CQCode } from "./bot/cqcode";
|
|
4
4
|
import { EventType, GroupMemberRole } from "./types/enum";
|
|
@@ -35,7 +35,7 @@ export const decodeGuildMember = (user, isBot = false) => ({
|
|
|
35
35
|
roles: [user.role]
|
|
36
36
|
});
|
|
37
37
|
export async function decodeMessage(bot, event, message = {}, payload = message) {
|
|
38
|
-
const [
|
|
38
|
+
const [_, channelId] = decodeGroupChannelId(event);
|
|
39
39
|
// message content
|
|
40
40
|
const chain = CQCode.parse(event.message);
|
|
41
41
|
// 映射
|
|
@@ -47,59 +47,61 @@ export async function decodeMessage(bot, event, message = {}, payload = message)
|
|
|
47
47
|
if (attrs.qq !== "all")
|
|
48
48
|
return h.at(attrs.qq, {
|
|
49
49
|
name: attrs.name,
|
|
50
|
-
...omit(attrs, [attrs.qq ? "qq" : undefined, attrs.name ? "name" : undefined])
|
|
50
|
+
...omit(attrs, [attrs.qq ? "qq" : undefined, attrs.name ? "name" : undefined].filter((k) => !!k))
|
|
51
51
|
});
|
|
52
52
|
return h.at("at", {
|
|
53
53
|
type: "all",
|
|
54
|
-
...omit(attrs, [attrs.qq ? "qq" : undefined, attrs.name ? "name" : undefined])
|
|
54
|
+
...omit(attrs, [attrs.qq ? "qq" : undefined, attrs.name ? "name" : undefined].filter((k) => !!k))
|
|
55
55
|
});
|
|
56
56
|
},
|
|
57
57
|
face(attrs) {
|
|
58
58
|
const name = qface.get(attrs.id)?.QDes.slice(1);
|
|
59
|
-
return h("face", { id: attrs.id, name
|
|
59
|
+
return h("face", { id: attrs.id, name }, [h.image(qface.getUrl(attrs.id))]);
|
|
60
60
|
},
|
|
61
61
|
image(attrs) {
|
|
62
62
|
return h.image(attrs.url || attrs.file, {
|
|
63
63
|
title: attrs.name || undefined,
|
|
64
|
-
...omit(
|
|
64
|
+
...omit([
|
|
65
65
|
attrs.name ? "name" : undefined,
|
|
66
66
|
attrs.url ? "url" : undefined,
|
|
67
67
|
attrs.file ? "file" : undefined
|
|
68
|
-
])
|
|
68
|
+
].filter((k) => !!k))
|
|
69
69
|
});
|
|
70
70
|
},
|
|
71
71
|
record(attrs) {
|
|
72
72
|
return h.audio(attrs.url || attrs.file, {
|
|
73
|
-
...omit(
|
|
73
|
+
...omit([attrs.url ? "url" : undefined, attrs.file ? "file" : undefined].filter((k) => !!k))
|
|
74
74
|
});
|
|
75
75
|
},
|
|
76
76
|
video(attrs) {
|
|
77
77
|
return h.video(attrs.url || attrs.file, {
|
|
78
|
-
...omit(
|
|
78
|
+
...omit([attrs.url ? "url" : undefined, attrs.file ? "file" : undefined].filter((k) => !!k))
|
|
79
79
|
});
|
|
80
80
|
},
|
|
81
81
|
file(attrs) {
|
|
82
82
|
return h.file(attrs.url || attrs.file, {
|
|
83
|
-
...omit(
|
|
83
|
+
...omit([attrs.url ? "url" : undefined, attrs.file ? "file" : undefined].filter((k) => !!k))
|
|
84
84
|
});
|
|
85
85
|
},
|
|
86
86
|
reply(attrs) {
|
|
87
87
|
return h("reply", { id: attrs.id });
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
|
-
if (message.elements[0].type === "reply") {
|
|
90
|
+
if (message.elements[0] && message.elements[0].type === "reply") {
|
|
91
91
|
const reply = message.elements.shift();
|
|
92
|
-
|
|
93
|
-
bot.
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
if (reply) {
|
|
93
|
+
message.quote = await bot.getMessage(channelId, reply.attrs.id).catch((error) => {
|
|
94
|
+
bot.logger.warn(error);
|
|
95
|
+
return undefined;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
96
98
|
}
|
|
97
99
|
message.content = message.elements.join("");
|
|
98
100
|
payload.timestamp = event.time * 1000;
|
|
99
101
|
message.id = event.message_id.toString();
|
|
100
102
|
payload.channel = {
|
|
101
103
|
id: channelId,
|
|
102
|
-
type: event.message_type === "group" ?
|
|
104
|
+
type: event.message_type === "group" ? Universal.Channel.Type.TEXT : Universal.Channel.Type.DIRECT,
|
|
103
105
|
name: event.message_type === "group" ? event.group_name || undefined : event.sender.nickname
|
|
104
106
|
};
|
|
105
107
|
payload.user = decodeUser(event);
|
|
@@ -114,7 +116,7 @@ export async function decodeMessage(bot, event, message = {}, payload = message)
|
|
|
114
116
|
name: event.sender.nickname,
|
|
115
117
|
nick: event.sender.card,
|
|
116
118
|
avatar: `https://q.qlogo.cn/headimg_dl?dst_uin=${event.user_id}&spec=640`,
|
|
117
|
-
roles: [event.sender.role]
|
|
119
|
+
roles: event.sender.role ? [event.sender.role] : []
|
|
118
120
|
};
|
|
119
121
|
}
|
|
120
122
|
return message;
|
|
@@ -123,9 +125,7 @@ const decodeGroupChannelId = (event) => {
|
|
|
123
125
|
if (event.message_type === "group") {
|
|
124
126
|
return [event.group_id.toString(), event.group_id.toString()];
|
|
125
127
|
}
|
|
126
|
-
|
|
127
|
-
return [undefined, "private:" + event.sender.user_id];
|
|
128
|
-
}
|
|
128
|
+
return [undefined, "private:" + event.sender.user_id];
|
|
129
129
|
};
|
|
130
130
|
export const adaptGuild = (info) => {
|
|
131
131
|
return {
|
|
@@ -138,7 +138,7 @@ export const adaptChannel = (info) => {
|
|
|
138
138
|
return {
|
|
139
139
|
id: info.group_id.toString(),
|
|
140
140
|
name: info.group_name,
|
|
141
|
-
type:
|
|
141
|
+
type: Universal.Channel.Type.TEXT
|
|
142
142
|
};
|
|
143
143
|
};
|
|
144
144
|
export async function dispatchSession(bot, data) {
|
package/lib/ws.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { WebSocketLayer } from "@koishijs/plugin-server";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { WebSocketLayer } from "@koishijs/plugin-server";
|
|
2
|
+
import type { Context, Logger } from "koishi";
|
|
3
|
+
import { Adapter, HTTP, Schema, Universal } from "koishi";
|
|
4
|
+
import type { OneBot } from "./bot";
|
|
4
5
|
export interface SharedConfig<T = "ws" | "ws-reverse"> {
|
|
5
6
|
protocol: T;
|
|
6
7
|
responseTimeout?: number;
|
package/lib/ws.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Adapter, HTTP, Schema, Time } from "koishi";
|
|
1
|
+
import { Adapter, HTTP, Schema, Time, Universal } from "koishi";
|
|
2
2
|
import { dispatchSession, TimeoutError } from "./utils";
|
|
3
3
|
let counter = 0;
|
|
4
4
|
const listeners = {};
|
|
@@ -17,7 +17,7 @@ export class WsClient extends Adapter.WsClient {
|
|
|
17
17
|
return http.ws(endpoint);
|
|
18
18
|
}
|
|
19
19
|
async disconnect(bot) {
|
|
20
|
-
bot.status =
|
|
20
|
+
bot.status = Universal.Status.RECONNECT;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
(function (WsClient) {
|
|
@@ -53,16 +53,16 @@ export class WsServer extends Adapter {
|
|
|
53
53
|
bot[kSocket] = socket;
|
|
54
54
|
accept(socket, bot);
|
|
55
55
|
});
|
|
56
|
-
ctx.on("dispose", () => {
|
|
56
|
+
ctx.on("dispose", async () => {
|
|
57
57
|
this.logger.debug("ws server closing");
|
|
58
58
|
this.wsServer.close();
|
|
59
|
-
this.disconnect(bot);
|
|
59
|
+
await this.disconnect(bot);
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
async disconnect(bot) {
|
|
63
63
|
bot[kSocket]?.close();
|
|
64
64
|
bot[kSocket] = null;
|
|
65
|
-
bot.status =
|
|
65
|
+
bot.status = Universal.Status.RECONNECT;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
(function (WsServer) {
|
|
@@ -83,19 +83,19 @@ export function accept(socket, bot) {
|
|
|
83
83
|
}
|
|
84
84
|
if ("post_type" in parsed) {
|
|
85
85
|
bot.logger.debug("[receive] %o", parsed);
|
|
86
|
-
|
|
86
|
+
void dispatchSession(bot, parsed);
|
|
87
87
|
}
|
|
88
88
|
else if (parsed.echo in listeners) {
|
|
89
89
|
listeners[parsed.echo](parsed);
|
|
90
90
|
delete listeners[parsed.echo];
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
|
-
socket.addEventListener("close", () => {
|
|
93
|
+
socket.addEventListener("close", async () => {
|
|
94
94
|
delete bot.internal._request;
|
|
95
95
|
Object.keys(listeners).forEach((echo) => {
|
|
96
96
|
delete listeners[Number(echo)];
|
|
97
97
|
});
|
|
98
|
-
bot.adapter.disconnect(bot);
|
|
98
|
+
await bot.adapter.disconnect(bot);
|
|
99
99
|
});
|
|
100
100
|
bot.internal._request = (action, params) => {
|
|
101
101
|
const echo = ++counter;
|
|
@@ -119,5 +119,5 @@ export function accept(socket, bot) {
|
|
|
119
119
|
})
|
|
120
120
|
]);
|
|
121
121
|
};
|
|
122
|
-
bot.initialize();
|
|
122
|
+
void bot.initialize();
|
|
123
123
|
}
|
package/package.json
CHANGED
|
@@ -1,62 +1,60 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
},
|
|
19
|
-
"bugs": {
|
|
20
|
-
"url": "https://github.com/CrashVibe/koishi-plugin-adapter-onebot/issues"
|
|
21
|
-
},
|
|
22
|
-
"keywords": [
|
|
23
|
-
"bot",
|
|
24
|
-
"chatbot",
|
|
25
|
-
"koishi",
|
|
26
|
-
"plugin",
|
|
27
|
-
"adapter",
|
|
28
|
-
"onebot",
|
|
29
|
-
"im",
|
|
30
|
-
"chat"
|
|
31
|
-
],
|
|
32
|
-
"koishi": {
|
|
33
|
-
"description": {
|
|
34
|
-
"en": "OneBot Adapter for Koishi",
|
|
35
|
-
"zh": "OneBot 适配器"
|
|
2
|
+
"name": "@mrlingxd/koishi-plugin-adapter-onebot",
|
|
3
|
+
"version": "0.2.7",
|
|
4
|
+
"description": "OneBot Adapter for Koishi",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"adapter",
|
|
7
|
+
"bot",
|
|
8
|
+
"chat",
|
|
9
|
+
"chatbot",
|
|
10
|
+
"im",
|
|
11
|
+
"koishi",
|
|
12
|
+
"onebot",
|
|
13
|
+
"plugin"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/CrashVibe/koishi-plugin-adapter-onebot",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/CrashVibe/koishi-plugin-adapter-onebot/issues"
|
|
36
18
|
},
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"contributors": [
|
|
21
|
+
"MrlingXD <90316914+CrashVibe@users.noreply.github.com>"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/CrashVibe/koishi-plugin-adapter-onebot.git"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"lib"
|
|
29
|
+
],
|
|
30
|
+
"main": "lib/index.js",
|
|
31
|
+
"typings": "lib/index.d.ts",
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "atsc -b"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@koishijs/plugin-server": "^3.2.7",
|
|
37
|
+
"@types/node": "^25.0.9",
|
|
38
|
+
"atsc": "^2.1.0",
|
|
39
|
+
"esbuild": "^0.27.2",
|
|
40
|
+
"esbuild-register": "^3.6.0",
|
|
41
|
+
"koishi": "^4.18.10",
|
|
42
|
+
"qface": "^1.4.1",
|
|
43
|
+
"typescript": "^5.9.3",
|
|
44
|
+
"yml-register": "^1.2.5"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"koishi": "^4.18.6"
|
|
48
|
+
},
|
|
49
|
+
"koishi": {
|
|
50
|
+
"description": {
|
|
51
|
+
"en": "OneBot Adapter for Koishi",
|
|
52
|
+
"zh": "OneBot 适配器"
|
|
53
|
+
},
|
|
54
|
+
"service": {
|
|
55
|
+
"implements": [
|
|
56
|
+
"adapter"
|
|
57
|
+
]
|
|
58
|
+
}
|
|
41
59
|
}
|
|
42
|
-
},
|
|
43
|
-
"scripts": {
|
|
44
|
-
"build": "atsc -b"
|
|
45
|
-
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"@cordisjs/eslint-config": "^1.1.1",
|
|
48
|
-
"@koishijs/plugin-server": "^3.2.7",
|
|
49
|
-
"@types/node": "^25.0.9",
|
|
50
|
-
"atsc": "^2.1.0",
|
|
51
|
-
"esbuild": "^0.27.2",
|
|
52
|
-
"esbuild-register": "^3.6.0",
|
|
53
|
-
"eslint": "^9.39.2",
|
|
54
|
-
"koishi": "^4.18.10",
|
|
55
|
-
"qface": "^1.4.1",
|
|
56
|
-
"typescript": "^5.9.3",
|
|
57
|
-
"yml-register": "^1.2.5"
|
|
58
|
-
},
|
|
59
|
-
"peerDependencies": {
|
|
60
|
-
"koishi": "^4.18.6"
|
|
61
|
-
}
|
|
62
60
|
}
|