diff --git a/src/filters.ts b/src/filters.ts index dcafadf..baab82a 100644 --- a/src/filters.ts +++ b/src/filters.ts @@ -6,6 +6,9 @@ type Predicate = (ctx: C) => MaybePromise; export const not = (predicate: Predicate) => (ctx: C) => Promise.resolve(predicate(ctx)).then((v) => !v); +export const is = (predicate: Predicate) => (ctx: C) => + Promise.resolve(predicate(ctx)).then((v) => v); + export const isChat = (ctx: C) => ctx.isChat === true; diff --git a/src/handlers/balabola.ts b/src/handlers/balabola.ts index b27fb1d..cbcd4c4 100644 --- a/src/handlers/balabola.ts +++ b/src/handlers/balabola.ts @@ -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(); const filter = composer - .filter(not(isChat), composer.compose()) - .filter(!!not(isHasText), composer.compose()); + .filter(is(isHasText), composer.compose()); const selectStyleKeyboard = (ctx: C) => { return Keyboard.builder() diff --git a/src/handlers/updates.ts b/src/handlers/updates.ts index 55212da..d44ebbd 100644 --- a/src/handlers/updates.ts +++ b/src/handlers/updates.ts @@ -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(); -const filter = composer.filter(!!not(isHasText), composer.compose()); +const filter = composer.filter(is(isHasText), composer.compose()); filter.use(async (ctx, next) => { const { messagePayload } = ctx;