refactor(): reply switch with dynamic telegraf method call

This commit is contained in:
unknown
2020-12-26 23:19:30 +03:00
parent f10df2e960
commit 36f67ce29d
29 changed files with 106 additions and 284 deletions

View File

@@ -1,3 +1,2 @@
export * from './on.decorator';
export * from './update.decorator';
export * from './use.decorator';
export * from './inject-bot.decorator';

View File

@@ -0,0 +1,4 @@
import { Inject } from '@nestjs/common';
import { TelegrafProvider } from '../../telegraf.provider';
export const InjectBot = (): ParameterDecorator => Inject(TelegrafProvider);

View File

@@ -1,25 +0,0 @@
import { applyDecorators, SetMetadata } from '@nestjs/common';
import {
UPDATE_LISTENER_OPTIONS_METADATA,
UPDATE_LISTENER_TYPE_METADATA,
} from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum';
import { TelegrafUpdateType } from '../../telegraf.types';
export interface OnOptions {
updateTypes: TelegrafUpdateType;
}
/**
* Registers middleware for provided update type.
*
* @see https://telegraf.js.org/#/?id=on
*/
export const On = (updateTypes: TelegrafUpdateType): MethodDecorator => {
return applyDecorators(
SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.On),
SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, {
updateTypes,
} as OnOptions),
);
};

View File

@@ -1,12 +0,0 @@
import { SetMetadata } from '@nestjs/common';
import { UPDATE_LISTENER_TYPE_METADATA } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum';
/**
* Registers a middleware.
*
* @see https://telegraf.js.org/#/?id=use
*/
export const Use = (): MethodDecorator => {
return SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Use);
};