2020-03-19 16:21:35 +03:00
|
|
|
import { Injectable, Type } from '@nestjs/common';
|
|
|
|
import { Reflector } from '@nestjs/core';
|
2020-03-19 18:20:07 +03:00
|
|
|
import {
|
2020-08-14 12:42:57 +03:00
|
|
|
ActionOptions,
|
|
|
|
CashtagOptions,
|
|
|
|
CommandOptions,
|
|
|
|
EntityOptions,
|
|
|
|
HashtagOptions,
|
|
|
|
HearsOptions,
|
|
|
|
InlineQueryOptions,
|
|
|
|
MentionOptions,
|
|
|
|
OnOptions,
|
|
|
|
PhoneOptions,
|
2020-09-09 22:46:25 +03:00
|
|
|
UpdateHookOptions,
|
2021-01-02 01:27:01 +03:00
|
|
|
} from '../decorators';
|
|
|
|
import { DECORATORS } from '../telegraf.constants';
|
2020-03-19 16:21:35 +03:00
|
|
|
|
|
|
|
@Injectable()
|
2021-01-02 01:27:01 +03:00
|
|
|
export class MetadataAccessorService {
|
2020-03-19 16:21:35 +03:00
|
|
|
constructor(private readonly reflector: Reflector) {}
|
|
|
|
|
2020-09-09 22:46:25 +03:00
|
|
|
isUpdate(target: Type<any> | Function): boolean {
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!this.reflector.get(DECORATORS.UPDATE, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
isUpdateHook(target: Type<any> | Function): boolean {
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!this.reflector.get(DECORATORS.UPDATE_HOOK, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
getUpdateHookMetadata(
|
|
|
|
target: Type<any> | Function,
|
|
|
|
): UpdateHookOptions | undefined {
|
|
|
|
return this.reflector.get(DECORATORS.UPDATE_HOOK, target);
|
|
|
|
}
|
|
|
|
|
2020-03-19 16:34:44 +03:00
|
|
|
isTelegrafUse(target: Type<any> | Function): boolean {
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!this.reflector.get(DECORATORS.USE, target);
|
|
|
|
}
|
|
|
|
|
2020-03-19 16:21:35 +03:00
|
|
|
isTelegrafOn(target: Type<any> | Function): boolean {
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!this.reflector.get(DECORATORS.ON, target);
|
|
|
|
}
|
|
|
|
|
2020-08-14 12:42:57 +03:00
|
|
|
getTelegrafOnMetadata(target: Type<any> | Function): OnOptions | undefined {
|
2020-03-19 16:21:35 +03:00
|
|
|
return this.reflector.get(DECORATORS.ON, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
isTelegrafHears(target: Type<any> | Function): boolean {
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!this.reflector.get(DECORATORS.HEARS, target);
|
|
|
|
}
|
|
|
|
|
2020-03-19 18:20:07 +03:00
|
|
|
getTelegrafHearsMetadata(
|
|
|
|
target: Type<any> | Function,
|
2020-08-14 12:42:57 +03:00
|
|
|
): HearsOptions | undefined {
|
2020-03-19 16:21:35 +03:00
|
|
|
return this.reflector.get(DECORATORS.HEARS, target);
|
|
|
|
}
|
2020-03-19 16:39:47 +03:00
|
|
|
|
|
|
|
isTelegrafCommand(target: Type<any> | Function): boolean {
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!this.reflector.get(DECORATORS.COMMAND, target);
|
|
|
|
}
|
|
|
|
|
2020-03-19 18:20:07 +03:00
|
|
|
getTelegrafCommandMetadata(
|
|
|
|
target: Type<any> | Function,
|
2020-08-14 12:42:57 +03:00
|
|
|
): CommandOptions | undefined {
|
2020-03-19 16:39:47 +03:00
|
|
|
return this.reflector.get(DECORATORS.COMMAND, target);
|
|
|
|
}
|
2020-03-19 16:44:05 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2020-03-19 16:46:31 +03:00
|
|
|
|
|
|
|
isTelegrafSettings(target: Type<any> | Function): boolean {
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!this.reflector.get(DECORATORS.SETTINGS, target);
|
|
|
|
}
|
2020-03-19 16:54:34 +03:00
|
|
|
|
|
|
|
isTelegrafEntity(target: Type<any> | Function): boolean {
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!this.reflector.get(DECORATORS.ENTITY, target);
|
|
|
|
}
|
|
|
|
|
2020-03-19 18:20:07 +03:00
|
|
|
getTelegrafEntityMetadata(
|
|
|
|
target: Type<any> | Function,
|
2020-08-14 12:42:57 +03:00
|
|
|
): EntityOptions | undefined {
|
2020-03-19 16:54:34 +03:00
|
|
|
return this.reflector.get(DECORATORS.ENTITY, target);
|
|
|
|
}
|
2020-03-19 16:58:27 +03:00
|
|
|
|
|
|
|
isTelegrafMention(target: Type<any> | Function): boolean {
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!this.reflector.get(DECORATORS.MENTION, target);
|
|
|
|
}
|
|
|
|
|
2020-03-19 18:20:07 +03:00
|
|
|
getTelegrafMentionMetadata(
|
|
|
|
target: Type<any> | Function,
|
2020-08-14 12:42:57 +03:00
|
|
|
): MentionOptions | undefined {
|
2020-03-19 16:58:27 +03:00
|
|
|
return this.reflector.get(DECORATORS.MENTION, target);
|
|
|
|
}
|
2020-03-19 17:02:37 +03:00
|
|
|
|
|
|
|
isTelegrafPhone(target: Type<any> | Function): boolean {
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!this.reflector.get(DECORATORS.PHONE, target);
|
|
|
|
}
|
|
|
|
|
2020-03-19 18:20:07 +03:00
|
|
|
getTelegrafPhoneMetadata(
|
|
|
|
target: Type<any> | Function,
|
2020-08-14 12:42:57 +03:00
|
|
|
): PhoneOptions | undefined {
|
2020-03-19 17:02:37 +03:00
|
|
|
return this.reflector.get(DECORATORS.PHONE, target);
|
|
|
|
}
|
2020-03-19 17:14:34 +03:00
|
|
|
|
|
|
|
isTelegrafHashtag(target: Type<any> | Function): boolean {
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!this.reflector.get(DECORATORS.HASHTAG, target);
|
|
|
|
}
|
|
|
|
|
2020-03-19 18:20:07 +03:00
|
|
|
getTelegrafHashtagMetadata(
|
|
|
|
target: Type<any> | Function,
|
2020-08-14 12:42:57 +03:00
|
|
|
): HashtagOptions | undefined {
|
2020-03-19 17:14:34 +03:00
|
|
|
return this.reflector.get(DECORATORS.HASHTAG, target);
|
|
|
|
}
|
2020-03-19 17:16:48 +03:00
|
|
|
|
|
|
|
isTelegrafCashtag(target: Type<any> | Function): boolean {
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!this.reflector.get(DECORATORS.CASHTAG, target);
|
|
|
|
}
|
|
|
|
|
2020-03-19 18:20:07 +03:00
|
|
|
getTelegrafCashtagMetadata(
|
|
|
|
target: Type<any> | Function,
|
2020-08-14 12:42:57 +03:00
|
|
|
): CashtagOptions | undefined {
|
2020-03-19 17:16:48 +03:00
|
|
|
return this.reflector.get(DECORATORS.CASHTAG, target);
|
|
|
|
}
|
2020-03-19 17:20:13 +03:00
|
|
|
|
|
|
|
isTelegrafAction(target: Type<any> | Function): boolean {
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!this.reflector.get(DECORATORS.ACTION, target);
|
|
|
|
}
|
|
|
|
|
2020-03-19 18:20:07 +03:00
|
|
|
getTelegrafActionMetadata(
|
|
|
|
target: Type<any> | Function,
|
2020-08-14 12:42:57 +03:00
|
|
|
): ActionOptions | undefined {
|
2020-03-19 17:20:13 +03:00
|
|
|
return this.reflector.get(DECORATORS.ACTION, target);
|
|
|
|
}
|
2020-03-19 17:25:47 +03:00
|
|
|
|
|
|
|
isTelegrafInlineQuery(target: Type<any> | Function): boolean {
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!this.reflector.get(DECORATORS.INLINE_QUERY, target);
|
|
|
|
}
|
|
|
|
|
2020-03-19 18:20:07 +03:00
|
|
|
getTelegrafInlineQueryMetadata(
|
|
|
|
target: Type<any> | Function,
|
2020-08-14 12:42:57 +03:00
|
|
|
): InlineQueryOptions | undefined {
|
2020-03-19 17:25:47 +03:00
|
|
|
return this.reflector.get(DECORATORS.INLINE_QUERY, target);
|
|
|
|
}
|
2020-03-19 17:28:56 +03:00
|
|
|
|
|
|
|
isTelegrafGameQuery(target: Type<any> | Function): boolean {
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!this.reflector.get(DECORATORS.GAME_QUERY, target);
|
|
|
|
}
|
2020-03-19 16:21:35 +03:00
|
|
|
}
|