@alemonjs/qq-bot 2.1.0-alpha.27 → 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.
- package/lib/sends.js +32 -7
- 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
|
|
6
|
-
|
|
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:
|
|
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']
|
|
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']
|
|
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) => {
|