@alemonjs/kook 0.0.3 → 0.1.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/lib/index.d.ts +5 -1
- package/lib/index.js +27 -5
- package/lib/sdk/core/config.js +46 -0
- package/lib/sdk/core/utils/from.js +42 -0
- package/lib/sdk/platform/kook/sdk/api.d.ts +276 -0
- package/lib/sdk/platform/kook/sdk/api.js +272 -0
- package/lib/sdk/platform/kook/sdk/config.js +7 -0
- package/lib/sdk/platform/kook/sdk/conversation.js +124 -0
- package/lib/sdk/platform/kook/sdk/message/INTERACTION.d.ts +8 -0
- package/lib/sdk/platform/kook/sdk/message/MEMBER_ADD.d.ts +10 -0
- package/lib/sdk/platform/kook/sdk/message/MEMBER_REMOVE.d.ts +10 -0
- package/lib/sdk/platform/kook/sdk/message/MESSAGES_DIRECT.d.ts +10 -0
- package/lib/sdk/platform/kook/sdk/message/MESSAGES_PUBLIC.d.ts +10 -0
- package/lib/sdk/platform/kook/sdk/message/REACTIONS.d.ts +10 -0
- package/lib/sdk/platform/kook/sdk/message.d.ts +18 -0
- package/lib/sdk/platform/kook/sdk/message.js +18 -0
- package/lib/sdk/platform/kook/sdk/typings.d.ts +192 -0
- package/lib/sdk/platform/kook/sdk/typings.js +168 -0
- package/lib/sdk/platform/kook/sdk/wss.d.ts +26 -0
- package/lib/sdk/platform/kook/sdk/wss.js +151 -0
- package/lib/sdk/platform/kook/sdk/wss.types.d.ts +12 -0
- package/package.json +5 -7
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { KOOKClient } from './sdk/platform/kook/sdk/wss.js';
|
|
2
|
+
|
|
3
|
+
type Client = typeof KOOKClient.prototype;
|
|
4
|
+
declare const client: Client;
|
|
1
5
|
declare const _default: () => typeof global.alemonjs;
|
|
2
6
|
|
|
3
|
-
export { _default as default };
|
|
7
|
+
export { type Client, client, _default as default };
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { defineBot, getConfig, Text, At, OnProcessor, useParse } from 'alemonjs';
|
|
2
|
-
import
|
|
2
|
+
import 'fs';
|
|
3
|
+
import 'axios';
|
|
4
|
+
import 'path';
|
|
5
|
+
import 'qrcode';
|
|
6
|
+
import 'public-ip';
|
|
7
|
+
import 'stream';
|
|
8
|
+
import 'file-type';
|
|
9
|
+
import 'form-data';
|
|
10
|
+
import './sdk/platform/kook/sdk/typings.js';
|
|
11
|
+
import { KOOKClient } from './sdk/platform/kook/sdk/wss.js';
|
|
3
12
|
|
|
13
|
+
const client = global.client;
|
|
4
14
|
var index = defineBot(() => {
|
|
5
15
|
const cfg = getConfig();
|
|
6
16
|
const config = cfg.value?.kook;
|
|
@@ -67,6 +77,9 @@ var index = defineBot(() => {
|
|
|
67
77
|
IsMaster: isMaster,
|
|
68
78
|
// 用户ID
|
|
69
79
|
UserId: event.author_id,
|
|
80
|
+
GuildIdName: '',
|
|
81
|
+
GuildIdAvatar: '',
|
|
82
|
+
ChannelName: '',
|
|
70
83
|
// 用户名
|
|
71
84
|
UserName: event.extra.author.username,
|
|
72
85
|
// 用户头像
|
|
@@ -74,14 +87,17 @@ var index = defineBot(() => {
|
|
|
74
87
|
// 格式化数据
|
|
75
88
|
MsgId: event.msg_id,
|
|
76
89
|
// 用户消息
|
|
77
|
-
|
|
90
|
+
MessageBody: [
|
|
78
91
|
Text(msg),
|
|
79
92
|
...at_users.map(item => At(item.id, 'user', { name: item.name, avatar: item.avatar, bot: item.bot }))
|
|
80
93
|
],
|
|
94
|
+
MessageText: msg,
|
|
81
95
|
// 用户openId
|
|
82
96
|
OpenID: data?.code,
|
|
83
97
|
// 创建时间
|
|
84
98
|
CreateAt: Date.now(),
|
|
99
|
+
// 表情
|
|
100
|
+
tag: 'MESSAGES_PUBLIC',
|
|
85
101
|
//
|
|
86
102
|
value: null
|
|
87
103
|
};
|
|
@@ -98,13 +114,17 @@ var index = defineBot(() => {
|
|
|
98
114
|
client.on('ERROR', msg => {
|
|
99
115
|
console.error(msg);
|
|
100
116
|
});
|
|
117
|
+
// 客户端全局化。
|
|
118
|
+
global.client = client;
|
|
101
119
|
return {
|
|
102
120
|
api: {
|
|
103
121
|
use: {
|
|
104
122
|
send: (event, val) => {
|
|
105
123
|
if (val.length < 0)
|
|
106
124
|
return Promise.all([]);
|
|
107
|
-
const content = useParse(
|
|
125
|
+
const content = useParse({
|
|
126
|
+
MessageBody: val
|
|
127
|
+
}, 'Text');
|
|
108
128
|
if (content) {
|
|
109
129
|
return Promise.all([content].map(item => client.createMessage({
|
|
110
130
|
type: 9,
|
|
@@ -112,7 +132,9 @@ var index = defineBot(() => {
|
|
|
112
132
|
content: item
|
|
113
133
|
})));
|
|
114
134
|
}
|
|
115
|
-
const images = useParse(
|
|
135
|
+
const images = useParse({
|
|
136
|
+
MessageBody: val
|
|
137
|
+
}, 'Image');
|
|
116
138
|
if (images) {
|
|
117
139
|
return Promise.all(images.map(async (item) => {
|
|
118
140
|
// 上传图片
|
|
@@ -134,4 +156,4 @@ var index = defineBot(() => {
|
|
|
134
156
|
};
|
|
135
157
|
});
|
|
136
158
|
|
|
137
|
-
export { index as default };
|
|
159
|
+
export { client, index as default };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 基础配置结构
|
|
3
|
+
*/
|
|
4
|
+
class BaseConfig {
|
|
5
|
+
#data = null;
|
|
6
|
+
constructor(val) {
|
|
7
|
+
this.#data = val;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 设置配置
|
|
11
|
+
* @param key
|
|
12
|
+
* @param val
|
|
13
|
+
*/
|
|
14
|
+
set(key, val) {
|
|
15
|
+
if (val !== undefined)
|
|
16
|
+
this.#data[key] = val;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param key
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
has(key) {
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(this.#data, key)) ;
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 读取配置
|
|
30
|
+
* @param key
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
all() {
|
|
34
|
+
return this.#data;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 读取配置
|
|
38
|
+
* @param key
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
get(key) {
|
|
42
|
+
return this.#data[key];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { BaseConfig };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { existsSync, createReadStream } from 'fs';
|
|
2
|
+
import { Readable, isReadable } from 'stream';
|
|
3
|
+
import { basename } from 'path';
|
|
4
|
+
import { fileTypeFromBuffer, fileTypeFromStream } from 'file-type';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 创建form
|
|
8
|
+
* @param image
|
|
9
|
+
* @param name
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
async function createPicFrom(image, name = 'image.jpg') {
|
|
13
|
+
let picData;
|
|
14
|
+
// 是 string
|
|
15
|
+
if (typeof image === 'string') {
|
|
16
|
+
if (!existsSync(image))
|
|
17
|
+
return false;
|
|
18
|
+
if (!name)
|
|
19
|
+
name = basename(image);
|
|
20
|
+
picData = createReadStream(image);
|
|
21
|
+
// 是 buffer
|
|
22
|
+
}
|
|
23
|
+
else if (Buffer.isBuffer(image)) {
|
|
24
|
+
if (!name)
|
|
25
|
+
name = 'file.' + (await fileTypeFromBuffer(image)).ext;
|
|
26
|
+
picData = new Readable();
|
|
27
|
+
picData.push(image);
|
|
28
|
+
picData.push(null);
|
|
29
|
+
// 是 文件流
|
|
30
|
+
}
|
|
31
|
+
else if (isReadable(image)) {
|
|
32
|
+
if (!name)
|
|
33
|
+
name = 'file.' + (await fileTypeFromStream(image)).ext;
|
|
34
|
+
picData = image;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return { picData, image, name };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { createPicFrom };
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import * as axios from 'axios';
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
|
+
import { SendMessageParams, SendDirectMessageParams } from './typings.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* api接口
|
|
8
|
+
*/
|
|
9
|
+
declare class KOOKAPI {
|
|
10
|
+
API_URL: string;
|
|
11
|
+
/**
|
|
12
|
+
* KOOK服务
|
|
13
|
+
* @param config
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
kookService(opstoin: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any>>;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
gateway(): Promise<any>;
|
|
22
|
+
/**
|
|
23
|
+
* ************
|
|
24
|
+
* 资源床单
|
|
25
|
+
* ***********
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* 发送buffer资源
|
|
29
|
+
* @param id 私信传频道id,公信传子频道id
|
|
30
|
+
* @param message {消息编号,图片,内容}
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
postImage(file: string | Buffer | Readable, Name?: string): Promise<false | {
|
|
34
|
+
data: {
|
|
35
|
+
url: string;
|
|
36
|
+
};
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* 发送buffer资源
|
|
40
|
+
* @param id 私信传频道id,公信传子频道id
|
|
41
|
+
* @param message {消息编号,图片,内容}
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
postFile(file: Buffer, Name?: string): Promise<false | {
|
|
45
|
+
data: {
|
|
46
|
+
url: string;
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* 转存
|
|
51
|
+
* @param formdata
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
createUrl(formdata: any): Promise<{
|
|
55
|
+
data: {
|
|
56
|
+
url: string;
|
|
57
|
+
};
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* *********
|
|
61
|
+
* 消息api
|
|
62
|
+
* *********
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* 创建消息
|
|
66
|
+
* @param data
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
createMessage(data: SendMessageParams): Promise<{
|
|
70
|
+
data: {
|
|
71
|
+
msg_id: string;
|
|
72
|
+
msg_timestamp: number;
|
|
73
|
+
nonce: string;
|
|
74
|
+
};
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* 创建私聊消息
|
|
78
|
+
*/
|
|
79
|
+
/**
|
|
80
|
+
* 创建消息
|
|
81
|
+
* @param target_id
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
userChatCreate(target_id: string): Promise<{
|
|
85
|
+
data: {
|
|
86
|
+
code: string;
|
|
87
|
+
last_read_time: number;
|
|
88
|
+
latest_msg_time: number;
|
|
89
|
+
unread_count: number;
|
|
90
|
+
is_friend: boolean;
|
|
91
|
+
is_blocked: boolean;
|
|
92
|
+
is_target_blocked: boolean;
|
|
93
|
+
target_info: {
|
|
94
|
+
id: string;
|
|
95
|
+
username: string;
|
|
96
|
+
online: boolean;
|
|
97
|
+
avatar: string;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* 创建消息
|
|
103
|
+
* @param data
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
createDirectMessage(data: SendDirectMessageParams): Promise<{
|
|
107
|
+
data: {
|
|
108
|
+
msg_id: string;
|
|
109
|
+
msg_timestamp: number;
|
|
110
|
+
nonce: string;
|
|
111
|
+
};
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* 删除指定消息
|
|
115
|
+
* @param msg_id
|
|
116
|
+
* @returns
|
|
117
|
+
*/
|
|
118
|
+
messageDelete(msg_id: string): Promise<{
|
|
119
|
+
data: {
|
|
120
|
+
code: number;
|
|
121
|
+
message: string;
|
|
122
|
+
data: any[];
|
|
123
|
+
};
|
|
124
|
+
}>;
|
|
125
|
+
/**
|
|
126
|
+
* 重编辑指定消息
|
|
127
|
+
* @param data
|
|
128
|
+
* @returns
|
|
129
|
+
*/
|
|
130
|
+
messageUpdate(data: {
|
|
131
|
+
msg_id: string;
|
|
132
|
+
content: any;
|
|
133
|
+
quote?: string;
|
|
134
|
+
temp_target_id?: string;
|
|
135
|
+
}): Promise<{
|
|
136
|
+
data: {
|
|
137
|
+
code: number;
|
|
138
|
+
message: string;
|
|
139
|
+
data: any[];
|
|
140
|
+
};
|
|
141
|
+
}>;
|
|
142
|
+
/**
|
|
143
|
+
* 删回应
|
|
144
|
+
* @param data
|
|
145
|
+
* @returns
|
|
146
|
+
*/
|
|
147
|
+
messageDeleteReaction(data: {
|
|
148
|
+
msg_id: string;
|
|
149
|
+
emoji: string;
|
|
150
|
+
user_id: string;
|
|
151
|
+
}): Promise<{
|
|
152
|
+
code: number;
|
|
153
|
+
message: string;
|
|
154
|
+
data: any[];
|
|
155
|
+
}>;
|
|
156
|
+
/**
|
|
157
|
+
* 发回应
|
|
158
|
+
* @param data
|
|
159
|
+
* @returns
|
|
160
|
+
*/
|
|
161
|
+
messageAddReaction(data: {
|
|
162
|
+
msg_id: string;
|
|
163
|
+
emoji: string;
|
|
164
|
+
}): Promise<{
|
|
165
|
+
code: number;
|
|
166
|
+
message: string;
|
|
167
|
+
data: any[];
|
|
168
|
+
}>;
|
|
169
|
+
/**
|
|
170
|
+
* 某个回应的所有用户
|
|
171
|
+
* @param data
|
|
172
|
+
* @returns
|
|
173
|
+
*/
|
|
174
|
+
messageReactionList(params: {
|
|
175
|
+
msg_id: string;
|
|
176
|
+
emoji: string;
|
|
177
|
+
}): Promise<{
|
|
178
|
+
code: number;
|
|
179
|
+
message: string;
|
|
180
|
+
data: {
|
|
181
|
+
id: string;
|
|
182
|
+
username: string;
|
|
183
|
+
identify_num: string;
|
|
184
|
+
online: boolean;
|
|
185
|
+
status: number;
|
|
186
|
+
avatar: string;
|
|
187
|
+
bot: boolean;
|
|
188
|
+
tag_info: {
|
|
189
|
+
color: string;
|
|
190
|
+
text: string;
|
|
191
|
+
};
|
|
192
|
+
nickname: string;
|
|
193
|
+
reaction_time: number;
|
|
194
|
+
};
|
|
195
|
+
}>;
|
|
196
|
+
/**
|
|
197
|
+
* **********
|
|
198
|
+
* user
|
|
199
|
+
* *********
|
|
200
|
+
*/
|
|
201
|
+
/**
|
|
202
|
+
* 得到当前信息
|
|
203
|
+
* @param guild_id
|
|
204
|
+
* @param user_id
|
|
205
|
+
* @returns
|
|
206
|
+
*/
|
|
207
|
+
userMe(): Promise<{
|
|
208
|
+
code: number;
|
|
209
|
+
message: string;
|
|
210
|
+
data: {
|
|
211
|
+
id: string;
|
|
212
|
+
username: string;
|
|
213
|
+
identify_num: string;
|
|
214
|
+
online: false;
|
|
215
|
+
os: string;
|
|
216
|
+
status: number;
|
|
217
|
+
avatar: string;
|
|
218
|
+
banner: string;
|
|
219
|
+
bot: true;
|
|
220
|
+
mobile_verified: true;
|
|
221
|
+
client_id: string;
|
|
222
|
+
mobile_prefix: string;
|
|
223
|
+
mobile: string;
|
|
224
|
+
invited_count: number;
|
|
225
|
+
};
|
|
226
|
+
}>;
|
|
227
|
+
/**
|
|
228
|
+
* 得到用户信息
|
|
229
|
+
* @param guild_id
|
|
230
|
+
* @param user_id
|
|
231
|
+
* @returns
|
|
232
|
+
*/
|
|
233
|
+
userView(guild_id: string, user_id: string): Promise<{
|
|
234
|
+
code: number;
|
|
235
|
+
message: string;
|
|
236
|
+
data: {
|
|
237
|
+
id: string;
|
|
238
|
+
username: string;
|
|
239
|
+
identify_num: string;
|
|
240
|
+
online: false;
|
|
241
|
+
status: 0;
|
|
242
|
+
bot: true;
|
|
243
|
+
avatar: string;
|
|
244
|
+
vip_avatar: string;
|
|
245
|
+
mobile_verified: true;
|
|
246
|
+
roles: number[];
|
|
247
|
+
joined_at: number;
|
|
248
|
+
active_time: number;
|
|
249
|
+
};
|
|
250
|
+
}>;
|
|
251
|
+
/**
|
|
252
|
+
* 踢出
|
|
253
|
+
* @param guild_id
|
|
254
|
+
* @param user_id
|
|
255
|
+
* @returns
|
|
256
|
+
*/
|
|
257
|
+
guildKickout(guild_id: string, user_id: string): Promise<{
|
|
258
|
+
code: number;
|
|
259
|
+
message: string;
|
|
260
|
+
data: any;
|
|
261
|
+
}>;
|
|
262
|
+
/**
|
|
263
|
+
* 创建角色
|
|
264
|
+
* @param channel_id
|
|
265
|
+
* @param type
|
|
266
|
+
* @param value
|
|
267
|
+
* @returns
|
|
268
|
+
*/
|
|
269
|
+
channelRoleCreate(channel_id: string, type: string, value: string): Promise<{
|
|
270
|
+
code: number;
|
|
271
|
+
message: string;
|
|
272
|
+
data: any;
|
|
273
|
+
}>;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export { KOOKAPI };
|