mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-11-08 01:31:22 +03:00
feat(decorators): TelegrafSettings added
This commit is contained in:
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);
|
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`,
|
COMMAND: `${DECORATORS_PREFIX}/COMMAND`,
|
||||||
START: `${DECORATORS_PREFIX}/START`,
|
START: `${DECORATORS_PREFIX}/START`,
|
||||||
HELP: `${DECORATORS_PREFIX}/HELP`,
|
HELP: `${DECORATORS_PREFIX}/HELP`,
|
||||||
|
SETTINGS: `${DECORATORS_PREFIX}/SETTINGS`,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
this.handleTelegrafStart(instance, key, telegraf);
|
this.handleTelegrafStart(instance, key, telegraf);
|
||||||
} else if (this.metadataAccessor.isTelegrafHelp(instance[key])) {
|
} else if (this.metadataAccessor.isTelegrafHelp(instance[key])) {
|
||||||
this.handleTelegrafHelp(instance, key, telegraf);
|
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));
|
telegraf.help(instance[key].bind(instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleTelegrafSettings(
|
||||||
|
instance: object,
|
||||||
|
key: string,
|
||||||
|
telegraf: Telegraf<ContextMessageUpdate>,
|
||||||
|
) {
|
||||||
|
// @ts-ignore
|
||||||
|
telegraf.settings(instance[key].bind(instance));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user