25 lines
665 B
TypeScript
25 lines
665 B
TypeScript
import { MessageContext } from "vk-io";
|
|
import { Composer } from "../composer";
|
|
import { isHasText, not } from "../filters";
|
|
import { logger } from "../logger";
|
|
|
|
export const composer = new Composer<MessageContext>();
|
|
const filter = composer.filter(!!not(isHasText), composer.compose());
|
|
|
|
filter.use(async (ctx, next) => {
|
|
const { messagePayload } = ctx;
|
|
|
|
ctx.state.command = messagePayload && messagePayload.command
|
|
? messagePayload.command
|
|
: null;
|
|
|
|
logger.debug({
|
|
payload: messagePayload,
|
|
state: ctx.state,
|
|
text: ctx.text
|
|
});
|
|
|
|
if (ctx.state.command) ctx.text = ctx.state.command;
|
|
|
|
return next();
|
|
}); |