@alemonjs/kook 0.1.2 → 0.2.1

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/README.md CHANGED
@@ -25,7 +25,7 @@ kook:
25
25
  # 令牌
26
26
  token: ''
27
27
  # 主人
28
- master_id:
28
+ master_key:
29
29
  - ''
30
30
  ```
31
31
 
package/lib/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
+ import * as alemonjs from 'alemonjs';
1
2
  import { KOOKClient } from './sdk/platform/kook/sdk/wss.js';
2
3
 
3
4
  type Client = typeof KOOKClient.prototype;
5
+ declare const platform = "gui";
4
6
  declare const client: Client;
5
- declare const _default: () => typeof global.alemonjs;
7
+ declare const _default: () => alemonjs.ClientAPI;
6
8
 
7
- export { type Client, client, _default as default };
9
+ export { type Client, client, _default as default, platform };
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineBot, getConfig, createHash, Text, At, OnProcessor, useParse } from 'alemonjs';
1
+ import { defineBot, getConfigValue, useUserHashKey, OnProcessor } from 'alemonjs';
2
2
  import 'fs';
3
3
  import 'axios';
4
4
  import 'path';
@@ -10,10 +10,18 @@ import 'form-data';
10
10
  import './sdk/platform/kook/sdk/typings.js';
11
11
  import { KOOKClient } from './sdk/platform/kook/sdk/wss.js';
12
12
 
13
- const client = global.client;
13
+ const platform = 'gui';
14
+ const client = new Proxy({}, {
15
+ get: (_, prop) => {
16
+ if (prop in global.client) {
17
+ return global.client[prop];
18
+ }
19
+ return undefined;
20
+ }
21
+ });
14
22
  var index = defineBot(() => {
15
- const cfg = getConfig();
16
- const config = cfg.value?.kook;
23
+ const value = getConfigValue();
24
+ const config = value?.kook;
17
25
  if (!config)
18
26
  return;
19
27
  // 创建客户端
@@ -27,14 +35,12 @@ var index = defineBot(() => {
27
35
  if (event.extra?.author?.bot)
28
36
  return false;
29
37
  // 主人
30
- const master_id = config?.master_id ?? [];
31
- const isMaster = master_id.includes(event.author_id);
38
+ const master_key = config?.master_key ?? [];
39
+ const isMaster = master_key.includes(event.author_id);
32
40
  // 头像
33
41
  const avatar = event.extra.author.avatar;
34
42
  // 获取消息
35
43
  let msg = event.content;
36
- // 艾特消息处理
37
- const at_users = [];
38
44
  const url = avatar.substring(0, avatar.indexOf('?'));
39
45
  const UserAvatar = {
40
46
  toBuffer: async () => {
@@ -49,24 +55,26 @@ var index = defineBot(() => {
49
55
  return url;
50
56
  }
51
57
  };
52
- const UserKey = createHash(`kook:${event.author_id}`);
58
+ const UserId = event.author_id;
59
+ const UserKey = useUserHashKey({
60
+ Platform: platform,
61
+ UserId
62
+ });
53
63
  // 定义消
54
64
  const e = {
55
65
  // 事件类型
56
- Platform: 'kook',
66
+ Platform: platform,
57
67
  // 用户Id
58
- UserId: event.author_id,
68
+ UserId: UserId,
59
69
  UserKey,
60
70
  UserName: event.extra.author.username,
61
71
  UserAvatar: UserAvatar,
62
72
  IsMaster: isMaster,
73
+ IsBot: false,
63
74
  // message
64
75
  MessageId: event.msg_id,
65
- MessageBody: [
66
- Text(msg),
67
- ...at_users.map(item => At(item.id, 'user', { name: item.name, avatar: item.avatar, bot: item.bot }))
68
- ],
69
76
  MessageText: msg,
77
+ OpenId: '',
70
78
  CreateAt: Date.now(),
71
79
  //
72
80
  tag: 'MESSAGES_PUBLIC',
@@ -89,26 +97,18 @@ var index = defineBot(() => {
89
97
  // 创建私聊标记
90
98
  const data = await client.userChatCreate(event.extra.author.id).then(res => res?.data);
91
99
  // 主人
92
- const master_id = config?.master_id ?? [];
93
- const isMaster = master_id.includes(event.author_id);
100
+ const master_key = config?.master_key ?? [];
101
+ const isMaster = master_key.includes(event.author_id);
94
102
  // 头像
95
103
  const avatar = event.extra.author.avatar;
96
104
  // 获取消息
97
105
  let msg = event.content;
98
- // 艾特消息处理
99
- const at_users = [];
100
106
  /**
101
107
  * 艾特类型所得到的
102
108
  * 包括机器人在内
103
109
  */
104
110
  const mention_role_part = event.extra.kmarkdown?.mention_role_part ?? [];
105
111
  for (const item of mention_role_part) {
106
- at_users.push({
107
- id: item.role_id,
108
- name: item.name,
109
- avatar: '',
110
- bot: true
111
- });
112
112
  msg = msg.replace(`(rol)${item.role_id}(rol)`, '').trim();
113
113
  }
114
114
  /**
@@ -116,12 +116,6 @@ var index = defineBot(() => {
116
116
  */
117
117
  const mention_part = event.extra.kmarkdown?.mention_part ?? [];
118
118
  for (const item of mention_part) {
119
- at_users.push({
120
- id: item.id,
121
- name: item.username,
122
- avatar: item.avatar,
123
- bot: false
124
- });
125
119
  msg = msg.replace(`(met)${item.id}(met)`, '').trim();
126
120
  }
127
121
  const url = avatar.substring(0, avatar.indexOf('?'));
@@ -138,26 +132,27 @@ var index = defineBot(() => {
138
132
  return url;
139
133
  }
140
134
  };
141
- const UserKey = createHash(`kook:${event.author_id}`);
135
+ const UserId = event.author_id;
136
+ const UserKey = useUserHashKey({
137
+ Platform: platform,
138
+ UserId
139
+ });
142
140
  // 定义消
143
141
  const e = {
144
142
  // 事件类型
145
- Platform: 'kook',
143
+ Platform: platform,
146
144
  //
147
145
  GuildId: event.extra.guild_id,
148
146
  ChannelId: event.target_id,
149
147
  // 用户Id
150
- UserId: event.author_id,
148
+ UserId: UserId,
151
149
  UserKey,
152
150
  UserName: event.extra.author.username,
153
151
  UserAvatar: UserAvatar,
154
152
  IsMaster: isMaster,
153
+ IsBot: false,
155
154
  // message
156
155
  MessageId: event.msg_id,
157
- MessageBody: [
158
- Text(msg),
159
- ...at_users.map(item => At(item.id, 'user', { name: item.name, avatar: item.avatar, bot: item.bot }))
160
- ],
161
156
  MessageText: msg,
162
157
  OpenId: data?.code,
163
158
  CreateAt: Date.now(),
@@ -186,9 +181,47 @@ var index = defineBot(() => {
186
181
  send: (event, val) => {
187
182
  if (val.length < 0)
188
183
  return Promise.all([]);
189
- const content = useParse({
190
- MessageBody: val
191
- }, 'Text');
184
+ const content = val
185
+ .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
186
+ .map(item => {
187
+ if (item.type == 'Link') {
188
+ return `[${item.options?.title ?? item.value}](${item.value})`;
189
+ }
190
+ else if (item.type == 'Mention') {
191
+ if (item.value == 'everyone' ||
192
+ item.value == 'all' ||
193
+ item.value == '' ||
194
+ typeof item.value != 'string') {
195
+ return `(met)all(met)`;
196
+ }
197
+ if (item.options?.belong == 'user') {
198
+ return `(met)${item.value}(met)`;
199
+ }
200
+ else if (item.options?.belong == 'channel') {
201
+ return `(chn)${item.value}(chn)`;
202
+ }
203
+ return '';
204
+ }
205
+ else if (item.type == 'Text') {
206
+ if (item.options?.style == 'block') {
207
+ return `\`${item.value}\``;
208
+ }
209
+ else if (item.options?.style == 'italic') {
210
+ return `*${item.value}*`;
211
+ }
212
+ else if (item.options?.style == 'bold') {
213
+ return `**${item.value}**`;
214
+ }
215
+ else if (item.options?.style == 'strikethrough') {
216
+ return `~~${item.value}~~`;
217
+ }
218
+ else if (item.options?.style == 'boldItalic') {
219
+ return `***${item.value}***`;
220
+ }
221
+ return item.value;
222
+ }
223
+ })
224
+ .join('');
192
225
  if (content) {
193
226
  return Promise.all([content].map(item => client.createMessage({
194
227
  type: 9,
@@ -196,9 +229,7 @@ var index = defineBot(() => {
196
229
  content: item
197
230
  })));
198
231
  }
199
- const images = useParse({
200
- MessageBody: val
201
- }, 'Image');
232
+ const images = val.filter(item => item.type == 'Image').map(item => item.value);
202
233
  if (images) {
203
234
  return Promise.all(images.map(async (item) => {
204
235
  // 上传图片
@@ -214,10 +245,48 @@ var index = defineBot(() => {
214
245
  }));
215
246
  }
216
247
  return Promise.all([]);
248
+ },
249
+ mention: async (e) => {
250
+ const event = e.value;
251
+ const MessageMention = [];
252
+ /**
253
+ * 艾特类型所得到的,包括机器人在内
254
+ */
255
+ const mention_role_part = event.extra.kmarkdown?.mention_role_part ?? [];
256
+ for (const item of mention_role_part) {
257
+ MessageMention.push({
258
+ UserId: item.role_id,
259
+ UserName: item.name,
260
+ UserKey: useUserHashKey({
261
+ Platform: platform,
262
+ UserId: item.role_id
263
+ }),
264
+ IsMaster: false,
265
+ IsBot: true
266
+ });
267
+ }
268
+ /**
269
+ * 艾特用户所得到的
270
+ */
271
+ const mention_part = event.extra.kmarkdown?.mention_part ?? [];
272
+ for (const item of mention_part) {
273
+ MessageMention.push({
274
+ // avatar: item.avatar,
275
+ UserId: item.id,
276
+ UserName: item.username,
277
+ UserKey: useUserHashKey({
278
+ Platform: platform,
279
+ UserId: item.role_id
280
+ }),
281
+ IsMaster: false,
282
+ IsBot: false
283
+ });
284
+ }
285
+ return MessageMention;
217
286
  }
218
287
  }
219
288
  }
220
289
  };
221
290
  });
222
291
 
223
- export { client, index as default };
292
+ export { client, index as default, platform };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/kook",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "description": "kook-bot",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",