mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-24 23:14:39 +03:00
feat(decorators): TelegrafHashtag added
This commit is contained in:
parent
225c931dbb
commit
68690da83e
@ -8,3 +8,4 @@ export * from './telegraf-settings.decorator';
|
|||||||
export * from './telegraf-entity.decorator';
|
export * from './telegraf-entity.decorator';
|
||||||
export * from './telegraf-mention.decorator';
|
export * from './telegraf-mention.decorator';
|
||||||
export * from './telegraf-phone.decorator';
|
export * from './telegraf-phone.decorator';
|
||||||
|
export * from './telegraf-hashtag.decorator';
|
||||||
|
12
lib/decorators/telegraf-hashtag.decorator.ts
Normal file
12
lib/decorators/telegraf-hashtag.decorator.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { SetMetadata } from '@nestjs/common';
|
||||||
|
import { DECORATORS } from '../telegraf.constants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hashtag handling.
|
||||||
|
* @param hashtag Hashtag
|
||||||
|
*
|
||||||
|
* https://telegraf.js.org/#/?id=hashtag
|
||||||
|
*/
|
||||||
|
export function TelegrafHashtag(hashtag: string | string[]): MethodDecorator {
|
||||||
|
return SetMetadata(DECORATORS.HASHTAG, { hashtag });
|
||||||
|
}
|
@ -100,4 +100,15 @@ export class TelegrafMetadataAccessor {
|
|||||||
getTelegrafPhoneMetadata(target: Type<any> | Function) {
|
getTelegrafPhoneMetadata(target: Type<any> | Function) {
|
||||||
return this.reflector.get(DECORATORS.PHONE, target);
|
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) {
|
||||||
|
return this.reflector.get(DECORATORS.HASHTAG, target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,4 +13,5 @@ export const DECORATORS = {
|
|||||||
ENTITY: `${DECORATORS_PREFIX}/ENTITY`,
|
ENTITY: `${DECORATORS_PREFIX}/ENTITY`,
|
||||||
MENTION: `${DECORATORS_PREFIX}/MENTION`,
|
MENTION: `${DECORATORS_PREFIX}/MENTION`,
|
||||||
PHONE: `${DECORATORS_PREFIX}/PHONE`,
|
PHONE: `${DECORATORS_PREFIX}/PHONE`,
|
||||||
|
HASHTAG: `${DECORATORS_PREFIX}/HASHTAG`,
|
||||||
};
|
};
|
||||||
|
@ -77,6 +77,11 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
instance[key],
|
instance[key],
|
||||||
);
|
);
|
||||||
this.handleTelegrafPhone(instance, key, telegraf, metadata);
|
this.handleTelegrafPhone(instance, key, telegraf, metadata);
|
||||||
|
} else if (this.metadataAccessor.isTelegrafHashtag(instance[key])) {
|
||||||
|
const metadata = this.metadataAccessor.getTelegrafHashtagMetadata(
|
||||||
|
instance[key],
|
||||||
|
);
|
||||||
|
this.handleTelegrafHashtag(instance, key, telegraf, metadata);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -172,4 +177,14 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
telegraf.phone(metadata.phone, instance[key].bind(instance));
|
telegraf.phone(metadata.phone, instance[key].bind(instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleTelegrafHashtag(
|
||||||
|
instance: object,
|
||||||
|
key: string,
|
||||||
|
telegraf: Telegraf<ContextMessageUpdate>,
|
||||||
|
metadata: any,
|
||||||
|
) {
|
||||||
|
// @ts-ignore
|
||||||
|
telegraf.hashtag(metadata.hashtag, instance[key].bind(instance));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user