mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-01-11 22:51:06 +03:00
feat(decorators): TelegrafGameQuery added
This commit is contained in:
parent
f65905ed0d
commit
a2eb619e6b
@ -12,3 +12,4 @@ export * from './telegraf-hashtag.decorator';
|
|||||||
export * from './telegraf-cashtag.decorator';
|
export * from './telegraf-cashtag.decorator';
|
||||||
export * from './telegraf-action.decorator';
|
export * from './telegraf-action.decorator';
|
||||||
export * from './telegraf-inline-query.decorator';
|
export * from './telegraf-inline-query.decorator';
|
||||||
|
export * from './telegraf-game-query.decorator';
|
||||||
|
11
lib/decorators/telegraf-game-query.decorator.ts
Normal file
11
lib/decorators/telegraf-game-query.decorator.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { SetMetadata } from '@nestjs/common';
|
||||||
|
import { DECORATORS } from '../telegraf.constants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers middleware for handling callback_data actions with game query.
|
||||||
|
*
|
||||||
|
* https://telegraf.js.org/#/?id=inlinequery
|
||||||
|
*/
|
||||||
|
export function TelegrafGameQuery(): MethodDecorator {
|
||||||
|
return SetMetadata(DECORATORS.GAME_QUERY, {});
|
||||||
|
}
|
@ -144,4 +144,11 @@ export class TelegrafMetadataAccessor {
|
|||||||
getTelegrafInlineQueryMetadata(target: Type<any> | Function) {
|
getTelegrafInlineQueryMetadata(target: Type<any> | Function) {
|
||||||
return this.reflector.get(DECORATORS.INLINE_QUERY, target);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,4 +17,5 @@ export const DECORATORS = {
|
|||||||
CASHTAG: `${DECORATORS_PREFIX}/CASHTAG`,
|
CASHTAG: `${DECORATORS_PREFIX}/CASHTAG`,
|
||||||
ACTION: `${DECORATORS_PREFIX}/ACTION`,
|
ACTION: `${DECORATORS_PREFIX}/ACTION`,
|
||||||
INLINE_QUERY: `${DECORATORS_PREFIX}/INLINE_QUERY`,
|
INLINE_QUERY: `${DECORATORS_PREFIX}/INLINE_QUERY`,
|
||||||
|
GAME_QUERY: `${DECORATORS_PREFIX}/GAME_QUERY`,
|
||||||
};
|
};
|
||||||
|
@ -99,6 +99,8 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
instance[key],
|
instance[key],
|
||||||
);
|
);
|
||||||
this.handleTelegrafInlineQuery(instance, key, telegraf, metadata);
|
this.handleTelegrafInlineQuery(instance, key, telegraf, metadata);
|
||||||
|
} else if (this.metadataAccessor.isTelegrafGameQuery(instance[key])) {
|
||||||
|
this.handleTelegrafGameQuery(instance, key, telegraf);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -233,4 +235,12 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
telegraf.inlineQuery(metadata.triggers, instance[key].bind(instance));
|
telegraf.inlineQuery(metadata.triggers, instance[key].bind(instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleTelegrafGameQuery(
|
||||||
|
instance: object,
|
||||||
|
key: string,
|
||||||
|
telegraf: Telegraf<ContextMessageUpdate>,
|
||||||
|
) {
|
||||||
|
telegraf.gameQuery(instance[key].bind(instance));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user