halbot 1990.1.14 → 1990.1.15
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 +2 -2
- package/skills/chat.mjs +15 -11
- package/skills/execute.mjs +3 -3
- package/skills/wording.mjs +18 -24
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "halbot",
|
|
3
3
|
"description": "Just another ChatGPT/Bing Chat Telegram bob, which is simple design, easy to use, extendable and fun.",
|
|
4
|
-
"version": "1990.1.
|
|
4
|
+
"version": "1990.1.15",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/Leask/halbot",
|
|
7
7
|
"type": "module",
|
|
@@ -36,6 +36,6 @@
|
|
|
36
36
|
"ioredis": "^5.3.1",
|
|
37
37
|
"mysql2": "^3.2.0",
|
|
38
38
|
"telegraf": "^4.12.2",
|
|
39
|
-
"utilitas": "^1993.0.
|
|
39
|
+
"utilitas": "^1993.0.12"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/skills/chat.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { utilitas } from 'utilitas';
|
|
2
2
|
|
|
3
|
+
// @todo: consider using md v2, see https://core.telegram.org/bots/api#markdownv2-style.
|
|
4
|
+
|
|
3
5
|
const onProgress = { onProgress: true };
|
|
4
6
|
const [YOU, BOT, LN2] = ['😸 You:', '🤖️ ', '\n\n'];
|
|
5
7
|
const [joinL1, joinL2] = [a => a.join(LN2), a => a.join(LN2)];
|
|
@@ -8,7 +10,7 @@ const log = content => utilitas.log(content, import.meta.url);
|
|
|
8
10
|
|
|
9
11
|
const action = async (ctx, next) => {
|
|
10
12
|
if (!ctx.text) { return await next(); }
|
|
11
|
-
const [msgs, tts, pms, extra] = [{}, {}, [], {}];
|
|
13
|
+
const [msgs, ctxs, tts, pms, extra] = [{}, {}, {}, [], {}];
|
|
12
14
|
let [lastMsg, lastSent] = ['', 0];
|
|
13
15
|
const packMsg = options => {
|
|
14
16
|
const packed = [...ctx._text && !options?.tts ? [joinL2([YOU, ctx.text])] : []];
|
|
@@ -20,9 +22,10 @@ const action = async (ctx, next) => {
|
|
|
20
22
|
) : (source[n] || '');
|
|
21
23
|
pure.push(content);
|
|
22
24
|
packed.push(joinL2([
|
|
23
|
-
...ctx.multiAi || !ctx.isDefaultAi(n) || ctx._text
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
...ctx.multiAi || !ctx.isDefaultAi(n) || ctx._text || ctxs[n]?.cmd ? [
|
|
26
|
+
`${BOT}${enrich(n)}${ctxs[n]?.cmd && ` > \`${ctxs[n].cmd}\` (exit by /clear)` || ''}:`
|
|
27
|
+
] : [], content,
|
|
28
|
+
]));
|
|
26
29
|
});
|
|
27
30
|
return options?.tts && !pure.join('').trim().length ? '' : joinL1(packed);
|
|
28
31
|
};
|
|
@@ -38,15 +41,16 @@ const action = async (ctx, next) => {
|
|
|
38
41
|
for (let n of ctx.selectedAi) {
|
|
39
42
|
pms.push((async () => {
|
|
40
43
|
try {
|
|
41
|
-
const resp = await ctx._.ai[n].send(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
);
|
|
44
|
+
const resp = await ctx._.ai[n].send(ctx.text, {
|
|
45
|
+
session: ctx.chatId, context: ctx.context
|
|
46
|
+
}, token => {
|
|
47
|
+
msgs[n] = `${(msgs[n] || '')}${token}`;
|
|
48
|
+
ok(onProgress);
|
|
49
|
+
});
|
|
50
|
+
ctxs[n] = resp.context;
|
|
47
51
|
msgs[n] = ctx.session.config?.render === false
|
|
48
52
|
? resp.response : resp.responseRendered;
|
|
49
|
-
tts[n] = resp.spokenText;
|
|
53
|
+
tts[n] = msgs[n].split('\n').some(x => /^```/.test(x)) ? '' : resp.spokenText;
|
|
50
54
|
extra.buttons = resp?.suggestedResponses?.map?.(label => ({
|
|
51
55
|
label, text: `/bing ${label}`,
|
|
52
56
|
}));
|
package/skills/execute.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
const action = async (ctx, next) => {
|
|
3
|
-
|
|
4
|
-
ctx._.prompts[ctx.cmdExt?.cmd]
|
|
5
|
-
);
|
|
3
|
+
const prompt = ctx.session.prompts?.[ctx.cmdExt?.cmd]
|
|
4
|
+
|| ctx._.prompts?.[ctx.cmdExt?.cmd]?.prompt;
|
|
6
5
|
if (prompt) {
|
|
7
6
|
ctx.clear();
|
|
7
|
+
ctx.context = { cmd: ctx.cmdExt.cmd, prompt };
|
|
8
8
|
ctx.overwrite(prompt);
|
|
9
9
|
}
|
|
10
10
|
await next();
|
package/skills/wording.mjs
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { bot, utilitas } from 'utilitas';
|
|
2
2
|
|
|
3
|
+
const execPrompt = (ctx, arrLines) => ctx.overwrite((ctx.context = {
|
|
4
|
+
cmd: ctx.cmd.cmd, prompt: bot.lines(arrLines),
|
|
5
|
+
}).prompt);
|
|
6
|
+
|
|
3
7
|
// Inspired by:
|
|
4
8
|
// https://github.com/yetone/bob-plugin-openai-translator/blob/main/src/main.js
|
|
5
|
-
const
|
|
6
|
-
'You are a translation engine that can only translate text and cannot interpret it.'
|
|
7
|
-
|
|
9
|
+
const promptTranslate = (ctx, lang) => execPrompt(ctx, [
|
|
10
|
+
'You are a translation engine that can only translate text and cannot interpret it.',
|
|
11
|
+
`Translate all the following text I send to you to ${lang}.`
|
|
12
|
+
]);
|
|
8
13
|
|
|
9
14
|
// Inspired by:
|
|
10
15
|
// https://github.com/yetone/bob-plugin-openai-polisher/blob/main/src/main.js
|
|
11
|
-
const
|
|
12
|
-
'Revise all the following text I send to you to make them more clear, concise, and coherent.'
|
|
13
|
-
|
|
16
|
+
const promptPolish = ctx => execPrompt(ctx, [
|
|
17
|
+
'Revise all the following text I send to you to make them more clear, concise, and coherent.',
|
|
18
|
+
'Please note that you need to list the changes and briefly explain why.',
|
|
19
|
+
]);
|
|
14
20
|
|
|
15
21
|
const action = async (ctx, next) => {
|
|
16
22
|
switch (ctx.cmd.cmd) {
|
|
@@ -31,24 +37,12 @@ const action = async (ctx, next) => {
|
|
|
31
37
|
await utilitas.timeout(1000);
|
|
32
38
|
await ctx.hello();
|
|
33
39
|
break;
|
|
34
|
-
case 'translate':
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
case '
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
case 'toen':
|
|
41
|
-
ctx.overwrite(getTranslatePrompt('English'));
|
|
42
|
-
break;
|
|
43
|
-
case 'tofr':
|
|
44
|
-
ctx.overwrite(getTranslatePrompt('French'));
|
|
45
|
-
break;
|
|
46
|
-
case 'tozht':
|
|
47
|
-
ctx.overwrite(getTranslatePrompt('Traditional Chinese'));
|
|
48
|
-
break;
|
|
49
|
-
case 'tozhs':
|
|
50
|
-
ctx.overwrite(getTranslatePrompt('Simplified Chinese'));
|
|
51
|
-
break;
|
|
40
|
+
case 'translate': promptTranslate(ctx, ctx.cmd.args || ctx.session.config?.lang || ctx._.lang); break;
|
|
41
|
+
case 'polish': promptPolish(ctx); break;
|
|
42
|
+
case 'toen': promptTranslate(ctx, 'English'); break;
|
|
43
|
+
case 'tofr': promptTranslate(ctx, 'French'); break;
|
|
44
|
+
case 'tozht': promptTranslate(ctx, 'Traditional Chinese'); break;
|
|
45
|
+
case 'tozhs': promptTranslate(ctx, 'Simplified Chinese'); break;
|
|
52
46
|
}
|
|
53
47
|
await next();
|
|
54
48
|
};
|