@onebots/adapter-kook 1.0.0
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/LICENSE +21 -0
- package/README.md +133 -0
- package/lib/adapter.d.ts +137 -0
- package/lib/adapter.js +817 -0
- package/lib/bot.d.ts +155 -0
- package/lib/bot.js +403 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +3 -0
- package/lib/types.d.ts +240 -0
- package/lib/types.js +20 -0
- package/lib/utils.d.ts +93 -0
- package/lib/utils.js +240 -0
- package/package.json +39 -0
package/lib/bot.d.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KOOK (开黑了) Bot 客户端
|
|
3
|
+
* 基于 kook-client 封装
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
import { Client } from 'kook-client';
|
|
7
|
+
import type { RouterContext, Next } from 'onebots';
|
|
8
|
+
import type { KookConfig, KookUser, KookGuild, KookChannel } from './types.js';
|
|
9
|
+
export declare class KookBot extends EventEmitter {
|
|
10
|
+
private client;
|
|
11
|
+
private config;
|
|
12
|
+
constructor(config: KookConfig);
|
|
13
|
+
/**
|
|
14
|
+
* 设置事件转发
|
|
15
|
+
*/
|
|
16
|
+
private setupEventForwarding;
|
|
17
|
+
/**
|
|
18
|
+
* 转换频道消息事件为内部格式
|
|
19
|
+
*/
|
|
20
|
+
private transformChannelEvent;
|
|
21
|
+
/**
|
|
22
|
+
* 转换私聊消息事件为内部格式
|
|
23
|
+
*/
|
|
24
|
+
private transformPrivateEvent;
|
|
25
|
+
/**
|
|
26
|
+
* 启动 Bot
|
|
27
|
+
*/
|
|
28
|
+
start(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* 停止 Bot
|
|
31
|
+
*/
|
|
32
|
+
stop(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* 处理 Webhook 请求(Webhook 模式下由 kook-client 内部处理)
|
|
35
|
+
* 这个方法保留用于兼容,但实际处理由 kook-client 完成
|
|
36
|
+
*/
|
|
37
|
+
handleWebhook(ctx: RouterContext, next: Next): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* 获取缓存的用户信息
|
|
40
|
+
*/
|
|
41
|
+
getCachedMe(): KookUser | null;
|
|
42
|
+
/**
|
|
43
|
+
* 获取当前用户信息
|
|
44
|
+
*/
|
|
45
|
+
getMe(): Promise<KookUser>;
|
|
46
|
+
/**
|
|
47
|
+
* 获取用户信息
|
|
48
|
+
*/
|
|
49
|
+
getUser(userId: string, guildId?: string): Promise<KookUser>;
|
|
50
|
+
/**
|
|
51
|
+
* 获取服务器列表
|
|
52
|
+
*/
|
|
53
|
+
getGuildList(page?: number, pageSize?: number): Promise<{
|
|
54
|
+
items: KookGuild[];
|
|
55
|
+
meta: any;
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* 获取服务器详情
|
|
59
|
+
*/
|
|
60
|
+
getGuild(guildId: string): Promise<KookGuild>;
|
|
61
|
+
/**
|
|
62
|
+
* 获取频道列表
|
|
63
|
+
*/
|
|
64
|
+
getChannelList(guildId: string, type?: 1 | 2, page?: number, pageSize?: number): Promise<{
|
|
65
|
+
items: KookChannel[];
|
|
66
|
+
meta: any;
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* 获取频道详情
|
|
70
|
+
*/
|
|
71
|
+
getChannel(channelId: string): Promise<KookChannel>;
|
|
72
|
+
/**
|
|
73
|
+
* 发送频道消息
|
|
74
|
+
*/
|
|
75
|
+
sendChannelMessage(channelId: string, content: string, quoteId?: string): Promise<any>;
|
|
76
|
+
/**
|
|
77
|
+
* 发送私聊消息
|
|
78
|
+
*/
|
|
79
|
+
sendDirectMessage(userId: string, content: string, quoteId?: string): Promise<any>;
|
|
80
|
+
/**
|
|
81
|
+
* 删除消息
|
|
82
|
+
*/
|
|
83
|
+
deleteMessage(channelId: string, messageId: string): Promise<boolean>;
|
|
84
|
+
/**
|
|
85
|
+
* 更新消息
|
|
86
|
+
*/
|
|
87
|
+
updateMessage(channelId: string, messageId: string, content: string): Promise<boolean>;
|
|
88
|
+
/**
|
|
89
|
+
* 获取消息
|
|
90
|
+
*/
|
|
91
|
+
getMessage(channelId: string, messageId: string): Promise<any>;
|
|
92
|
+
/**
|
|
93
|
+
* 获取聊天历史
|
|
94
|
+
*/
|
|
95
|
+
getChatHistory(channelId: string, messageId?: string, limit?: number): Promise<any[]>;
|
|
96
|
+
/**
|
|
97
|
+
* 获取用户私聊会话列表(KOOK 不支持,返回空数组)
|
|
98
|
+
*/
|
|
99
|
+
getUserChatList(page?: number, pageSize?: number): Promise<{
|
|
100
|
+
items: any[];
|
|
101
|
+
meta: any;
|
|
102
|
+
}>;
|
|
103
|
+
/**
|
|
104
|
+
* 获取频道用户列表
|
|
105
|
+
*/
|
|
106
|
+
getChannelUserList(channelId: string): Promise<{
|
|
107
|
+
items: KookUser[];
|
|
108
|
+
meta: any;
|
|
109
|
+
}>;
|
|
110
|
+
/**
|
|
111
|
+
* 创建频道
|
|
112
|
+
*/
|
|
113
|
+
createChannel(guildId: string, name: string, type?: 1 | 2, parentId?: string): Promise<KookChannel>;
|
|
114
|
+
/**
|
|
115
|
+
* 更新频道
|
|
116
|
+
*/
|
|
117
|
+
updateChannel(channelId: string, name?: string, topic?: string, slowMode?: number): Promise<KookChannel>;
|
|
118
|
+
/**
|
|
119
|
+
* 删除频道
|
|
120
|
+
*/
|
|
121
|
+
deleteChannel(channelId: string): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* 获取服务器成员列表
|
|
124
|
+
*/
|
|
125
|
+
getGuildMemberList(guildId: string, channelId?: string, search?: string, roleId?: number, mobileVerified?: boolean, activeTime?: number, joinedAt?: number, page?: number, pageSize?: number): Promise<{
|
|
126
|
+
items: KookUser[];
|
|
127
|
+
meta: any;
|
|
128
|
+
}>;
|
|
129
|
+
/**
|
|
130
|
+
* 离开服务器
|
|
131
|
+
*/
|
|
132
|
+
leaveGuild(guildId: string): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* 踢出服务器成员
|
|
135
|
+
*/
|
|
136
|
+
kickGuildMember(guildId: string, userId: string): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* 设置服务器昵称
|
|
139
|
+
*/
|
|
140
|
+
setGuildNickname(guildId: string, nickname?: string, userId?: string): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* 上传文件
|
|
143
|
+
*/
|
|
144
|
+
uploadAsset(fileBuffer: Buffer, filename: string): Promise<{
|
|
145
|
+
url: string;
|
|
146
|
+
}>;
|
|
147
|
+
private transformUser;
|
|
148
|
+
private transformGuild;
|
|
149
|
+
private transformChannel;
|
|
150
|
+
/**
|
|
151
|
+
* 获取 kook-client 实例(用于高级操作)
|
|
152
|
+
*/
|
|
153
|
+
getClient(): Client;
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=bot.d.ts.map
|
package/lib/bot.js
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KOOK (开黑了) Bot 客户端
|
|
3
|
+
* 基于 kook-client 封装
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
import { Client, ChannelMessageEvent } from 'kook-client';
|
|
7
|
+
export class KookBot extends EventEmitter {
|
|
8
|
+
client;
|
|
9
|
+
config;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
super();
|
|
12
|
+
this.config = config;
|
|
13
|
+
// 创建 kook-client 实例
|
|
14
|
+
this.client = new Client({
|
|
15
|
+
token: config.token,
|
|
16
|
+
mode: config.mode || 'websocket',
|
|
17
|
+
verify_token: config.verifyToken,
|
|
18
|
+
encrypt_key: config.encryptKey,
|
|
19
|
+
ignore: 'bot', // 忽略机器人消息
|
|
20
|
+
logLevel: 'warn', // 使用 warn 级别,避免过多日志
|
|
21
|
+
});
|
|
22
|
+
// 转发 kook-client 的事件
|
|
23
|
+
this.setupEventForwarding();
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 设置事件转发
|
|
27
|
+
*/
|
|
28
|
+
setupEventForwarding() {
|
|
29
|
+
// 转发 ready 事件
|
|
30
|
+
this.client.on('ready', () => {
|
|
31
|
+
this.emit('ready');
|
|
32
|
+
});
|
|
33
|
+
// 转发频道消息事件
|
|
34
|
+
this.client.on('message.channel', (event) => {
|
|
35
|
+
this.emit('channel_message', this.transformChannelEvent(event));
|
|
36
|
+
});
|
|
37
|
+
// 转发私聊消息事件
|
|
38
|
+
this.client.on('message.private', (event) => {
|
|
39
|
+
this.emit('direct_message', this.transformPrivateEvent(event));
|
|
40
|
+
});
|
|
41
|
+
// 转发通用消息事件
|
|
42
|
+
this.client.on('message', (event) => {
|
|
43
|
+
if (event instanceof ChannelMessageEvent) {
|
|
44
|
+
this.emit('message', this.transformChannelEvent(event));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this.emit('message', this.transformPrivateEvent(event));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
// 转发错误事件
|
|
51
|
+
this.client.on('error', (error) => {
|
|
52
|
+
this.emit('error', error);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 转换频道消息事件为内部格式
|
|
57
|
+
*/
|
|
58
|
+
transformChannelEvent(event) {
|
|
59
|
+
const payload = event.payload || {};
|
|
60
|
+
const extra = payload.extra || {};
|
|
61
|
+
return {
|
|
62
|
+
type: payload.type || extra.type || 9,
|
|
63
|
+
channel_type: 'GROUP',
|
|
64
|
+
author_id: event.author_id,
|
|
65
|
+
content: event.raw_message || payload.content || '',
|
|
66
|
+
msg_id: event.message_id || payload.msg_id || '',
|
|
67
|
+
msg_timestamp: event.timestamp || payload.msg_timestamp || Date.now(),
|
|
68
|
+
channel_id: event.channel_id,
|
|
69
|
+
guild_id: extra.guild_id || '',
|
|
70
|
+
extra: extra,
|
|
71
|
+
// 保留原始事件引用
|
|
72
|
+
_original: event,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 转换私聊消息事件为内部格式
|
|
77
|
+
*/
|
|
78
|
+
transformPrivateEvent(event) {
|
|
79
|
+
const payload = event.payload || {};
|
|
80
|
+
const extra = payload.extra || {};
|
|
81
|
+
return {
|
|
82
|
+
type: payload.type || extra.type || 9,
|
|
83
|
+
channel_type: 'PERSON',
|
|
84
|
+
author_id: event.author_id,
|
|
85
|
+
content: event.raw_message || payload.content || '',
|
|
86
|
+
msg_id: event.message_id || payload.msg_id || '',
|
|
87
|
+
msg_timestamp: event.timestamp || payload.msg_timestamp || Date.now(),
|
|
88
|
+
code: extra.code || '',
|
|
89
|
+
extra: extra,
|
|
90
|
+
// 保留原始事件引用
|
|
91
|
+
_original: event,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 启动 Bot
|
|
96
|
+
*/
|
|
97
|
+
async start() {
|
|
98
|
+
try {
|
|
99
|
+
await this.client.connect();
|
|
100
|
+
// connect() 会自动调用 init(),所以不需要手动调用
|
|
101
|
+
this.emit('ready');
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
this.emit('error', error);
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 停止 Bot
|
|
110
|
+
*/
|
|
111
|
+
async stop() {
|
|
112
|
+
try {
|
|
113
|
+
await this.client.disconnect();
|
|
114
|
+
this.emit('stopped');
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
this.emit('error', error);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 处理 Webhook 请求(Webhook 模式下由 kook-client 内部处理)
|
|
123
|
+
* 这个方法保留用于兼容,但实际处理由 kook-client 完成
|
|
124
|
+
*/
|
|
125
|
+
async handleWebhook(ctx, next) {
|
|
126
|
+
// kook-client 的 webhook receiver 是空的,需要我们自己实现
|
|
127
|
+
// 但为了保持接口一致性,这里保留方法签名
|
|
128
|
+
await next();
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* 获取缓存的用户信息
|
|
132
|
+
*/
|
|
133
|
+
getCachedMe() {
|
|
134
|
+
if (!this.client.self_id)
|
|
135
|
+
return null;
|
|
136
|
+
return {
|
|
137
|
+
id: this.client.self_id,
|
|
138
|
+
username: this.client.nickname || '',
|
|
139
|
+
nickname: this.client.nickname,
|
|
140
|
+
identify_num: '',
|
|
141
|
+
online: true,
|
|
142
|
+
bot: true,
|
|
143
|
+
status: 0,
|
|
144
|
+
avatar: '',
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
// ============================================
|
|
148
|
+
// API 方法代理到 kook-client
|
|
149
|
+
// ============================================
|
|
150
|
+
/**
|
|
151
|
+
* 获取当前用户信息
|
|
152
|
+
*/
|
|
153
|
+
async getMe() {
|
|
154
|
+
const userInfo = await this.client.getSelfInfo();
|
|
155
|
+
return this.transformUser(userInfo);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* 获取用户信息
|
|
159
|
+
*/
|
|
160
|
+
async getUser(userId, guildId) {
|
|
161
|
+
const user = await this.client.pickUser(userId);
|
|
162
|
+
return this.transformUser(user.info);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* 获取服务器列表
|
|
166
|
+
*/
|
|
167
|
+
async getGuildList(page, pageSize) {
|
|
168
|
+
const guilds = await this.client.getGuildList();
|
|
169
|
+
return {
|
|
170
|
+
items: guilds.map(g => this.transformGuild(g)),
|
|
171
|
+
meta: { page_total: 1 },
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* 获取服务器详情
|
|
176
|
+
*/
|
|
177
|
+
async getGuild(guildId) {
|
|
178
|
+
const guild = await this.client.getGuildInfo(guildId);
|
|
179
|
+
return this.transformGuild(guild);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* 获取频道列表
|
|
183
|
+
*/
|
|
184
|
+
async getChannelList(guildId, type, page, pageSize) {
|
|
185
|
+
const channels = await this.client.getChannelList(guildId);
|
|
186
|
+
return {
|
|
187
|
+
items: channels.map(c => this.transformChannel(c)),
|
|
188
|
+
meta: { page_total: 1 },
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* 获取频道详情
|
|
193
|
+
*/
|
|
194
|
+
async getChannel(channelId) {
|
|
195
|
+
const channel = this.client.pickChannel(channelId);
|
|
196
|
+
return this.transformChannel(channel.info);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* 发送频道消息
|
|
200
|
+
*/
|
|
201
|
+
async sendChannelMessage(channelId, content, quoteId) {
|
|
202
|
+
const channel = this.client.pickChannel(channelId);
|
|
203
|
+
const quote = quoteId ? { message_id: quoteId } : undefined;
|
|
204
|
+
return await channel.sendMsg(content, quote);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* 发送私聊消息
|
|
208
|
+
*/
|
|
209
|
+
async sendDirectMessage(userId, content, quoteId) {
|
|
210
|
+
const user = this.client.pickUser(userId);
|
|
211
|
+
const quote = quoteId ? { message_id: quoteId } : undefined;
|
|
212
|
+
return await user.sendMsg(content, quote);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* 删除消息
|
|
216
|
+
*/
|
|
217
|
+
async deleteMessage(channelId, messageId) {
|
|
218
|
+
const channel = this.client.pickChannel(channelId);
|
|
219
|
+
return await channel.recallMsg(messageId);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* 更新消息
|
|
223
|
+
*/
|
|
224
|
+
async updateMessage(channelId, messageId, content) {
|
|
225
|
+
const channel = this.client.pickChannel(channelId);
|
|
226
|
+
return await channel.updateMsg(messageId, content);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* 获取消息
|
|
230
|
+
*/
|
|
231
|
+
async getMessage(channelId, messageId) {
|
|
232
|
+
const channel = this.client.pickChannel(channelId);
|
|
233
|
+
return await channel.getMsg(messageId);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* 获取聊天历史
|
|
237
|
+
*/
|
|
238
|
+
async getChatHistory(channelId, messageId, limit = 50) {
|
|
239
|
+
const channel = this.client.pickChannel(channelId);
|
|
240
|
+
return await channel.getChatHistory(messageId, limit);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* 获取用户私聊会话列表(KOOK 不支持,返回空数组)
|
|
244
|
+
*/
|
|
245
|
+
async getUserChatList(page = 1, pageSize = 50) {
|
|
246
|
+
// KOOK 不提供私聊会话列表 API,返回空数组
|
|
247
|
+
return { items: [], meta: { page_total: 1 } };
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* 获取频道用户列表
|
|
251
|
+
*/
|
|
252
|
+
async getChannelUserList(channelId) {
|
|
253
|
+
const channel = this.client.pickChannel(channelId);
|
|
254
|
+
const users = await channel.getUserList();
|
|
255
|
+
return {
|
|
256
|
+
items: users.map(u => this.transformUser(u)),
|
|
257
|
+
meta: { page_total: 1 },
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* 创建频道
|
|
262
|
+
*/
|
|
263
|
+
async createChannel(guildId, name, type, parentId) {
|
|
264
|
+
// kook-client 没有直接的 createChannel,需要通过 API
|
|
265
|
+
const response = await this.client.request.post('/v3/channel/create', {
|
|
266
|
+
guild_id: guildId,
|
|
267
|
+
name,
|
|
268
|
+
type,
|
|
269
|
+
parent_id: parentId,
|
|
270
|
+
});
|
|
271
|
+
return this.transformChannel(response.data);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* 更新频道
|
|
275
|
+
*/
|
|
276
|
+
async updateChannel(channelId, name, topic, slowMode) {
|
|
277
|
+
const channel = this.client.pickChannel(channelId);
|
|
278
|
+
const updateData = {};
|
|
279
|
+
if (name !== undefined)
|
|
280
|
+
updateData.name = name;
|
|
281
|
+
if (slowMode !== undefined)
|
|
282
|
+
updateData.slow_mode = slowMode;
|
|
283
|
+
await channel.update(updateData);
|
|
284
|
+
return this.transformChannel(channel.info);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* 删除频道
|
|
288
|
+
*/
|
|
289
|
+
async deleteChannel(channelId) {
|
|
290
|
+
const channel = this.client.pickChannel(channelId);
|
|
291
|
+
await channel.delete();
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* 获取服务器成员列表
|
|
295
|
+
*/
|
|
296
|
+
async getGuildMemberList(guildId, channelId, search, roleId, mobileVerified, activeTime, joinedAt, page, pageSize) {
|
|
297
|
+
const users = await this.client.getGuildUserList(guildId, channelId);
|
|
298
|
+
return {
|
|
299
|
+
items: users.map(u => this.transformUser(u)),
|
|
300
|
+
meta: { page_total: 1 },
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* 离开服务器
|
|
305
|
+
*/
|
|
306
|
+
async leaveGuild(guildId) {
|
|
307
|
+
// kook-client 没有直接的 leaveGuild 方法,需要通过 API
|
|
308
|
+
await this.client.request.post('/v3/guild/leave', {
|
|
309
|
+
guild_id: guildId,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* 踢出服务器成员
|
|
314
|
+
*/
|
|
315
|
+
async kickGuildMember(guildId, userId) {
|
|
316
|
+
// kook-client 没有直接的 kickGuildMember 方法,需要通过 API
|
|
317
|
+
await this.client.request.post('/v3/guild/kickout', {
|
|
318
|
+
guild_id: guildId,
|
|
319
|
+
target_id: userId,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* 设置服务器昵称
|
|
324
|
+
*/
|
|
325
|
+
async setGuildNickname(guildId, nickname, userId) {
|
|
326
|
+
// kook-client 没有直接的 setGuildNickname 方法,需要通过 API
|
|
327
|
+
await this.client.request.post('/v3/guild/nickname', {
|
|
328
|
+
guild_id: guildId,
|
|
329
|
+
nickname,
|
|
330
|
+
user_id: userId,
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* 上传文件
|
|
335
|
+
*/
|
|
336
|
+
async uploadAsset(fileBuffer, filename) {
|
|
337
|
+
// kook-client 使用 uploadMedia 方法
|
|
338
|
+
const url = await this.client.uploadMedia(fileBuffer);
|
|
339
|
+
return { url };
|
|
340
|
+
}
|
|
341
|
+
// ============================================
|
|
342
|
+
// 类型转换方法
|
|
343
|
+
// ============================================
|
|
344
|
+
transformUser(user) {
|
|
345
|
+
return {
|
|
346
|
+
id: user.id,
|
|
347
|
+
username: user.username || '',
|
|
348
|
+
nickname: user.nickname,
|
|
349
|
+
identify_num: user.identify_num || '',
|
|
350
|
+
online: user.online || false,
|
|
351
|
+
bot: user.bot || false,
|
|
352
|
+
status: user.status || 0,
|
|
353
|
+
avatar: user.avatar || '',
|
|
354
|
+
vip_avatar: user.vip_avatar,
|
|
355
|
+
mobile_verified: user.mobile_verified,
|
|
356
|
+
roles: user.roles,
|
|
357
|
+
joined_at: user.joined_at,
|
|
358
|
+
active_time: user.active_time,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
transformGuild(guild) {
|
|
362
|
+
return {
|
|
363
|
+
id: guild.id,
|
|
364
|
+
name: guild.name,
|
|
365
|
+
topic: guild.topic || '',
|
|
366
|
+
user_id: guild.user_id || '',
|
|
367
|
+
icon: guild.icon || '',
|
|
368
|
+
notify_type: guild.notify_type || 0,
|
|
369
|
+
region: guild.region || '',
|
|
370
|
+
enable_open: guild.enable_open || false,
|
|
371
|
+
open_id: guild.open_id || '',
|
|
372
|
+
default_channel_id: guild.default_channel_id || '',
|
|
373
|
+
welcome_channel_id: guild.welcome_channel_id || '',
|
|
374
|
+
roles: guild.roles,
|
|
375
|
+
channels: guild.channels,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
transformChannel(channel) {
|
|
379
|
+
return {
|
|
380
|
+
id: channel.id,
|
|
381
|
+
name: channel.name,
|
|
382
|
+
user_id: channel.user_id || '',
|
|
383
|
+
guild_id: channel.guild_id || '',
|
|
384
|
+
topic: channel.topic || '',
|
|
385
|
+
is_category: channel.is_category || false,
|
|
386
|
+
parent_id: channel.parent_id || '',
|
|
387
|
+
level: channel.level || 0,
|
|
388
|
+
slow_mode: channel.slow_mode || 0,
|
|
389
|
+
type: channel.type || 1,
|
|
390
|
+
permission_overwrites: channel.permission_overwrites || [],
|
|
391
|
+
permission_users: channel.permission_users || [],
|
|
392
|
+
permission_sync: channel.permission_sync || 0,
|
|
393
|
+
has_password: channel.has_password || false,
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* 获取 kook-client 实例(用于高级操作)
|
|
398
|
+
*/
|
|
399
|
+
getClient() {
|
|
400
|
+
return this.client;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
//# sourceMappingURL=bot.js.map
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED