halbot 1989.6.35 → 1989.6.37

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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/index.mjs +31 -6
  3. package/package.json +4 -3
package/README.md CHANGED
@@ -61,6 +61,7 @@ All supported configuration fields:
61
61
  "chatGptKey": "[[ChatGPT API Key]]",
62
62
 
63
63
  // OPTIONAL, string.
64
+ // How to get your bing user token: https://github.com/Leask/halbot/issues/13
64
65
  // One of the chatGptKey or bingToken is required.
65
66
  "bingToken": "[[Bing Usertoken from cookies]]",
66
67
 
package/index.mjs CHANGED
@@ -1,11 +1,17 @@
1
- import { bot, hal, speech, utilitas } from 'utilitas';
1
+ import { bot, hal, shot, speech, utilitas } from 'utilitas';
2
+ import { parse } from 'csv-parse/sync';
2
3
 
3
4
  await utilitas.locate(utilitas.__(import.meta.url, 'package.json'));
4
5
  const skillPath = utilitas.__(import.meta.url, 'skills');
6
+ const MAX_MENU_LENGTH = 32;
7
+
8
+ const promptSource = new Set([
9
+ 'https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv',
10
+ ]);
5
11
 
6
12
  const init = async (options) => {
7
- assert(options?.telegramToken, 'Telegram Bot API Token is required.', 400);
8
- const [ai, _speech] = [{}, {}];
13
+ assert(options?.telegramToken, 'Telegram Bot API Token is required.');
14
+ const [ai, _speech, prompts] = [{}, {}, {}];
9
15
  if (options?.googleApiKey) {
10
16
  await speech.init({ apiKey: options?.googleApiKey, tts: true, stt: true });
11
17
  Object.assign(_speech, { stt: speech.stt, tts: speech.tts });
@@ -20,17 +26,36 @@ const init = async (options) => {
20
26
  provider: 'BING', clientOptions: { userToken: options.bingToken },
21
27
  });
22
28
  }
23
- assert(utilitas.countKeys(ai), 'No AI provider is configured.', 400);
24
- return await bot.init({
29
+ utilitas.ensureArray(options?.prompts).filter(x => x).map(promptSource.add);
30
+ for (let source of promptSource) {
31
+ try {
32
+ const resp = (await shot.get(source)).content;
33
+ const pmts = parse(resp, { columns: true, skip_empty_lines: true });
34
+ assert(pmts?.length, `Failed to load external prompts: ${source}.`);
35
+ pmts.filter(x => x.act && x.prompt).map(x => {
36
+ const cmd = utilitas.ensureString(x.act, { case: 'SNAKE' });
37
+ prompts[cmd.slice(0, MAX_MENU_LENGTH)]
38
+ = { description: x.act, prompt: x.prompt }
39
+ });
40
+ } catch (err) { utilitas.log(err?.message || err); }
41
+ }
42
+ assert(utilitas.countKeys(ai), 'No AI provider is configured.');
43
+ const _bot = await bot.init({
25
44
  ai, auth: options?.auth,
26
45
  botToken: options?.telegramToken,
27
46
  chatType: options?.chatType,
28
47
  homeGroup: options?.homeGroup,
29
48
  magicWord: options?.magicWord,
30
49
  private: options?.private,
31
- provider: 'telegram', speech: _speech,
50
+ prompts, provider: 'telegram',
32
51
  skillPath: options?.skillPath || skillPath,
52
+ speech: _speech,
33
53
  });
54
+ // https://limits.tginfo.me/en
55
+ await _bot.telegram.setMyCommands(Object.keys(prompts).slice(0, 100).map(
56
+ command => ({ command, description: prompts[command].description })
57
+ ));
58
+ return _bot;
34
59
  };
35
60
 
36
61
  export default init;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "halbot",
3
3
  "description": "Just another ChatGPT/Bing Telegram bob.",
4
- "version": "1989.6.35",
4
+ "version": "1989.6.37",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/halbot",
7
7
  "type": "module",
@@ -31,8 +31,9 @@
31
31
  "dependencies": {
32
32
  "@google-cloud/speech": "^5.4.0",
33
33
  "@google-cloud/text-to-speech": "^4.2.1",
34
- "@waylaidwanderer/chatgpt-api": "^1.33.0",
34
+ "@waylaidwanderer/chatgpt-api": "^1.33.1",
35
+ "csv-parse": "^5.3.6",
35
36
  "telegraf": "^4.12.2",
36
- "utilitas": "^1992.4.44"
37
+ "utilitas": "^1992.4.46"
37
38
  }
38
39
  }