halbot 1990.1.29 → 1990.1.30

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
@@ -30,7 +30,7 @@ const fetchPrompts = async () => {
30
30
  const init = async (options) => {
31
31
  assert(options?.telegramToken, 'Telegram Bot API Token is required.');
32
32
  const [pkg, ai, _speech] = [await utilitas.which(), {}, {}];
33
- const info = bot.lines([`[🤖️ ${pkg.title}](${pkg.homepage})`, pkg.description]);
33
+ const info = bot.lines([`[${bot.EMOJI_BOT} ${pkg.title}](${pkg.homepage})`, pkg.description]);
34
34
  if (options?.googleApiKey) {
35
35
  await speech.init({ apiKey: options?.googleApiKey, tts: true, stt: true });
36
36
  Object.assign(_speech, { stt: speech.stt, tts: speech.tts });
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.29",
4
+ "version": "1990.1.30",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/halbot",
7
7
  "type": "module",
@@ -38,7 +38,7 @@
38
38
  "jsdom": "^21.1.1",
39
39
  "mysql2": "^3.2.0",
40
40
  "telegraf": "^4.12.2",
41
- "utilitas": "^1993.3.13",
41
+ "utilitas": "^1993.3.20",
42
42
  "youtube-transcript": "^1.0.5"
43
43
  }
44
44
  }
package/skills/chat.mjs CHANGED
@@ -1,12 +1,10 @@
1
- import { utilitas } from 'utilitas';
2
- import { countKeys } from 'utilitas/lib/utilitas.mjs';
1
+ import { bot, utilitas } from 'utilitas';
3
2
 
4
3
  const onProgress = { onProgress: true };
5
- const [BOT, LN2] = ['🤖️ ', '\n\n'];
4
+ const [BOT, LN2] = [`${bot.EMOJI_BOT} `, '\n\n'];
6
5
  const [joinL1, joinL2] = [a => a.join(LN2), a => a.join(LN2)];
7
6
  const enrich = name => name === 'Bing' ? `${name} (Sydney)` : name;
8
7
  const log = content => utilitas.log(content, import.meta.url);
9
- const countTokens = text => text.split(/[^a-z0-9]/i).length;
10
8
 
11
9
  const action = async (ctx, next) => {
12
10
  if (!ctx.text) { return await next(); }
@@ -14,8 +12,8 @@ const action = async (ctx, next) => {
14
12
  = [`${ctx.avatar} You:`, {}, {}, {}, [], {}];
15
13
  let [lastMsg, lastSent] = ['', 0];
16
14
  const packMsg = options => {
17
- const addition = !options?.tts && (ctx._text || ctx.action) ? (ctx.text || ctx.action) : '';
18
- const packed = [...addition ? [joinL2([YOU, addition])] : []];
15
+ const said = !options?.tts && ctx.action ? ctx.action : '';
16
+ const packed = [...said ? [joinL2([YOU, said])] : []];
19
17
  const source = options?.tts ? tts : msgs;
20
18
  const pure = [];
21
19
  ctx.selectedAi.map(n => {
@@ -24,7 +22,7 @@ const action = async (ctx, next) => {
24
22
  ) : (source[n] || '');
25
23
  pure.push(content);
26
24
  packed.push(joinL2([
27
- ...ctx.multiAi || !ctx.isDefaultAi(n) || addition || ctxs[n]?.cmd ? [
25
+ ...ctx.multiAi || !ctx.isDefaultAi(n) || said || ctxs[n]?.cmd ? [
28
26
  `${BOT}${enrich(n)}${ctxs[n]?.cmd && ` > \`${ctxs[n].cmd}\` (exit by /clear)` || ''}:`
29
27
  ] : [], content,
30
28
  ]));
@@ -40,20 +38,10 @@ const action = async (ctx, next) => {
40
38
  return await ctx.ok(curMsg, { md: true, ...options || {}, ...extra });
41
39
  };
42
40
  await ok(onProgress);
43
- // https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them
44
- const additionInfo = countKeys(ctx.urls) ? Object.keys(ctx.urls).map(
45
- u => ctx.urls[u]
46
- ).join('\n').split(' ') : [];
47
- while (countTokens(ctx.text) < 2250 && additionInfo.length) {
48
- ctx.text += ` ${additionInfo.shift()}`;
49
- }
50
- additionInfo.filter(x => x).length && (ctx.text += '...');
51
41
  for (let n of ctx.selectedAi) {
52
42
  pms.push((async () => {
53
43
  try {
54
- const resp = await ctx._.ai[n].send(ctx.text, {
55
- session: ctx.chatId, context: ctx.context
56
- }, token => {
44
+ const resp = await ctx._.ai[n].send(ctx.text, ctx.carry, token => {
57
45
  msgs[n] = `${(msgs[n] || '')}${token}`;
58
46
  ok(onProgress);
59
47
  });
@@ -80,6 +68,6 @@ const action = async (ctx, next) => {
80
68
 
81
69
  export const { run, priority, func } = {
82
70
  run: true,
83
- priority: 80,
71
+ priority: 70,
84
72
  func: action,
85
73
  };
@@ -1,11 +1,11 @@
1
1
 
2
2
  const action = async (ctx, next) => {
3
- const prompt = ctx.session.prompts?.[ctx.cmdExt?.cmd]
4
- || ctx._.prompts?.[ctx.cmdExt?.cmd]?.prompt;
3
+ const cmd = ctx.cmd?.cmd;
4
+ const prompt = ctx.session.prompts?.[cmd] || ctx._.prompts?.[cmd]?.prompt;
5
5
  if (prompt) {
6
6
  ctx.clear();
7
- ctx.context = { cmd: ctx.cmdExt.cmd, prompt };
8
- ctx.overwrite(prompt);
7
+ ctx.context = { cmd, prompt };
8
+ ctx.collect(prompt);
9
9
  }
10
10
  await next();
11
11
  };
@@ -0,0 +1,41 @@
1
+ import { bot, utilitas } from 'utilitas';
2
+
3
+ // https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them
4
+ const countTokens = text => text.split(/[^a-z0-9]/i).length;
5
+
6
+ const action = async (ctx, next) => {
7
+ // avatar
8
+ if (ctx.action) {
9
+ ctx.avatar = '⚙️';
10
+ } else if (ctx.msg?.voice) {
11
+ ctx.avatar = bot.EMOJI_SPEECH; ctx.action = utilitas.trim(ctx.text);
12
+ } else if (ctx.msg?.data) {
13
+ ctx.avatar = '🔘'; ctx.action = utilitas.trim(ctx.text);
14
+ } else if (ctx.msg?.poll) {
15
+ ctx.avatar = '📊';
16
+ } else if (ctx.cmd?.cmd) {
17
+ ctx.avatar = '🚀'; ctx.action = utilitas.trim(ctx.text);
18
+ } else {
19
+ ctx.avatar = '😸';
20
+ }
21
+ // prompt
22
+ console.log(ctx.collected);
23
+ const additionInfo = ctx.collected.length ? ctx.collected.map(
24
+ x => x.content
25
+ ).join('\n').split(' ') : [];
26
+ ctx.text += '\n\n';
27
+ while (countTokens(ctx.text) < 2250 && additionInfo.length) {
28
+ ctx.text += ` ${additionInfo.shift()}`;
29
+ }
30
+ ctx.text = utilitas.trim(ctx.text);
31
+ additionInfo.filter(x => x).length && (ctx.text += '...');
32
+ // next
33
+ ctx.carry = { session: ctx.chatId, context: ctx.context };
34
+ await next();
35
+ };
36
+
37
+ export const { run, priority, func } = {
38
+ run: true,
39
+ priority: 60,
40
+ func: action,
41
+ };
@@ -1,6 +1,6 @@
1
1
  import { bot } from 'utilitas';
2
2
 
3
- const execPrompt = (ctx, arrLines) => ctx.overwrite((ctx.context = {
3
+ const execPrompt = (ctx, arrLines) => ctx.collect((ctx.context = {
4
4
  cmd: ctx.cmd.cmd, prompt: bot.lines(arrLines),
5
5
  }).prompt);
6
6
 
package/skills/avatar.mjs DELETED
@@ -1,20 +0,0 @@
1
- const action = async (ctx, next) => {
2
- if (ctx.message?.voice?.mime_type === 'audio/ogg') {
3
- ctx.avatar = '🗣️';
4
- } else if (ctx.update?.[ctx.type]?.data) {
5
- ctx.avatar = '🔘';
6
- } else if (ctx.update?.message?.poll) {
7
- ctx.avatar = '📊';
8
- } else if (ctx?.cmd?.cmd || ctx?.cmdExt?.cmd) {
9
- ctx.avatar = '🚀';
10
- } else {
11
- ctx.avatar = '😸';
12
- }
13
- await next();
14
- };
15
-
16
- export const { run, priority, func } = {
17
- run: true,
18
- priority: 70,
19
- func: action,
20
- };
package/skills/poll.mjs DELETED
@@ -1,33 +0,0 @@
1
- import { bot } from 'utilitas';
2
-
3
- const action = async (ctx, next) => {
4
- if (!ctx.update?.message?.poll) { return next(); }
5
- ctx.text = bot.lines([
6
- 'Please help me select the best option in this poll.',
7
- 'Try your best to choose between these options.',
8
- 'If you know the answer, please select the best one and justify it.',
9
- 'If you do not have enough info to pick one, explain why.',
10
- 'If you can choose, put option id in the box brackets like [1].',
11
- '',
12
- 'Question:',
13
- ctx.update.message.poll.question,
14
- '',
15
- 'Options:',
16
- bot.oList(ctx.update.message.poll.options.map(x => x.text)),
17
- ]);
18
- await next();
19
- // let id;
20
- // for (let key in ctx.responses) {
21
- // for (let line of ctx.responses[key].split('\n')) {
22
- // id = ~~line.match(/\[\d+\]/)?.[0]?.replace(/^\[(.*)\]$/i, '$1');
23
- // if (id) { break; }
24
- // }
25
- // if (id) { break; }
26
- // }
27
- };
28
-
29
- export const { run, priority, func } = {
30
- run: true,
31
- priority: 60,
32
- func: action,
33
- };