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