- `is` filter
This commit is contained in:
parent
4673348f38
commit
94a475ab21
|
@ -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;
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue