From e63870fac63446c4d91849d5b48ef44e54884ed0 Mon Sep 17 00:00:00 2001 From: xzeldon Date: Fri, 21 Oct 2022 10:22:22 +0300 Subject: [PATCH] some improvements --- src/handlers/balabola.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/handlers/balabola.ts b/src/handlers/balabola.ts index 385a584..69745e2 100644 --- a/src/handlers/balabola.ts +++ b/src/handlers/balabola.ts @@ -40,15 +40,6 @@ const BALABOLA_INTROS = [0, 24, 25, 11, 6, 8, 9]; const spammers = new Map(); -filter.use((ctx, next) => { - if (spammers.has(ctx.senderId) && spammers.get(ctx.senderId)! > Date.now()) { - return ctx.reply('отказ', { disable_mentions: true }); - } - - spammers.set(ctx.senderId, Date.now() + 5000); - return next(); -}); - filter.hear(/^(?:продолжи)\s(.*)?$/i, async (ctx, next) => { if (ctx.isChat) { ctx.text = `пр 1 ${ctx.$match[1]}`; @@ -61,12 +52,18 @@ filter.hear(/^(?:продолжи)\s(.*)?$/i, async (ctx, next) => { }); filter.hear(/^(?:пр)\s(1|2|3|4|5|6|7)\s(.*)?$/i, async ctx => { + if (spammers.has(ctx.senderId) && spammers.get(ctx.senderId)! > Date.now()) { + return ctx.reply('отказ', { disable_mentions: true }); + } + + spammers.set(ctx.senderId, Date.now() + 5000); + const intro = ctx.$match[1]; const query = ctx.$match[2]; await ctx.send('генерирую!!!'); const result = await throttledBalabola(() => balabola(query, BALABOLA_INTROS[+intro - 1])); - await ctx.send(result); + await ctx.reply(result); }); filter.use(async ctx => { @@ -74,5 +71,5 @@ filter.use(async ctx => { await ctx.send('генерирую!!'); const result = await throttledBalabola(() => balabola(ctx.text!, 0)); - await ctx.send(result); + await ctx.reply(result); });