nestjs-telegraf/lib/telegraf-metadata.accessor.ts

187 lines
4.7 KiB
TypeScript
Raw Normal View History

2020-03-19 16:21:35 +03:00
import { Injectable, Type } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import {
TelegrafActionMetadata,
TelegrafCashtagMetadata,
TelegrafCommandMetadata,
TelegrafEntityMetadata,
TelegrafHashtagMetadata,
TelegrafHearsMetadata,
TelegrafInlineQueryMetadata,
TelegrafMentionMetadata,
TelegrafOnMetadata,
TelegrafPhoneMetadata,
TelegrafStart,
} from './decorators';
2020-03-19 16:21:35 +03:00
import { DECORATORS } from './telegraf.constants';
@Injectable()
export class TelegrafMetadataAccessor {
constructor(private readonly reflector: Reflector) {}
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);
}
getTelegrafOnMetadata(
target: Type<any> | Function,
): TelegrafOnMetadata | 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);
}
getTelegrafHearsMetadata(
target: Type<any> | Function,
): TelegrafHearsMetadata | undefined {
2020-03-19 16:21:35 +03:00
return this.reflector.get(DECORATORS.HEARS, target);
}
isTelegrafCommand(target: Type<any> | Function): boolean {
if (!target) {
return false;
}
return !!this.reflector.get(DECORATORS.COMMAND, target);
}
getTelegrafCommandMetadata(
target: Type<any> | Function,
): TelegrafCommandMetadata | undefined {
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);
}
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);
}
getTelegrafEntityMetadata(
target: Type<any> | Function,
): TelegrafEntityMetadata | undefined {
2020-03-19 16:54:34 +03:00
return this.reflector.get(DECORATORS.ENTITY, target);
}
isTelegrafMention(target: Type<any> | Function): boolean {
if (!target) {
return false;
}
return !!this.reflector.get(DECORATORS.MENTION, target);
}
getTelegrafMentionMetadata(
target: Type<any> | Function,
): TelegrafMentionMetadata | undefined {
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);
}
getTelegrafPhoneMetadata(
target: Type<any> | Function,
): TelegrafPhoneMetadata | undefined {
2020-03-19 17:02:37 +03:00
return this.reflector.get(DECORATORS.PHONE, target);
}
isTelegrafHashtag(target: Type<any> | Function): boolean {
if (!target) {
return false;
}
return !!this.reflector.get(DECORATORS.HASHTAG, target);
}
getTelegrafHashtagMetadata(
target: Type<any> | Function,
): TelegrafHashtagMetadata | undefined {
return this.reflector.get(DECORATORS.HASHTAG, target);
}
isTelegrafCashtag(target: Type<any> | Function): boolean {
if (!target) {
return false;
}
return !!this.reflector.get(DECORATORS.CASHTAG, target);
}
getTelegrafCashtagMetadata(
target: Type<any> | Function,
): TelegrafCashtagMetadata | undefined {
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);
}
getTelegrafActionMetadata(
target: Type<any> | Function,
): TelegrafActionMetadata | undefined {
2020-03-19 17:20:13 +03:00
return this.reflector.get(DECORATORS.ACTION, target);
}
isTelegrafInlineQuery(target: Type<any> | Function): boolean {
if (!target) {
return false;
}
return !!this.reflector.get(DECORATORS.INLINE_QUERY, target);
}
getTelegrafInlineQueryMetadata(
target: Type<any> | Function,
): TelegrafInlineQueryMetadata | undefined {
return this.reflector.get(DECORATORS.INLINE_QUERY, target);
}
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
}