halbot 1995.1.7 → 1995.1.9
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/hal.mjs +1 -1
- package/package.json +1 -1
- package/pipeline/010_broca.mjs +27 -22
- package/pipeline/030_echo.mjs +5 -5
- package/pipeline/040_help.mjs +1 -1
- package/pipeline/080_history.mjs +18 -13
- package/pipeline/090_ai.mjs +1 -1
- package/pipeline/100_chat.mjs +3 -2
package/lib/hal.mjs
CHANGED
|
@@ -144,7 +144,7 @@ const parseArgs = async (args, ctx) => {
|
|
|
144
144
|
};
|
|
145
145
|
|
|
146
146
|
const packMessage = (messages) => messages.map(x => ({
|
|
147
|
-
message_id: x.message_id, score: x.score,
|
|
147
|
+
message_id: x.message_id, score: x.score, created_at: x.created_at,
|
|
148
148
|
request: x.received_text, response: x.response_text,
|
|
149
149
|
}));
|
|
150
150
|
|
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
|
+
"version": "1995.1.9",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/Leask/halbot",
|
|
7
7
|
"type": "module",
|
package/pipeline/010_broca.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { alan, bot, hal, uoid, utilitas } from '../index.mjs';
|
|
2
|
-
import { paginate } from 'tellegram';
|
|
2
|
+
import { convert, paginate } from 'tellegram';
|
|
3
3
|
|
|
4
4
|
const _name = 'Broca';
|
|
5
5
|
const [PRIVATE_LIMIT, GROUP_LIMIT] = [60 / 60, 60 / 20].map(x => x * 1000);
|
|
@@ -44,41 +44,45 @@ const getExtra = (ctx, options) => {
|
|
|
44
44
|
return resp;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
const resp = async (ctx, text,
|
|
47
|
+
const resp = async (ctx, text, extra) => {
|
|
48
48
|
// if (ctx._.type === 'inline_query') {
|
|
49
49
|
// return await ctx.answerInlineQuery([{}, {}]);
|
|
50
50
|
// }
|
|
51
|
+
extra = getExtra(ctx, extra);
|
|
51
52
|
let resp;
|
|
52
|
-
if (
|
|
53
|
+
if (!extra?.noMd) {
|
|
54
|
+
const txt = extra?.parsed ? text : convert(text);
|
|
53
55
|
resp = await utilitas.ignoreErrFunc(async (
|
|
54
56
|
) => await (extra?.reply_parameters?.message_id
|
|
55
|
-
? ctx.
|
|
56
|
-
: ctx.
|
|
57
|
+
? ctx.sendMessage(txt, { parse_mode, ...extra })
|
|
58
|
+
: ctx.replyWithMarkdown(txt, { parse_mode, ...extra })), hal.logOptions);
|
|
57
59
|
}
|
|
58
60
|
if (!resp) {
|
|
59
61
|
await ctx.timeout();
|
|
60
62
|
resp = await utilitas.ignoreErrFunc(
|
|
61
63
|
async () => await (extra?.reply_parameters?.message_id
|
|
62
|
-
? ctx.
|
|
64
|
+
? ctx.sendMessage(text, extra) : ctx.reply(text, extra)
|
|
63
65
|
), hal.logOptions
|
|
64
66
|
);
|
|
65
67
|
}
|
|
66
|
-
resp && ctx._.done.push(resp);
|
|
68
|
+
resp && ctx._.done.push({ ...resp, raw: text });
|
|
67
69
|
return resp;
|
|
68
70
|
};
|
|
69
71
|
|
|
70
72
|
const replyWith = async (ctx, func, src, options) => ctx._.done.push(
|
|
71
73
|
await ctx[func](Array.isArray(src) ? src.map(x => ({
|
|
72
74
|
type: x.type || 'photo', media: { [getKey(x.src)]: x.src },
|
|
73
|
-
})) : { [getKey(src)]: src },
|
|
75
|
+
})) : { [getKey(src)]: src }, getExtra(ctx, options))
|
|
74
76
|
);
|
|
75
77
|
|
|
76
|
-
const edit = async (ctx, lastMsgId, text,
|
|
78
|
+
const edit = async (ctx, lastMsgId, text, extra) => {
|
|
79
|
+
extra = getExtra(ctx, extra);
|
|
77
80
|
let resp;
|
|
78
|
-
if (
|
|
81
|
+
if (!extra?.noMd) {
|
|
82
|
+
const txt = extra?.parsed ? text : convert(text);
|
|
79
83
|
resp = await utilitas.ignoreErrFunc(async (
|
|
80
84
|
) => await ctx.telegram.editMessageText(
|
|
81
|
-
ctx._.chatId, lastMsgId, '',
|
|
85
|
+
ctx._.chatId, lastMsgId, '', txt, { parse_mode, ...extra }
|
|
82
86
|
), hal.logOptions);
|
|
83
87
|
}
|
|
84
88
|
if (!resp) {
|
|
@@ -88,7 +92,7 @@ const edit = async (ctx, lastMsgId, text, md, extra) => {
|
|
|
88
92
|
ctx._.chatId, lastMsgId, '', text, extra
|
|
89
93
|
), hal.logOptions);
|
|
90
94
|
}
|
|
91
|
-
resp && ctx._.done.push(resp);
|
|
95
|
+
resp && ctx._.done.push({ ...resp, raw: text });
|
|
92
96
|
return resp;
|
|
93
97
|
};
|
|
94
98
|
|
|
@@ -118,16 +122,15 @@ const ctxExt = ctx => {
|
|
|
118
122
|
ctx.collect(str, null, { refresh: true });
|
|
119
123
|
return str;
|
|
120
124
|
};
|
|
121
|
-
ctx.
|
|
122
|
-
ctx.
|
|
123
|
-
|
|
124
|
-
await edit(ctx, lastMsgId, text, md, extra);
|
|
125
|
+
ctx.resp = async (text, extra) => await resp(ctx, text, extra);
|
|
126
|
+
ctx.edit = async (lastMsgId, text, extra) =>
|
|
127
|
+
await edit(ctx, lastMsgId, text, extra);
|
|
125
128
|
ctx.ok = async (message, options) => {
|
|
126
129
|
let pages = paginate(message, options);
|
|
127
|
-
const extra =
|
|
130
|
+
const extra = { ...getExtra(ctx, options), parsed: true };
|
|
128
131
|
const [pageIds, pageMap] = [[], {}];
|
|
129
132
|
options?.pageBreak || ctx._.done.filter(x => x).map(x => {
|
|
130
|
-
pageMap[x?.message_id] ||
|
|
133
|
+
pageMap[x?.message_id] || pageIds.push(x?.message_id);
|
|
131
134
|
pageMap[x?.message_id] = x;
|
|
132
135
|
});
|
|
133
136
|
for (let i in pages) {
|
|
@@ -135,18 +138,20 @@ const ctxExt = ctx => {
|
|
|
135
138
|
const shouldExtra = options?.lastMessageId || lastPage;
|
|
136
139
|
const _extra = shouldExtra ? extra : {};
|
|
137
140
|
const lastMsgId = ~~(options?.lastMessageId || pageIds[~~i]);
|
|
138
|
-
if (lastMsgId && pageMap[lastMsgId]?.
|
|
141
|
+
if (lastMsgId && pageMap[lastMsgId]?.raw === pages[i]) {
|
|
139
142
|
continue;
|
|
140
143
|
}
|
|
141
|
-
await (lastMsgId ? ctx.edit(lastMsgId, pages[i],
|
|
142
|
-
: ctx.resp(pages[i],
|
|
144
|
+
await (lastMsgId ? ctx.edit(lastMsgId, pages[i], _extra) // ongoing, edit
|
|
145
|
+
: ctx.resp(pages[i], _extra)); // new page, reply
|
|
143
146
|
await ctx.timeout();
|
|
144
147
|
}
|
|
145
148
|
return ctx._.done;
|
|
146
149
|
};
|
|
147
150
|
ctx.err = async (m, opts) => {
|
|
148
151
|
log(m);
|
|
149
|
-
return await ctx.ok(`${bot.EMOJI_WARNING} ${m?.message || m} `,
|
|
152
|
+
return await ctx.ok(`${bot.EMOJI_WARNING} ${m?.message || m} `, {
|
|
153
|
+
...opts, pageBreak: true,
|
|
154
|
+
});
|
|
150
155
|
};
|
|
151
156
|
ctx.shouldReply = async (text, options) => {
|
|
152
157
|
const should = utilitas.insensitiveHas(hal._?.chatType, ctx._.chatType)
|
package/pipeline/030_echo.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { bot, hal, utilitas } from '../index.mjs';
|
|
|
3
3
|
let lorem;
|
|
4
4
|
|
|
5
5
|
const action = async (ctx, next) => {
|
|
6
|
-
let resp
|
|
6
|
+
let resp;
|
|
7
7
|
switch (ctx._.cmd.cmd) {
|
|
8
8
|
case 'echo':
|
|
9
9
|
const carry = { ...ctx._ };
|
|
@@ -41,17 +41,17 @@ const action = async (ctx, next) => {
|
|
|
41
41
|
await ctx.ok(ipsum(), { ...extra, processing: true });
|
|
42
42
|
}
|
|
43
43
|
await ctx.timeout();
|
|
44
|
-
await ctx.ok(ipsum(),
|
|
44
|
+
await ctx.ok(ipsum(), extra);
|
|
45
45
|
// testing incomplete markdown reply {
|
|
46
|
-
// await ctx.ok('_8964',
|
|
46
|
+
// await ctx.ok('_8964', extra);
|
|
47
47
|
// }
|
|
48
48
|
// test pagebreak {
|
|
49
49
|
// await ctx.timeout();
|
|
50
|
-
// await ctx.ok(ipsum(), {
|
|
50
|
+
// await ctx.ok(ipsum(), { pageBreak: true });
|
|
51
51
|
// }
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
-
await ctx.ok(resp
|
|
54
|
+
await ctx.ok(resp);
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
export const { _NEED, name, hidden, priority, func, help, cmds } = {
|
package/pipeline/040_help.mjs
CHANGED
|
@@ -30,7 +30,7 @@ const action = async (ctx, next) => {
|
|
|
30
30
|
}
|
|
31
31
|
_help.length && help.push(bot.lines([`*${i.toUpperCase()}*`, ..._help]));
|
|
32
32
|
}
|
|
33
|
-
await ctx.ok(lines2(help)
|
|
33
|
+
await ctx.ok(lines2(help));
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
export const { name, priority, func, help, cmds } = {
|
package/pipeline/080_history.mjs
CHANGED
|
@@ -40,15 +40,16 @@ const memorize = async (ctx) => {
|
|
|
40
40
|
const ctxExt = ctx => {
|
|
41
41
|
ctx.memorize = async () => await memorize(ctx);
|
|
42
42
|
ctx.recall = async (keyword, offset = 0, limit = hal.SEARCH_LIMIT, options = {}) =>
|
|
43
|
-
await recall(ctx._.chatId, keyword, offset, limit, options);
|
|
43
|
+
await hal.recall(ctx._.chatId, keyword, offset, limit, options);
|
|
44
44
|
// ctx.getContext = async (offset = 0, limit = hal.SEARCH_LIMIT, options = {}) =>
|
|
45
|
-
// await getContext(ctx._.chatId, offset, limit, options);
|
|
45
|
+
// await hal.getContext(ctx._.chatId, offset, limit, options);
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
const action = async (ctx, next) => {
|
|
49
49
|
ctxExt(ctx);
|
|
50
50
|
switch (ctx._.cmd?.cmd) {
|
|
51
51
|
case 'search':
|
|
52
|
+
// print(ctx.update.callback_query?.message);
|
|
52
53
|
(ctx._.type === 'callback_query')
|
|
53
54
|
&& await ctx.deleteMessage(ctx._.message.message_id);
|
|
54
55
|
const regex = '[-—]+skip=[0-9]*';
|
|
@@ -60,26 +61,30 @@ const action = async (ctx, next) => {
|
|
|
60
61
|
const result = await ctx.recall(keywords, offset);
|
|
61
62
|
for (const i in result) {
|
|
62
63
|
const content = bot.lines([
|
|
63
|
-
'```↩️', compactLimit(result[i].
|
|
64
|
+
'```↩️', compactLimit(result[i].response), '```',
|
|
64
65
|
[`${utilitas.getTimeIcon(result[i].created_at)} ${result[i].created_at.toLocaleString()}`,
|
|
65
66
|
`🏆 ${(Math.round(result[i].score * 100) / 100).toFixed(2)}`].join(' '),
|
|
66
67
|
]);
|
|
67
|
-
await ctx.resp(content,
|
|
68
|
+
await ctx.resp(content, {
|
|
68
69
|
reply_parameters: {
|
|
69
70
|
message_id: result[i].message_id,
|
|
70
71
|
}, disable_notification: ~~i > 0,
|
|
71
72
|
});
|
|
72
73
|
await ctx.timeout();
|
|
73
74
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
75
|
+
const options = {
|
|
76
|
+
reply_parameters: {
|
|
77
|
+
message_id: ctx.update.callback_query?.message?.reply_to_message?.message_id
|
|
78
|
+
|| ctx._.message.message_id,
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
result.length === hal.SEARCH_LIMIT ? await ctx.resp('___', {
|
|
82
|
+
buttons: [{
|
|
83
|
+
label: '🔍 More',
|
|
84
|
+
text: `/search@${ctx.botInfo.username} ${keywords} `
|
|
85
|
+
+ `--skip=${offset + result.length}`,
|
|
86
|
+
}], ...options,
|
|
87
|
+
}) : await ctx.err('No more records.', options);
|
|
83
88
|
break;
|
|
84
89
|
default:
|
|
85
90
|
await next();
|
package/pipeline/090_ai.mjs
CHANGED
|
@@ -17,7 +17,7 @@ const listAIs = async ctx => {
|
|
|
17
17
|
: ''}${x.label}`,
|
|
18
18
|
text: `/set --ai=${x.id}`,
|
|
19
19
|
}));
|
|
20
|
-
return await ctx.ok(message, { lastMessageId, buttons
|
|
20
|
+
return await ctx.ok(message, { lastMessageId, buttons });
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
const action = async (ctx, next) => {
|
package/pipeline/100_chat.mjs
CHANGED
|
@@ -6,7 +6,7 @@ const log = (c, o) => utilitas.log(c, _name, { time: 1, ...o || {} });
|
|
|
6
6
|
const action = async (ctx, next) => {
|
|
7
7
|
if (!ctx._.text && !ctx._.collected.length) { return await next(); }
|
|
8
8
|
let [resp, extra, lock, sResp, lastMsg, lastSent] =
|
|
9
|
-
[null, { buttons: [] }, 1000 *
|
|
9
|
+
[null, { buttons: [] }, 1000 * 3, null, null, 0];
|
|
10
10
|
const ok = async options => {
|
|
11
11
|
const curTime = Date.now();
|
|
12
12
|
if (options?.processing && (
|
|
@@ -20,7 +20,7 @@ const action = async (ctx, next) => {
|
|
|
20
20
|
}
|
|
21
21
|
sResp = await ctx.ok(resp.text, {
|
|
22
22
|
...ctx._.keyboards ? { keyboards: ctx._.keyboards } : {},
|
|
23
|
-
|
|
23
|
+
...extra, ...options || {},
|
|
24
24
|
});
|
|
25
25
|
lastSent = curTime;
|
|
26
26
|
return sResp;
|
|
@@ -42,6 +42,7 @@ const action = async (ctx, next) => {
|
|
|
42
42
|
await ctx.audio(audio.data, { caption: audio.caption });
|
|
43
43
|
}
|
|
44
44
|
// print(resp);
|
|
45
|
+
await ctx.timeout();
|
|
45
46
|
await resp.text.trim() ? ok({ processing: false })
|
|
46
47
|
: ctx.deleteMessage(ctx._.done[0].message_id);
|
|
47
48
|
ctx._.request = resp.request;
|