mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-24 15:04:38 +03:00
feat(decorators): TelegrafSettings added
This commit is contained in:
parent
fa3a7f5258
commit
55c6f939a4
11
lib/decorators/telegraf-settings.decorator.ts
Normal file
11
lib/decorators/telegraf-settings.decorator.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
import { DECORATORS } from '../telegraf.constants';
|
||||
|
||||
/**
|
||||
* Handler for /settings command.
|
||||
*
|
||||
* https://telegraf.js.org/#/?id=settings
|
||||
*/
|
||||
export function TelegrafSettings(): MethodDecorator {
|
||||
return SetMetadata(DECORATORS.SETTINGS, {});
|
||||
}
|
@ -60,4 +60,11 @@ export class TelegrafMetadataAccessor {
|
||||
}
|
||||
return !!this.reflector.get(DECORATORS.HELP, target);
|
||||
}
|
||||
|
||||
isTelegrafSettings(target: Type<any> | Function): boolean {
|
||||
if (!target) {
|
||||
return false;
|
||||
}
|
||||
return !!this.reflector.get(DECORATORS.SETTINGS, target);
|
||||
}
|
||||
}
|
||||
|
@ -9,4 +9,5 @@ export const DECORATORS = {
|
||||
COMMAND: `${DECORATORS_PREFIX}/COMMAND`,
|
||||
START: `${DECORATORS_PREFIX}/START`,
|
||||
HELP: `${DECORATORS_PREFIX}/HELP`,
|
||||
SETTINGS: `${DECORATORS_PREFIX}/SETTINGS`,
|
||||
};
|
||||
|
@ -60,6 +60,8 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
this.handleTelegrafStart(instance, key, telegraf);
|
||||
} else if (this.metadataAccessor.isTelegrafHelp(instance[key])) {
|
||||
this.handleTelegrafHelp(instance, key, telegraf);
|
||||
} else if (this.metadataAccessor.isTelegrafSettings(instance[key])) {
|
||||
this.handleTelegrafSettings(instance, key, telegraf);
|
||||
}
|
||||
},
|
||||
);
|
||||
@ -116,4 +118,13 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
) {
|
||||
telegraf.help(instance[key].bind(instance));
|
||||
}
|
||||
|
||||
handleTelegrafSettings(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
) {
|
||||
// @ts-ignore
|
||||
telegraf.settings(instance[key].bind(instance));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user