@alemonjs/qq-bot 0.0.17 → 0.0.18

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/dist/index.html CHANGED
@@ -6,7 +6,7 @@
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>AlemonJS</title>
8
8
  <script type="module" crossorigin src="/assets/index.js"></script>
9
- <link rel="stylesheet" crossorigin href="/assets/index.css">
9
+ <link rel="stylesheet" crossorigin href="/assets/index.css" />
10
10
  </head>
11
11
 
12
12
  <body>
@@ -21,7 +21,7 @@ var QQBotGroup = defineBot(() => {
21
21
  mode: config?.mode
22
22
  });
23
23
  // 连接
24
- client.connect();
24
+ client.connect(config?.gatewayURL);
25
25
  /**
26
26
  * group
27
27
  *
@@ -27,7 +27,7 @@ var QQBotGuild = defineBot(() => {
27
27
  mode: config?.mode
28
28
  });
29
29
  // 连接
30
- client.connect();
30
+ client.connect(config?.gatewayURL);
31
31
  /**
32
32
  * guild
33
33
  */
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineBot, getConfigValue, useUserHashKey, onProcessor } from 'alemonjs';
1
+ import { getConfigValue, useUserHashKey, onProcessor } from 'alemonjs';
2
2
  import { QQBotClient } from './sdk/client.js';
3
3
  import { AT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, MESSAGE_CREATE } from './send/index.js';
4
4
  import QQBotGroup from './index.group.js';
@@ -16,7 +16,7 @@ const client = new Proxy({}, {
16
16
  }
17
17
  });
18
18
  const platform = 'qq-bot';
19
- var index = defineBot(() => {
19
+ var index = definePlatform(() => {
20
20
  let value = getConfigValue();
21
21
  if (!value)
22
22
  value = {};
@@ -53,11 +53,14 @@ var index = defineBot(() => {
53
53
  * GROUP_AT_MESSAGE_CREATE
54
54
  * C2C_MESSAGE_CREATE
55
55
  */
56
+ const createUserAvatarURL = (author_id) => {
57
+ return `https://q.qlogo.cn/qqapp/${config.app_id}/${author_id}/ 640`;
58
+ };
56
59
  // 监听消息
57
60
  client.on('GROUP_AT_MESSAGE_CREATE', async (event) => {
58
61
  const master_key = config?.master_key ?? [];
59
62
  const isMaster = master_key.includes(event.author.id);
60
- const url = `https://q.qlogo.cn/qqapp/${config.app_id}/${event.author.id}/640`;
63
+ const url = createUserAvatarURL(event.author.id);
61
64
  const UserAvatar = {
62
65
  toBuffer: async () => {
63
66
  const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
@@ -104,7 +107,7 @@ var index = defineBot(() => {
104
107
  client.on('C2C_MESSAGE_CREATE', async (event) => {
105
108
  const master_key = config?.master_key ?? [];
106
109
  const isMaster = master_key.includes(event.author.id);
107
- const url = `https://q.qlogo.cn/qqapp/${config.app_id}/${event.author.id}/640`;
110
+ const url = createUserAvatarURL(event.author.id);
108
111
  const UserAvatar = {
109
112
  toBuffer: async () => {
110
113
  const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
@@ -377,21 +380,23 @@ var index = defineBot(() => {
377
380
  // 打 tag
378
381
  const tag = event.tag;
379
382
  try {
383
+ // 群at
380
384
  if (tag == 'GROUP_AT_MESSAGE_CREATE') {
381
385
  return await GROUP_AT_MESSAGE_CREATE(client, event, val);
382
386
  }
387
+ // 私聊
383
388
  if (tag == 'C2C_MESSAGE_CREATE') {
384
389
  return await C2C_MESSAGE_CREATE(client, event, val);
385
390
  }
391
+ // 频道私聊
386
392
  if (tag == 'DIRECT_MESSAGE_CREATE') {
387
393
  return await DIRECT_MESSAGE_CREATE(client, event, val);
388
394
  }
395
+ // 频道at
389
396
  if (tag == 'AT_MESSAGE_CREATE') {
390
397
  return await AT_MESSAGE_CREATE(client, event, val);
391
398
  }
392
- if (tag == 'MESSAGE_CREATE') {
393
- return await AT_MESSAGE_CREATE(client, event, val);
394
- }
399
+ // 频道消息
395
400
  if (tag == 'MESSAGE_CREATE') {
396
401
  return await MESSAGE_CREATE(client, event, val);
397
402
  }
package/lib/sdk/client.js CHANGED
@@ -169,7 +169,7 @@ class QQBotClient extends QQBotAPI {
169
169
  });
170
170
  }
171
171
  else {
172
- const reconnect = () => {
172
+ const reConnect = () => {
173
173
  // 使用了ws服务器
174
174
  this.#ws = new WebSocket(ws);
175
175
  this.#ws.on('open', () => {
@@ -198,14 +198,14 @@ class QQBotClient extends QQBotAPI {
198
198
  return;
199
199
  // 1.3s 后重连
200
200
  setTimeout(() => {
201
- reconnect();
201
+ reConnect();
202
202
  }, 1300);
203
203
  });
204
204
  this.#ws.on('error', e => {
205
205
  this.#error(e);
206
206
  });
207
207
  };
208
- reconnect();
208
+ reConnect();
209
209
  }
210
210
  }
211
211
  catch (e) {
@@ -93,7 +93,7 @@ const intentsMap = {
93
93
  GROUP_ADD_ROBOT: 1 << 25,
94
94
  GROUP_DEL_ROBOT: 1 << 25,
95
95
  GROUP_MSG_REJECT: 1 << 25,
96
- GROUP_MSG_RECEIVE: 1 << 25,
96
+ GROUP_MSG_RECEIVE: 1 << 25
97
97
  };
98
98
  /**
99
99
  *
@@ -5,7 +5,7 @@ interface ButtonType {
5
5
  render_data: {
6
6
  label: string;
7
7
  visited_label: string;
8
- style: number;
8
+ style?: number;
9
9
  };
10
10
  action: {
11
11
  type: number;
@@ -14,8 +14,13 @@ interface ButtonType {
14
14
  };
15
15
  reply?: boolean;
16
16
  enter?: boolean;
17
- unsupport_tips: string;
18
- data: string;
17
+ unsupport_tips?: string;
18
+ data: string | {
19
+ click: string;
20
+ confirm: string;
21
+ cancel: string;
22
+ };
23
+ at_bot_show_channel_list?: boolean;
19
24
  };
20
25
  }
21
26
  interface KeyboardType {
@@ -88,12 +88,12 @@ class QQBotGroupClient extends QQBotAPI {
88
88
  * @param cfg
89
89
  * @param conversation
90
90
  */
91
- async connect() {
91
+ async connect(gatewayURL) {
92
92
  // 定时模式
93
93
  await this.#setTimeoutBotConfig();
94
94
  // 请求url
95
95
  if (!this.#gatewayUrl) {
96
- this.#gatewayUrl = await this.gateway().then(res => res?.url);
96
+ this.#gatewayUrl = gatewayURL ?? await this.gateway().then(res => res?.url);
97
97
  }
98
98
  if (!this.#gatewayUrl)
99
99
  return;
@@ -68,9 +68,9 @@ class QQBotGuildClient extends QQBotAPI {
68
68
  *
69
69
  * @param cfg
70
70
  */
71
- async connect() {
71
+ async connect(gatewayURL) {
72
72
  //
73
- this.#gatewayUrl = await this.gateway()
73
+ this.#gatewayUrl = gatewayURL ?? await this.gateway()
74
74
  .then(res => res.url)
75
75
  .catch(err => {
76
76
  if (this.#events['ERROR']) {
package/lib/send/index.js CHANGED
@@ -1,14 +1,54 @@
1
1
  import { readFileSync } from 'fs';
2
2
  import axios from 'axios';
3
3
 
4
+ const createButtonsData = (rows) => {
5
+ let id = 0;
6
+ const data = {
7
+ rows: rows.map(row => {
8
+ const val = row.value;
9
+ return {
10
+ buttons: val.map(button => {
11
+ const value = button.value;
12
+ const options = button.options;
13
+ id++;
14
+ return {
15
+ "id": String(id),
16
+ "render_data": {
17
+ "label": typeof value == 'object' ? value.title : value,
18
+ "visited_label": typeof value == 'object' ? value.label : value,
19
+ // tudo
20
+ "style": 0
21
+ },
22
+ "action": {
23
+ // 0 link 1 callback , 2 command
24
+ "type": typeof options.data === 'object' ? 1 : (options?.isLink ? 0 : 2),
25
+ "permission": {
26
+ // 所有人
27
+ "type": 2,
28
+ // "specify_role_ids": ["1", "2", "3"]
29
+ },
30
+ // "click_limit": 10,
31
+ "unsupport_tips": options?.toolTip ?? '',
32
+ "data": options?.data ?? '',
33
+ // reply: true,
34
+ "at_bot_show_channel_list": options.showList ?? false,
35
+ "enter": options?.autoEnter ?? false
36
+ }
37
+ };
38
+ })
39
+ };
40
+ })
41
+ };
42
+ return data;
43
+ };
4
44
  const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
5
45
  const content = val
6
- .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
46
+ .filter(item => item.type == 'Mention' || item.type == 'Text')
7
47
  .map(item => {
8
- if (item.type == 'Link') {
9
- return `[${item.options?.title ?? item.value}](${item.value})`;
10
- }
11
- else if (item.type == 'Mention') {
48
+ // if (item.type == 'Link') {
49
+ // return `[${item.options?.title ?? item.value}](${item.value})`
50
+ // } else
51
+ if (item.type == 'Mention') {
12
52
  if (item.value == 'everyone' ||
13
53
  item.value == 'all' ||
14
54
  item.value == '' ||
@@ -34,7 +74,7 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
34
74
  })));
35
75
  }
36
76
  const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
37
- if (images) {
77
+ if (images && images.length > 0) {
38
78
  return Promise.all(images.map(async (item) => {
39
79
  if (item.type == 'ImageURL') {
40
80
  return client.groupOpenMessages(event.GuildId, {
@@ -69,11 +109,41 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
69
109
  });
70
110
  }));
71
111
  }
72
- return [];
112
+ // buttons
113
+ const buttons = val.filter(item => item.type == 'BT.group');
114
+ if (buttons && buttons.length > 0) {
115
+ return Promise.all(buttons.map(async (item) => {
116
+ const template_id = item?.options?.template_id;
117
+ if (template_id) {
118
+ return client.groupOpenMessages(event.GuildId, {
119
+ content: '',
120
+ msg_id: event.MessageId,
121
+ keyboard: {
122
+ id: template_id
123
+ },
124
+ msg_type: 2,
125
+ msg_seq: client.getMessageSeq(event.MessageId)
126
+ });
127
+ }
128
+ const rows = item.value;
129
+ // 构造成按钮
130
+ const data = createButtonsData(rows);
131
+ return client.groupOpenMessages(event.GuildId, {
132
+ content: '',
133
+ msg_id: event.MessageId,
134
+ keyboard: {
135
+ content: data
136
+ },
137
+ msg_type: 2,
138
+ msg_seq: client.getMessageSeq(event.MessageId)
139
+ });
140
+ }));
141
+ }
142
+ return Promise.all([]);
73
143
  };
74
144
  const C2C_MESSAGE_CREATE = (client, event, val) => {
75
145
  const content = val
76
- .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
146
+ .filter(item => item.type == 'Mention' || item.type == 'Text')
77
147
  .map(item => {
78
148
  if (item.type == 'Text') {
79
149
  return item.value;
@@ -90,7 +160,7 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
90
160
  })));
91
161
  }
92
162
  const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
93
- if (images) {
163
+ if (images && images.length > 0) {
94
164
  return Promise.all(images.map(async (item) => {
95
165
  if (item.type == 'ImageURL') {
96
166
  return client.usersOpenMessages(event.OpenId, {
@@ -125,7 +195,41 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
125
195
  });
126
196
  }));
127
197
  }
128
- return [];
198
+ // buttons
199
+ const buttons = val.filter(item => item.type == 'BT.group');
200
+ if (buttons && buttons.length > 0) {
201
+ return Promise.all(buttons.map(async (item) => {
202
+ const template_id = item?.options?.template_id;
203
+ if (template_id) {
204
+ return client.groupOpenMessages(event.GuildId, {
205
+ content: '',
206
+ msg_id: event.MessageId,
207
+ keyboard: {
208
+ id: template_id
209
+ },
210
+ msg_type: 2,
211
+ msg_seq: client.getMessageSeq(event.MessageId)
212
+ });
213
+ }
214
+ const rows = item.value;
215
+ // 看看是否是模板id的
216
+ rows.map(row => {
217
+ return row;
218
+ });
219
+ // 构造成按钮
220
+ const data = createButtonsData(rows);
221
+ return client.groupOpenMessages(event.GuildId, {
222
+ content: '',
223
+ msg_id: event.MessageId,
224
+ keyboard: {
225
+ content: data
226
+ },
227
+ msg_type: 2,
228
+ msg_seq: client.getMessageSeq(event.MessageId)
229
+ });
230
+ }));
231
+ }
232
+ return Promise.all([]);
129
233
  };
130
234
  /**
131
235
  * 频道私聊
@@ -136,7 +240,7 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
136
240
  */
137
241
  const DIRECT_MESSAGE_CREATE = (client, event, val) => {
138
242
  const content = val
139
- .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
243
+ .filter(item => item.type == 'Mention' || item.type == 'Text')
140
244
  .map(item => {
141
245
  if (item.type == 'Text') {
142
246
  return item.value;
@@ -176,12 +280,12 @@ const DIRECT_MESSAGE_CREATE = (client, event, val) => {
176
280
  };
177
281
  const AT_MESSAGE_CREATE = (client, event, val) => {
178
282
  const content = val
179
- .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
283
+ .filter(item => item.type == 'Mention' || item.type == 'Text')
180
284
  .map(item => {
181
- if (item.type == 'Link') {
182
- return `[${item.options?.title ?? item.value}](${item.value})`;
183
- }
184
- else if (item.type == 'Mention') {
285
+ // if (item.type == 'Link') {
286
+ // return `[${item.options?.title ?? item.value}](${item.value})`
287
+ // } else
288
+ if (item.type == 'Mention') {
185
289
  if (item.value == 'everyone' ||
186
290
  item.value == 'all' ||
187
291
  item.value == '' ||
@@ -208,7 +312,7 @@ const AT_MESSAGE_CREATE = (client, event, val) => {
208
312
  })));
209
313
  }
210
314
  const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
211
- if (images) {
315
+ if (images && images.length > 0) {
212
316
  return Promise.all(images.map(async (item) => {
213
317
  if (item.value == 'ImageURL') {
214
318
  // 请求得到buffer
@@ -229,7 +333,7 @@ const AT_MESSAGE_CREATE = (client, event, val) => {
229
333
  });
230
334
  }));
231
335
  }
232
- return [];
336
+ return Promise.all([]);
233
337
  };
234
338
  /**
235
339
  *
@@ -239,12 +343,12 @@ const AT_MESSAGE_CREATE = (client, event, val) => {
239
343
  */
240
344
  const MESSAGE_CREATE = (client, event, val) => {
241
345
  const content = val
242
- .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
346
+ .filter(item => item.type == 'Mention' || item.type == 'Text')
243
347
  .map(item => {
244
- if (item.type == 'Link') {
245
- return `[${item.options?.title ?? item.value}](${item.value})`;
246
- }
247
- else if (item.type == 'Mention') {
348
+ // if (item.type == 'Link') {
349
+ // return `[${item.options?.title ?? item.value}](${item.value})`
350
+ // } else
351
+ if (item.type == 'Mention') {
248
352
  if (item.value == 'everyone' ||
249
353
  item.value == 'all' ||
250
354
  item.value == '' ||
@@ -271,7 +375,7 @@ const MESSAGE_CREATE = (client, event, val) => {
271
375
  })));
272
376
  }
273
377
  const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
274
- if (images) {
378
+ if (images && images.length > 0) {
275
379
  return Promise.all(images.map(async (item) => {
276
380
  if (item.value == 'ImageURL') {
277
381
  // 请求得到buffer
@@ -292,7 +396,7 @@ const MESSAGE_CREATE = (client, event, val) => {
292
396
  });
293
397
  }));
294
398
  }
295
- return [];
399
+ return Promise.all([]);
296
400
  };
297
401
 
298
402
  export { AT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, MESSAGE_CREATE };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/qq-bot",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "description": "阿柠檬qqbot平台连接",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",