utilitas 2001.1.82 → 2001.1.84

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/bot.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { insensitiveCompare, log as _log, need, trim } from './utilitas.mjs';
1
+ import { insensitiveCompare, log as _log, need } from './utilitas.mjs';
2
2
  import { isPrimary, on, report } from './callosum.mjs';
3
3
 
4
4
  const _NEED = ['telegraf'];
@@ -9,54 +9,16 @@ const sendMd = (cId, cnt, opt) => send(cId, cnt, { parse_mode, ...opt || {} });
9
9
 
10
10
  const [ // https://limits.tginfo.me/en
11
11
  BOT_SEND, provider, signals, MESSAGE_LENGTH_LIMIT, EMOJI_THINKING,
12
- PARSE_MODE_MD, PARSE_MODE_MD_V2, BOT
12
+ PARSE_MODE_MD, PARSE_MODE_MD_V2, BOT, EMOJI_WARNING,
13
13
  ] = [
14
14
  'BOT_SEND', 'TELEGRAM', ['SIGINT', 'SIGTERM'], parseInt(4096 * 0.93), // ~= 3800
15
- '💬', 'Markdown', 'MarkdownV2', '🤖',
15
+ '💬', 'Markdown', 'MarkdownV2', '🤖', '⚠️',
16
16
  ];
17
17
 
18
18
  const parse_mode = PARSE_MODE_MD;
19
19
 
20
20
  let bot;
21
21
 
22
- const paging = (message, options) => {
23
- let [pages, page, size, codeMark] =
24
- [[], [], ~~options?.size || MESSAGE_LENGTH_LIMIT, ''];
25
- const submit = () => {
26
- const content = trim(lines(page));
27
- content && pages.push(content + (codeMark ? '\n```' : ''));
28
- page.length = 0;
29
- if (codeMark) {
30
- message = codeMark + '\n' + message;
31
- codeMark = '';
32
- }
33
- };
34
- while ((message || '').length) {
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
41
- continue;
42
- } // cut as much as possible vs cut line by line
43
- const cut = cat ? (size - cur - cat.length) : (n + 1);
44
- const line = message.substring(0, cut).trimEnd() + cat;
45
- page.push(line);
46
- /^```.{0,20}$/.test(line) && (codeMark = codeMark ? '' : line);
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
- }
52
- }
53
- submit();
54
- return pages.map((p, i) => (
55
- pages.length > 1 && !options?.noPageNum
56
- ? `📃 PAGE ${i + 1} / ${pages.length}:\n\n` : ''
57
- ) + p);
58
- };
59
-
60
22
  const send = async (chatId, content, options) => {
61
23
  try {
62
24
  return (await init()).telegram.sendMessage(chatId, content, options);
@@ -99,13 +61,13 @@ export {
99
61
  _NEED,
100
62
  BOT,
101
63
  EMOJI_THINKING,
64
+ EMOJI_WARNING,
102
65
  MESSAGE_LENGTH_LIMIT,
103
66
  PARSE_MODE_MD_V2,
104
67
  PARSE_MODE_MD,
105
68
  end,
106
69
  init,
107
70
  lines,
108
- paging,
109
71
  parse_mode,
110
72
  send,
111
73
  sendMd,
package/lib/manifest.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const manifest = {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "2001.1.82",
4
+ "version": "2001.1.84",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "2001.1.82",
4
+ "version": "2001.1.84",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",