From b394f5274b40a1554eeacc54a2dabdd70d07b38b Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 23 Dec 2020 21:48:07 +0300 Subject: [PATCH] feat(wip): add updates decorators --- .../{listeners => core}/on.decorator.ts | 0 .../{listeners => core}/use.decorator.ts | 0 lib/decorators/index.ts | 2 +- lib/decorators/update-hooks.decorators.ts | 104 ------------------ lib/decorators/updates.decorator.ts | 70 ++++++++++++ 5 files changed, 71 insertions(+), 105 deletions(-) rename lib/decorators/{listeners => core}/on.decorator.ts (100%) rename lib/decorators/{listeners => core}/use.decorator.ts (100%) delete mode 100644 lib/decorators/update-hooks.decorators.ts create mode 100644 lib/decorators/updates.decorator.ts diff --git a/lib/decorators/listeners/on.decorator.ts b/lib/decorators/core/on.decorator.ts similarity index 100% rename from lib/decorators/listeners/on.decorator.ts rename to lib/decorators/core/on.decorator.ts diff --git a/lib/decorators/listeners/use.decorator.ts b/lib/decorators/core/use.decorator.ts similarity index 100% rename from lib/decorators/listeners/use.decorator.ts rename to lib/decorators/core/use.decorator.ts diff --git a/lib/decorators/index.ts b/lib/decorators/index.ts index 03af4ba..c49f9c0 100644 --- a/lib/decorators/index.ts +++ b/lib/decorators/index.ts @@ -15,4 +15,4 @@ export * from './settings.decorator'; export * from './start.decorator'; export * from './update.decorator'; export * from './update-hooks.decorators'; -export * from './use.decorator'; +export * from './core/use.decorator'; diff --git a/lib/decorators/update-hooks.decorators.ts b/lib/decorators/update-hooks.decorators.ts deleted file mode 100644 index 75621d8..0000000 --- a/lib/decorators/update-hooks.decorators.ts +++ /dev/null @@ -1,104 +0,0 @@ -import { SetMetadata } from '@nestjs/common'; -import { DECORATORS } from '../telegraf.constants'; -import * as tt from 'telegraf/typings/telegram-types'; - -export interface UpdateHookOptions { - updateType: - | tt.UpdateType - | tt.UpdateType[] - | tt.MessageSubTypes - | tt.MessageSubTypes[]; -} - -/** - * New incoming message of any kind — text, photo, sticker, etc. - * @constructor - */ -export const Message = (): MethodDecorator => { - return SetMetadata(DECORATORS.UPDATE_HOOK, { - updateType: 'message', - }); -}; - -/** - * New version of a message that is known to the bot and was edited - * @constructor - */ -export const EditedMessage = (): MethodDecorator => { - return SetMetadata(DECORATORS.UPDATE_HOOK, { - updateType: 'edited_message', - }); -}; - -/** - * New incoming channel post of any kind — text, photo, sticker, etc. - * @constructor - */ -export const ChannelPost = (): MethodDecorator => { - return SetMetadata(DECORATORS.UPDATE_HOOK, { - updateType: 'channel_post', - }); -}; - -/** - * New version of a channel post that is known to the bot and was edited - * @constructor - */ -export const EditedChannelPost = (): MethodDecorator => { - return SetMetadata(DECORATORS.UPDATE_HOOK, { - updateType: 'edited_channel_post', - }); -}; - -/** - * New incoming inline query - * See this decorator in inline-query.decorator.ts - * @constructor - */ -// export const InlineQuery = (): MethodDecorator => { -// return SetMetadata(DECORATORS.UPDATE_HOOK, { -// updateType: 'inline_query', -// }); -// }; - -/** - * The result of an inline query that was chosen by a user and sent to their chat partner. - * @constructor - */ -export const ChosenInlineResult = (): MethodDecorator => { - return SetMetadata(DECORATORS.UPDATE_HOOK, { - updateType: 'chosen_inline_result', - }); -}; - -/** - * New incoming callback query - * @constructor - */ -export const CallbackQuery = (): MethodDecorator => { - return SetMetadata(DECORATORS.UPDATE_HOOK, { - updateType: 'callback_query', - }); -}; - -/** - * New incoming shipping query. Only for invoices with flexible price - * @constructor - */ -export const ShippingQuery = (): MethodDecorator => { - return SetMetadata(DECORATORS.UPDATE_HOOK, { - updateType: 'shipping_query', - }); -}; - -/** - * New incoming pre-checkout query. Contains full information about checkout - * @constructor - */ -export const PreCheckoutQuery = (): MethodDecorator => { - return SetMetadata(DECORATORS.UPDATE_HOOK, { - updateType: 'pre_checkout_query', - }); -}; - -// Two more decorators are missing here. For 'poll' and 'poll_answer' update types. diff --git a/lib/decorators/updates.decorator.ts b/lib/decorators/updates.decorator.ts new file mode 100644 index 0000000..b186a21 --- /dev/null +++ b/lib/decorators/updates.decorator.ts @@ -0,0 +1,70 @@ +import { On } from './core/on.decorator'; + +/** + * New incoming message of any kind — text, photo, sticker, etc. + * @constructor + */ +export const Message = (): MethodDecorator => On('message'); + +/** + * New version of a message that is known to the bot and was edited + * @constructor + */ +export const EditedMessage = (): MethodDecorator => On('edited_message'); + +/** + * New incoming channel post of any kind — text, photo, sticker, etc. + * @constructor + */ +export const ChannelPost = (): MethodDecorator => On('channel_post'); + +/** + * New version of a channel post that is known to the bot and was edited + * @constructor + */ +export const EditedChannelPost = (): MethodDecorator => + On('edited_channel_post'); + +/** + * New incoming inline query + * See this decorator in inline-query.decorator.ts + * @constructor + */ +// export const InlineQuery = (): MethodDecorator => On('inline_query'); + +/** + * The result of an inline query that was chosen by a user and sent to their chat partner. + * @constructor + */ +export const ChosenInlineResult = (): MethodDecorator => + On('chosen_inline_result'); + +/** + * New incoming callback query + * @constructor + */ +export const CallbackQuery = (): MethodDecorator => On('callback_query'); + +/** + * New incoming shipping query. Only for invoices with flexible price + * @constructor + */ +export const ShippingQuery = (): MethodDecorator => On('shipping_query'); + +/** + * New incoming pre-checkout query. Contains full information about checkout + * @constructor + */ +export const PreCheckoutQuery = (): MethodDecorator => On('pre_checkout_query'); + +/** + * New poll state. Bots receive only updates about stopped polls and polls, which are sent by the bot + * @constructor + */ +export const Poll = (): MethodDecorator => On('poll'); + +/** + * A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself. + * @constructor + */ +export const PollAnswer = (): MethodDecorator => On('poll_answer');