halbot 1995.1.9 → 1995.1.10
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 +1 -1
- package/pipeline/010_broca.mjs +5 -0
- package/pipeline/020_cmd.mjs +13 -15
- package/pipeline/060_config.mjs +1 -1
- package/pipeline/100_chat.mjs +5 -6
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.10",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/Leask/halbot",
|
|
7
7
|
"type": "module",
|
package/pipeline/010_broca.mjs
CHANGED
|
@@ -141,6 +141,11 @@ const ctxExt = ctx => {
|
|
|
141
141
|
if (lastMsgId && pageMap[lastMsgId]?.raw === pages[i]) {
|
|
142
142
|
continue;
|
|
143
143
|
}
|
|
144
|
+
if (!options?.processing && !_extra?.buttons?.length
|
|
145
|
+
&& !_extra.keyboards && !lastMsgId && ctx.getKeyboard) {
|
|
146
|
+
delete _extra?.buttons;
|
|
147
|
+
_extra.keyboards = ctx.getKeyboard();
|
|
148
|
+
}
|
|
144
149
|
await (lastMsgId ? ctx.edit(lastMsgId, pages[i], _extra) // ongoing, edit
|
|
145
150
|
: ctx.resp(pages[i], _extra)); // new page, reply
|
|
146
151
|
await ctx.timeout();
|
package/pipeline/020_cmd.mjs
CHANGED
|
@@ -6,24 +6,22 @@ const log = (c, o) => utilitas.log(c, _name, { time: 1, ...o || {} });
|
|
|
6
6
|
|
|
7
7
|
// https://stackoverflow.com/questions/69924954/an-error-is-issued-when-opening-the-telebot-keyboard
|
|
8
8
|
const keyboards = [[
|
|
9
|
-
{ text: `/ai ${bot.BOT}` },
|
|
10
|
-
{ text: '/help 🛟' },
|
|
9
|
+
{ text: `/ai ${bot.BOT}` }, { text: '/help 🛟' },
|
|
11
10
|
], [
|
|
12
|
-
{ text: '/set --tts=🔊' },
|
|
13
|
-
{ text: '/set --tts=🔇' },
|
|
14
|
-
], [
|
|
15
|
-
{ text: '/set --chatty=🐵' },
|
|
16
|
-
{ text: '/set --chatty=🙊' },
|
|
11
|
+
{ text: '/set --tts=🔊' }, { text: '/set --tts=🔇' },
|
|
17
12
|
]];
|
|
18
13
|
|
|
14
|
+
const getKeyboard = ctx => ctx._.chatType === hal.GROUP ? [
|
|
15
|
+
...keyboards, [{ text: '/set --chatty=🐵' }, { text: '/set --chatty=🙊' }]
|
|
16
|
+
] : keyboards;
|
|
17
|
+
|
|
18
|
+
const ctxExt = ctx => {
|
|
19
|
+
ctx.getKeyboard = () => getKeyboard(ctx);
|
|
20
|
+
};
|
|
21
|
+
|
|
19
22
|
const action = async (ctx, next) => {
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
// @TODO: this will case keyboard showup everytime
|
|
23
|
-
// ctx.ok = async (message, options) => await _ok(message, {
|
|
24
|
-
// ...options || {},
|
|
25
|
-
// ...options?.buttons ? {} : (options?.keyboards || { keyboards }),
|
|
26
|
-
// });
|
|
23
|
+
// extend ctx
|
|
24
|
+
ctxExt(ctx);
|
|
27
25
|
// handle callback query
|
|
28
26
|
if (ctx._.type === 'callback_query') {
|
|
29
27
|
const data = utilitas.parseJson(ctx.update.callback_query.data);
|
|
@@ -64,7 +62,7 @@ const action = async (ctx, next) => {
|
|
|
64
62
|
= { args: ctx._.cmd.args, touchedAt: Date.now() };
|
|
65
63
|
}
|
|
66
64
|
// handle commands
|
|
67
|
-
switch (ctx.cmd?.cmd) {
|
|
65
|
+
switch (ctx._.cmd?.cmd) {
|
|
68
66
|
case 'clearkb':
|
|
69
67
|
return await ctx.complete({ keyboards: [] });
|
|
70
68
|
}
|
package/pipeline/060_config.mjs
CHANGED
package/pipeline/100_chat.mjs
CHANGED
|
@@ -8,11 +8,10 @@ const action = async (ctx, next) => {
|
|
|
8
8
|
let [resp, extra, lock, sResp, lastMsg, lastSent] =
|
|
9
9
|
[null, { buttons: [] }, 1000 * 3, null, null, 0];
|
|
10
10
|
const ok = async options => {
|
|
11
|
-
const curTime = Date.now();
|
|
12
11
|
if (options?.processing && (
|
|
13
|
-
|
|
12
|
+
Date.now() - lastSent < ctx._.limit || lastMsg === resp.text
|
|
14
13
|
)) { return; }
|
|
15
|
-
[lastSent, lastMsg] = [
|
|
14
|
+
[lastSent, lastMsg] = [Date.now() + lock, resp.text];
|
|
16
15
|
if (!options?.processing) {
|
|
17
16
|
(resp.annotations || []).map((x, i) => extra.buttons.push({
|
|
18
17
|
label: `${i + 1}. ${x.title}`, url: x.url,
|
|
@@ -22,7 +21,7 @@ const action = async (ctx, next) => {
|
|
|
22
21
|
...ctx._.keyboards ? { keyboards: ctx._.keyboards } : {},
|
|
23
22
|
...extra, ...options || {},
|
|
24
23
|
});
|
|
25
|
-
lastSent =
|
|
24
|
+
lastSent = Date.now();
|
|
26
25
|
return sResp;
|
|
27
26
|
};
|
|
28
27
|
resp = await alan.talk(ctx._.text, {
|
|
@@ -43,8 +42,8 @@ const action = async (ctx, next) => {
|
|
|
43
42
|
}
|
|
44
43
|
// print(resp);
|
|
45
44
|
await ctx.timeout();
|
|
46
|
-
await resp.text.trim() ? ok({ processing: false })
|
|
47
|
-
: ctx.deleteMessage(ctx._.done[0].message_id);
|
|
45
|
+
await (resp.text.trim() ? ok({ processing: false })
|
|
46
|
+
: ctx.deleteMessage(ctx._.done[0].message_id));
|
|
48
47
|
ctx._.request = resp.request;
|
|
49
48
|
ctx._.response = resp.response;
|
|
50
49
|
ctx.memorize && await ctx.memorize();
|