From e43ad41d2f67d96cae686181c8cf46186f80537a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 00:56:32 +0600 Subject: [PATCH] complete filling of requests extensions --- .../TelegramBotAPI/requests/GetUpdates.kt | 21 +++++++++++ .../TelegramBotAPI/requests/LiveLocation.kt | 35 +++++++++++++++++++ .../requests/get/GetStickerSet.kt | 4 +-- .../requests/send/SendLocation.kt | 32 +++++++++++++++++ .../requests/send/media/SendMediaGroup.kt | 22 ++++++++++++ .../requests/webhook/GetWebhookInfo.kt | 3 ++ .../requests/webhook/SetWebhook.kt | 26 ++++++++++++++ 7 files changed, 141 insertions(+), 2 deletions(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt index 3cce646457..c4094cb6a9 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ALL_UPDATES_LIST import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier @@ -27,3 +28,23 @@ data class GetUpdates( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.getUpdates( + offset: UpdateIdentifier? = null, + limit: Int? = null, + timeout: Int? = null, + allowed_updates: List? = ALL_UPDATES_LIST +) = execute( + GetUpdates( + offset, limit, timeout, allowed_updates + ) +) + +suspend fun RequestsExecutor.getUpdates( + lastUpdate: Update, + limit: Int? = null, + timeout: Int? = null, + allowed_updates: List? = ALL_UPDATES_LIST +) = getUpdates( + lastUpdate.updateId + 1, limit, timeout, allowed_updates +) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/LiveLocation.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/LiveLocation.kt index f3bd84d8d7..657440b45d 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/LiveLocation.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/LiveLocation.kt @@ -6,6 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendLocation import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.LocationContent import com.soywiz.klock.DateTime @@ -98,3 +99,37 @@ suspend fun RequestsExecutor.startLiveLocation( locationMessage ) } + +suspend fun RequestsExecutor.startLiveLocation( + scope: CoroutineScope, + chat: Chat, + latitude: Double, + longitude: Double, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +): LiveLocation = startLiveLocation( + scope, chat.id, latitude, longitude, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.startLiveLocation( + scope: CoroutineScope, + chatId: ChatId, + location: Location, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +): LiveLocation = startLiveLocation( + scope, chatId, location.latitude, location.longitude, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.startLiveLocation( + scope: CoroutineScope, + chat: Chat, + location: Location, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +): LiveLocation = startLiveLocation( + scope, chat.id, location.latitude, location.longitude, disableNotification, replyToMessageId, replyMarkup +) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetStickerSet.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetStickerSet.kt index 6e587a7bc6..51da528a29 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetStickerSet.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetStickerSet.kt @@ -27,6 +27,6 @@ suspend fun RequestsExecutor.getStickerSet( suspend fun RequestsExecutor.getStickerSet( sticker: Sticker -) = execute( - GetStickerSet(sticker.stickerSetName ?: error("Sticker must contains stickerSetName to be correctly used in getStickerSet method")) +) = getStickerSet( + sticker.stickerSetName ?: error("Sticker must contains stickerSetName to be correctly used in getStickerSet method") ) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendLocation.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendLocation.kt index f7e7d42c56..45ba243ff3 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendLocation.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendLocation.kt @@ -7,6 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.LocationContent @@ -87,3 +88,34 @@ suspend fun RequestsExecutor.sendLocation( replyToMessageId, replyMarkup ) + +suspend fun RequestsExecutor.sendLocation( + chat: Chat, + latitude: Double, + longitude: Double, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendLocation( + chat.id, + latitude, + longitude, + disableNotification, + replyToMessageId, + replyMarkup +) + +suspend fun RequestsExecutor.sendLocation( + chat: Chat, + location: Location, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendLocation( + chat.id, + location.latitude, + location.longitude, + disableNotification, + replyToMessageId, + replyMarkup +) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt index a19819805e..3a1f6ce296 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt @@ -1,11 +1,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.* import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializerClass import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls @@ -85,3 +87,23 @@ data class SendMediaGroupData internal constructor( data class SendMediaGroupFiles internal constructor( val files: List ) : Files by (files.map { it.fileId to it }.toMap()) + +suspend fun RequestsExecutor.sendMediaGroup( + chatId: ChatIdentifier, + media: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null +) = execute( + SendMediaGroup( + chatId, media, disableNotification, replyToMessageId + ) +) + +suspend fun RequestsExecutor.sendMediaGroup( + chat: Chat, + media: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null +) = sendMediaGroup( + chat.id, media, disableNotification, replyToMessageId +) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/GetWebhookInfo.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/GetWebhookInfo.kt index 607a5aa7fd..b7c462b355 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/GetWebhookInfo.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/GetWebhookInfo.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.webhook +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.WebhookInfo import kotlinx.serialization.* @@ -13,3 +14,5 @@ class GetWebhookInfo : SimpleRequest { override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.getWebhookInfo() = execute(GetWebhookInfo()) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/SetWebhook.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/SetWebhook.kt index 7a066d096c..78a68c72b5 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/SetWebhook.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/SetWebhook.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.webhook +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.DataRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.MultipartRequestImpl @@ -64,3 +65,28 @@ data class SetWebhook internal constructor( } } } + +suspend fun RequestsExecutor.setWebhookInfo( + url: String, + certificate: FileId, + maxAllowedConnections: Int? = null, + allowedUpdates: List? = null +) = execute( + SetWebhook( + url, certificate.fileId, maxAllowedConnections, allowedUpdates + ) +) + +suspend fun RequestsExecutor.setWebhookInfo( + url: String, + certificate: MultipartFile, + maxAllowedConnections: Int? = null, + allowedUpdates: List? = null +) = execute( + MultipartRequestImpl( + SetWebhook( + url, null, maxAllowedConnections, allowedUpdates + ), + mapOf(certificateField to certificate) + ) +)