From a76a7ae630c7c07cc16b44d1e0b45c0511e916c7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 8 Nov 2021 18:36:17 +0600 Subject: [PATCH] add choose_sticker --- .../inmo/tgbotapi/extensions/api/send/SendAction.kt | 4 ++++ .../tgbotapi/extensions/api/send/SendActionDSL.kt | 2 ++ .../dev/inmo/tgbotapi/types/actions/BotAction.kt | 12 ++++++++++++ .../dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt | 9 +++++++++ 4 files changed, 27 insertions(+) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt index bf6af8adf9..c07ada572e 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt @@ -100,3 +100,7 @@ suspend fun TelegramBot.sendActionUploadVideoNote( chat: Chat ) = sendBotAction(chat, UploadVideoNoteAction) +suspend fun TelegramBot.sendActionChooseStickerAction( + chat: Chat +) = sendBotAction(chat, ChooseStickerAction) + diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt index d4ebb42816..c247ad55c1 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt @@ -59,6 +59,7 @@ suspend fun TelegramBot.withUploadDocumentAction(chatId: ChatId, block: Tele suspend fun TelegramBot.withFindLocationAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, FindLocationAction, block) suspend fun TelegramBot.withRecordVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, RecordVideoNoteAction, block) suspend fun TelegramBot.withUploadVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, UploadVideoNoteAction, block) +suspend fun TelegramBot.withChooseStickerAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, ChooseStickerAction, block) suspend fun TelegramBot.withTypingAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, TypingAction, block) @@ -71,3 +72,4 @@ suspend fun TelegramBot.withUploadDocumentAction(chat: Chat, block: Telegram suspend fun TelegramBot.withFindLocationAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, FindLocationAction, block) suspend fun TelegramBot.withRecordVideoNoteAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, RecordVideoNoteAction, block) suspend fun TelegramBot.withUploadVideoNoteAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, UploadVideoNoteAction, block) +suspend fun TelegramBot.withChooseStickerAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, ChooseStickerAction, block) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/actions/BotAction.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/actions/BotAction.kt index 8abad36be6..856f3d8899 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/actions/BotAction.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/actions/BotAction.kt @@ -36,6 +36,7 @@ object BotActionSerializer: KSerializer { FindLocationAction.actionName -> FindLocationAction RecordVideoNoteAction.actionName -> RecordVideoNoteAction UploadVideoNoteAction.actionName -> UploadVideoNoteAction + ChooseStickerAction.actionName -> ChooseStickerAction else -> CustomBotAction(actionName) } } @@ -151,6 +152,17 @@ inline val uploadVideoNote get() = UploadVideoNoteAction inline fun BotAction.asUploadVideoNote() = this as? UploadVideoNoteAction +/** + * Will notify user that bot is uploading video note + */ +@Serializable(BotActionSerializer::class) +object ChooseStickerAction : BotAction { + override val actionName: String = "choose_sticker" +} +inline val chooseSticker + get() = ChooseStickerAction +inline fun BotAction.asChooseStickerAction() = this as? ChooseStickerAction + @Serializable(BotActionSerializer::class) @Warning("Use this action only in case you are pretty sure that there are no other action for your needs") class CustomBotAction @RiskFeature("Usage of this action may lead to errors") constructor( diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index 491ae1c958..009d4d8988 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -1274,6 +1274,15 @@ inline fun BotAction.asTypingAction(): TypingAction? = this as? TypingAction @PreviewFeature inline fun BotAction.requireTypingAction(): TypingAction = this as TypingAction +@PreviewFeature +inline fun BotAction.whenChooseStickerAction(block: (ChooseStickerAction) -> T) = asChooseStickerAction() ?.let(block) + +@PreviewFeature +inline fun BotAction.asChooseStickerAction(): ChooseStickerAction? = this as? ChooseStickerAction + +@PreviewFeature +inline fun BotAction.requireChooseStickerAction(): ChooseStickerAction = this as ChooseStickerAction + @PreviewFeature inline fun BotAction.whenUploadVoiceAction(block: (UploadVoiceAction) -> T) = asUploadVoiceAction() ?.let(block)