halbot 1990.1.8 → 1990.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/index.mjs CHANGED
@@ -18,10 +18,8 @@ const fetchPrompts = async () => {
18
18
  const pmts = parse(resp, { columns: true, skip_empty_lines: true });
19
19
  assert(pmts?.length, `Failed to load external prompts: ${source}.`);
20
20
  pmts.filter(x => x.act && x.prompt).map(x => {
21
- const command = utilitas.ensureString(
22
- x.act, { case: 'SNAKE' }
23
- ).slice(0, bot.MAX_MENU_LENGTH);
24
- prompts[command] = { command, ...x };
21
+ const { command, description } = bot.newCommand(x.act, x.act);
22
+ prompts[command] = { ...x, command, act: description };
25
23
  });
26
24
  } catch (err) { log(err?.message || err); }
27
25
  }
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.8",
4
+ "version": "1990.1.9",
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.4"
39
+ "utilitas": "^1993.0.7"
40
40
  }
41
41
  }
package/skills/chat.mjs CHANGED
@@ -2,7 +2,7 @@ import { utilitas } from 'utilitas';
2
2
 
3
3
  const onProgress = { onProgress: true };
4
4
  const [YOU, BOT, LN2] = ['😸 You:', '🤖️ ', '\n\n'];
5
- const [joinL1, joinL2] = [a => a.join(`${LN2}---${LN2}`), a => a.join(LN2)];
5
+ const [joinL1, joinL2] = [a => a.join(LN2), a => a.join(LN2)];
6
6
  const enrich = name => name === 'Bing' ? `${name} (Sydney)` : name;
7
7
  const log = content => utilitas.log(content, import.meta.url);
8
8
 
@@ -11,10 +11,10 @@ const action = async (ctx, next) => {
11
11
  const [msgs, tts, pms, extra] = [{}, {}, [], {}];
12
12
  let [lastMsg, lastSent] = ['', 0];
13
13
  const packMsg = options => {
14
- const packed = [...ctx.overwrite ? [joinL2([YOU, ctx.overwrite])] : []];
14
+ const packed = [...ctx._text && !options?.tts ? [joinL2([YOU, ctx.text])] : []];
15
15
  const source = options?.tts ? tts : msgs;
16
16
  ctx.selectedAi.map(n => packed.push(joinL2([
17
- ...ctx.multiAi || !ctx.isDefaultAi(n) || ctx.overwrite ? [`${BOT}${enrich(n)}:`] : [],
17
+ ...ctx.multiAi || !ctx.isDefaultAi(n) || ctx._text ? [`${BOT}${enrich(n)}:`] : [],
18
18
  options?.onProgress ? (
19
19
  source[n] ? `${source[n].trim()} █` : '💬'
20
20
  ) : (source[n] || ''),
@@ -39,7 +39,8 @@ const action = async (ctx, next) => {
39
39
  ok(onProgress);
40
40
  }
41
41
  );
42
- msgs[n] = ctx.session.config?.render === false ? resp.response : resp.responseRendered;
42
+ msgs[n] = ctx.session.config?.render === false
43
+ ? resp.response : resp.responseRendered;
43
44
  tts[n] = resp.spokenText;
44
45
  extra.buttons = resp?.suggestedResponses?.map?.(label => ({
45
46
  label, text: `/bing ${label}`,
package/skills/engine.mjs CHANGED
@@ -35,22 +35,14 @@ export const { run, priority, func, help, args } = {
35
35
  'Set initial prompt to the AI engine.',
36
36
  'Select between AI engines.',
37
37
  'Tweak output rendering.',
38
- "Tips 1: Set `hello ''` to reset to default initial prompt.",
39
- "Tips 2: Set `ai ''` to use default AI engine.",
40
- 'Tips 3: Set `ai @` to use all AI engines simultaneously.',
41
- "Example 1: /set --hello 'Bonjour!'",
42
- "Example 1: /set --hello ''",
43
- 'Example 2: /set --ai ChatGPT',
44
- 'Example 3: /set --ai Bing',
45
- "Example 4: /set --ai ''",
46
- 'Example 5: /set --ai @',
47
- 'Example 6: /set --render on',
48
- 'Example 7: /set --render off',
38
+ "Tip 1: Set `hello ''` to reset to default initial prompt.",
39
+ "Tip 2: Set `ai ''` to use default AI engine.",
40
+ 'Tip 3: Set `ai @` to use all AI engines simultaneously.',
49
41
  ]),
50
42
  args: {
51
43
  hello: {
52
44
  type: 'string', short: 'h', default: 'Hello!',
53
- desc: 'Your initial prompt to the AI engine.',
45
+ desc: "Change initial prompt: /set --hello 'Bonjour!'",
54
46
  },
55
47
  ai: {
56
48
  type: 'string', short: 'a', default: '',
@@ -1,4 +1,3 @@
1
- import { bot, shot, utilitas } from 'utilitas';
2
1
 
3
2
  const action = async (ctx, next) => {
4
3
  let prompt = ctx.session.prompts?.[ctx.cmdExt?.cmd] || (
@@ -6,7 +5,7 @@ const action = async (ctx, next) => {
6
5
  );
7
6
  if (prompt) {
8
7
  ctx.clear();
9
- ctx.overwrite = ctx.text = prompt;
8
+ ctx.overwrite(prompt);
10
9
  }
11
10
  await next();
12
11
  };
@@ -27,14 +27,11 @@ export const { run, priority, func, help, cmds } = {
27
27
  priority: 20,
28
28
  func: action,
29
29
  help: bot.lines([
30
- 'Use an AI engine temporary.',
31
- 'Example 1: /chatgpt Say hello to ChatGPT!',
32
- 'Example 2: /bing Say hello to Bing!',
33
- 'Example 3: /all Say hello to all AI engines!',
30
+ 'Use an AI engine `temporary` without touching your settings.',
34
31
  ]),
35
32
  cmds: {
36
- all: 'Use all AI engines simultaneously temporary.',
37
- bing: 'Use Bing as temporary AI engine.',
38
- chatgpt: 'Use ChatGPT as temporary AI engine.',
33
+ all: 'Use all AI engines simultaneously: /all Say hello to all AIs!',
34
+ chatgpt: 'Use ChatGPT temporary: /chatgpt Say hello to ChatGPT!',
35
+ bing: 'Use Bing temporary: /bing Say hello to Bing!',
39
36
  },
40
37
  };
package/skills/prompt.mjs CHANGED
@@ -61,18 +61,13 @@ export const { run, priority, func, help, cmds } = {
61
61
  func: action,
62
62
  help: bot.lines([
63
63
  'Maintain custom prompts.',
64
- `Get prompts from ${ACP}.`,
65
- `Tips: Use /clear to end current prompted AI conversation session.`,
66
- 'Example 1: /prompts',
67
- 'Example 2: /add code > Code with me.',
68
- 'Example 3: /del code',
69
- 'Example 4: /acplist',
70
- 'Example 5: /acpdetail',
71
- 'Example 6: /clear',
64
+ 'Example 1: /add code > Code with me.',
65
+ 'Example 2: /del code',
66
+ `Get interesting prompts from ${ACP}.`,
72
67
  ]),
73
68
  cmds: {
74
- prompts: 'List custom prompts.',
75
- add: 'Add or update a custom prompt: `/add [COMMAND] > [PROMPT]`.',
69
+ prompts: 'List all custom prompts.',
70
+ add: 'Add or edit a custom prompt: `/add [COMMAND] > [PROMPT]`.',
76
71
  del: 'Delete a custom prompt: `/del [COMMAND]`.',
77
72
  acplist: `List prompts from ${ACP}.`,
78
73
  acpdetail: `Show details of ${ACP}.`,
@@ -1,38 +1,56 @@
1
- // @todo: This is a temporary solution, and will be replaced by a more elegant solution in the future.
1
+ import { bot } from 'utilitas';
2
2
 
3
- const getTranslatePrompt = (lang) => // https://github.com/yetone/bob-plugin-openai-translator/blob/main/src/main.js
3
+ // Inspired by:
4
+ // https://github.com/yetone/bob-plugin-openai-translator/blob/main/src/main.js
5
+ const getTranslatePrompt = lang =>
4
6
  'You are a translation engine that can only translate text and cannot interpret it.'
5
- + ` Translate the following text into ${lang}: `;
6
- const getPolishPrompt = () => // https://github.com/yetone/bob-plugin-openai-polisher/blob/main/src/main.js
7
- 'Revise the following text to make them more clear, concise, and coherent.'
8
- + ' Please note that you need to list the changes and briefly explain why: ';
7
+ + ` Translate all the following text I send to you to ${lang}.`;
8
+
9
+ // Inspired by:
10
+ // https://github.com/yetone/bob-plugin-openai-polisher/blob/main/src/main.js
11
+ const getPolishPrompt = () =>
12
+ 'Revise all the following text I send to you to make them more clear, concise, and coherent.'
13
+ + ' Please note that you need to list the changes and briefly explain why.';
9
14
 
10
15
  const action = async (ctx, next) => {
11
- switch (ctx.cmdExt?.cmd) {
12
- case '2en':
13
- ctx.text = ctx.text.replace(`/${ctx.cmdExt?.cmd}`, getTranslatePrompt('English'));
16
+ switch (ctx.cmd.cmd) {
17
+ case 'translate':
18
+ ctx.overwrite(getTranslatePrompt(ctx.cmd.args || 'English'));
14
19
  break;
15
- case '2zh':
16
- ctx.text = ctx.text.replace(`/${ctx.cmdExt?.cmd}`, getTranslatePrompt('Traditional Chinese'));
20
+ case 'polish':
21
+ ctx.overwrite(getPolishPrompt());
17
22
  break;
18
- case '2zht':
19
- ctx.text = ctx.text.replace(`/${ctx.cmdExt?.cmd}`, getTranslatePrompt('Traditional Chinese'));
23
+ case 'toen':
24
+ ctx.overwrite(getTranslatePrompt('English'));
20
25
  break;
21
- case '2zhs':
22
- ctx.text = ctx.text.replace(`/${ctx.cmdExt?.cmd}`, getTranslatePrompt('Simplified Chinese'));
26
+ case 'tofr':
27
+ ctx.overwrite(getTranslatePrompt('French'));
23
28
  break;
24
- case '2fr':
25
- ctx.text = ctx.text.replace(`/${ctx.cmdExt?.cmd}`, getTranslatePrompt('French'));
29
+ case 'tozht':
30
+ ctx.overwrite(getTranslatePrompt('Traditional Chinese'));
26
31
  break;
27
- case 'p':
28
- ctx.text = ctx.text.replace(`/${ctx.cmdExt?.cmd}`, getPolishPrompt());
32
+ case 'tozhs':
33
+ ctx.overwrite(getTranslatePrompt('Simplified Chinese'));
29
34
  break;
30
35
  }
31
36
  await next();
32
37
  };
33
38
 
34
- export const { run, priority, func } = {
39
+ export const { run, priority, func, cmds, help } = {
35
40
  run: true,
36
41
  priority: 50,
37
42
  func: action,
43
+ help: bot.lines([
44
+ 'Prompt the AI engine to translate or polish your text.',
45
+ 'If `TO_LANG` is not specified, English is used by default.',
46
+ 'Example: /translate français',
47
+ ]),
48
+ cmds: {
49
+ translate: 'Translate your text to any language: /translate `TO_LANG`',
50
+ polish: 'Polish your text.',
51
+ toen: 'Translate your text to English.',
52
+ tofr: 'Translate your text to French.',
53
+ tozht: 'Translate your text to Traditional Chinese.',
54
+ tozhs: 'Translate your text to Simplified Chinese.',
55
+ },
38
56
  };