@alemonjs/kook 0.2.9 → 2.1.0-alpha.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/config.js +20 -0
- package/lib/hook.d.ts +38 -0
- package/lib/hook.js +24 -0
- package/lib/index.d.ts +5 -6
- package/lib/index.js +209 -196
- package/lib/sdk/{platform/kook/sdk/api.d.ts → api.d.ts} +1 -2
- package/lib/sdk/{platform/kook/sdk/api.js → api.js} +25 -26
- package/lib/sdk/{platform/kook/sdk/config.js → config.js} +1 -1
- package/lib/sdk/{platform/kook/sdk/message.js → message.js} +1 -4
- package/lib/sdk/typings.d.ts +109 -0
- package/package.json +2 -2
- package/dist/assets/index.css +0 -1
- package/dist/assets/index.js +0 -29
- package/dist/index.html +0 -15
- package/lib/sdk/core/utils/from.js +0 -42
- package/lib/sdk/platform/kook/sdk/message/INTERACTION.d.ts +0 -8
- package/lib/sdk/platform/kook/sdk/message/MEMBER_ADD.d.ts +0 -10
- package/lib/sdk/platform/kook/sdk/message/MEMBER_REMOVE.d.ts +0 -10
- package/lib/sdk/platform/kook/sdk/message/MESSAGES_DIRECT.d.ts +0 -10
- package/lib/sdk/platform/kook/sdk/message/MESSAGES_PUBLIC.d.ts +0 -10
- package/lib/sdk/platform/kook/sdk/message/REACTIONS.d.ts +0 -10
- package/lib/sdk/platform/kook/sdk/message.d.ts +0 -18
- package/lib/sdk/platform/kook/sdk/typings.d.ts +0 -192
- package/lib/sdk/platform/kook/sdk/wss.d.ts +0 -26
- package/lib/sdk/platform/kook/sdk/wss.types.d.ts +0 -12
- /package/lib/{sdk/core → core}/config.js +0 -0
- /package/lib/sdk/{platform/kook/sdk/conversation.js → conversation.js} +0 -0
- /package/lib/sdk/{platform/kook/sdk/typings.js → typings.js} +0 -0
- /package/lib/sdk/{platform/kook/sdk/wss.js → wss.js} +0 -0
package/lib/config.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useUserHashKey, getConfigValue } from 'alemonjs';
|
|
2
|
+
|
|
3
|
+
const platform = 'telegram';
|
|
4
|
+
const getKOOKConfig = () => {
|
|
5
|
+
const value = getConfigValue() || {};
|
|
6
|
+
return value[platform] || {};
|
|
7
|
+
};
|
|
8
|
+
const getMaster = (UserId) => {
|
|
9
|
+
const config = getKOOKConfig();
|
|
10
|
+
const master_key = config.master_key || [];
|
|
11
|
+
const master_id = config.master_id || [];
|
|
12
|
+
const UserKey = useUserHashKey({
|
|
13
|
+
Platform: platform,
|
|
14
|
+
UserId: UserId
|
|
15
|
+
});
|
|
16
|
+
const is = master_key.includes(UserKey) || master_id.includes(UserId);
|
|
17
|
+
return [is, UserKey];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { getKOOKConfig, getMaster, platform };
|
package/lib/hook.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { EventKeys, Events } from 'alemonjs';
|
|
2
|
+
import API from 'node-telegram-bot-api';
|
|
3
|
+
import { EventData } from './sdk/typings.js';
|
|
4
|
+
|
|
5
|
+
type MAP = {
|
|
6
|
+
'message.create': EventData;
|
|
7
|
+
'private.message.create': EventData;
|
|
8
|
+
'interaction.create': undefined;
|
|
9
|
+
'private.interaction.create': undefined;
|
|
10
|
+
'message.update': undefined;
|
|
11
|
+
'message.delete': undefined;
|
|
12
|
+
'message.reaction.add': undefined;
|
|
13
|
+
'message.reaction.remove': undefined;
|
|
14
|
+
'channal.create': undefined;
|
|
15
|
+
'channal.delete': undefined;
|
|
16
|
+
'guild.join': undefined;
|
|
17
|
+
'guild.exit': undefined;
|
|
18
|
+
'member.add': undefined;
|
|
19
|
+
'member.remove': undefined;
|
|
20
|
+
'private.message.update': undefined;
|
|
21
|
+
'private.message.delete': undefined;
|
|
22
|
+
'private.friend.add': undefined;
|
|
23
|
+
'private.guild.add': undefined;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param event
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
declare const useValue: <T extends EventKeys>(event: Events[T]) => readonly [MAP[T]];
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param event
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [API, MAP[T]];
|
|
37
|
+
|
|
38
|
+
export { useClient, useValue };
|
package/lib/hook.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createEventValue, useClient as useClient$1 } from 'alemonjs';
|
|
2
|
+
import API from 'node-telegram-bot-api';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param event
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
const useValue = (event) => {
|
|
10
|
+
const value = createEventValue(event);
|
|
11
|
+
return [value];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param event
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
const useClient = (event) => {
|
|
19
|
+
const [client] = useClient$1(event, API);
|
|
20
|
+
const value = createEventValue(event);
|
|
21
|
+
return [client, value];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { useClient, useValue };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { useClient, useValue } from './hook.js';
|
|
2
|
+
export { KOOKAPI as API } from './sdk/api.js';
|
|
3
3
|
|
|
4
|
-
type Client = typeof KOOKClient.prototype;
|
|
5
4
|
declare const platform = "kook";
|
|
6
|
-
declare const client: Client;
|
|
7
|
-
declare const _default: alemonjs.DefineBotValue;
|
|
8
5
|
|
|
9
|
-
|
|
6
|
+
declare const _default: () => void;
|
|
7
|
+
|
|
8
|
+
export { _default as default, platform };
|
package/lib/index.js
CHANGED
|
@@ -1,27 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getConfigValue, cbpPlatform, createResult, ResultCode } from 'alemonjs';
|
|
2
|
+
export { KOOKAPI as API } from './sdk/api.js';
|
|
3
|
+
import { KOOKClient } from './sdk/wss.js';
|
|
2
4
|
import { readFileSync } from 'fs';
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
5
|
-
|
|
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';
|
|
5
|
+
import { getMaster } from './config.js';
|
|
6
|
+
import { getBufferByURL } from 'alemonjs/utils';
|
|
7
|
+
export { useClient, useValue } from './hook.js';
|
|
12
8
|
|
|
13
9
|
const platform = 'kook';
|
|
14
|
-
|
|
15
|
-
get: (_, prop) => {
|
|
16
|
-
if (prop in global.client) {
|
|
17
|
-
const original = global.client[prop];
|
|
18
|
-
// 防止函数内this丢失
|
|
19
|
-
return typeof original === 'function' ? original.bind(global.client) : original;
|
|
20
|
-
}
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
var index = defineBot(() => {
|
|
10
|
+
var index = () => {
|
|
25
11
|
let value = getConfigValue();
|
|
26
12
|
if (!value)
|
|
27
13
|
value = {};
|
|
@@ -32,38 +18,22 @@ var index = defineBot(() => {
|
|
|
32
18
|
});
|
|
33
19
|
// 连接
|
|
34
20
|
client.connect();
|
|
21
|
+
const url = `ws://127.0.0.1:${process.env?.port || config?.port || 17117}`;
|
|
22
|
+
const cbp = cbpPlatform(url);
|
|
35
23
|
client.on('MESSAGES_DIRECT', async (event) => {
|
|
36
24
|
// 过滤机器人
|
|
37
25
|
if (event.extra?.author?.bot)
|
|
38
26
|
return false;
|
|
39
27
|
// 创建私聊标记
|
|
40
28
|
const data = await client.userChatCreate(event.extra.author.id).then(res => res?.data);
|
|
41
|
-
// 主人
|
|
42
|
-
const master_key = config?.master_key ?? [];
|
|
43
|
-
const isMaster = master_key.includes(event.author_id);
|
|
44
29
|
// 头像
|
|
45
30
|
const avatar = event.extra.author.avatar;
|
|
46
31
|
// 获取消息
|
|
47
32
|
let msg = event.content;
|
|
48
33
|
const url = avatar.substring(0, avatar.indexOf('?'));
|
|
49
|
-
const UserAvatar =
|
|
50
|
-
toBuffer: async () => {
|
|
51
|
-
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
52
|
-
return Buffer.from(arrayBuffer);
|
|
53
|
-
},
|
|
54
|
-
toBase64: async () => {
|
|
55
|
-
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
56
|
-
return Buffer.from(arrayBuffer).toString('base64');
|
|
57
|
-
},
|
|
58
|
-
toURL: async () => {
|
|
59
|
-
return url;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
34
|
+
const UserAvatar = url;
|
|
62
35
|
const UserId = event.author_id;
|
|
63
|
-
const UserKey =
|
|
64
|
-
Platform: platform,
|
|
65
|
-
UserId
|
|
66
|
-
});
|
|
36
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
67
37
|
// 定义消
|
|
68
38
|
const e = {
|
|
69
39
|
name: 'private.message.create',
|
|
@@ -83,10 +53,9 @@ var index = defineBot(() => {
|
|
|
83
53
|
CreateAt: Date.now(),
|
|
84
54
|
//
|
|
85
55
|
tag: 'MESSAGES_PUBLIC',
|
|
86
|
-
value:
|
|
56
|
+
value: event
|
|
87
57
|
};
|
|
88
|
-
|
|
89
|
-
onProcessor('private.message.create', e, event);
|
|
58
|
+
cbp.send(e);
|
|
90
59
|
});
|
|
91
60
|
// 监听消息
|
|
92
61
|
client.on('MESSAGES_PUBLIC', async (event) => {
|
|
@@ -95,9 +64,6 @@ var index = defineBot(() => {
|
|
|
95
64
|
return false;
|
|
96
65
|
// 创建私聊标记
|
|
97
66
|
const data = await client.userChatCreate(event.extra.author.id).then(res => res?.data);
|
|
98
|
-
// 主人
|
|
99
|
-
const master_key = config?.master_key ?? [];
|
|
100
|
-
const isMaster = master_key.includes(event.author_id);
|
|
101
67
|
// 头像
|
|
102
68
|
const avatar = event.extra.author.avatar;
|
|
103
69
|
// 获取消息
|
|
@@ -117,25 +83,9 @@ var index = defineBot(() => {
|
|
|
117
83
|
for (const item of mention_part) {
|
|
118
84
|
msg = msg.replace(`(met)${item.id}(met)`, '').trim();
|
|
119
85
|
}
|
|
120
|
-
const
|
|
121
|
-
const UserAvatar = {
|
|
122
|
-
toBuffer: async () => {
|
|
123
|
-
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
124
|
-
return Buffer.from(arrayBuffer);
|
|
125
|
-
},
|
|
126
|
-
toBase64: async () => {
|
|
127
|
-
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
128
|
-
return Buffer.from(arrayBuffer).toString('base64');
|
|
129
|
-
},
|
|
130
|
-
toURL: async () => {
|
|
131
|
-
return url;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
86
|
+
const UserAvatar = avatar.substring(0, avatar.indexOf('?'));
|
|
134
87
|
const UserId = event.author_id;
|
|
135
|
-
const UserKey =
|
|
136
|
-
Platform: platform,
|
|
137
|
-
UserId
|
|
138
|
-
});
|
|
88
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
139
89
|
// 定义消
|
|
140
90
|
const e = {
|
|
141
91
|
name: 'message.create',
|
|
@@ -144,6 +94,7 @@ var index = defineBot(() => {
|
|
|
144
94
|
//
|
|
145
95
|
GuildId: event.extra.guild_id,
|
|
146
96
|
ChannelId: event.target_id,
|
|
97
|
+
SpaceId: event.target_id,
|
|
147
98
|
// 用户Id
|
|
148
99
|
UserId: UserId,
|
|
149
100
|
UserKey,
|
|
@@ -158,32 +109,26 @@ var index = defineBot(() => {
|
|
|
158
109
|
CreateAt: Date.now(),
|
|
159
110
|
//
|
|
160
111
|
tag: 'MESSAGES_PUBLIC',
|
|
161
|
-
value:
|
|
112
|
+
value: event
|
|
162
113
|
};
|
|
163
|
-
|
|
164
|
-
onProcessor('message.create', e, event);
|
|
114
|
+
cbp.send(e);
|
|
165
115
|
});
|
|
166
116
|
// 发送错误时
|
|
167
117
|
client.on('ERROR', msg => {
|
|
168
118
|
console.error(msg);
|
|
169
119
|
});
|
|
170
|
-
// 客户端全局化。
|
|
171
|
-
global.client = client;
|
|
172
120
|
/**
|
|
173
121
|
*
|
|
174
122
|
* @param channel_id
|
|
175
123
|
* @param val
|
|
176
124
|
* @returns
|
|
177
125
|
*/
|
|
178
|
-
const sendChannel = (
|
|
126
|
+
const sendChannel = async (target_id, val) => {
|
|
179
127
|
if (val.length < 0)
|
|
180
128
|
return Promise.all([]);
|
|
181
129
|
const content = val
|
|
182
130
|
.filter(item => item.type == 'Mention' || item.type == 'Text')
|
|
183
131
|
.map(item => {
|
|
184
|
-
// if (item.type == 'Link') {
|
|
185
|
-
// return `[${item.options?.title ?? item.value}](${item.value})`
|
|
186
|
-
// } else
|
|
187
132
|
if (item.type == 'Mention') {
|
|
188
133
|
if (item.value == 'everyone' ||
|
|
189
134
|
item.value == 'all' ||
|
|
@@ -219,40 +164,54 @@ var index = defineBot(() => {
|
|
|
219
164
|
}
|
|
220
165
|
})
|
|
221
166
|
.join('');
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
167
|
+
try {
|
|
168
|
+
if (content) {
|
|
169
|
+
const res = await client.createMessage({
|
|
170
|
+
type: 9,
|
|
171
|
+
target_id: target_id,
|
|
172
|
+
content: content
|
|
173
|
+
});
|
|
174
|
+
return [createResult(ResultCode.Ok, 'client.createMessage', res)];
|
|
175
|
+
}
|
|
176
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
177
|
+
if (images.length > 0) {
|
|
178
|
+
let bufferData = null;
|
|
179
|
+
for (let i = 0; i < images.length; i++) {
|
|
180
|
+
if (bufferData)
|
|
181
|
+
break;
|
|
182
|
+
const item = images[i];
|
|
183
|
+
if (item.type == 'Image') {
|
|
184
|
+
bufferData = Buffer.from(item.value, 'base64');
|
|
185
|
+
}
|
|
186
|
+
else if (item.type == 'ImageURL') {
|
|
187
|
+
bufferData = await getBufferByURL(item.value);
|
|
188
|
+
}
|
|
189
|
+
else if (item.type == 'ImageFile') {
|
|
190
|
+
bufferData = readFileSync(item.value);
|
|
191
|
+
}
|
|
242
192
|
}
|
|
193
|
+
if (!bufferData)
|
|
194
|
+
return [];
|
|
243
195
|
// 上传图片
|
|
244
|
-
const
|
|
245
|
-
if (!
|
|
246
|
-
return
|
|
196
|
+
const imageRes = await client.postImage(bufferData);
|
|
197
|
+
if (!imageRes)
|
|
198
|
+
return [];
|
|
199
|
+
const url = imageRes.data?.url;
|
|
200
|
+
if (!url)
|
|
201
|
+
return [];
|
|
247
202
|
// 发送消息
|
|
248
|
-
|
|
203
|
+
const res = await client.createMessage({
|
|
249
204
|
type: 2,
|
|
250
|
-
target_id:
|
|
251
|
-
content:
|
|
205
|
+
target_id: target_id,
|
|
206
|
+
content: url
|
|
252
207
|
});
|
|
253
|
-
|
|
208
|
+
return [createResult(ResultCode.Ok, 'client.createMessage', res)];
|
|
209
|
+
}
|
|
210
|
+
return [];
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
return [createResult(ResultCode.Fail, 'client.createMessage', error)];
|
|
254
214
|
}
|
|
255
|
-
return Promise.all([]);
|
|
256
215
|
};
|
|
257
216
|
/**
|
|
258
217
|
*
|
|
@@ -260,18 +219,12 @@ var index = defineBot(() => {
|
|
|
260
219
|
* @param val
|
|
261
220
|
* @returns
|
|
262
221
|
*/
|
|
263
|
-
const sendUser = async (
|
|
222
|
+
const sendUser = async (open_id, val) => {
|
|
264
223
|
if (val.length < 0)
|
|
265
|
-
return
|
|
266
|
-
// 创建私聊标记
|
|
267
|
-
const data = await client.userChatCreate(user_id).then(res => res?.data);
|
|
268
|
-
const open_id = data?.code;
|
|
224
|
+
return [];
|
|
269
225
|
const content = val
|
|
270
226
|
.filter(item => item.type == 'Mention' || item.type == 'Text')
|
|
271
227
|
.map(item => {
|
|
272
|
-
// if (item.type == 'Link') {
|
|
273
|
-
// return `[${item.options?.title ?? item.value}](${item.value})`
|
|
274
|
-
// } else
|
|
275
228
|
if (item.type == 'Mention') {
|
|
276
229
|
if (item.value == 'everyone' ||
|
|
277
230
|
item.value == 'all' ||
|
|
@@ -307,103 +260,163 @@ var index = defineBot(() => {
|
|
|
307
260
|
}
|
|
308
261
|
})
|
|
309
262
|
.join('');
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
263
|
+
try {
|
|
264
|
+
if (content) {
|
|
265
|
+
const res = await client.createDirectMessage({
|
|
266
|
+
type: 9,
|
|
267
|
+
chat_code: open_id,
|
|
268
|
+
content: content
|
|
269
|
+
});
|
|
270
|
+
return [createResult(ResultCode.Ok, 'client.createDirectMessage', res)];
|
|
271
|
+
}
|
|
272
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
273
|
+
if (images.length > 0) {
|
|
274
|
+
let bufferData = null;
|
|
275
|
+
for (let i = 0; i < images.length; i++) {
|
|
276
|
+
if (bufferData)
|
|
277
|
+
break;
|
|
278
|
+
const item = images[i];
|
|
279
|
+
if (item.type == 'Image') {
|
|
280
|
+
bufferData = Buffer.from(item.value, 'base64');
|
|
281
|
+
}
|
|
282
|
+
else if (item.type == 'ImageURL') {
|
|
283
|
+
bufferData = await getBufferByURL(item.value);
|
|
284
|
+
}
|
|
285
|
+
else if (item.type == 'ImageFile') {
|
|
286
|
+
bufferData = readFileSync(item.value);
|
|
287
|
+
}
|
|
330
288
|
}
|
|
289
|
+
if (!bufferData)
|
|
290
|
+
return [];
|
|
331
291
|
// 上传图片
|
|
332
|
-
const
|
|
333
|
-
if (!
|
|
334
|
-
return
|
|
335
|
-
|
|
336
|
-
|
|
292
|
+
const imageRes = await client.postImage(bufferData);
|
|
293
|
+
if (!imageRes)
|
|
294
|
+
return [];
|
|
295
|
+
const url = imageRes.data?.url;
|
|
296
|
+
if (!url)
|
|
297
|
+
return [];
|
|
298
|
+
const res = await client.createDirectMessage({
|
|
337
299
|
type: 2,
|
|
338
300
|
chat_code: open_id,
|
|
339
|
-
content:
|
|
301
|
+
content: url
|
|
340
302
|
});
|
|
341
|
-
|
|
303
|
+
return [createResult(ResultCode.Ok, 'client.createDirectMessage', res)];
|
|
304
|
+
}
|
|
305
|
+
return [];
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
return [createResult(ResultCode.Fail, 'client.createDirectMessage', error)];
|
|
342
309
|
}
|
|
343
|
-
return Promise.all([]);
|
|
344
310
|
};
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
311
|
+
/**
|
|
312
|
+
*
|
|
313
|
+
* @param user_id
|
|
314
|
+
* @param val
|
|
315
|
+
* @returns
|
|
316
|
+
*/
|
|
317
|
+
// const sendUserByUserId = async (user_id: string, val: DataEnums[]) => {
|
|
318
|
+
// if (val.length < 0) return []
|
|
319
|
+
// // 创建私聊标记
|
|
320
|
+
// const data = await client.userChatCreate(user_id).then(res => res?.data)
|
|
321
|
+
// const open_id = data?.code
|
|
322
|
+
// return await sendUser(open_id, val)
|
|
323
|
+
// }
|
|
324
|
+
const api = {
|
|
325
|
+
active: {
|
|
326
|
+
send: {
|
|
327
|
+
channel: sendChannel,
|
|
328
|
+
user: sendUser
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
use: {
|
|
332
|
+
send: async (event, val) => {
|
|
333
|
+
if (val.length < 0)
|
|
334
|
+
return [];
|
|
335
|
+
if (event.name == 'message.create') {
|
|
336
|
+
return await sendChannel(event.ChannelId, val);
|
|
352
337
|
}
|
|
338
|
+
else if (event.name == 'private.message.create') {
|
|
339
|
+
return await sendUser(event.OpenId, val);
|
|
340
|
+
}
|
|
341
|
+
return [];
|
|
353
342
|
},
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}),
|
|
381
|
-
IsMaster: false,
|
|
382
|
-
IsBot: true
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* 艾特用户所得到的
|
|
387
|
-
*/
|
|
388
|
-
const mention_part = event.extra.kmarkdown?.mention_part ?? [];
|
|
389
|
-
for (const item of mention_part) {
|
|
390
|
-
MessageMention.push({
|
|
391
|
-
// avatar: item.avatar,
|
|
392
|
-
UserId: item.id,
|
|
393
|
-
UserName: item.username,
|
|
394
|
-
UserKey: useUserHashKey({
|
|
395
|
-
Platform: platform,
|
|
396
|
-
UserId: item.role_id
|
|
397
|
-
}),
|
|
398
|
-
IsMaster: false,
|
|
399
|
-
IsBot: false
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
return MessageMention;
|
|
343
|
+
mention: async (e) => {
|
|
344
|
+
const event = e.value;
|
|
345
|
+
const MessageMention = [];
|
|
346
|
+
const mention_role_part = event.extra.kmarkdown?.mention_role_part ?? [];
|
|
347
|
+
for (const item of mention_role_part) {
|
|
348
|
+
const UserId = item.role_id;
|
|
349
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
350
|
+
MessageMention.push({
|
|
351
|
+
UserId: UserId,
|
|
352
|
+
UserName: item.name,
|
|
353
|
+
UserKey: UserKey,
|
|
354
|
+
IsMaster: isMaster,
|
|
355
|
+
IsBot: true
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
const mention_part = event.extra.kmarkdown?.mention_part ?? [];
|
|
359
|
+
for (const item of mention_part) {
|
|
360
|
+
const UserId = item.id;
|
|
361
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
362
|
+
MessageMention.push({
|
|
363
|
+
UserId: UserId,
|
|
364
|
+
UserName: item.username,
|
|
365
|
+
UserKey: UserKey,
|
|
366
|
+
IsMaster: isMaster,
|
|
367
|
+
IsBot: false
|
|
368
|
+
});
|
|
403
369
|
}
|
|
370
|
+
return MessageMention;
|
|
404
371
|
}
|
|
405
372
|
}
|
|
406
373
|
};
|
|
407
|
-
|
|
374
|
+
cbp.onactions(async (data, consume) => {
|
|
375
|
+
if (data.action === 'message.send') {
|
|
376
|
+
const event = data.payload.event;
|
|
377
|
+
const paramFormat = data.payload.params.format;
|
|
378
|
+
const res = await api.use.send(event, paramFormat);
|
|
379
|
+
if (!res) {
|
|
380
|
+
consume([createResult(ResultCode.Ok, '请求完成', null)]);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
consume(res.map(item => createResult(ResultCode.Ok, '请求完成', item)));
|
|
384
|
+
}
|
|
385
|
+
else if (data.action === 'message.send.channel') {
|
|
386
|
+
const channel_id = data.payload.ChannelId;
|
|
387
|
+
const val = data.payload.params.format;
|
|
388
|
+
const res = await api.active.send.channel(channel_id, val);
|
|
389
|
+
if (!res) {
|
|
390
|
+
consume([createResult(ResultCode.Ok, '请求完成', null)]);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
consume(res.map(item => createResult(ResultCode.Ok, '请求完成', item)));
|
|
394
|
+
}
|
|
395
|
+
else if (data.action === 'message.send.user') {
|
|
396
|
+
const user_id = data.payload.UserId;
|
|
397
|
+
const val = data.payload.params.format;
|
|
398
|
+
const res = await api.active.send.user(user_id, val);
|
|
399
|
+
if (!res) {
|
|
400
|
+
consume([createResult(ResultCode.Ok, '请求完成', null)]);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
consume(res.map(item => createResult(ResultCode.Ok, '请求完成', item)));
|
|
404
|
+
}
|
|
405
|
+
else if (data.action === 'mention.get') {
|
|
406
|
+
const event = data.payload.event;
|
|
407
|
+
const res = await api.use.mention(event);
|
|
408
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
cbp.onapis(async (data, consume) => {
|
|
412
|
+
const key = data.payload?.key;
|
|
413
|
+
if (client[key]) {
|
|
414
|
+
// 如果 client 上有对应的 key,直接调用。
|
|
415
|
+
const params = data.payload.params;
|
|
416
|
+
const res = await client[key](...params);
|
|
417
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
};
|
|
408
421
|
|
|
409
|
-
export {
|
|
422
|
+
export { index as default, platform };
|
|
@@ -7,13 +7,12 @@ import { SendMessageParams, SendDirectMessageParams } from './typings.js';
|
|
|
7
7
|
* api接口
|
|
8
8
|
*/
|
|
9
9
|
declare class KOOKAPI {
|
|
10
|
-
API_URL: string;
|
|
11
10
|
/**
|
|
12
11
|
* KOOK服务
|
|
13
12
|
* @param config
|
|
14
13
|
* @returns
|
|
15
14
|
*/
|
|
16
|
-
|
|
15
|
+
service(opstoin: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any>>;
|
|
17
16
|
/**
|
|
18
17
|
*
|
|
19
18
|
* @returns
|