halbot 1995.1.7 → 1995.1.8
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 +20 -16
- package/pipeline/030_echo.mjs +5 -5
- package/pipeline/040_help.mjs +1 -1
- package/pipeline/080_history.mjs +16 -9
- package/pipeline/090_ai.mjs +1 -1
- package/pipeline/100_chat.mjs +1 -1
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.8",
|
|
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,22 +44,23 @@ 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
51
|
let resp;
|
|
52
|
-
if (
|
|
52
|
+
if (!extra?.noMd) {
|
|
53
|
+
const txt = extra?.parsed ? text : convert(text);
|
|
53
54
|
resp = await utilitas.ignoreErrFunc(async (
|
|
54
55
|
) => await (extra?.reply_parameters?.message_id
|
|
55
|
-
? ctx.
|
|
56
|
-
: ctx.
|
|
56
|
+
? ctx.sendMessage(txt, { parse_mode, ...extra })
|
|
57
|
+
: ctx.replyWithMarkdown(txt, { parse_mode, ...extra })), hal.logOptions);
|
|
57
58
|
}
|
|
58
59
|
if (!resp) {
|
|
59
60
|
await ctx.timeout();
|
|
60
61
|
resp = await utilitas.ignoreErrFunc(
|
|
61
62
|
async () => await (extra?.reply_parameters?.message_id
|
|
62
|
-
? ctx.
|
|
63
|
+
? ctx.sendMessage(text, extra) : ctx.reply(text, extra)
|
|
63
64
|
), hal.logOptions
|
|
64
65
|
);
|
|
65
66
|
}
|
|
@@ -73,12 +74,13 @@ const replyWith = async (ctx, func, src, options) => ctx._.done.push(
|
|
|
73
74
|
})) : { [getKey(src)]: src }, ctx.getExtra(options))
|
|
74
75
|
);
|
|
75
76
|
|
|
76
|
-
const edit = async (ctx, lastMsgId, text,
|
|
77
|
+
const edit = async (ctx, lastMsgId, text, extra) => {
|
|
77
78
|
let resp;
|
|
78
|
-
if (
|
|
79
|
+
if (!extra?.noMd) {
|
|
80
|
+
const txt = extra?.parsed ? text : convert(text);
|
|
79
81
|
resp = await utilitas.ignoreErrFunc(async (
|
|
80
82
|
) => await ctx.telegram.editMessageText(
|
|
81
|
-
ctx._.chatId, lastMsgId, '',
|
|
83
|
+
ctx._.chatId, lastMsgId, '', txt, { parse_mode, ...extra }
|
|
82
84
|
), hal.logOptions);
|
|
83
85
|
}
|
|
84
86
|
if (!resp) {
|
|
@@ -119,12 +121,12 @@ const ctxExt = ctx => {
|
|
|
119
121
|
return str;
|
|
120
122
|
};
|
|
121
123
|
ctx.getExtra = (options) => getExtra(ctx, options);
|
|
122
|
-
ctx.resp = async (text,
|
|
123
|
-
ctx.edit = async (lastMsgId, text,
|
|
124
|
-
await edit(ctx, lastMsgId, text,
|
|
124
|
+
ctx.resp = async (text, extra) => await resp(ctx, text, extra);
|
|
125
|
+
ctx.edit = async (lastMsgId, text, extra) =>
|
|
126
|
+
await edit(ctx, lastMsgId, text, extra);
|
|
125
127
|
ctx.ok = async (message, options) => {
|
|
126
128
|
let pages = paginate(message, options);
|
|
127
|
-
const extra = ctx.getExtra(options);
|
|
129
|
+
const extra = { ...ctx.getExtra(options), parsed: true };
|
|
128
130
|
const [pageIds, pageMap] = [[], {}];
|
|
129
131
|
options?.pageBreak || ctx._.done.filter(x => x).map(x => {
|
|
130
132
|
pageMap[x?.message_id] || (pageIds.push(x?.message_id));
|
|
@@ -138,15 +140,17 @@ const ctxExt = ctx => {
|
|
|
138
140
|
if (lastMsgId && pageMap[lastMsgId]?.text === pages[i]) {
|
|
139
141
|
continue;
|
|
140
142
|
}
|
|
141
|
-
await (lastMsgId ? ctx.edit(lastMsgId, pages[i],
|
|
142
|
-
: ctx.resp(pages[i],
|
|
143
|
+
await (lastMsgId ? ctx.edit(lastMsgId, pages[i], _extra) // ongoing, edit
|
|
144
|
+
: ctx.resp(pages[i], _extra)); // new page, reply
|
|
143
145
|
await ctx.timeout();
|
|
144
146
|
}
|
|
145
147
|
return ctx._.done;
|
|
146
148
|
};
|
|
147
149
|
ctx.err = async (m, opts) => {
|
|
148
150
|
log(m);
|
|
149
|
-
return await ctx.ok(`${bot.EMOJI_WARNING} ${m?.message || m} `,
|
|
151
|
+
return await ctx.ok(`${bot.EMOJI_WARNING} ${m?.message || m} `, {
|
|
152
|
+
...opts, pageBreak: true,
|
|
153
|
+
});
|
|
150
154
|
};
|
|
151
155
|
ctx.shouldReply = async (text, options) => {
|
|
152
156
|
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,32 @@ 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
|
-
|
|
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
|
+
'___', ctx.getExtra({
|
|
76
83
|
buttons: [{
|
|
77
84
|
label: '🔍 More',
|
|
78
85
|
text: `/search@${ctx.botInfo.username} ${keywords} `
|
|
79
86
|
+ `--skip=${offset + result.length}`,
|
|
80
|
-
}]
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
}],
|
|
88
|
+
...options,
|
|
89
|
+
})) : await ctx.err('No more records.', options);
|
|
83
90
|
break;
|
|
84
91
|
default:
|
|
85
92
|
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