utilitas 1995.3.12 → 1995.3.13
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/dist/utilitas.lite.mjs +1 -1
- package/dist/utilitas.lite.mjs.map +1 -1
- package/lib/bot.mjs +33 -33
- package/lib/manifest.mjs +1 -1
- package/package.json +1 -1
package/lib/bot.mjs
CHANGED
|
@@ -231,8 +231,8 @@ const reply = async (ctx, md, text, extra) => {
|
|
|
231
231
|
try {
|
|
232
232
|
if (md) {
|
|
233
233
|
return await (extra?.reply_to_message_id
|
|
234
|
-
? ctx.replyWithMarkdown(text, extra)
|
|
235
|
-
: ctx.sendMessage(text, extra));
|
|
234
|
+
? ctx.replyWithMarkdown(text, { ...extra, parse_mode: 'Markdown' })
|
|
235
|
+
: ctx.sendMessage(text, { ...extra, parse_mode: 'Markdown' }));
|
|
236
236
|
}
|
|
237
237
|
} catch (err) {
|
|
238
238
|
assert(isMarkdownError(err), err, 500);
|
|
@@ -435,7 +435,30 @@ const subconscious = [{
|
|
|
435
435
|
await sessionSet(ctx.chatId);
|
|
436
436
|
},
|
|
437
437
|
}, {
|
|
438
|
-
run: true, priority: -8940, name: '
|
|
438
|
+
run: true, priority: -8940, name: 'commands', func: async (ctx, next) => {
|
|
439
|
+
for (let e of ctx.entities) {
|
|
440
|
+
if (e.type !== bot_command) { continue; }
|
|
441
|
+
if (!COMMAND_REGEXP.test(e.matched)) { continue; }
|
|
442
|
+
const cmd = trim(e.matched.replace(
|
|
443
|
+
COMMAND_REGEXP, '$1'
|
|
444
|
+
), { case: 'LOW' });
|
|
445
|
+
ctx.cmd = { cmd, args: e.text.substring(e.offset + e.length + 1) };
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
for (let str of [ctx.txt || '', ctx.m.caption || ''].map(trim)) {
|
|
449
|
+
if (!ctx.cmd && COMMAND_REGEXP.test(str)) {
|
|
450
|
+
ctx.cmd = { // this will faild if command includes urls
|
|
451
|
+
cmd: str.replace(COMMAND_REGEXP, '$1').toLowerCase(),
|
|
452
|
+
args: str.replace(COMMAND_REGEXP, '$4'),
|
|
453
|
+
};
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
ctx.cmd && log(`Command: ${JSON.stringify(ctx.cmd)}`);
|
|
458
|
+
await next();
|
|
459
|
+
},
|
|
460
|
+
}, {
|
|
461
|
+
run: true, priority: -8930, name: 'echo', hidden: true, func: async (ctx, next) => {
|
|
439
462
|
let resp, md = false;
|
|
440
463
|
switch (ctx.cmd.cmd) {
|
|
441
464
|
case 'echo':
|
|
@@ -495,7 +518,7 @@ const subconscious = [{
|
|
|
495
518
|
lorem: '[Lorem ipsum](https://en.wikipedia.org/wiki/Lorem_ipsum)',
|
|
496
519
|
},
|
|
497
520
|
}, {
|
|
498
|
-
run: true, priority: -
|
|
521
|
+
run: true, priority: -8920, name: 'authenticate', func: async (ctx, next) => {
|
|
499
522
|
if (!await ctx.shouldReply()) { return; } // if chatType is not in whitelist, exit.
|
|
500
523
|
if (!ctx._.private) { return await next(); } // if not private, go next.
|
|
501
524
|
if (ctx._.magicWord && insensitiveHas(ctx._.magicWord, ctx.txt)) { // auth by magicWord
|
|
@@ -522,7 +545,7 @@ const subconscious = [{
|
|
|
522
545
|
await ctx.ok('😿 Sorry, I am not allowed to talk to strangers.');
|
|
523
546
|
},
|
|
524
547
|
}, {
|
|
525
|
-
run: true, priority: -
|
|
548
|
+
run: true, priority: -8910, name: 'speech-to-text', func: async (ctx, next) => {
|
|
526
549
|
if (ctx._.speech?.stt && ctx.m.voice?.mime_type === 'audio/ogg') {
|
|
527
550
|
await ctx.ok(EMOJI_SPEECH);
|
|
528
551
|
try {
|
|
@@ -537,7 +560,7 @@ const subconscious = [{
|
|
|
537
560
|
await next();
|
|
538
561
|
},
|
|
539
562
|
}, {
|
|
540
|
-
run: true, priority: -
|
|
563
|
+
run: true, priority: -8900, name: 'callback', func: async (ctx, next) => {
|
|
541
564
|
if (ctx.type === 'callback_query') {
|
|
542
565
|
const data = parseJson(ctx.update[ctx.type].data);
|
|
543
566
|
const cb = ctx.session.callback.filter(x => x.id == data?.callback)[0];
|
|
@@ -553,7 +576,7 @@ const subconscious = [{
|
|
|
553
576
|
await next();
|
|
554
577
|
},
|
|
555
578
|
}, {
|
|
556
|
-
run: true, priority: -
|
|
579
|
+
run: true, priority: -8890, name: 'poll', func: async (ctx, next) => {
|
|
557
580
|
ctx.m.poll && ctx.collect(lines([
|
|
558
581
|
'Question:', ctx.m.poll.question, '',
|
|
559
582
|
'Options:', oList(ctx.m.poll.options.map(x => x.text)),
|
|
@@ -561,14 +584,14 @@ const subconscious = [{
|
|
|
561
584
|
await next();
|
|
562
585
|
},
|
|
563
586
|
}, {
|
|
564
|
-
run: true, priority: -
|
|
587
|
+
run: true, priority: -8880, name: 'contaxt', func: async (ctx, next) => {
|
|
565
588
|
ctx.m.reply_to_message?.text && ctx.collect(
|
|
566
589
|
ctx.m.reply_to_message.text, 'CONTAXT'
|
|
567
590
|
);
|
|
568
591
|
await next();
|
|
569
592
|
},
|
|
570
593
|
}, {
|
|
571
|
-
run: true, priority: -
|
|
594
|
+
run: true, priority: -8870, name: 'web', func: async (ctx, next) => {
|
|
572
595
|
if (ctx.entities.some(e => e.type === 'url')) {
|
|
573
596
|
await ctx.ok(EMOJI_LOOK);
|
|
574
597
|
for (let e of ctx.entities) {
|
|
@@ -582,7 +605,7 @@ const subconscious = [{
|
|
|
582
605
|
await next();
|
|
583
606
|
},
|
|
584
607
|
}, {
|
|
585
|
-
run: true, priority: -
|
|
608
|
+
run: true, priority: -8860, name: 'vision', func: async (ctx, next) => {
|
|
586
609
|
let fileId, type, file_name, mime_type, ocrFunc, asPrompt = false;
|
|
587
610
|
if ('application/pdf' === ctx.m.document?.mime_type) {
|
|
588
611
|
ocrFunc = ctx._.vision?.read;
|
|
@@ -647,29 +670,6 @@ const subconscious = [{
|
|
|
647
670
|
}
|
|
648
671
|
await next();
|
|
649
672
|
},
|
|
650
|
-
}, {
|
|
651
|
-
run: true, priority: -8860, name: 'commands', func: async (ctx, next) => {
|
|
652
|
-
for (let e of ctx.entities) {
|
|
653
|
-
if (e.type !== bot_command) { continue; }
|
|
654
|
-
if (!COMMAND_REGEXP.test(e.matched)) { continue; }
|
|
655
|
-
const cmd = trim(e.matched.replace(
|
|
656
|
-
COMMAND_REGEXP, '$1'
|
|
657
|
-
), { case: 'LOW' });
|
|
658
|
-
ctx.cmd = { cmd, args: e.text.substring(e.offset + e.length + 1) };
|
|
659
|
-
break;
|
|
660
|
-
}
|
|
661
|
-
for (let str of [ctx.txt || '', ctx.m.caption || ''].map(trim)) {
|
|
662
|
-
if (!ctx.cmd && COMMAND_REGEXP.test(str)) {
|
|
663
|
-
ctx.cmd = { // this will faild if command includes urls
|
|
664
|
-
cmd: str.replace(COMMAND_REGEXP, '$1').toLowerCase(),
|
|
665
|
-
args: str.replace(COMMAND_REGEXP, '$4'),
|
|
666
|
-
};
|
|
667
|
-
break;
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
ctx.cmd && log(`Command: ${JSON.stringify(ctx.cmd)}`);
|
|
671
|
-
await next();
|
|
672
|
-
},
|
|
673
673
|
}, {
|
|
674
674
|
run: true, priority: -8850, name: 'help', func: async (ctx, next) => {
|
|
675
675
|
const help = ctx._.info ? [ctx._.info] : [];
|
package/lib/manifest.mjs
CHANGED