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