utilitas 2001.1.74 → 2001.1.75
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 +1 -1
- package/dist/utilitas.lite.mjs +1 -1
- package/dist/utilitas.lite.mjs.map +1 -1
- package/lib/bot.mjs +16 -14
- package/lib/manifest.mjs +1 -1
- package/package.json +1 -1
package/lib/bot.mjs
CHANGED
|
@@ -11,7 +11,7 @@ const [ // https://limits.tginfo.me/en
|
|
|
11
11
|
BOT_SEND, provider, signals, MESSAGE_LENGTH_LIMIT, EMOJI_THINKING,
|
|
12
12
|
PARSE_MODE_MD, BOT
|
|
13
13
|
] = [
|
|
14
|
-
'BOT_SEND', 'TELEGRAM', ['SIGINT', 'SIGTERM'], parseInt(4096 * 0.
|
|
14
|
+
'BOT_SEND', 'TELEGRAM', ['SIGINT', 'SIGTERM'], parseInt(4096 * 0.93), // ~= 3800
|
|
15
15
|
'💬', 'Markdown', '🤖',
|
|
16
16
|
];
|
|
17
17
|
|
|
@@ -20,9 +20,8 @@ const parse_mode = PARSE_MODE_MD;
|
|
|
20
20
|
let bot;
|
|
21
21
|
|
|
22
22
|
const paging = (message, options) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const [pages, page, size] = [[], [], ~~options?.size || MESSAGE_LENGTH_LIMIT];
|
|
23
|
+
let [pages, page, size, codeMark] =
|
|
24
|
+
[[], [], ~~options?.size || MESSAGE_LENGTH_LIMIT, ''];
|
|
26
25
|
const submit = () => {
|
|
27
26
|
const content = trim(lines(page));
|
|
28
27
|
content && pages.push(content + (codeMark ? '\n```' : ''));
|
|
@@ -32,21 +31,24 @@ const paging = (message, options) => {
|
|
|
32
31
|
codeMark = '';
|
|
33
32
|
}
|
|
34
33
|
};
|
|
35
|
-
let codeMark = '';
|
|
36
34
|
while ((message || '').length) {
|
|
37
|
-
let n = message.indexOf('\n');
|
|
38
|
-
n === -1 && (n = message.length);
|
|
39
|
-
const cat = n > size ? '...' : '';
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
let n = message.indexOf('\n'); // check next line break
|
|
36
|
+
n === -1 && (n = message.length); // a single line remaining
|
|
37
|
+
const cat = n > size ? '...' : ''; // the row length exceeds the limit
|
|
38
|
+
const cur = lines(page).length; // get current page length
|
|
39
|
+
if (!cat && cur + n > size) {
|
|
40
|
+
submit(); // line length ok, but the current + next line will exceed
|
|
42
41
|
continue;
|
|
43
|
-
}
|
|
44
|
-
const cut = cat ? (size - cat.length) : (n + 1);
|
|
42
|
+
} // cut as much as possible vs cut line by line
|
|
43
|
+
const cut = cat ? (size - cur - cat.length) : (n + 1);
|
|
45
44
|
const line = message.substring(0, cut).trimEnd() + cat;
|
|
46
45
|
page.push(line);
|
|
47
46
|
/^```.{0,20}$/.test(line) && (codeMark = codeMark ? '' : line);
|
|
48
|
-
message = message.slice(cut);
|
|
49
|
-
|
|
47
|
+
message = message.slice(cut); // cut message
|
|
48
|
+
if (cat) {
|
|
49
|
+
message = cat + message.trimStart(); // tidy up
|
|
50
|
+
submit(); // submit if line break is needed
|
|
51
|
+
}
|
|
50
52
|
}
|
|
51
53
|
submit();
|
|
52
54
|
return pages.map((p, i) => (
|
package/lib/manifest.mjs
CHANGED