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 17:50:42 +00:00
|
|
|
|
import { throttledQueue } from "../utilities/throttledQueue";
|
2022-10-20 14:32:46 +00:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-10-20 17:50:42 +00:00
|
|
|
|
const throttledBalabola = throttledQueue(1, 1000);
|
|
|
|
|
|
2022-10-20 14:32:46 +00:00
|
|
|
|
const selectStyleKeyboard = <C extends MessageContext>(ctx: C) => {
|
|
|
|
|
return Keyboard.builder()
|
2022-10-20 16:54:24 +00:00
|
|
|
|
.textButton({ label: '1', payload: { command: 'пр 0 ' + ctx.$match[1] } })
|
|
|
|
|
.textButton({ label: '2', payload: { command: 'пр 24 ' + ctx.$match[1] } })
|
|
|
|
|
.textButton({ label: '3', payload: { command: 'пр 25 ' + ctx.$match[1] } })
|
|
|
|
|
.textButton({ label: '4', payload: { command: 'пр 11 ' + ctx.$match[1] } })
|
2022-10-20 14:32:46 +00:00
|
|
|
|
.row()
|
2022-10-20 16:54:24 +00:00
|
|
|
|
.textButton({ label: '5', payload: { command: 'пр 6 ' + ctx.$match[1] } })
|
|
|
|
|
.textButton({ label: '6', payload: { command: 'пр 8 ' + ctx.$match[1] } })
|
|
|
|
|
.textButton({ label: '7', payload: { command: 'пр 9 ' + ctx.$match[1] } })
|
2022-10-20 14:32:46 +00:00
|
|
|
|
.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-21 06:58:42 +00:00
|
|
|
|
const spammers = new Map<number, number>();
|
|
|
|
|
|
|
|
|
|
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]}`;
|
|
|
|
|
return next();
|
|
|
|
|
}
|
|
|
|
|
|
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];
|
|
|
|
|
|
2022-10-20 16:54:24 +00:00
|
|
|
|
await ctx.send('генерирую!!!');
|
2022-10-20 17:50:42 +00:00
|
|
|
|
const result = await throttledBalabola(() => 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-21 06:58:42 +00:00
|
|
|
|
|
2022-10-20 17:50:42 +00:00
|
|
|
|
await ctx.send('генерирую!!');
|
|
|
|
|
const result = await throttledBalabola(() => balabola(ctx.text!, 0));
|
2022-10-20 14:32:46 +00:00
|
|
|
|
await ctx.send(result);
|
|
|
|
|
});
|