halbot 1995.1.4 → 1995.1.5

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "halbot",
3
3
  "description": "Just another AI powered Telegram bot, which is simple design, easy to use, extendable and fun.",
4
- "version": "1995.1.4",
4
+ "version": "1995.1.5",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/halbot",
7
7
  "type": "module",
@@ -32,7 +32,7 @@
32
32
  "@ffmpeg-installer/ffmpeg": "^1.1.0",
33
33
  "@ffprobe-installer/ffprobe": "^2.1.2",
34
34
  "@google-cloud/discoveryengine": "^2.5.2",
35
- "@google/genai": "^1.33.0",
35
+ "@google/genai": "^1.34.0",
36
36
  "@mozilla/readability": "^0.6.0",
37
37
  "fluent-ffmpeg": "^2.1.3",
38
38
  "google-gax": "^5.0.6",
@@ -40,14 +40,15 @@
40
40
  "jsdom": "^27.3.0",
41
41
  "lorem-ipsum": "^2.0.8",
42
42
  "mime": "^4.1.0",
43
- "mysql2": "^3.15.3",
43
+ "mysql2": "^3.16.0",
44
44
  "office-text-extractor": "^3.0.3",
45
- "openai": "^6.10.0",
45
+ "openai": "^6.15.0",
46
46
  "pg": "^8.16.3",
47
47
  "pgvector": "^0.2.1",
48
48
  "telegraf": "^4.16.3",
49
+ "tellegram": "^1.1.2",
49
50
  "tesseract.js": "^7.0.0",
50
- "utilitas": "^2001.1.77",
51
+ "utilitas": "^2001.1.84",
51
52
  "youtube-transcript": "^1.2.1"
52
53
  }
53
54
  }
@@ -1,12 +1,12 @@
1
1
  import { alan, bot, hal, uoid, utilitas } from '../index.mjs';
2
+ import { paginate } from 'tellegram';
2
3
 
3
4
  const _name = 'Broca';
4
5
  const [PRIVATE_LIMIT, GROUP_LIMIT] = [60 / 60, 60 / 20].map(x => x * 1000);
5
6
  const log = (c, o) => utilitas.log(c, _name, { time: 1, ...o || {} });
6
7
  const getKey = s => s?.toLowerCase?.()?.startsWith?.('http') ? 'url' : 'source';
7
8
  const isMarkdownError = e => e?.description?.includes?.("can't parse entities");
8
-
9
- const [CALLBACK_LIMIT, parse_mode] = [30, bot.parse_mode];
9
+ const [CALLBACK_LIMIT, parse_mode] = [30, bot.PARSE_MODE_MD_V2];
10
10
 
11
11
  const KNOWN_UPDATE_TYPES = [
12
12
  'callback_query', 'channel_post', 'edited_message', 'message',
@@ -54,8 +54,8 @@ const resp = async (ctx, text, md, extra) => {
54
54
  resp = await (extra?.reply_parameters?.message_id
55
55
  ? ctx.replyWithMarkdown(text, { parse_mode, ...extra })
56
56
  : ctx.sendMessage(text, { parse_mode, ...extra }));
57
- } catch (err) { // utilitas.throwError('Error sending message.');
58
- isMarkdownError(err) || log(err);
57
+ } catch (err) {
58
+ log(err);
59
59
  await ctx.timeout();
60
60
  }
61
61
  }
@@ -81,8 +81,8 @@ const edit = async (ctx, lastMsgId, text, md, extra) => {
81
81
  resp = await ctx.telegram.editMessageText(
82
82
  ctx._.chatId, lastMsgId, '', text, { parse_mode, ...extra }
83
83
  );
84
- } catch (err) { // utilitas.throwError('Error editing message.');
85
- isMarkdownError(err) || log(err);
84
+ } catch (err) {
85
+ log(err);
86
86
  await ctx.timeout();
87
87
  }
88
88
  }
@@ -125,7 +125,7 @@ const ctxExt = ctx => {
125
125
  ctx.edit = async (lastMsgId, text, md, extra) =>
126
126
  await edit(ctx, lastMsgId, text, md, extra);
127
127
  ctx.ok = async (message, options) => {
128
- let pages = bot.paging(message, options);
128
+ let pages = paginate(message, options);
129
129
  const extra = ctx.getExtra(options);
130
130
  const [pageIds, pageMap] = [[], {}];
131
131
  options?.pageBreak || ctx._.done.filter(x => x).map(x => {
@@ -135,22 +135,13 @@ const ctxExt = ctx => {
135
135
  for (let i in pages) {
136
136
  const lastPage = ~~i === pages.length - 1;
137
137
  const shouldExtra = options?.lastMessageId || lastPage;
138
- if (options?.processing && !options?.lastMessageId
139
- && pageMap[pageIds[~~i]]?.text === pages[i]) { continue; }
140
- if (options?.processing && !pageIds[~~i]) { // progress: new page, reply text
141
- await ctx.resp(pages[i], false, extra);
142
- } else if (options?.processing) { // progress: ongoing, edit text
143
- await ctx.edit(
144
- pageIds[~~i], pages[i], false, shouldExtra ? extra : {}
145
- );
146
- } else if (options?.lastMessageId || pageIds[~~i]) { // progress: final, edit markdown
147
- await ctx.edit(
148
- options?.lastMessageId || pageIds[~~i],
149
- pages[i], true, shouldExtra ? extra : {}
150
- );
151
- } else { // never progress, reply markdown
152
- await ctx.resp(pages[i], true, extra);
138
+ const _extra = shouldExtra ? extra : {};
139
+ const lastMsgId = ~~(options?.lastMessageId || pageIds[~~i]);
140
+ if (lastMsgId && pageMap[lastMsgId]?.text === pages[i]) {
141
+ continue;
153
142
  }
143
+ await (lastMsgId ? ctx.edit(lastMsgId, pages[i], options?.md, _extra) // ongoing, edit
144
+ : ctx.resp(pages[i], options?.md, _extra)); // new page, reply
154
145
  await ctx.timeout();
155
146
  }
156
147
  return ctx._.done;
@@ -256,6 +247,7 @@ const action = async (ctx, next) => {
256
247
  await ctx.shouldReply(errStr);
257
248
  };
258
249
 
259
- export const { name, run, priority, func } = {
260
- name: _name, run: true, priority: 10, func: action,
250
+ export const { _NEED, name, run, priority, func } = {
251
+ _NEED: ['telegramifyMarkdown'], name: _name,
252
+ run: true, priority: 10, func: action,
261
253
  };