- is filter

This commit is contained in:
Timofey Gelazoniya 2022-10-20 17:37:44 +03:00
parent 4673348f38
commit 94a475ab21
Signed by: zeldon
GPG Key ID: 047886915281DD2A
3 changed files with 7 additions and 5 deletions

View File

@ -6,6 +6,9 @@ type Predicate<C extends MessageContext> = (ctx: C) => MaybePromise<boolean>;
export const not = <C extends MessageContext>(predicate: Predicate<C>) => (ctx: C) =>
Promise.resolve(predicate(ctx)).then((v) => !v);
export const is = <C extends MessageContext>(predicate: Predicate<C>) => (ctx: C) =>
Promise.resolve(predicate(ctx)).then((v) => v);
export const isChat = <C extends MessageContext>(ctx: C) =>
ctx.isChat === true;

View File

@ -1,14 +1,13 @@
import { Keyboard, MessageContext } from "vk-io";
import { balabola } from "../balabola_api";
import { Composer } from "../composer";
import { isChat, isHasText, not } from "../filters";
import { is, isHasText } 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());
.filter(is(isHasText), composer.compose());
const selectStyleKeyboard = <C extends MessageContext>(ctx: C) => {
return Keyboard.builder()

View File

@ -1,10 +1,10 @@
import { MessageContext } from "vk-io";
import { Composer } from "../composer";
import { isHasText, not } from "../filters";
import { is, isHasText } from "../filters";
import { logger } from "../logger";
export const composer = new Composer<MessageContext>();
const filter = composer.filter(!!not(isHasText), composer.compose());
const filter = composer.filter(is(isHasText), composer.compose());
filter.use(async (ctx, next) => {
const { messagePayload } = ctx;