import { Keyboard, MessageContext } from "vk-io"; import { balabola } from "../balabola_api"; import { Composer } from "../composer"; import { is, isHasText } from "../filters"; import { balabolaQueue } from "../queue"; export const composer = new Composer(); const filter = composer .filter(is(isHasText), composer.compose()); const selectStyleKeyboard = (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`; const BALABOLA_INTROS = [0, 24, 25, 11, 6, 8, 9]; filter.hear(/^(?:продолжи)\s(.*)?$/i, async ctx => { if (ctx.isChat) return; await ctx.send(balabolaMessage, { keyboard: selectStyleKeyboard(ctx) }); }); filter.hear(/^(?:пр)\s(1|2|3|4|5|6|7)\s(.*)?$/i, async ctx => { const intro = ctx.$match[1]; const query = ctx.$match[2]; await ctx.send('генерирую!!'); const result = await balabolaQueue.add(() => balabola(query, BALABOLA_INTROS[+intro - 1])); await ctx.send(result); }); filter.use(async ctx => { if (ctx.isChat) return; const result = await balabolaQueue.add(() => balabola(ctx.text!, 6)); await ctx.send(result); });