@alemonjs/qq-bot 2.1.0-alpha.26 → 2.1.0-alpha.28

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.
Files changed (2) hide show
  1. package/lib/sends.js +35 -7
  2. package/package.json +1 -1
package/lib/sends.js CHANGED
@@ -2,11 +2,14 @@ import { readFileSync } from 'fs';
2
2
  import { createResult, ResultCode } from 'alemonjs';
3
3
  import axios from 'axios';
4
4
 
5
- const createButtonsData = (rows) => {
6
- let id = 0;
5
+ const MAX_BUTTON_ROWS = 5;
6
+ const MAX_BUTTONS_PER_ROW = 5;
7
+ const createButtonsData = (rows, startId = 0) => {
8
+ let id = startId;
9
+ const clippedRows = rows.slice(0, MAX_BUTTON_ROWS);
7
10
  return {
8
- rows: rows.map(row => ({
9
- buttons: row.value.map(button => {
11
+ rows: clippedRows.map(row => ({
12
+ buttons: row.value.slice(0, MAX_BUTTONS_PER_ROW).map(button => {
10
13
  const value = button.value;
11
14
  const options = button.options;
12
15
  id++;
@@ -29,7 +32,8 @@ const createButtonsData = (rows) => {
29
32
  }
30
33
  };
31
34
  })
32
- }))
35
+ })),
36
+ nextId: id
33
37
  };
34
38
  };
35
39
  const createArkCardData = (value) => ({
@@ -196,15 +200,36 @@ const buildMdAndButtonsParams = (val) => {
196
200
  }
197
201
  }
198
202
  else if (item.type === 'BT.group' && typeof item?.value !== 'string') {
199
- params['keyboard'] = { content: createButtonsData(item.value) };
203
+ if (params['keyboard']?.content?.rows) {
204
+ const existingRows = params['keyboard'].content.rows;
205
+ const currentId = params['keyboard'].content.nextId ?? existingRows.length;
206
+ const remaining = MAX_BUTTON_ROWS - existingRows.length;
207
+ if (remaining > 0) {
208
+ const { rows: newRows, nextId } = createButtonsData(item.value.slice(0, remaining), currentId);
209
+ existingRows.push(...newRows);
210
+ params['keyboard'].content.nextId = nextId;
211
+ }
212
+ }
213
+ else {
214
+ const result = createButtonsData(item.value);
215
+ params['keyboard'] = { content: result };
216
+ }
200
217
  }
201
218
  else if (item.type === 'Markdown' && typeof item?.value !== 'string') {
202
219
  const content = createMarkdownText(item.value);
203
220
  if (content) {
204
- params['markdown'] = { content };
221
+ if (params['markdown']?.content) {
222
+ params['markdown'].content += content;
223
+ }
224
+ else {
225
+ params['markdown'] = { content };
226
+ }
205
227
  }
206
228
  }
207
229
  }
230
+ if (params['keyboard']?.content?.nextId !== undefined) {
231
+ delete params['keyboard'].content.nextId;
232
+ }
208
233
  return params;
209
234
  };
210
235
  const buildArkParams = (val) => {
@@ -266,6 +291,9 @@ const sendOpenApiMessage = async (content, val, baseParams, uploadMedia, sendMes
266
291
  const images = filterImages(val);
267
292
  if (images.length > 0) {
268
293
  const url = await resolveRichMediaUrl(images, uploadMedia);
294
+ if (!url) {
295
+ return [createResult(ResultCode.Fail, '图片上传失败', null)];
296
+ }
269
297
  const res = await sendMessage({
270
298
  content,
271
299
  media: { file_info: url },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/qq-bot",
3
- "version": "2.1.0-alpha.26",
3
+ "version": "2.1.0-alpha.28",
4
4
  "description": "阿柠檬qq-bot平台连接",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",