From 94e5f74a904858a53bb7acf87a0208028f82ad9f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 29 Mar 2022 12:20:52 +0600 Subject: [PATCH] reply with content --- CHANGELOG.md | 3 + .../tgbotapi/extensions/api/send/Replies.kt | 74 ++++++++++++++++++- .../extensions/api/send/SendLocation.kt | 20 ++++- 3 files changed, 92 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe76c9f780..573d2a5192 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ * `Klock`: `2.6.3` -> `2.7.0` * `Core`: * Fixes in `TextSourcesList` creating in from `RawMessageEntities` +* `API`: + * Add opportunity to `reply` with `Poll` + * Add opportunity to `reply` with any `MessageContent` ## 0.38.10 diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt index eafb27672d..9dadb6e31a 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt @@ -19,8 +19,10 @@ import dev.inmo.tgbotapi.types.dice.DiceAnimationType import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.files.sticker.Sticker import dev.inmo.tgbotapi.types.games.Game -import dev.inmo.tgbotapi.types.location.StaticLocation +import dev.inmo.tgbotapi.types.location.* import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.content.* +import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent import dev.inmo.tgbotapi.types.payments.LabeledPrice import dev.inmo.tgbotapi.types.payments.abstracts.Currency import dev.inmo.tgbotapi.types.polls.* @@ -118,6 +120,7 @@ suspend inline fun TelegramBot.reply( longitude: Double, disableNotification: Boolean = false, protectContent: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendLocation( to.chat, @@ -125,6 +128,7 @@ suspend inline fun TelegramBot.reply( longitude, disableNotification, protectContent, + allowSendingWithoutReply, to.messageId, replyMarkup ) @@ -138,12 +142,14 @@ suspend inline fun TelegramBot.reply( location: StaticLocation, disableNotification: Boolean = false, protectContent: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendLocation( to.chat, location, disableNotification, protectContent, + allowSendingWithoutReply, to.messageId, replyMarkup ) @@ -887,6 +893,52 @@ suspend inline fun TelegramBot.reply( replyMarkup: KeyboardMarkup? = null ) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, entities, closeInfo, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + poll: Poll, + isClosed: Boolean = false, + question: String = poll.question, + options: List = poll.options.map { it.text }, + isAnonymous: Boolean = poll.isAnonymous, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + protectContent: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = when (poll) { + is RegularPoll -> reply( + to = to, + poll = poll, + isClosed = isClosed, + question = question, + options = options, + isAnonymous = isAnonymous, + allowMultipleAnswers = isAnonymous, + closeInfo = closeInfo, + disableNotification = disableNotification, + protectContent = protectContent, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup + ) + is UnknownPollType -> error("Unable to send poll with unknown type ($poll)") + is QuizPoll -> reply( + to = to, + quizPoll = poll, + entities = poll.textSources, + isClosed = isClosed, + question = question, + options = options, + isAnonymous = isAnonymous, + closeInfo = closeInfo, + disableNotification = disableNotification, + protectContent = protectContent, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup + ) +} + + suspend inline fun TelegramBot.reply( to: Message, fromChatId: ChatIdentifier, @@ -921,3 +973,23 @@ suspend inline fun TelegramBot.reply( allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = reply(to, copy.chat.id, copy.messageId, text, parseMode, disableNotification, protectContent, allowSendingWithoutReply, replyMarkup) + +suspend fun TelegramBot.reply( + to: Message, + content: MessageContent, + disableNotification: Boolean = false, + protectContent: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) { + execute( + content.createResend( + to.chat.id, + disableNotification, + protectContent, + to.messageId, + allowSendingWithoutReply, + replyMarkup + ) + ) +} diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt index 5f6c75ffcd..69100cf049 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt @@ -18,6 +18,7 @@ suspend fun TelegramBot.sendLocation( longitude: Double, disableNotification: Boolean = false, protectContent: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null ) = execute( @@ -27,6 +28,7 @@ suspend fun TelegramBot.sendLocation( longitude, disableNotification = disableNotification, protectContent = protectContent, + allowSendingWithoutReply = allowSendingWithoutReply, replyToMessageId = replyToMessageId, replyMarkup = replyMarkup ) @@ -41,6 +43,7 @@ suspend fun TelegramBot.sendLocation( location: StaticLocation, disableNotification: Boolean = false, protectContent: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null ) = sendLocation( @@ -49,6 +52,7 @@ suspend fun TelegramBot.sendLocation( location.longitude, disableNotification, protectContent, + allowSendingWithoutReply, replyToMessageId, replyMarkup ) @@ -63,6 +67,7 @@ suspend fun TelegramBot.sendLocation( longitude: Double, disableNotification: Boolean = false, protectContent: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null ) = sendLocation( @@ -71,6 +76,7 @@ suspend fun TelegramBot.sendLocation( longitude, disableNotification, protectContent, + allowSendingWithoutReply, replyToMessageId, replyMarkup ) @@ -84,6 +90,7 @@ suspend fun TelegramBot.sendLocation( location: StaticLocation, disableNotification: Boolean = false, protectContent: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null ) = sendLocation( @@ -92,6 +99,7 @@ suspend fun TelegramBot.sendLocation( location.longitude, disableNotification, protectContent, + allowSendingWithoutReply, replyToMessageId, replyMarkup ) @@ -106,9 +114,10 @@ suspend fun TelegramBot.sendStaticLocation( longitude: Double, disableNotification: Boolean = false, protectContent: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null -) = sendLocation(chatId, latitude, longitude, disableNotification, protectContent, replyToMessageId, replyMarkup) +) = sendLocation(chatId, latitude, longitude, disableNotification, protectContent, allowSendingWithoutReply, replyToMessageId, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -119,9 +128,10 @@ suspend fun TelegramBot.sendStaticLocation( location: StaticLocation, disableNotification: Boolean = false, protectContent: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null -) = sendLocation(chatId, location.latitude, location.longitude, disableNotification, protectContent, replyToMessageId, replyMarkup) +) = sendLocation(chatId, location.latitude, location.longitude, disableNotification, protectContent, allowSendingWithoutReply, replyToMessageId, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -133,9 +143,10 @@ suspend fun TelegramBot.sendStaticLocation( longitude: Double, disableNotification: Boolean = false, protectContent: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null -) = sendLocation(chat.id, latitude, longitude, disableNotification, protectContent, replyToMessageId, replyMarkup) +) = sendLocation(chat.id, latitude, longitude, disableNotification, protectContent, allowSendingWithoutReply, replyToMessageId, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -146,6 +157,7 @@ suspend fun TelegramBot.sendStaticLocation( location: StaticLocation, disableNotification: Boolean = false, protectContent: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null -) = sendLocation(chat.id, location.latitude, location.longitude, disableNotification, protectContent, replyToMessageId, replyMarkup) +) = sendLocation(chat.id, location.latitude, location.longitude, disableNotification, protectContent, allowSendingWithoutReply, replyToMessageId, replyMarkup)