diff --git a/lib/decorators/telegraf-settings.decorator.ts b/lib/decorators/telegraf-settings.decorator.ts new file mode 100644 index 0000000..aed3741 --- /dev/null +++ b/lib/decorators/telegraf-settings.decorator.ts @@ -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, {}); +} diff --git a/lib/telegraf-metadata.accessor.ts b/lib/telegraf-metadata.accessor.ts index 30ce062..7895bce 100644 --- a/lib/telegraf-metadata.accessor.ts +++ b/lib/telegraf-metadata.accessor.ts @@ -60,4 +60,11 @@ export class TelegrafMetadataAccessor { } return !!this.reflector.get(DECORATORS.HELP, target); } + + isTelegrafSettings(target: Type | Function): boolean { + if (!target) { + return false; + } + return !!this.reflector.get(DECORATORS.SETTINGS, target); + } } diff --git a/lib/telegraf.constants.ts b/lib/telegraf.constants.ts index 78ee19a..e48a9a8 100644 --- a/lib/telegraf.constants.ts +++ b/lib/telegraf.constants.ts @@ -9,4 +9,5 @@ export const DECORATORS = { COMMAND: `${DECORATORS_PREFIX}/COMMAND`, START: `${DECORATORS_PREFIX}/START`, HELP: `${DECORATORS_PREFIX}/HELP`, + SETTINGS: `${DECORATORS_PREFIX}/SETTINGS`, }; diff --git a/lib/telegraf.explorer.ts b/lib/telegraf.explorer.ts index 2187ffd..1528843 100644 --- a/lib/telegraf.explorer.ts +++ b/lib/telegraf.explorer.ts @@ -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, + ) { + // @ts-ignore + telegraf.settings(instance[key].bind(instance)); + } }