2022-10-20 14:32:46 +00:00
|
|
|
|
import { Keyboard, MessageContext } from "vk-io";
|
|
|
|
|
import { balabola } from "../balabola_api";
|
|
|
|
|
import { Composer } from "../composer";
|
2022-10-20 14:37:44 +00:00
|
|
|
|
import { is, isHasText } from "../filters";
|
2022-10-20 14:32:46 +00:00
|
|
|
|
import { balabolaQueue } from "../queue";
|
|
|
|
|
|
|
|
|
|
export const composer = new Composer<MessageContext>();
|
|
|
|
|
|
|
|
|
|
const filter = composer
|
2022-10-20 14:37:44 +00:00
|
|
|
|
.filter(is(isHasText), composer.compose());
|
2022-10-20 14:32:46 +00:00
|
|
|
|
|
|
|
|
|
const selectStyleKeyboard = <C extends MessageContext>(ctx: C) => {
|
|
|
|
|
return Keyboard.builder()
|
|
|
|
|
.textButton({ label: '1', payload: { command: 'пр 0 ' + ctx.text! } })
|
|
|
|
|
.textButton({ label: '2', payload: { command: 'пр 24 ' + ctx.text! } })
|
|
|
|
|
.textButton({ label: '3', payload: { command: 'пр 25 ' + ctx.text! } })
|
|
|
|
|
.textButton({ label: '4', payload: { command: 'пр 11 ' + ctx.text! } })
|
|
|
|
|
.row()
|
|
|
|
|
.textButton({ label: '5', payload: { command: 'пр 6 ' + ctx.text! } })
|
|
|
|
|
.textButton({ label: '6', payload: { command: 'пр 8 ' + ctx.text! } })
|
|
|
|
|
.textButton({ label: '7', payload: { command: 'пр 9 ' + ctx.text! } })
|
|
|
|
|
.row()
|
|
|
|
|
.textButton({ label: 'чзх', payload: { command: 'help' } })
|
|
|
|
|
.inline();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const balabolaMessage = `Выбери стилизацию ответа:
|
|
|
|
|
1: без стилизации
|
|
|
|
|
2: инструкция
|
|
|
|
|
3: рецепт
|
|
|
|
|
4: мудрость
|
|
|
|
|
5: история
|
|
|
|
|
6: википедия
|
|
|
|
|
7: синопсис
|
|
|
|
|
более подробно команда help`;
|
|
|
|
|
|
2022-10-20 14:44:54 +00:00
|
|
|
|
const BALABOLA_INTROS = [0, 24, 25, 11, 6, 8, 9];
|
|
|
|
|
|
2022-10-20 14:32:46 +00:00
|
|
|
|
filter.hear(/^(?:продолжи)\s(.*)?$/i, async ctx => {
|
2022-10-20 16:39:05 +00:00
|
|
|
|
if (ctx.isChat) return;
|
2022-10-20 14:32:46 +00:00
|
|
|
|
await ctx.send(balabolaMessage, {
|
|
|
|
|
keyboard: selectStyleKeyboard(ctx)
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2022-10-20 14:44:54 +00:00
|
|
|
|
filter.hear(/^(?:пр)\s(1|2|3|4|5|6|7)\s(.*)?$/i, async ctx => {
|
2022-10-20 14:32:46 +00:00
|
|
|
|
const intro = ctx.$match[1];
|
|
|
|
|
const query = ctx.$match[2];
|
|
|
|
|
|
|
|
|
|
await ctx.send('генерирую!!');
|
|
|
|
|
|
2022-10-20 14:44:54 +00:00
|
|
|
|
const result = await balabolaQueue.add(() => balabola(query, BALABOLA_INTROS[+intro - 1]));
|
2022-10-20 14:32:46 +00:00
|
|
|
|
await ctx.send(result);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
filter.use(async ctx => {
|
2022-10-20 15:08:18 +00:00
|
|
|
|
if (ctx.isChat) return;
|
2022-10-20 14:32:46 +00:00
|
|
|
|
const result = await balabolaQueue.add(() => balabola(ctx.text!, 6));
|
|
|
|
|
await ctx.send(result);
|
|
|
|
|
});
|