mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-03-16 06:53:44 +03:00
feat(decorators): TelegrafCashtag added
This commit is contained in:
parent
68690da83e
commit
7d3e266f0f
@ -9,3 +9,4 @@ 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';
|
export * from './telegraf-hashtag.decorator';
|
||||||
|
export * from './telegraf-cashtag.decorator';
|
||||||
|
12
lib/decorators/telegraf-cashtag.decorator.ts
Normal file
12
lib/decorators/telegraf-cashtag.decorator.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { SetMetadata } from '@nestjs/common';
|
||||||
|
import { DECORATORS } from '../telegraf.constants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cashtag handling.
|
||||||
|
* @param cashtag Cashtag
|
||||||
|
*
|
||||||
|
* https://telegraf.js.org/#/?id=cashtag
|
||||||
|
*/
|
||||||
|
export function TelegrafCashtag(cashtag: string | string[]): MethodDecorator {
|
||||||
|
return SetMetadata(DECORATORS.CASHTAG, { cashtag });
|
||||||
|
}
|
@ -111,4 +111,15 @@ export class TelegrafMetadataAccessor {
|
|||||||
getTelegrafHashtagMetadata(target: Type<any> | Function) {
|
getTelegrafHashtagMetadata(target: Type<any> | Function) {
|
||||||
return this.reflector.get(DECORATORS.HASHTAG, target);
|
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) {
|
||||||
|
return this.reflector.get(DECORATORS.CASHTAG, target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,4 +14,5 @@ export const DECORATORS = {
|
|||||||
MENTION: `${DECORATORS_PREFIX}/MENTION`,
|
MENTION: `${DECORATORS_PREFIX}/MENTION`,
|
||||||
PHONE: `${DECORATORS_PREFIX}/PHONE`,
|
PHONE: `${DECORATORS_PREFIX}/PHONE`,
|
||||||
HASHTAG: `${DECORATORS_PREFIX}/HASHTAG`,
|
HASHTAG: `${DECORATORS_PREFIX}/HASHTAG`,
|
||||||
|
CASHTAG: `${DECORATORS_PREFIX}/CASHTAG`,
|
||||||
};
|
};
|
||||||
|
@ -82,6 +82,11 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
instance[key],
|
instance[key],
|
||||||
);
|
);
|
||||||
this.handleTelegrafHashtag(instance, key, telegraf, metadata);
|
this.handleTelegrafHashtag(instance, key, telegraf, metadata);
|
||||||
|
} else if (this.metadataAccessor.isTelegrafCashtag(instance[key])) {
|
||||||
|
const metadata = this.metadataAccessor.getTelegrafCashtagMetadata(
|
||||||
|
instance[key],
|
||||||
|
);
|
||||||
|
this.handleTelegrafCashtag(instance, key, telegraf, metadata);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -187,4 +192,14 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
telegraf.hashtag(metadata.hashtag, instance[key].bind(instance));
|
telegraf.hashtag(metadata.hashtag, instance[key].bind(instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleTelegrafCashtag(
|
||||||
|
instance: object,
|
||||||
|
key: string,
|
||||||
|
telegraf: Telegraf<ContextMessageUpdate>,
|
||||||
|
metadata: any,
|
||||||
|
) {
|
||||||
|
// @ts-ignore
|
||||||
|
telegraf.cashtag(metadata.cashtag, instance[key].bind(instance));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user