mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-24 23:14:39 +03:00
feat(decorators): TelegrafHelp added
This commit is contained in:
parent
c0ffdeff34
commit
fa3a7f5258
@ -3,3 +3,4 @@ export * from './telegraf-on.decorator';
|
||||
export * from './telegraf-hears.decorator';
|
||||
export * from './telegraf-command.decorator';
|
||||
export * from './telegraf-start.decorator';
|
||||
export * from './telegraf-help.decorator';
|
||||
|
11
lib/decorators/telegraf-help.decorator.ts
Normal file
11
lib/decorators/telegraf-help.decorator.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
import { DECORATORS } from '../telegraf.constants';
|
||||
|
||||
/**
|
||||
* Handler for /help command.
|
||||
*
|
||||
* https://telegraf.js.org/#/?id=help
|
||||
*/
|
||||
export function TelegrafHelp(): MethodDecorator {
|
||||
return SetMetadata(DECORATORS.HELP, {});
|
||||
}
|
@ -14,13 +14,6 @@ export class TelegrafMetadataAccessor {
|
||||
return !!this.reflector.get(DECORATORS.USE, target);
|
||||
}
|
||||
|
||||
isTelegrafStart(target: Type<any> | Function): boolean {
|
||||
if (!target) {
|
||||
return false;
|
||||
}
|
||||
return !!this.reflector.get(DECORATORS.START, target);
|
||||
}
|
||||
|
||||
isTelegrafOn(target: Type<any> | Function): boolean {
|
||||
if (!target) {
|
||||
return false;
|
||||
@ -53,4 +46,18 @@ export class TelegrafMetadataAccessor {
|
||||
getTelegrafCommandMetadata(target: Type<any> | Function) {
|
||||
return this.reflector.get(DECORATORS.COMMAND, target);
|
||||
}
|
||||
|
||||
isTelegrafStart(target: Type<any> | Function): boolean {
|
||||
if (!target) {
|
||||
return false;
|
||||
}
|
||||
return !!this.reflector.get(DECORATORS.START, target);
|
||||
}
|
||||
|
||||
isTelegrafHelp(target: Type<any> | Function): boolean {
|
||||
if (!target) {
|
||||
return false;
|
||||
}
|
||||
return !!this.reflector.get(DECORATORS.HELP, target);
|
||||
}
|
||||
}
|
||||
|
@ -8,4 +8,5 @@ export const DECORATORS = {
|
||||
HEARS: `${DECORATORS_PREFIX}/HEARS`,
|
||||
COMMAND: `${DECORATORS_PREFIX}/COMMAND`,
|
||||
START: `${DECORATORS_PREFIX}/START`,
|
||||
HELP: `${DECORATORS_PREFIX}/HELP`,
|
||||
};
|
||||
|
@ -41,8 +41,6 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
(key: string) => {
|
||||
if (this.metadataAccessor.isTelegrafUse(instance[key])) {
|
||||
this.handleTelegrafUse(instance, key, telegraf);
|
||||
} else if (this.metadataAccessor.isTelegrafStart(instance[key])) {
|
||||
this.handleTelegrafStart(instance, key, telegraf);
|
||||
} else if (this.metadataAccessor.isTelegrafOn(instance[key])) {
|
||||
const metadata = this.metadataAccessor.getTelegrafOnMetadata(
|
||||
instance[key],
|
||||
@ -58,6 +56,10 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
instance[key],
|
||||
);
|
||||
this.handleTelegrafCommand(instance, key, telegraf, metadata);
|
||||
} else if (this.metadataAccessor.isTelegrafStart(instance[key])) {
|
||||
this.handleTelegrafStart(instance, key, telegraf);
|
||||
} else if (this.metadataAccessor.isTelegrafHelp(instance[key])) {
|
||||
this.handleTelegrafHelp(instance, key, telegraf);
|
||||
}
|
||||
},
|
||||
);
|
||||
@ -81,14 +83,6 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
telegraf.on(metadata.updateTypes, instance[key].bind(instance));
|
||||
}
|
||||
|
||||
handleTelegrafStart(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
) {
|
||||
telegraf.start(instance[key].bind(instance));
|
||||
}
|
||||
|
||||
handleTelegrafHears(
|
||||
instance: object,
|
||||
key: string,
|
||||
@ -106,4 +100,20 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
) {
|
||||
telegraf.command(metadata.commands, instance[key].bind(instance));
|
||||
}
|
||||
|
||||
handleTelegrafStart(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
) {
|
||||
telegraf.start(instance[key].bind(instance));
|
||||
}
|
||||
|
||||
handleTelegrafHelp(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
) {
|
||||
telegraf.help(instance[key].bind(instance));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user