custom queue

This commit is contained in:
2022-10-20 20:50:42 +03:00
parent bb8a0eb761
commit 257d80f0f6
6 changed files with 60 additions and 89 deletions

View File

@ -2,13 +2,15 @@ import { Keyboard, MessageContext } from "vk-io";
import { balabola } from "../balabola_api";
import { Composer } from "../composer";
import { is, isHasText } from "../filters";
import { balabolaQueue } from "../queue";
import { throttledQueue } from "../utilities/throttledQueue";
export const composer = new Composer<MessageContext>();
const filter = composer
.filter(is(isHasText), composer.compose());
const throttledBalabola = throttledQueue(1, 1000);
const selectStyleKeyboard = <C extends MessageContext>(ctx: C) => {
return Keyboard.builder()
.textButton({ label: '1', payload: { command: 'пр 0 ' + ctx.$match[1] } })
@ -48,13 +50,13 @@ filter.hear(/^(?:пр)\s(1|2|3|4|5|6|7)\s(.*)?$/i, async ctx => {
const query = ctx.$match[2];
await ctx.send('генерирую!!!');
const result = await balabolaQueue.add(() => balabola(query, BALABOLA_INTROS[+intro - 1]));
const result = await throttledBalabola(() => 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!, 0));
await ctx.send('генерирую!!');
const result = await throttledBalabola(() => balabola(ctx.text!, 0));
await ctx.send(result);
});