From fbe8c9419d542dc3256dcaeb4fc8c6097638309a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 8 Nov 2022 22:23:32 +0600 Subject: [PATCH] add send extensions with sendLiveLocations --- .../extensions/api/LiveFlowLocation.kt | 6 +- .../tgbotapi/extensions/api/send/Sends.kt | 104 ++++++++++++++++++ 2 files changed, 108 insertions(+), 2 deletions(-) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveFlowLocation.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveFlowLocation.kt index 228cdb192b..76d59ce25e 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveFlowLocation.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveFlowLocation.kt @@ -5,7 +5,9 @@ import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions import dev.inmo.tgbotapi.abstracts.* import dev.inmo.tgbotapi.abstracts.types.WithReplyMarkup import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.edit.edit import dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation +import dev.inmo.tgbotapi.extensions.api.send.send import dev.inmo.tgbotapi.extensions.api.send.sendLiveLocation import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -57,7 +59,7 @@ suspend fun TelegramBot.handleLiveLocation( val capturedLiveLocationMessage = currentLiveLocationMessage if (capturedLiveLocationMessage == null) { updateMessageJob.start() - currentLiveLocationMessage = sendLiveLocation( + currentLiveLocationMessage = send( chatId, it.latitude, it.longitude, @@ -73,7 +75,7 @@ suspend fun TelegramBot.handleLiveLocation( it.replyMarkup ) } else { - editLiveLocation( + edit( capturedLiveLocationMessage, it.latitude, it.longitude, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Sends.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Sends.kt index 20071b1e2c..45df51e091 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Sends.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Sends.kt @@ -16,6 +16,7 @@ import dev.inmo.tgbotapi.types.chat.CommonUser import dev.inmo.tgbotapi.types.dice.DiceAnimationType import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.games.Game +import dev.inmo.tgbotapi.types.location.Location import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.media.* import dev.inmo.tgbotapi.types.message.ParseMode @@ -1122,6 +1123,109 @@ suspend fun TelegramBot.send( replyMarkup: KeyboardMarkup? = null ) = sendSticker(chat, sticker, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +/** + * Will execute [sendLiveLocation] request + * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or + * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param + */ +suspend fun TelegramBot.send( + chatId: ChatIdentifier, + latitude: Double, + longitude: Double, + livePeriod: Seconds, + horizontalAccuracy: Meters? = null, + heading: Degrees? = null, + proximityAlertRadius: Meters? = null, + threadId: MessageThreadId? = null, + disableNotification: Boolean = false, + protectContent: Boolean = false, + replyToMessageId: MessageId? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendLiveLocation( + chatId = chatId, + latitude = latitude, + longitude = longitude, + livePeriod = livePeriod, + horizontalAccuracy = horizontalAccuracy, + heading = heading, + proximityAlertRadius = proximityAlertRadius, + threadId = threadId, + disableNotification = disableNotification, + protectContent = protectContent, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup +) + +/** + * Will execute [sendLiveLocation] request + * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or + * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param + */ +suspend fun TelegramBot.send( + chatId: ChatIdentifier, + location: Location, + livePeriod: Seconds, + horizontalAccuracy: Meters? = null, + heading: Degrees? = null, + proximityAlertRadius: Meters? = null, + threadId: MessageThreadId? = null, + disableNotification: Boolean = false, + protectContent: Boolean = false, + replyToMessageId: MessageId? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendLiveLocation( + chatId, location, livePeriod, horizontalAccuracy, heading, proximityAlertRadius, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup +) + +/** + * Will execute [sendLiveLocation] request + * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or + * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param + */ +suspend fun TelegramBot.send( + chat: Chat, + latitude: Double, + longitude: Double, + livePeriod: Seconds, + horizontalAccuracy: Meters? = null, + heading: Degrees? = null, + proximityAlertRadius: Meters? = null, + threadId: MessageThreadId? = null, + disableNotification: Boolean = false, + protectContent: Boolean = false, + replyToMessageId: MessageId? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendLiveLocation( + chat, latitude, longitude, livePeriod, horizontalAccuracy, heading, proximityAlertRadius, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup +) + +/** + * Will execute [sendLiveLocation] request + * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or + * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param + */ +suspend fun TelegramBot.send( + chat: Chat, + location: Location, + livePeriod: Seconds, + horizontalAccuracy: Meters? = null, + heading: Degrees? = null, + proximityAlertRadius: Meters? = null, + threadId: MessageThreadId? = null, + disableNotification: Boolean = false, + protectContent: Boolean = false, + replyToMessageId: MessageId? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendLiveLocation( + chat, location, livePeriod, horizontalAccuracy, heading, proximityAlertRadius, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup +) + /** * Will execute [sendVenue] request * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or