From f2701b920f0ae306a8721c85c1ef998bb07a9e35 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 1 Feb 2020 14:14:45 +0600 Subject: [PATCH 01/53] start 0.23.1 --- CHANGELOG.md | 2 ++ build.gradle | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0266904fce..7e94a69ea5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ * `GetMe` now return `ExtendedBot` object * Now extension `javaLocale` is extension for `CommonUser` +### 0.23.1 + ## 0.22.0 * **`KtorCallFactory` must return `HttpStatement` instead of `HttpClientCall`** diff --git a/build.gradle b/build.gradle index 4c9e3f55a0..6ce5ce96d9 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ plugins { id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version" } -project.version = "0.23.0" +project.version = "0.23.1" project.group = "com.github.insanusmokrassar" apply from: "publish.gradle" From ab6688bbaa6b85d9b88a22b756fe07d7c2ba27c5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 12:07:23 +0600 Subject: [PATCH 02/53] additional KtorUpdatesPoller method --- CHANGELOG.md | 5 +++ gradle.properties | 4 +-- .../updateshandlers/KtorUpdatesCIOPoller.kt | 33 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e94a69ea5..b99e1792e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,11 @@ ### 0.23.1 +* Versions updates: + * Klock `1.8.6` -> `1.8.7` + * Ktor `1.3.0` -> `1.3.1` +* Now it is possible to get updates by polling with custom executor engine + ## 0.22.0 * **`KtorCallFactory` must return `HttpStatement` instead of `HttpClientCall`** diff --git a/gradle.properties b/gradle.properties index 6e11c9788e..a1baaceff5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,8 +2,8 @@ kotlin.code.style=official kotlin_version=1.3.61 kotlin_coroutines_version=1.3.3 kotlin_serialisation_runtime_version=0.14.0 -klock_version=1.8.6 +klock_version=1.8.7 uuid_version=0.0.7 -ktor_version=1.3.0 +ktor_version=1.3.1 gradle_bintray_plugin_version=1.8.4 diff --git a/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/KtorUpdatesCIOPoller.kt b/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/KtorUpdatesCIOPoller.kt index 0d7906a6a1..626119b11d 100644 --- a/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/KtorUpdatesCIOPoller.kt +++ b/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/KtorUpdatesCIOPoller.kt @@ -6,6 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.UpdateReceiver import io.ktor.client.HttpClient +import io.ktor.client.engine.HttpClientEngine import io.ktor.client.engine.cio.CIO import io.ktor.client.engine.cio.endpoint import io.ktor.util.KtorExperimentalAPI @@ -42,3 +43,35 @@ fun KtorUpdatesPoller( updatesReceiver ) } + +@KtorExperimentalAPI +fun KtorUpdatesPoller( + telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper, + timeoutSeconds: Int? = null, + oneTimeUpdatesLimit: Int? = null, + allowedUpdates: List = ALL_UPDATES_LIST, + exceptionsHandler: (Exception) -> Boolean = { true }, + clientEngine: HttpClientEngine = CIO.create { + endpoint { + timeoutSeconds ?.times(1000) ?.also { timeOutMillis -> + keepAliveTime = timeOutMillis.toLong() + } + connectTimeout = 1000 + } + }, + updatesReceiver: UpdateReceiver +): KtorUpdatesPoller { + val executor = KtorRequestsExecutor( + telegramAPIUrlsKeeper, + HttpClient(clientEngine) + ) + + return KtorUpdatesPoller( + executor, + timeoutSeconds, + oneTimeUpdatesLimit, + allowedUpdates, + exceptionsHandler, + updatesReceiver + ) +} From 601958a5132350a19bc1af14e6172461a2fd87de Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 12:12:20 +0600 Subject: [PATCH 03/53] AnswerCallbackQuery simple sending extensions --- .../requests/answers/AnswerCallbackQuery.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerCallbackQuery.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerCallbackQuery.kt index 5fee21cc13..0f4188d3ee 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerCallbackQuery.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerCallbackQuery.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.CallbackQuery.CallbackQuery @@ -32,3 +33,19 @@ fun CallbackQuery.createAnswer( url: String? = null, cachedTimeSeconds: Int? = null ): AnswerCallbackQuery = AnswerCallbackQuery(id, text, showAlert, url, cachedTimeSeconds) + +suspend fun RequestsExecutor.sendCallbackQueryAnswer( + callbackQueryId: CallbackQueryIdentifier, + text: String? = null, + showAlert: Boolean? = null, + url: String? = null, + cachedTimeSeconds: Int? = null +) = execute(AnswerCallbackQuery(callbackQueryId, text, showAlert, url, cachedTimeSeconds)) + +suspend fun RequestsExecutor.sendCallbackQueryAnswer( + callbackQuery: CallbackQuery, + text: String? = null, + showAlert: Boolean? = null, + url: String? = null, + cachedTimeSeconds: Int? = null +) = sendCallbackQueryAnswer(callbackQuery.id, text, showAlert, url, cachedTimeSeconds) From 9c2525493730d7865714113aee588ae96230a429 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 12:38:56 +0600 Subject: [PATCH 04/53] AnswerInlineQuery simple sending extensions --- .../requests/answers/AnswerInlineQuery.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerInlineQuery.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerInlineQuery.kt index e31f1c7eb0..c4205bfec7 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerInlineQuery.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerInlineQuery.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult @@ -51,6 +52,28 @@ fun InlineQuery.createAnswer( switchPmParameter ) +suspend fun RequestsExecutor.sendInlineQueryAnswer( + inlineQueryID: InlineQueryIdentifier, + results: List = emptyList(), + cachedTime: Int? = null, + isPersonal: Boolean? = null, + nextOffset: String? = null, + switchPmText: String? = null, + switchPmParameter: String? = null +) = execute( + AnswerInlineQuery(inlineQueryID, results, cachedTime, isPersonal, nextOffset, switchPmText, switchPmParameter) +) + +suspend fun RequestsExecutor.sendInlineQueryAnswer( + inlineQuery: InlineQuery, + results: List = emptyList(), + cachedTime: Int? = null, + isPersonal: Boolean? = null, + nextOffset: String? = null, + switchPmText: String? = null, + switchPmParameter: String? = null +) = sendInlineQueryAnswer(inlineQuery.id, results, cachedTime, isPersonal, nextOffset, switchPmText, switchPmParameter) + internal object InlineQueryAnswersResultsSerializer: KSerializer> by ArrayListSerializer( InlineQueryResultSerializer ) From 2eb2d25662d6f8a8f2066c402ae237c7699589b7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 12:54:55 +0600 Subject: [PATCH 05/53] complete answers extensions --- .../requests/answers/AnswerCallbackQuery.kt | 6 +++--- .../requests/answers/AnswerInlineQuery.kt | 6 +++--- .../payments/AnswerPreCheckoutQuery.kt | 19 ++++++++++++++++- .../answers/payments/AnswerShippingQuery.kt | 21 +++++++++++++++++++ 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerCallbackQuery.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerCallbackQuery.kt index 0f4188d3ee..0c92f280e0 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerCallbackQuery.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerCallbackQuery.kt @@ -34,7 +34,7 @@ fun CallbackQuery.createAnswer( cachedTimeSeconds: Int? = null ): AnswerCallbackQuery = AnswerCallbackQuery(id, text, showAlert, url, cachedTimeSeconds) -suspend fun RequestsExecutor.sendCallbackQueryAnswer( +suspend fun RequestsExecutor.answerCallbackQuery( callbackQueryId: CallbackQueryIdentifier, text: String? = null, showAlert: Boolean? = null, @@ -42,10 +42,10 @@ suspend fun RequestsExecutor.sendCallbackQueryAnswer( cachedTimeSeconds: Int? = null ) = execute(AnswerCallbackQuery(callbackQueryId, text, showAlert, url, cachedTimeSeconds)) -suspend fun RequestsExecutor.sendCallbackQueryAnswer( +suspend fun RequestsExecutor.answerCallbackQuery( callbackQuery: CallbackQuery, text: String? = null, showAlert: Boolean? = null, url: String? = null, cachedTimeSeconds: Int? = null -) = sendCallbackQueryAnswer(callbackQuery.id, text, showAlert, url, cachedTimeSeconds) +) = answerCallbackQuery(callbackQuery.id, text, showAlert, url, cachedTimeSeconds) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerInlineQuery.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerInlineQuery.kt index c4205bfec7..6d42f8162e 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerInlineQuery.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/AnswerInlineQuery.kt @@ -52,7 +52,7 @@ fun InlineQuery.createAnswer( switchPmParameter ) -suspend fun RequestsExecutor.sendInlineQueryAnswer( +suspend fun RequestsExecutor.answerInlineQuery( inlineQueryID: InlineQueryIdentifier, results: List = emptyList(), cachedTime: Int? = null, @@ -64,7 +64,7 @@ suspend fun RequestsExecutor.sendInlineQueryAnswer( AnswerInlineQuery(inlineQueryID, results, cachedTime, isPersonal, nextOffset, switchPmText, switchPmParameter) ) -suspend fun RequestsExecutor.sendInlineQueryAnswer( +suspend fun RequestsExecutor.answerInlineQuery( inlineQuery: InlineQuery, results: List = emptyList(), cachedTime: Int? = null, @@ -72,7 +72,7 @@ suspend fun RequestsExecutor.sendInlineQueryAnswer( nextOffset: String? = null, switchPmText: String? = null, switchPmParameter: String? = null -) = sendInlineQueryAnswer(inlineQuery.id, results, cachedTime, isPersonal, nextOffset, switchPmText, switchPmParameter) +) = answerInlineQuery(inlineQuery.id, results, cachedTime, isPersonal, nextOffset, switchPmText, switchPmParameter) internal object InlineQueryAnswersResultsSerializer: KSerializer> by ArrayListSerializer( InlineQueryResultSerializer diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/AnswerPreCheckoutQuery.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/AnswerPreCheckoutQuery.kt index ff7d297270..e5a9790695 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/AnswerPreCheckoutQuery.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/AnswerPreCheckoutQuery.kt @@ -1,8 +1,9 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abstracts.AnswerPreCheckoutQuery import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.payments.PreCheckoutQuery +import com.github.insanusmokrassar.TelegramBotAPI.types.payments.* import kotlinx.serialization.* @Serializable @@ -40,3 +41,19 @@ fun PreCheckoutQuery.createAnswerError( id, error ) + +suspend fun RequestsExecutor.answerPreCheckoutQueryOk( + id: PreCheckoutQueryId +) = execute(AnswerPreCheckoutQueryOk(id)) +suspend fun RequestsExecutor.answerPreCheckoutQueryOk( + preCheckoutQuery: PreCheckoutQuery +) = answerPreCheckoutQueryOk(preCheckoutQuery.id) + +suspend fun RequestsExecutor.answerPreCheckoutQueryError( + id: PreCheckoutQueryId, + error: String +) = execute(AnswerPreCheckoutQueryError(id, error)) +suspend fun RequestsExecutor.answerPreCheckoutQueryError( + preCheckoutQuery: PreCheckoutQuery, + error: String +) = answerPreCheckoutQueryError(preCheckoutQuery.id, error) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/AnswerShippingQuery.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/AnswerShippingQuery.kt index 70d9d8626c..9f6ab3ed03 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/AnswerShippingQuery.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/answers/payments/AnswerShippingQuery.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abstracts.AnswerShippingQuery import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.payments.ShippingOption @@ -51,3 +52,23 @@ fun ShippingQuery.createAnswerError( id, error ) + +suspend fun RequestsExecutor.answerShippingQueryOk( + id: ShippingQueryIdentifier, + shippingOptions: List +) = execute(AnswerShippingQueryOk(id, shippingOptions)) +suspend fun RequestsExecutor.answerShippingQueryOk( + shippingQuery: ShippingQuery, + shippingOptions: List +) = answerShippingQueryOk(shippingQuery.id, shippingOptions) + +suspend fun RequestsExecutor.answerShippingQueryError( + id: ShippingQueryIdentifier, + error: String +) = execute(AnswerShippingQueryError(id, error)) +suspend fun RequestsExecutor.answerShippingQueryError( + shippingQuery: ShippingQuery, + error: String +) = answerShippingQueryError(shippingQuery.id, error) + + From 527b718f55fe279ba497a1f75638e06b3432adbc Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 13:27:58 +0600 Subject: [PATCH 06/53] chat methods now have additional usefull extensions --- .../requests/chat/ExportChatInviteLink.kt | 5 + .../TelegramBotAPI/requests/chat/LeaveChat.kt | 5 + .../requests/chat/get/GetChat.kt | 10 ++ .../chat/get/GetChatAdministrators.kt | 10 ++ .../requests/chat/get/GetChatMembersCount.kt | 10 ++ .../requests/chat/members/GetChatMember.kt | 23 ++++ .../requests/chat/members/KickChatMember.kt | 26 +++++ .../chat/members/PromoteChatMember.kt | 108 ++++++++++++++++++ .../chat/members/RestrictChatMember.kt | 33 +++++- .../SetChatAdministratorCustomTitle.kt | 30 ++++- .../requests/chat/members/UnbanChatMember.kt | 23 ++++ .../requests/chat/modify/DeleteChatPhoto.kt | 11 ++ .../requests/chat/modify/PinChatMessage.kt | 27 +++++ .../chat/modify/SetChatDescription.kt | 12 ++ .../chat/modify/SetChatPermissions.kt | 12 ++ .../requests/chat/modify/SetChatPhoto.kt | 13 +++ .../requests/chat/modify/SetChatTitle.kt | 13 +++ .../requests/chat/modify/UnpinChatMessage.kt | 10 ++ .../chat/stickers/DeleteChatStickerSet.kt | 11 ++ .../chat/stickers/SetChatStickerSet.kt | 12 ++ 20 files changed, 401 insertions(+), 3 deletions(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt index 6316c1d007..cba0da145d 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField @@ -18,3 +19,7 @@ data class ExportChatInviteLink( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.exportChatInviteLink( + chatId: ChatIdentifier +) = execute(ExportChatInviteLink(chatId)) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt index 15dd8af79d..7f87712464 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField @@ -18,3 +19,7 @@ data class LeaveChat( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.leaveChat( + chatId: ChatIdentifier +) = execute(LeaveChat(chatId)) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChat.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChat.kt index fb0decdbad..9ef14933b5 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChat.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChat.kt @@ -1,9 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ExtendedChatSerializer +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* @@ -19,3 +21,11 @@ data class GetChat( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.getChat( + chatId: ChatIdentifier +) = execute(GetChat(chatId)) + +suspend fun RequestsExecutor.getChat( + chat: Chat +) = getChat(chat.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatAdministrators.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatAdministrators.kt index 65a366ee6c..51d8a2665f 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatAdministrators.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatAdministrators.kt @@ -1,10 +1,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.AdministratorChatMember import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.AdministratorChatMemberSerializerWithoutDeserialization +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* import kotlinx.serialization.internal.ArrayListSerializer @@ -24,3 +26,11 @@ data class GetChatAdministrators( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.getChatAdministrators( + chatId: ChatIdentifier +) = execute(GetChatAdministrators(chatId)) + +suspend fun RequestsExecutor.getChatAdministrators( + chat: Chat +) = getChatAdministrators(chat.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatMembersCount.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatMembersCount.kt index a1313a1bf5..8d30508a91 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatMembersCount.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatMembersCount.kt @@ -1,8 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* import kotlinx.serialization.internal.IntSerializer @@ -18,3 +20,11 @@ data class GetChatMembersCount( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.getChatMembersCount( + chatId: ChatIdentifier +) = execute(GetChatMembersCount(chatId)) + +suspend fun RequestsExecutor.getChatMembersCount( + chat: Chat +) = getChatMembersCount(chat.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/GetChatMember.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/GetChatMember.kt index 7ec1b18bab..073170c003 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/GetChatMember.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/GetChatMember.kt @@ -1,9 +1,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get.getChatMembersCount import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMember import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMemberDeserializationStrategy +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import kotlinx.serialization.* @Serializable @@ -19,3 +22,23 @@ data class GetChatMember( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.getChatMember( + chatId: ChatIdentifier, + userId: UserId +) = execute(GetChatMember(chatId, userId)) + +suspend fun RequestsExecutor.getChatMember( + chat: Chat, + userId: UserId +) = getChatMember(chat.id, userId) + +suspend fun RequestsExecutor.getChatMember( + chatId: ChatId, + user: User +) = getChatMember(chatId, user.id) + +suspend fun RequestsExecutor.getChatMember( + chat: Chat, + user: User +) = getChatMember(chat.id, user.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/KickChatMember.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/KickChatMember.kt index ba28fcbf94..365075b1f2 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/KickChatMember.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/KickChatMember.kt @@ -1,8 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.UntilDate +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -21,3 +23,27 @@ data class KickChatMember( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.kickChatMember( + chatId: ChatIdentifier, + userId: UserId, + untilDate: TelegramDate? = null +) = execute(KickChatMember(chatId, userId, untilDate)) + +suspend fun RequestsExecutor.kickChatMember( + chat: Chat, + userId: UserId, + untilDate: TelegramDate? = null +) = kickChatMember(chat.id, userId, untilDate) + +suspend fun RequestsExecutor.kickChatMember( + chatId: ChatId, + user: User, + untilDate: TelegramDate? = null +) = kickChatMember(chatId, user.id, untilDate) + +suspend fun RequestsExecutor.kickChatMember( + chat: Chat, + user: User, + untilDate: TelegramDate? = null +) = kickChatMember(chat.id, user.id, untilDate) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/PromoteChatMember.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/PromoteChatMember.kt index b3289f28d5..ad0c26f55f 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/PromoteChatMember.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/PromoteChatMember.kt @@ -1,8 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.UntilDate +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -37,3 +39,109 @@ data class PromoteChatMember( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.promoteChatMember( + chatId: ChatIdentifier, + userId: UserId, + untilDate: TelegramDate? = null, + canChangeInfo: Boolean? = null, + canPostMessages: Boolean? = null, + canEditMessages: Boolean? = null, + canDeleteMessages: Boolean? = null, + canInviteUsers: Boolean? = null, + canRestrictMembers: Boolean? = null, + canPinMessages: Boolean? = null, + canPromoteMembers: Boolean? = null +) = execute( + PromoteChatMember( + chatId, + userId, + untilDate, + canChangeInfo, + canPostMessages, + canEditMessages, + canDeleteMessages, + canInviteUsers, + canRestrictMembers, + canPinMessages, + canPromoteMembers + ) +) + +suspend fun RequestsExecutor.promoteChatMember( + chat: Chat, + userId: UserId, + untilDate: TelegramDate? = null, + canChangeInfo: Boolean? = null, + canPostMessages: Boolean? = null, + canEditMessages: Boolean? = null, + canDeleteMessages: Boolean? = null, + canInviteUsers: Boolean? = null, + canRestrictMembers: Boolean? = null, + canPinMessages: Boolean? = null, + canPromoteMembers: Boolean? = null +) = promoteChatMember( + chat.id, + userId, + untilDate, + canChangeInfo, + canPostMessages, + canEditMessages, + canDeleteMessages, + canInviteUsers, + canRestrictMembers, + canPinMessages, + canPromoteMembers +) + +suspend fun RequestsExecutor.promoteChatMember( + chatId: ChatId, + user: User, + untilDate: TelegramDate? = null, + canChangeInfo: Boolean? = null, + canPostMessages: Boolean? = null, + canEditMessages: Boolean? = null, + canDeleteMessages: Boolean? = null, + canInviteUsers: Boolean? = null, + canRestrictMembers: Boolean? = null, + canPinMessages: Boolean? = null, + canPromoteMembers: Boolean? = null +) = promoteChatMember( + chatId, + user.id, + untilDate, + canChangeInfo, + canPostMessages, + canEditMessages, + canDeleteMessages, + canInviteUsers, + canRestrictMembers, + canPinMessages, + canPromoteMembers +) + +suspend fun RequestsExecutor.promoteChatMember( + chat: Chat, + user: User, + untilDate: TelegramDate? = null, + canChangeInfo: Boolean? = null, + canPostMessages: Boolean? = null, + canEditMessages: Boolean? = null, + canDeleteMessages: Boolean? = null, + canInviteUsers: Boolean? = null, + canRestrictMembers: Boolean? = null, + canPinMessages: Boolean? = null, + canPromoteMembers: Boolean? = null +) = promoteChatMember( + chat.id, + user.id, + untilDate, + canChangeInfo, + canPostMessages, + canEditMessages, + canDeleteMessages, + canInviteUsers, + canRestrictMembers, + canPinMessages, + canPromoteMembers +) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt index 95e2c1a375..2457510f29 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt @@ -1,9 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.UntilDate +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -16,7 +18,7 @@ data class RestrictChatMember( @SerialName(untilDateField) override val untilDate: TelegramDate? = null, @SerialName(permissionsField) - val permissions: ChatPermissions + val permissions: ChatPermissions = ChatPermissions() ) : ChatMemberRequest, UntilDate { override fun method(): String = "restrictChatMember" override val resultDeserializer: DeserializationStrategy @@ -24,3 +26,32 @@ data class RestrictChatMember( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.restrictChatMember( + chatId: ChatIdentifier, + userId: UserId, + untilDate: TelegramDate? = null, + permissions: ChatPermissions = ChatPermissions() +) = execute(RestrictChatMember(chatId, userId, untilDate, permissions)) + +suspend fun RequestsExecutor.restrictChatMember( + chat: Chat, + userId: UserId, + untilDate: TelegramDate? = null, + permissions: ChatPermissions = ChatPermissions() +) = restrictChatMember(chat.id, userId, untilDate, permissions) + +suspend fun RequestsExecutor.restrictChatMember( + chatId: ChatId, + user: User, + untilDate: TelegramDate? = null, + permissions: ChatPermissions = ChatPermissions() +) = restrictChatMember(chatId, user.id, untilDate, permissions) + +suspend fun RequestsExecutor.restrictChatMember( + chat: Chat, + user: User, + untilDate: TelegramDate? = null, + permissions: ChatPermissions = ChatPermissions() +) = restrictChatMember(chat.id, user.id, untilDate, permissions) + diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/SetChatAdministratorCustomTitle.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/SetChatAdministratorCustomTitle.kt index 0595455bf2..d54676c93c 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/SetChatAdministratorCustomTitle.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/SetChatAdministratorCustomTitle.kt @@ -1,7 +1,9 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -13,7 +15,7 @@ import kotlinx.serialization.internal.BooleanSerializer @Serializable data class SetChatAdministratorCustomTitle( @SerialName(chatIdField) - override val chatId: ChatId, + override val chatId: ChatIdentifier, @SerialName(userIdField) override val userId: UserId, @SerialName(customTitleField) @@ -30,4 +32,28 @@ data class SetChatAdministratorCustomTitle( throw IllegalArgumentException("Custom title length must be in range $customTitleLength, but was ${customTitle.length}") } } -} \ No newline at end of file +} + +suspend fun RequestsExecutor.setChatAdministratorCustomTitle( + chatId: ChatId, + userId: UserId, + customTitle: String +) = execute(SetChatAdministratorCustomTitle(chatId, userId, customTitle)) + +suspend fun RequestsExecutor.setChatAdministratorCustomTitle( + chat: Chat, + userId: UserId, + customTitle: String +) = setChatAdministratorCustomTitle(chat.id, userId, customTitle) + +suspend fun RequestsExecutor.setChatAdministratorCustomTitle( + chatId: ChatId, + user: User, + customTitle: String +) = setChatAdministratorCustomTitle(chatId, user.id, customTitle) + +suspend fun RequestsExecutor.setChatAdministratorCustomTitle( + chat: Chat, + user: User, + customTitle: String +) = setChatAdministratorCustomTitle(chat.id, user.id, customTitle) \ No newline at end of file diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/UnbanChatMember.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/UnbanChatMember.kt index d1853fc12e..f35b9a2523 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/UnbanChatMember.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/UnbanChatMember.kt @@ -1,7 +1,9 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -18,3 +20,24 @@ data class UnbanChatMember( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.unbanChatMember( + chatId: ChatIdentifier, + userId: UserId +) = execute(UnbanChatMember(chatId, userId)) + +suspend fun RequestsExecutor.unbanChatMember( + chat: Chat, + userId: UserId +) = unbanChatMember(chat.id, userId) + +suspend fun RequestsExecutor.unbanChatMember( + chatId: ChatId, + user: User +) = unbanChatMember(chatId, user.id) + +suspend fun RequestsExecutor.unbanChatMember( + chat: Chat, + user: User +) = unbanChatMember(chat.id, user.id) + diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/DeleteChatPhoto.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/DeleteChatPhoto.kt index 13727ff832..84f91bc964 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/DeleteChatPhoto.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/DeleteChatPhoto.kt @@ -1,8 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get.GetChat import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -18,3 +21,11 @@ data class DeleteChatPhoto( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.deleteChatPhoto( + chatId: ChatIdentifier +) = execute(DeleteChatPhoto(chatId)) + +suspend fun RequestsExecutor.deleteChatPhoto( + chat: Chat +) = deleteChatPhoto(chat.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt index faf9efde1d..7b98e0684a 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt @@ -1,8 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.* +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -21,3 +24,27 @@ data class PinChatMessage ( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.pinChatMessage( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + disableNotification: Boolean = false +) = execute(PinChatMessage(chatId, messageId, disableNotification)) + +suspend fun RequestsExecutor.pinChatMessage( + chat: Chat, + messageId: MessageIdentifier, + disableNotification: Boolean = false +) = pinChatMessage(chat.id, messageId, disableNotification) + +suspend fun RequestsExecutor.pinChatMessage( + chatId: ChatIdentifier, + message: Message, + disableNotification: Boolean = false +) = execute(PinChatMessage(chatId, message.messageId, disableNotification)) + +suspend fun RequestsExecutor.pinChatMessage( + chat: Chat, + message: Message, + disableNotification: Boolean = false +) = pinChatMessage(chat.id, message.messageId, disableNotification) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatDescription.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatDescription.kt index da66ac385d..b4fbbfea5f 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatDescription.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatDescription.kt @@ -1,8 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -25,3 +27,13 @@ data class SetChatDescription ( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.setChatDescription( + chatId: ChatIdentifier, + description: String +) = execute(SetChatDescription(chatId, description)) + +suspend fun RequestsExecutor.setChatDescription( + chat: Chat, + description: String +) = setChatDescription(chat.id, description) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt index 54af9d3010..c57dfabe11 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt @@ -1,9 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -20,3 +22,13 @@ data class SetChatPermissions ( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.setChatPermissions( + chatId: ChatIdentifier, + permissions: ChatPermissions +) = execute(SetChatPermissions(chatId, permissions)) + +suspend fun RequestsExecutor.setChatPermissions( + chat: Chat, + permissions: ChatPermissions +) = setChatPermissions(chat.id, permissions) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt index abc42992d3..65282ef225 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt @@ -1,9 +1,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.utils.toJson import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -21,3 +24,13 @@ data class SetChatPhoto ( override val mediaMap: Map = mapOf(photoField to photo) override val paramsJson: JsonObject = toJson(serializer()) } + +suspend fun RequestsExecutor.setChatPermissions( + chatId: ChatIdentifier, + photo: MultipartFile +) = execute(SetChatPhoto(chatId, photo)) + +suspend fun RequestsExecutor.setChatPermissions( + chat: Chat, + photo: MultipartFile +) = setChatPermissions(chat.id, photo) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatTitle.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatTitle.kt index 3b56fda15c..d66a7122ba 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatTitle.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatTitle.kt @@ -1,8 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -25,3 +28,13 @@ data class SetChatTitle ( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.setChatTitle( + chatId: ChatIdentifier, + title: String +) = execute(SetChatTitle(chatId, title)) + +suspend fun RequestsExecutor.setChatTitle( + chat: Chat, + title: String +) = setChatTitle(chat.id, title) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/UnpinChatMessage.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/UnpinChatMessage.kt index b755a6a96d..1d845df7aa 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/UnpinChatMessage.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/UnpinChatMessage.kt @@ -1,8 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -18,3 +20,11 @@ data class UnpinChatMessage( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.unpinChatMessage( + chatId: ChatIdentifier +) = execute(UnpinChatMessage(chatId)) + +suspend fun RequestsExecutor.unpinChatMessage( + chat: Chat +) = unpinChatMessage(chat.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt index e8563e75bc..dd0b896680 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt @@ -1,8 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.stickers import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify.DeleteChatPhoto import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -18,3 +21,11 @@ data class DeleteChatStickerSet( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.deleteChatStickerSet( + chatId: ChatIdentifier +) = execute(DeleteChatStickerSet(chatId)) + +suspend fun RequestsExecutor.deleteChatStickerSet( + chat: Chat +) = deleteChatStickerSet(chat.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt index 0aa4f73729..6eb1234a24 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt @@ -1,8 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.stickers import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -19,3 +21,13 @@ data class SetChatStickerSet( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.setChatStickerSet( + chatId: ChatIdentifier, + stickerSetName: StickerSetName +) = execute(SetChatStickerSet(chatId, stickerSetName)) + +suspend fun RequestsExecutor.setChatStickerSet( + chat: Chat, + stickerSetName: StickerSetName +) = setChatStickerSet(chat.id, stickerSetName) From 90d5833021dcb464bcd7396b3b13d753c7ba1666 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 13:29:14 +0600 Subject: [PATCH 07/53] CommonMultipartFileRequest now is internal --- CHANGELOG.md | 1 + .../requests/common/CommonMultipartFileRequest.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b99e1792e1..01928c9549 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ * Klock `1.8.6` -> `1.8.7` * Ktor `1.3.0` -> `1.3.1` * Now it is possible to get updates by polling with custom executor engine +* `CommonMultipartFileRequest` now is internal ## 0.22.0 diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/common/CommonMultipartFileRequest.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/common/CommonMultipartFileRequest.kt index 783eb02400..723661b011 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/common/CommonMultipartFileRequest.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/common/CommonMultipartFileRequest.kt @@ -3,7 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.common import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import kotlinx.serialization.json.JsonObject -data class CommonMultipartFileRequest( +internal data class CommonMultipartFileRequest( val data: SimpleRequest, override val mediaMap: Map ) : MultipartRequest, Request by data { From de1d6aa70c1609a590cc8be9be25bbcb83e30ccc Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 13:31:53 +0600 Subject: [PATCH 08/53] LeaveChat and ExportChatInviteLink now have one more extension --- .../TelegramBotAPI/requests/chat/ExportChatInviteLink.kt | 5 +++++ .../TelegramBotAPI/requests/chat/LeaveChat.kt | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt index cba0da145d..e10e837238 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt @@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* import kotlinx.serialization.internal.StringSerializer @@ -23,3 +24,7 @@ data class ExportChatInviteLink( suspend fun RequestsExecutor.exportChatInviteLink( chatId: ChatIdentifier ) = execute(ExportChatInviteLink(chatId)) + +suspend fun RequestsExecutor.exportChatInviteLink( + chat: Chat +) = exportChatInviteLink(chat.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt index 7f87712464..edd469342a 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt @@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -23,3 +24,7 @@ data class LeaveChat( suspend fun RequestsExecutor.leaveChat( chatId: ChatIdentifier ) = execute(LeaveChat(chatId)) + +suspend fun RequestsExecutor.leaveChat( + chat: Chat +) = leaveChat(chat.id) From 2cfabb1c2ab8b1e192bd0584d248486deece87dc Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 13:38:52 +0600 Subject: [PATCH 09/53] update Chat dependency in methods --- .../TelegramBotAPI/requests/chat/ExportChatInviteLink.kt | 3 ++- .../TelegramBotAPI/requests/chat/LeaveChat.kt | 3 ++- .../requests/chat/get/GetChatAdministrators.kt | 3 ++- .../TelegramBotAPI/requests/chat/get/GetChatMembersCount.kt | 3 ++- .../TelegramBotAPI/requests/chat/members/GetChatMember.kt | 5 +++-- .../TelegramBotAPI/requests/chat/members/KickChatMember.kt | 5 +++-- .../requests/chat/members/PromoteChatMember.kt | 5 +++-- .../requests/chat/members/RestrictChatMember.kt | 5 +++-- .../requests/chat/members/SetChatAdministratorCustomTitle.kt | 5 +++-- .../TelegramBotAPI/requests/chat/members/UnbanChatMember.kt | 5 +++-- .../TelegramBotAPI/requests/chat/modify/DeleteChatPhoto.kt | 3 ++- .../TelegramBotAPI/requests/chat/modify/PinChatMessage.kt | 5 +++-- .../requests/chat/modify/SetChatDescription.kt | 3 ++- .../requests/chat/modify/SetChatPermissions.kt | 3 ++- .../TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt | 3 ++- .../TelegramBotAPI/requests/chat/modify/SetChatTitle.kt | 3 ++- .../TelegramBotAPI/requests/chat/modify/UnpinChatMessage.kt | 3 ++- .../requests/chat/stickers/DeleteChatStickerSet.kt | 3 ++- .../requests/chat/stickers/SetChatStickerSet.kt | 3 ++- 19 files changed, 45 insertions(+), 26 deletions(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt index e10e837238..44fd294ef5 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/ExportChatInviteLink.kt @@ -5,6 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* import kotlinx.serialization.internal.StringSerializer @@ -26,5 +27,5 @@ suspend fun RequestsExecutor.exportChatInviteLink( ) = execute(ExportChatInviteLink(chatId)) suspend fun RequestsExecutor.exportChatInviteLink( - chat: Chat + chat: PublicChat ) = exportChatInviteLink(chat.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt index edd469342a..2c9b1f6e88 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/LeaveChat.kt @@ -5,6 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -26,5 +27,5 @@ suspend fun RequestsExecutor.leaveChat( ) = execute(LeaveChat(chatId)) suspend fun RequestsExecutor.leaveChat( - chat: Chat + chat: PublicChat ) = leaveChat(chat.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatAdministrators.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatAdministrators.kt index 51d8a2665f..5536179497 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatAdministrators.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatAdministrators.kt @@ -7,6 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.AdministratorChatMember import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.AdministratorChatMemberSerializerWithoutDeserialization import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* import kotlinx.serialization.internal.ArrayListSerializer @@ -32,5 +33,5 @@ suspend fun RequestsExecutor.getChatAdministrators( ) = execute(GetChatAdministrators(chatId)) suspend fun RequestsExecutor.getChatAdministrators( - chat: Chat + chat: PublicChat ) = getChatAdministrators(chat.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatMembersCount.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatMembersCount.kt index 8d30508a91..0b8921a8b6 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatMembersCount.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChatMembersCount.kt @@ -5,6 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* import kotlinx.serialization.internal.IntSerializer @@ -26,5 +27,5 @@ suspend fun RequestsExecutor.getChatMembersCount( ) = execute(GetChatMembersCount(chatId)) suspend fun RequestsExecutor.getChatMembersCount( - chat: Chat + chat: PublicChat ) = getChatMembersCount(chat.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/GetChatMember.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/GetChatMember.kt index 073170c003..31e2b092f1 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/GetChatMember.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/GetChatMember.kt @@ -7,6 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMember import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMemberDeserializationStrategy import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* @Serializable @@ -29,7 +30,7 @@ suspend fun RequestsExecutor.getChatMember( ) = execute(GetChatMember(chatId, userId)) suspend fun RequestsExecutor.getChatMember( - chat: Chat, + chat: PublicChat, userId: UserId ) = getChatMember(chat.id, userId) @@ -39,6 +40,6 @@ suspend fun RequestsExecutor.getChatMember( ) = getChatMember(chatId, user.id) suspend fun RequestsExecutor.getChatMember( - chat: Chat, + chat: PublicChat, user: User ) = getChatMember(chat.id, user.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/KickChatMember.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/KickChatMember.kt index 365075b1f2..c7edc4e10e 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/KickChatMember.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/KickChatMember.kt @@ -5,6 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -31,7 +32,7 @@ suspend fun RequestsExecutor.kickChatMember( ) = execute(KickChatMember(chatId, userId, untilDate)) suspend fun RequestsExecutor.kickChatMember( - chat: Chat, + chat: PublicChat, userId: UserId, untilDate: TelegramDate? = null ) = kickChatMember(chat.id, userId, untilDate) @@ -43,7 +44,7 @@ suspend fun RequestsExecutor.kickChatMember( ) = kickChatMember(chatId, user.id, untilDate) suspend fun RequestsExecutor.kickChatMember( - chat: Chat, + chat: PublicChat, user: User, untilDate: TelegramDate? = null ) = kickChatMember(chat.id, user.id, untilDate) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/PromoteChatMember.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/PromoteChatMember.kt index ad0c26f55f..a6906518c8 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/PromoteChatMember.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/PromoteChatMember.kt @@ -5,6 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -69,7 +70,7 @@ suspend fun RequestsExecutor.promoteChatMember( ) suspend fun RequestsExecutor.promoteChatMember( - chat: Chat, + chat: PublicChat, userId: UserId, untilDate: TelegramDate? = null, canChangeInfo: Boolean? = null, @@ -121,7 +122,7 @@ suspend fun RequestsExecutor.promoteChatMember( ) suspend fun RequestsExecutor.promoteChatMember( - chat: Chat, + chat: PublicChat, user: User, untilDate: TelegramDate? = null, canChangeInfo: Boolean? = null, diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt index 2457510f29..37b048956d 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt @@ -6,6 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMe import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -35,7 +36,7 @@ suspend fun RequestsExecutor.restrictChatMember( ) = execute(RestrictChatMember(chatId, userId, untilDate, permissions)) suspend fun RequestsExecutor.restrictChatMember( - chat: Chat, + chat: PublicChat, userId: UserId, untilDate: TelegramDate? = null, permissions: ChatPermissions = ChatPermissions() @@ -49,7 +50,7 @@ suspend fun RequestsExecutor.restrictChatMember( ) = restrictChatMember(chatId, user.id, untilDate, permissions) suspend fun RequestsExecutor.restrictChatMember( - chat: Chat, + chat: PublicChat, user: User, untilDate: TelegramDate? = null, permissions: ChatPermissions = ChatPermissions() diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/SetChatAdministratorCustomTitle.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/SetChatAdministratorCustomTitle.kt index d54676c93c..21106423a6 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/SetChatAdministratorCustomTitle.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/SetChatAdministratorCustomTitle.kt @@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -41,7 +42,7 @@ suspend fun RequestsExecutor.setChatAdministratorCustomTitle( ) = execute(SetChatAdministratorCustomTitle(chatId, userId, customTitle)) suspend fun RequestsExecutor.setChatAdministratorCustomTitle( - chat: Chat, + chat: PublicChat, userId: UserId, customTitle: String ) = setChatAdministratorCustomTitle(chat.id, userId, customTitle) @@ -53,7 +54,7 @@ suspend fun RequestsExecutor.setChatAdministratorCustomTitle( ) = setChatAdministratorCustomTitle(chatId, user.id, customTitle) suspend fun RequestsExecutor.setChatAdministratorCustomTitle( - chat: Chat, + chat: PublicChat, user: User, customTitle: String ) = setChatAdministratorCustomTitle(chat.id, user.id, customTitle) \ No newline at end of file diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/UnbanChatMember.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/UnbanChatMember.kt index f35b9a2523..470b328684 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/UnbanChatMember.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/UnbanChatMember.kt @@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -27,7 +28,7 @@ suspend fun RequestsExecutor.unbanChatMember( ) = execute(UnbanChatMember(chatId, userId)) suspend fun RequestsExecutor.unbanChatMember( - chat: Chat, + chat: PublicChat, userId: UserId ) = unbanChatMember(chat.id, userId) @@ -37,7 +38,7 @@ suspend fun RequestsExecutor.unbanChatMember( ) = unbanChatMember(chatId, user.id) suspend fun RequestsExecutor.unbanChatMember( - chat: Chat, + chat: PublicChat, user: User ) = unbanChatMember(chat.id, user.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/DeleteChatPhoto.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/DeleteChatPhoto.kt index 84f91bc964..6a8eaa4f06 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/DeleteChatPhoto.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/DeleteChatPhoto.kt @@ -6,6 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleReque import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get.GetChat import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -27,5 +28,5 @@ suspend fun RequestsExecutor.deleteChatPhoto( ) = execute(DeleteChatPhoto(chatId)) suspend fun RequestsExecutor.deleteChatPhoto( - chat: Chat + chat: PublicChat ) = deleteChatPhoto(chat.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt index 7b98e0684a..ef1f239cad 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt @@ -5,6 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -32,7 +33,7 @@ suspend fun RequestsExecutor.pinChatMessage( ) = execute(PinChatMessage(chatId, messageId, disableNotification)) suspend fun RequestsExecutor.pinChatMessage( - chat: Chat, + chat: PublicChat, messageId: MessageIdentifier, disableNotification: Boolean = false ) = pinChatMessage(chat.id, messageId, disableNotification) @@ -44,7 +45,7 @@ suspend fun RequestsExecutor.pinChatMessage( ) = execute(PinChatMessage(chatId, message.messageId, disableNotification)) suspend fun RequestsExecutor.pinChatMessage( - chat: Chat, + chat: PublicChat, message: Message, disableNotification: Boolean = false ) = pinChatMessage(chat.id, message.messageId, disableNotification) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatDescription.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatDescription.kt index b4fbbfea5f..82dc2e9e61 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatDescription.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatDescription.kt @@ -5,6 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -34,6 +35,6 @@ suspend fun RequestsExecutor.setChatDescription( ) = execute(SetChatDescription(chatId, description)) suspend fun RequestsExecutor.setChatDescription( - chat: Chat, + chat: PublicChat, description: String ) = setChatDescription(chat.id, description) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt index c57dfabe11..57fa318efb 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt @@ -6,6 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleReque import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -29,6 +30,6 @@ suspend fun RequestsExecutor.setChatPermissions( ) = execute(SetChatPermissions(chatId, permissions)) suspend fun RequestsExecutor.setChatPermissions( - chat: Chat, + chat: PublicChat, permissions: ChatPermissions ) = setChatPermissions(chat.id, permissions) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt index 65282ef225..66104e00fa 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt @@ -7,6 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartRe import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.utils.toJson import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -31,6 +32,6 @@ suspend fun RequestsExecutor.setChatPermissions( ) = execute(SetChatPhoto(chatId, photo)) suspend fun RequestsExecutor.setChatPermissions( - chat: Chat, + chat: PublicChat, photo: MultipartFile ) = setChatPermissions(chat.id, photo) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatTitle.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatTitle.kt index d66a7122ba..a6c040c2ea 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatTitle.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatTitle.kt @@ -6,6 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFi import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -35,6 +36,6 @@ suspend fun RequestsExecutor.setChatTitle( ) = execute(SetChatTitle(chatId, title)) suspend fun RequestsExecutor.setChatTitle( - chat: Chat, + chat: PublicChat, title: String ) = setChatTitle(chat.id, title) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/UnpinChatMessage.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/UnpinChatMessage.kt index 1d845df7aa..c746e14fe9 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/UnpinChatMessage.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/UnpinChatMessage.kt @@ -5,6 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -26,5 +27,5 @@ suspend fun RequestsExecutor.unpinChatMessage( ) = execute(UnpinChatMessage(chatId)) suspend fun RequestsExecutor.unpinChatMessage( - chat: Chat + chat: PublicChat ) = unpinChatMessage(chat.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt index dd0b896680..f3f5ef202c 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt @@ -6,6 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleReque import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify.DeleteChatPhoto import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -27,5 +28,5 @@ suspend fun RequestsExecutor.deleteChatStickerSet( ) = execute(DeleteChatStickerSet(chatId)) suspend fun RequestsExecutor.deleteChatStickerSet( - chat: Chat + chat: PublicChat ) = deleteChatStickerSet(chat.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt index 6eb1234a24..15ded57e65 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt @@ -5,6 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -28,6 +29,6 @@ suspend fun RequestsExecutor.setChatStickerSet( ) = execute(SetChatStickerSet(chatId, stickerSetName)) suspend fun RequestsExecutor.setChatStickerSet( - chat: Chat, + chat: PublicChat, stickerSetName: StickerSetName ) = setChatStickerSet(chat.id, stickerSetName) From 5e6ff01940d136b148c4b657c3c9cd98e982a958 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 14:05:36 +0600 Subject: [PATCH 10/53] complete update methods --- .../TelegramBotAPI/requests/DeleteMessage.kt | 25 +++++++++++ .../TelegramBotAPI/requests/StopPoll.kt | 30 ++++++++++++++ .../chat/stickers/DeleteChatStickerSet.kt | 5 +-- .../chat/stickers/SetChatStickerSet.kt | 5 +-- .../ReplyMarkup/EditChatMessageReplyMarkup.kt | 33 ++++++++++++++- .../EditInlineMessageReplyMarkup.kt | 8 ++++ .../edit/caption/EditChatMessageCaption.kt | 38 +++++++++++++++++ .../edit/caption/EditInlineMessageCaption.kt | 9 ++++ .../edit/media/EditChatMessageMedia.kt | 36 +++++++++++++++- .../edit/media/EditInlineMessageMedia.kt | 9 ++++ .../requests/edit/text/EditChatMessageText.kt | 41 +++++++++++++++++++ .../edit/text/EditInlineMessageText.kt | 10 +++++ 12 files changed, 241 insertions(+), 8 deletions(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt index dadfa80790..42c8b8bbed 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt @@ -1,8 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -20,3 +23,25 @@ data class DeleteMessage( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.deleteMessage( + chatId: ChatIdentifier, + messageId: MessageIdentifier +) = execute( + DeleteMessage(chatId, messageId) +) + +suspend fun RequestsExecutor.deleteMessage( + chat: Chat, + messageId: MessageIdentifier +) = deleteMessage(chat.id, messageId) + +suspend fun RequestsExecutor.deleteMessage( + chatId: ChatId, + message: Message +) = deleteMessage(chatId, message.messageId) + +suspend fun RequestsExecutor.deleteMessage( + chat: Chat, + message: Message +) = deleteMessage(chat.id, message.messageId) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/StopPoll.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/StopPoll.kt index 9b8b83166b..127843be4d 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/StopPoll.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/StopPoll.kt @@ -2,9 +2,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ReplyMarkup +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.ReplyMarkup.EditChatMessageReplyMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll import kotlinx.serialization.* @@ -23,3 +27,29 @@ data class StopPoll( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.stopPoll( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + replyMarkup: InlineKeyboardMarkup? = null +) = execute( + StopPoll(chatId, messageId, replyMarkup) +) + +suspend fun RequestsExecutor.stopPoll( + chat: Chat, + messageId: MessageIdentifier, + replyMarkup: InlineKeyboardMarkup? = null +) = stopPoll(chat.id, messageId, replyMarkup) + +suspend fun RequestsExecutor.stopPoll( + chatId: ChatId, + message: Message, + replyMarkup: InlineKeyboardMarkup? = null +) = stopPoll(chatId, message.messageId, replyMarkup) + +suspend fun RequestsExecutor.stopPoll( + chat: Chat, + message: Message, + replyMarkup: InlineKeyboardMarkup? = null +) = stopPoll(chat.id, message.messageId, replyMarkup) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt index f3f5ef202c..ad81d2c9e6 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/DeleteChatStickerSet.kt @@ -5,8 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify.DeleteChatPhoto import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -28,5 +27,5 @@ suspend fun RequestsExecutor.deleteChatStickerSet( ) = execute(DeleteChatStickerSet(chatId)) suspend fun RequestsExecutor.deleteChatStickerSet( - chat: PublicChat + chat: SupergroupChat ) = deleteChatStickerSet(chat.id) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt index 15ded57e65..1a0c0b0670 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt @@ -4,8 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -29,6 +28,6 @@ suspend fun RequestsExecutor.setChatStickerSet( ) = execute(SetChatStickerSet(chatId, stickerSetName)) suspend fun RequestsExecutor.setChatStickerSet( - chat: PublicChat, + chat: SupergroupChat, stickerSetName: StickerSetName ) = setChatStickerSet(chat.id, stickerSetName) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditChatMessageReplyMarkup.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditChatMessageReplyMarkup.kt index 702e233ea7..69be48676d 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditChatMessageReplyMarkup.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditChatMessageReplyMarkup.kt @@ -1,10 +1,14 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.ReplyMarkup +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditChatMessage import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage +import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media.EditChatMessageMedia import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMedia import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup -import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent import kotlinx.serialization.* @@ -29,3 +33,30 @@ data class EditChatMessageReplyMarkup( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.editMessageReplyMarkup( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + replyMarkup: InlineKeyboardMarkup? = null +) = execute( + EditChatMessageReplyMarkup(chatId, messageId, replyMarkup) +) + +suspend fun RequestsExecutor.editMessageReplyMarkup( + chat: Chat, + messageId: MessageIdentifier, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageReplyMarkup(chat.id, messageId, replyMarkup) + +suspend fun RequestsExecutor.editMessageReplyMarkup( + chatId: ChatId, + message: Message, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageReplyMarkup(chatId, message.messageId, replyMarkup) + +suspend fun RequestsExecutor.editMessageReplyMarkup( + chat: Chat, + message: Message, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageReplyMarkup(chat.id, message.messageId, replyMarkup) + diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditInlineMessageReplyMarkup.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditInlineMessageReplyMarkup.kt index 15a51074af..bca85f0199 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditInlineMessageReplyMarkup.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditInlineMessageReplyMarkup.kt @@ -1,8 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.ReplyMarkup +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditInlineMessage import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage +import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media.EditInlineMessageMedia import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMedia import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.* @@ -17,3 +20,8 @@ data class EditInlineMessageReplyMarkup( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.editMessageReplyMarkup( + inlineMessageId: InlineMessageIdentifier, + replyMarkup: InlineKeyboardMarkup? = null +) = execute(EditInlineMessageReplyMarkup(inlineMessageId, replyMarkup)) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt index 855366a788..c860bd5183 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt @@ -1,12 +1,16 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.caption +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media.MediaContentMessageResultDeserializer +import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.text.EditChatMessageText import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup +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.Message import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent import kotlinx.serialization.* @@ -32,3 +36,37 @@ data class EditChatMessageCaption( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.editMessageCaption( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + text: String, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = execute( + EditChatMessageCaption(chatId, messageId, text, parseMode, replyMarkup) +) + +suspend fun RequestsExecutor.editMessageCaption( + chat: Chat, + messageId: MessageIdentifier, + text: String, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageCaption(chat.id, messageId, text, parseMode, replyMarkup) + +suspend fun RequestsExecutor.editMessageCaption( + chatId: ChatId, + message: Message, + text: String, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageCaption(chatId, message.messageId, text, parseMode, replyMarkup) + +suspend fun RequestsExecutor.editMessageCaption( + chat: Chat, + message: Message, + text: String, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageCaption(chat.id, message.messageId, text, parseMode, replyMarkup) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditInlineMessageCaption.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditInlineMessageCaption.kt index b918ae79fd..df9c334389 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditInlineMessageCaption.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditInlineMessageCaption.kt @@ -1,6 +1,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.caption +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.text.EditInlineMessageText import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField @@ -22,3 +24,10 @@ data class EditInlineMessageCaption( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.editMessageCaption( + inlineMessageId: InlineMessageIdentifier, + text: String, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = execute(EditInlineMessageCaption(inlineMessageId, text, parseMode, replyMarkup)) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt index af97409eda..81243ad9b0 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt @@ -1,11 +1,15 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.caption.EditChatMessageCaption import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMedia +import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup -import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent import kotlinx.serialization.* @@ -38,3 +42,33 @@ data class EditChatMessageMedia( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.editMessageMedia( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + media: InputMedia, + replyMarkup: InlineKeyboardMarkup? = null +) = execute( + EditChatMessageMedia(chatId, messageId, media, replyMarkup) +) + +suspend fun RequestsExecutor.editMessageMedia( + chat: Chat, + messageId: MessageIdentifier, + media: InputMedia, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageMedia(chat.id, messageId, media, replyMarkup) + +suspend fun RequestsExecutor.editMessageMedia( + chatId: ChatId, + message: Message, + media: InputMedia, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageMedia(chatId, message.messageId, media, replyMarkup) + +suspend fun RequestsExecutor.editMessageMedia( + chat: Chat, + message: Message, + media: InputMedia, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageMedia(chat.id, message.messageId, media, replyMarkup) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditInlineMessageMedia.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditInlineMessageMedia.kt index fed5b7c66c..59d5489998 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditInlineMessageMedia.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditInlineMessageMedia.kt @@ -1,9 +1,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.caption.EditInlineMessageCaption import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMedia +import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.* @@ -27,3 +30,9 @@ data class EditInlineMessageMedia( override fun method(): String = editMessageMediaMethod } + +suspend fun RequestsExecutor.editMessageCaption( + inlineMessageId: InlineMessageIdentifier, + media: InputMedia, + replyMarkup: InlineKeyboardMarkup? = null +) = execute(EditInlineMessageMedia(inlineMessageId, media, replyMarkup)) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt index 1596f45cfc..b1e5ed9112 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt @@ -1,12 +1,15 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.text +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.TextContentMessageResultDeserializer import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup +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.Message import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent import kotlinx.serialization.* @@ -34,3 +37,41 @@ data class EditChatMessageText( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.editMessageText( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = execute( + EditChatMessageText(chatId, messageId, text, parseMode, disableWebPagePreview, replyMarkup) +) + +suspend fun RequestsExecutor.editMessageText( + chat: Chat, + messageId: MessageIdentifier, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageText(chat.id, messageId, text, parseMode, disableWebPagePreview, replyMarkup) + +suspend fun RequestsExecutor.editMessageText( + chatId: ChatId, + message: Message, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageText(chatId, message.messageId, text, parseMode, disableWebPagePreview, replyMarkup) + +suspend fun RequestsExecutor.editMessageText( + chat: Chat, + message: Message, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageText(chat.id, message.messageId, text, parseMode, disableWebPagePreview, replyMarkup) \ No newline at end of file diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditInlineMessageText.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditInlineMessageText.kt index 9219cd0949..c5093ef4ae 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditInlineMessageText.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditInlineMessageText.kt @@ -1,11 +1,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.text +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media.editMessageMediaMethod import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import kotlinx.serialization.* @Serializable @@ -25,3 +27,11 @@ data class EditInlineMessageText( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.editMessageText( + inlineMessageId: InlineMessageIdentifier, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = execute(EditInlineMessageText(inlineMessageId, text, parseMode, disableWebPagePreview, replyMarkup)) From 6cf836708d11ce4dea638d198ee096ee6666a285 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 14:25:17 +0600 Subject: [PATCH 11/53] complete filling of until SendPhoto for usefull extensions --- .../TelegramBotAPI/requests/ForwardMessage.kt | 46 +++++++++- .../TelegramBotAPI/requests/GetMe.kt | 5 +- .../requests/send/SendMessage.kt | 47 ++++++++++ .../requests/send/media/SendPhoto.kt | 89 +++++++++++++++++++ .../types/message/ChatEvents/NewChatPhoto.kt | 3 +- .../message/content/media/PhotoContent.kt | 5 +- 6 files changed, 189 insertions(+), 6 deletions(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/ForwardMessage.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/ForwardMessage.kt index 21c92f71cd..a5e5caee51 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/ForwardMessage.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/ForwardMessage.kt @@ -1,9 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.PossiblyForwardedMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import kotlinx.serialization.* @@ -30,3 +32,45 @@ data class ForwardMessage( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.forwardMessage( + fromChatId: ChatIdentifier, + toChatId: ChatIdentifier, + messageId: MessageIdentifier, + disableNotification: Boolean = false +) = execute( + ForwardMessage(fromChatId, toChatId, messageId, disableNotification) +) + +suspend fun RequestsExecutor.forwardMessage( + fromChat: Chat, + toChatId: ChatIdentifier, + messageId: MessageIdentifier, + disableNotification: Boolean = false +) = forwardMessage(fromChat.id, toChatId, messageId, disableNotification) + +suspend fun RequestsExecutor.forwardMessage( + fromChatId: ChatIdentifier, + toChat: Chat, + messageId: MessageIdentifier, + disableNotification: Boolean = false +) = forwardMessage(fromChatId, toChat.id, messageId, disableNotification) + +suspend fun RequestsExecutor.forwardMessage( + fromChat: Chat, + toChat: Chat, + messageId: MessageIdentifier, + disableNotification: Boolean = false +) = forwardMessage(fromChat.id, toChat.id, messageId, disableNotification) + +suspend fun RequestsExecutor.forwardMessage( + toChatId: ChatIdentifier, + message: Message, + disableNotification: Boolean = false +) = forwardMessage(message.chat, toChatId, message.messageId, disableNotification) + +suspend fun RequestsExecutor.forwardMessage( + toChat: Chat, + message: Message, + disableNotification: Boolean = false +) = forwardMessage(message.chat, toChat, message.messageId, disableNotification) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt index 2f19df4909..8dd4b06eac 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.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.* import kotlinx.serialization.* @@ -11,4 +12,6 @@ class GetMe : SimpleRequest { get() = ExtendedBot.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() -} \ No newline at end of file +} + +suspend fun RequestsExecutor.getMe() = execute(GetMe()) \ No newline at end of file diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendMessage.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendMessage.kt index 91ebbad8a6..8594d7400d 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendMessage.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendMessage.kt @@ -1,11 +1,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.DisableWebPagePreview +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField 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.TextContent @@ -55,3 +57,48 @@ data class SendTextMessage( ) ) typealias SendMessage = SendTextMessage + +suspend fun RequestsExecutor.sendMessage( + chatId: ChatIdentifier, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendTextMessage(chatId, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup) +) + +suspend fun RequestsExecutor.sendTextMessage( + chatId: ChatIdentifier, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendMessage( + chatId, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendMessage( + chat: Chat, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendMessage(chat.id, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup) + + +suspend fun RequestsExecutor.sendTextMessage( + chat: Chat, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendTextMessage(chat.id, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendPhoto.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendPhoto.kt index b9b005d8b4..8edecd4053 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendPhoto.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendPhoto.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.* @@ -7,6 +8,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.files.* 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.media.PhotoContent @@ -82,3 +85,89 @@ data class SendPhotoFiles internal constructor( ) : Files by mapOf( photoField to photo ) + +suspend fun RequestsExecutor.sendPhoto( + chatId: ChatIdentifier, + fileId: FileId, + caption: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendPhotoData( + chatId, + fileId.fileId, + caption, + parseMode, + disableNotification, + replyToMessageId, + replyMarkup + ) +) + +suspend fun RequestsExecutor.sendPhoto( + chatId: ChatIdentifier, + file: PhotoSize, + caption: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto( + chatId, file.fileId, caption, parseMode, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendPhoto( + chatId: ChatIdentifier, + photo: Photo, + caption: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto( + chatId, photo.biggest() ?: throw IllegalArgumentException("Photo $photo is empty"), caption, parseMode, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendPhoto( + chat: Chat, + fileId: FileId, + caption: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto( + chat.id, + fileId, + caption, + parseMode, + disableNotification, + replyToMessageId, + replyMarkup +) + +suspend fun RequestsExecutor.sendPhoto( + chat: Chat, + file: PhotoSize, + caption: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto( + chat.id, file.fileId, caption, parseMode, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendPhoto( + chat: Chat, + photo: Photo, + caption: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto( + chat.id, photo.biggest() ?: throw IllegalArgumentException("Photo $photo is empty"), caption, parseMode, disableNotification, replyToMessageId, replyMarkup +) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChatEvents/NewChatPhoto.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChatEvents/NewChatPhoto.kt index 60c3e5d56c..5396d4e69b 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChatEvents/NewChatPhoto.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChatEvents/NewChatPhoto.kt @@ -1,8 +1,9 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents +import com.github.insanusmokrassar.TelegramBotAPI.types.files.Photo import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.CommonEvent data class NewChatPhoto( - val photo: List + val photo: Photo ): CommonEvent diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/PhotoContent.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/PhotoContent.kt index ade1597e0d..9363a9f8f0 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/PhotoContent.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/PhotoContent.kt @@ -10,8 +10,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.MarkdownV2 import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup -import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize -import com.github.insanusmokrassar.TelegramBotAPI.types.files.biggest +import com.github.insanusmokrassar.TelegramBotAPI.types.files.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaCollectionContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent @@ -19,7 +18,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownV2Captions data class PhotoContent( - override val mediaCollection: List, + override val mediaCollection: Photo, override val caption: String? = null, override val captionEntities: List = emptyList() ) : MediaCollectionContent, MediaGroupContent { From 5e5dc105a57746a4ebc4662792527aa9cb939a12 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 20:36:29 +0600 Subject: [PATCH 12/53] refactor type inside edit messages extensions --- .../edit/caption/EditChatMessageCaption.kt | 20 +++++++++++++------ .../edit/media/EditChatMessageMedia.kt | 7 +++++-- .../requests/edit/text/EditChatMessageText.kt | 4 ++-- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt index c860bd5183..e3406789bd 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.caption +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media.MediaContentMessageResultDeserializer @@ -9,9 +10,12 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.CommonMessageImpl import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.PhotoContent import kotlinx.serialization.* const val editMessageCaptionMethod = "editMessageCaption" @@ -55,18 +59,22 @@ suspend fun RequestsExecutor.editMessageCaption( replyMarkup: InlineKeyboardMarkup? = null ) = editMessageCaption(chat.id, messageId, text, parseMode, replyMarkup) -suspend fun RequestsExecutor.editMessageCaption( +suspend fun RequestsExecutor.editMessageCaption( chatId: ChatId, - message: Message, + message: ContentMessage, text: String, parseMode: ParseMode? = null, replyMarkup: InlineKeyboardMarkup? = null -) = editMessageCaption(chatId, message.messageId, text, parseMode, replyMarkup) +): ContentMessage where T : CaptionedInput, T : MediaContent { + return editMessageCaption(chatId, message.messageId, text, parseMode, replyMarkup) +} -suspend fun RequestsExecutor.editMessageCaption( +suspend fun RequestsExecutor.editMessageCaption( chat: Chat, - message: Message, + message: ContentMessage, text: String, parseMode: ParseMode? = null, replyMarkup: InlineKeyboardMarkup? = null -) = editMessageCaption(chat.id, message.messageId, text, parseMode, replyMarkup) +): ContentMessage where T : CaptionedInput, T : MediaContent { + return editMessageCaption(chat.id, message.messageId, text, parseMode, replyMarkup) +} diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt index 81243ad9b0..e01842db23 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt @@ -9,9 +9,12 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMedia import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.CommonMessageImpl import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.PhotoContent import kotlinx.serialization.* const val editMessageMediaMethod = "editMessageMedia" @@ -61,14 +64,14 @@ suspend fun RequestsExecutor.editMessageMedia( suspend fun RequestsExecutor.editMessageMedia( chatId: ChatId, - message: Message, + message: ContentMessage, media: InputMedia, replyMarkup: InlineKeyboardMarkup? = null ) = editMessageMedia(chatId, message.messageId, media, replyMarkup) suspend fun RequestsExecutor.editMessageMedia( chat: Chat, - message: Message, + message: ContentMessage, media: InputMedia, replyMarkup: InlineKeyboardMarkup? = null ) = editMessageMedia(chat.id, message.messageId, media, replyMarkup) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt index b1e5ed9112..b18c23259e 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt @@ -60,7 +60,7 @@ suspend fun RequestsExecutor.editMessageText( suspend fun RequestsExecutor.editMessageText( chatId: ChatId, - message: Message, + message: ContentMessage, text: String, parseMode: ParseMode? = null, disableWebPagePreview: Boolean? = null, @@ -69,7 +69,7 @@ suspend fun RequestsExecutor.editMessageText( suspend fun RequestsExecutor.editMessageText( chat: Chat, - message: Message, + message: ContentMessage, text: String, parseMode: ParseMode? = null, disableWebPagePreview: Boolean? = null, From 2fd842746b3f79dd347197eaa09e92744b91171c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 21:05:16 +0600 Subject: [PATCH 13/53] add send audio extensions --- .../requests/send/media/SendAudio.kt | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAudio.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAudio.kt index 5facb438f5..19bf99e4df 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAudio.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAudio.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Performerable +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.* @@ -8,6 +9,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.files.AudioFile +import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize 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.media.AudioContent @@ -114,3 +117,138 @@ data class SendAudioFiles internal constructor( audioField to audio, thumbField to thumb ) + +suspend fun RequestsExecutor.sendAudio( + chatId: ChatIdentifier, + audio: FileId, + thumb: FileId? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendAudioData( + chatId, + audio.fileId, + thumb ?.fileId, + text, + parseMode, + duration, + performer, + title, + disableNotification, + replyToMessageId, + replyMarkup + ) +) + +suspend fun RequestsExecutor.sendAudio( + chatId: ChatIdentifier, + audio: AudioFile, + thumb: PhotoSize? = audio.thumb, + text: String? = null, + parseMode: ParseMode? = null, + title: String? = audio.title, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio( + chatId, audio.fileId, thumb ?.fileId, text, parseMode, audio.duration, audio.performer, title, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendAudio( + chatId: ChatIdentifier, + audio: MultipartFile, + thumb: FileId? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendAudioData( + chatId, null, thumb ?.fileId, text, parseMode, duration, performer, title, disableNotification, replyToMessageId, replyMarkup + ), + SendAudioFiles(audio) + ) +) + +suspend fun RequestsExecutor.sendAudio( + chatId: ChatIdentifier, + audio: MultipartFile, + thumb: MultipartFile? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendAudioData( + chatId, null, null, text, parseMode, duration, performer, title, disableNotification, replyToMessageId, replyMarkup + ), + SendAudioFiles(audio, thumb) + ) +) + +suspend fun RequestsExecutor.sendAudio( + chatId: ChatIdentifier, + audio: FileId, + thumb: MultipartFile, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendAudioData( + chatId, audio.fileId, null, text, parseMode, duration, performer, title, disableNotification, replyToMessageId, replyMarkup + ), + SendAudioFiles(null, thumb) + ) +) + +suspend fun RequestsExecutor.sendAudio( + chatId: ChatIdentifier, + audio: MultipartFile, + thumb: PhotoSize? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio( + chatId, audio, thumb ?.fileId , text, parseMode, duration, performer, title, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendAudio( + chatId: ChatIdentifier, + audio: AudioFile, + thumb: MultipartFile, + text: String? = null, + parseMode: ParseMode? = null, + title: String? = audio.title, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio( + chatId, audio.fileId, thumb, text, parseMode, audio.duration, audio.performer, title, disableNotification, replyToMessageId, replyMarkup +) From 56663d8e735d30d895a0722149610052f34010bd Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 21:15:17 +0600 Subject: [PATCH 14/53] add send document extensions --- .../requests/send/media/SendDocument.kt | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendDocument.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendDocument.kt index 44ff036ec2..e770bc6f4e 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendDocument.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendDocument.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.* @@ -7,6 +8,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.files.DocumentFile +import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize 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.media.DocumentContent @@ -98,3 +101,118 @@ data class SendDocumentFiles internal constructor( documentField to document, thumbField to thumb ) + +suspend fun RequestsExecutor.sendDocument( + chatId: ChatIdentifier, + document: FileId, + thumb: FileId? = null, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendDocumentData( + chatId, + document.fileId, + thumb ?.fileId, + text, + parseMode, + disableNotification, + replyToMessageId, + replyMarkup + ) +) + +suspend fun RequestsExecutor.sendDocument( + chatId: ChatIdentifier, + document: DocumentFile, + thumb: PhotoSize? = document.thumb, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendDocument( + chatId, document.fileId, thumb ?.fileId, text, parseMode, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendDocument( + chatId: ChatIdentifier, + document: MultipartFile, + thumb: FileId? = null, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendDocumentData( + chatId, null, thumb ?.fileId, text, parseMode, disableNotification, replyToMessageId, replyMarkup + ), + SendDocumentFiles(document) + ) +) + +suspend fun RequestsExecutor.sendDocument( + chatId: ChatIdentifier, + document: MultipartFile, + thumb: MultipartFile? = null, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendDocumentData( + chatId, null, null, text, parseMode, disableNotification, replyToMessageId, replyMarkup + ), + SendDocumentFiles(document, thumb) + ) +) + +suspend fun RequestsExecutor.sendDocument( + chatId: ChatIdentifier, + document: FileId, + thumb: MultipartFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendDocumentData( + chatId, document.fileId, null, text, parseMode, disableNotification, replyToMessageId, replyMarkup + ), + SendDocumentFiles(null, thumb) + ) +) + +suspend fun RequestsExecutor.sendDocument( + chatId: ChatIdentifier, + document: MultipartFile, + thumb: PhotoSize? = null, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendDocument( + chatId, document, thumb ?.fileId , text, parseMode, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendDocument( + chatId: ChatIdentifier, + document: DocumentFile, + thumb: MultipartFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendDocument( + chatId, document.fileId, thumb, text, parseMode, disableNotification, replyToMessageId, replyMarkup +) From 28eecfa3effb169dc18bcc46f50af719fb4fba77 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 21:23:59 +0600 Subject: [PATCH 15/53] add send animation extensions --- .../requests/send/media/SendAnimation.kt | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAnimation.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAnimation.kt index 0de73f8fdc..e8be272d5d 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAnimation.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAnimation.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.* @@ -7,6 +8,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.files.AnimationFile +import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize 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.media.AnimationContent @@ -112,3 +115,137 @@ data class SendAnimationFiles internal constructor( animationField to animation, thumbField to thumb ) + +suspend fun RequestsExecutor.sendAnimation( + chatId: ChatIdentifier, + animation: FileId, + thumb: FileId? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendAnimationData( + chatId, + animation.fileId, + thumb ?.fileId, + text, + parseMode, + duration, + width, + height, + disableNotification, + replyToMessageId, + replyMarkup + ) +) + +suspend fun RequestsExecutor.sendAnimation( + chatId: ChatIdentifier, + animation: AnimationFile, + thumb: PhotoSize? = animation.thumb, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation( + chatId, animation.fileId, thumb ?.fileId, text, parseMode, animation.duration, animation.width, animation.height, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendAnimation( + chatId: ChatIdentifier, + animation: MultipartFile, + thumb: FileId? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendAnimationData( + chatId, null, thumb ?.fileId, text, parseMode, duration, width, height, disableNotification, replyToMessageId, replyMarkup + ), + SendAnimationFiles(animation) + ) +) + +suspend fun RequestsExecutor.sendAnimation( + chatId: ChatIdentifier, + animation: MultipartFile, + thumb: MultipartFile? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendAnimationData( + chatId, null, null, text, parseMode, duration, width, height, disableNotification, replyToMessageId, replyMarkup + ), + SendAnimationFiles(animation, thumb) + ) +) + +suspend fun RequestsExecutor.sendAnimation( + chatId: ChatIdentifier, + animation: FileId, + thumb: MultipartFile, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendAnimationData( + chatId, animation.fileId, null, text, parseMode, duration, width, height, disableNotification, replyToMessageId, replyMarkup + ), + SendAnimationFiles(null, thumb) + ) +) + +suspend fun RequestsExecutor.sendAnimation( + chatId: ChatIdentifier, + animation: MultipartFile, + thumb: PhotoSize? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation( + chatId, animation, thumb ?.fileId , text, parseMode, duration, width, height, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendAnimation( + chatId: ChatIdentifier, + animation: AnimationFile, + thumb: MultipartFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation( + chatId, animation.fileId, thumb, text, parseMode, animation.duration, animation.width, animation.height, disableNotification, replyToMessageId, replyMarkup +) + From ff3ef6e957f806ef2ab2dd62b8f1499b3427d7e2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 21:27:42 +0600 Subject: [PATCH 16/53] add send voice extensions --- .../requests/send/media/SendVoice.kt | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVoice.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVoice.kt index a341372e5c..6f87306573 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVoice.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVoice.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.* @@ -7,6 +8,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.files.AudioFile +import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize 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.media.VoiceContent @@ -103,3 +106,125 @@ data class SendVoiceFiles internal constructor( voiceField to voice, thumbField to thumb ) + +suspend fun RequestsExecutor.sendVoice( + chatId: ChatIdentifier, + voice: FileId, + thumb: FileId? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendVoiceData( + chatId, + voice.fileId, + thumb ?.fileId, + text, + parseMode, + duration, + disableNotification, + replyToMessageId, + replyMarkup + ) +) + +suspend fun RequestsExecutor.sendVoice( + chatId: ChatIdentifier, + voice: AudioFile, + thumb: PhotoSize? = voice.thumb, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice( + chatId, voice.fileId, thumb ?.fileId, text, parseMode, voice.duration, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendVoice( + chatId: ChatIdentifier, + voice: MultipartFile, + thumb: FileId? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendVoiceData( + chatId, null, thumb ?.fileId, text, parseMode, duration, disableNotification, replyToMessageId, replyMarkup + ), + SendVoiceFiles(voice) + ) +) + +suspend fun RequestsExecutor.sendVoice( + chatId: ChatIdentifier, + voice: MultipartFile, + thumb: MultipartFile? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendVoiceData( + chatId, null, null, text, parseMode, duration, disableNotification, replyToMessageId, replyMarkup + ), + SendVoiceFiles(voice, thumb) + ) +) + +suspend fun RequestsExecutor.sendVoice( + chatId: ChatIdentifier, + voice: FileId, + thumb: MultipartFile, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendVoiceData( + chatId, voice.fileId, null, text, parseMode, duration, disableNotification, replyToMessageId, replyMarkup + ), + SendVoiceFiles(null, thumb) + ) +) + +suspend fun RequestsExecutor.sendVoice( + chatId: ChatIdentifier, + voice: MultipartFile, + thumb: PhotoSize? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice( + chatId, voice, thumb ?.fileId , text, parseMode, duration, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendVoice( + chatId: ChatIdentifier, + voice: AudioFile, + thumb: MultipartFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice( + chatId, voice.fileId, thumb, text, parseMode, voice.duration, disableNotification, replyToMessageId, replyMarkup +) + From 6d425cc0f67bb9e687278293f676dbe2ec9d3f7a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 21:36:18 +0600 Subject: [PATCH 17/53] add send video extensions --- .../requests/send/media/SendVideo.kt | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideo.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideo.kt index 97781a1f7a..6b88aecacc 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideo.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideo.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.* @@ -7,6 +8,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.files.VideoFile +import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize 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.media.VideoContent @@ -116,3 +119,141 @@ data class SendVideoFiles internal constructor( videoField to video, thumbField to thumb ) + +suspend fun RequestsExecutor.sendVideo( + chatId: ChatIdentifier, + video: FileId, + thumb: FileId? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendVideoData( + chatId, + video.fileId, + thumb ?.fileId, + text, + parseMode, + duration, + width, + height, + null, + disableNotification, + replyToMessageId, + replyMarkup + ) +) + +suspend fun RequestsExecutor.sendVideo( + chatId: ChatIdentifier, + video: VideoFile, + thumb: PhotoSize? = video.thumb, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo( + chatId, video.fileId, thumb ?.fileId, text, parseMode, video.duration, video.width, video.height, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendVideo( + chatId: ChatIdentifier, + video: MultipartFile, + thumb: FileId? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + supportStreaming: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendVideoData( + chatId, null, thumb ?.fileId, text, parseMode, duration, width, height, supportStreaming, disableNotification, replyToMessageId, replyMarkup + ), + SendVideoFiles(video) + ) +) + +suspend fun RequestsExecutor.sendVideo( + chatId: ChatIdentifier, + video: MultipartFile, + thumb: MultipartFile? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + supportStreaming: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendVideoData( + chatId, null, null, text, parseMode, duration, width, height, supportStreaming, disableNotification, replyToMessageId, replyMarkup + ), + SendVideoFiles(video, thumb) + ) +) + +suspend fun RequestsExecutor.sendVideo( + chatId: ChatIdentifier, + video: FileId, + thumb: MultipartFile, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendVideoData( + chatId, video.fileId, null, text, parseMode, duration, width, height, null, disableNotification, replyToMessageId, replyMarkup + ), + SendVideoFiles(null, thumb) + ) +) + +suspend fun RequestsExecutor.sendVideo( + chatId: ChatIdentifier, + video: MultipartFile, + thumb: PhotoSize? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + supportStreaming: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo( + chatId, video, thumb ?.fileId , text, parseMode, duration, width, height, supportStreaming, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendVideo( + chatId: ChatIdentifier, + video: VideoFile, + thumb: MultipartFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo( + chatId, video.fileId, thumb, text, parseMode, video.duration, video.width, video.height, disableNotification, replyToMessageId, replyMarkup +) + From 5475f27a24428d14ba37a9fde02014ce79e71782 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 21:41:46 +0600 Subject: [PATCH 18/53] add send video note extensions --- .../requests/send/media/SendVideoNote.kt | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideoNote.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideoNote.kt index e4e3d11bfd..0062f8c6bd 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideoNote.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideoNote.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.* @@ -7,6 +8,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize +import com.github.insanusmokrassar.TelegramBotAPI.types.files.VideoFile 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.media.VideoNoteContent @@ -111,3 +114,130 @@ data class SendVideoNoteFiles internal constructor( videoNoteField to videoNote, thumbField to thumb ) + +suspend fun RequestsExecutor.sendVideoNote( + chatId: ChatIdentifier, + videoNote: FileId, + thumb: FileId? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + size: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendVideoNoteData( + chatId, + videoNote.fileId, + thumb ?.fileId, + text, + parseMode, + duration, + size, + disableNotification, + replyToMessageId, + replyMarkup + ) +) + +suspend fun RequestsExecutor.sendVideoNote( + chatId: ChatIdentifier, + videoNote: VideoFile, + thumb: PhotoSize? = videoNote.thumb, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideoNote( + chatId, videoNote.fileId, thumb ?.fileId, text, parseMode, videoNote.duration, videoNote.width, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendVideoNote( + chatId: ChatIdentifier, + videoNote: MultipartFile, + thumb: FileId? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + size: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendVideoNoteData( + chatId, null, thumb ?.fileId, text, parseMode, duration, size, disableNotification, replyToMessageId, replyMarkup + ), + SendVideoNoteFiles(videoNote) + ) +) + +suspend fun RequestsExecutor.sendVideoNote( + chatId: ChatIdentifier, + videoNote: MultipartFile, + thumb: MultipartFile? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + size: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendVideoNoteData( + chatId, null, null, text, parseMode, duration, size, disableNotification, replyToMessageId, replyMarkup + ), + SendVideoNoteFiles(videoNote, thumb) + ) +) + +suspend fun RequestsExecutor.sendVideoNote( + chatId: ChatIdentifier, + videoNote: FileId, + thumb: MultipartFile, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + size: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + MultipartRequestImpl( + SendVideoNoteData( + chatId, videoNote.fileId, null, text, parseMode, duration, size, disableNotification, replyToMessageId, replyMarkup + ), + SendVideoNoteFiles(null, thumb) + ) +) + +suspend fun RequestsExecutor.sendVideoNote( + chatId: ChatIdentifier, + videoNote: MultipartFile, + thumb: PhotoSize? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + size: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideoNote( + chatId, videoNote, thumb ?.fileId , text, parseMode, duration, size, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendVideoNote( + chatId: ChatIdentifier, + videoNote: VideoFile, + thumb: MultipartFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideoNote( + chatId, videoNote.fileId, thumb, text, parseMode, videoNote.duration, videoNote.width, disableNotification, replyToMessageId, replyMarkup +) From 4ca8125637b3980cbc65decb21d2b168eb7aed51 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 22:32:20 +0600 Subject: [PATCH 19/53] add send location extensions and LiveLocation --- CHANGELOG.md | 1 + .../TelegramBotAPI/requests/LiveLocation.kt | 110 ++++++++++++++++++ .../requests/send/SendLocation.kt | 49 +++++++- 3 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/LiveLocation.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 01928c9549..6a0e26ee31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ * Ktor `1.3.0` -> `1.3.1` * Now it is possible to get updates by polling with custom executor engine * `CommonMultipartFileRequest` now is internal +* Added `LiveLocation` class for more useful tracking live locations ## 0.22.0 diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/LiveLocation.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/LiveLocation.kt new file mode 100644 index 0000000000..a769e86bc1 --- /dev/null +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/LiveLocation.kt @@ -0,0 +1,110 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests + +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor +import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation.EditChatMessageLiveLocation +import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation.StopChatMessageLiveLocation +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.soywiz.klock.DateTime +import com.soywiz.klock.TimeSpan +import io.ktor.utils.io.core.Closeable +import kotlinx.coroutines.* + +private val livePeriodDelayDouble = ((livePeriodLimit.last - 60L) * 1000L).toDouble() +class LiveLocation internal constructor( + private val scope: CoroutineScope, + private val requestsExecutor: RequestsExecutor, + private val chatId: ChatIdentifier, + private val messageId: MessageIdentifier, + location: Location +) : Closeable { + var isClosed: Boolean = false + private set + private var autoCloseTime = DateTime.now() + TimeSpan(livePeriodDelayDouble) + val leftUntilCloseMillis: TimeSpan + get() = autoCloseTime - DateTime.now() + private var updateJob: Job? = null + var lastLocation: Location = location + private set(value) { + field = value + updateJob ?.cancel() + updateJob = scope.launch { + autoCloseTime = DateTime.now() + TimeSpan(livePeriodDelayDouble) + delay(leftUntilCloseMillis.millisecondsLong) + updateJob = null + close() + } + } + + init { + this.lastLocation = location // required to init updateJob + } + + suspend fun updateLocation( + location: Location, + replyMarkup: InlineKeyboardMarkup? = null + ): Location { + if (!isClosed) { + lastLocation = requestsExecutor.execute( + EditChatMessageLiveLocation( + chatId, + messageId, + location.latitude, + location.longitude, + replyMarkup + ) + ).content.location + return lastLocation + } else { + error("LiveLocation is closed") + } + } + + override fun close() { + if (isClosed) { + return + } + isClosed = true + updateJob ?.cancel() + scope.launch { + requestsExecutor.execute( + StopChatMessageLiveLocation( + chatId, + messageId + ) + ) + } + } +} + +suspend fun RequestsExecutor.startLiveLocation( + scope: CoroutineScope, + chatId: ChatIdentifier, + latitude: Double, + longitude: Double, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +): LiveLocation { + val locationMessage = execute( + SendLocation( + chatId, + latitude, + longitude, + livePeriodLimit.last.toLong(), + disableNotification, + replyToMessageId, + replyMarkup + ) + ) + + return LiveLocation( + scope, + this, + chatId, + locationMessage.messageId, + locationMessage.content.location + ) +} 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 67ff01360f..f7e7d42c56 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 @@ -1,11 +1,20 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor +import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation.EditChatMessageLiveLocation +import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation.StopChatMessageLiveLocation 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.message.abstracts.ContentMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.LocationContent +import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.executeAsync +import com.soywiz.klock.DateTime +import com.soywiz.klock.TimeSpan +import io.ktor.utils.io.core.Closeable +import kotlinx.coroutines.* import kotlinx.serialization.* @@ -33,10 +42,48 @@ data class SendLocation( ReplyingMarkupSendMessageRequest>, PositionedSendMessageRequest> { - override fun method(): String = "sendLocation" override val resultDeserializer: DeserializationStrategy> get() = commonResultDeserializer override val requestSerializer: SerializationStrategy<*> get() = serializer() + + init { + if (livePeriod != null && livePeriod !in livePeriodLimit) { + error("Live period for sending location must be in $livePeriodLimit") + } + } } + +suspend fun RequestsExecutor.sendLocation( + chatId: ChatIdentifier, + latitude: Double, + longitude: Double, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendLocation( + chatId, + latitude, + longitude, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + replyMarkup = replyMarkup + ) +) + +suspend fun RequestsExecutor.sendLocation( + chatId: ChatIdentifier, + location: Location, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendLocation( + chatId, + location.latitude, + location.longitude, + disableNotification, + replyToMessageId, + replyMarkup +) From bc7cfc0d32bfb02f45bffca1f63a483aefea1e37 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 22:40:19 +0600 Subject: [PATCH 20/53] add send venue extensions --- .../TelegramBotAPI/requests/send/SendVenue.kt | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendVenue.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendVenue.kt index 18e3931cfe..d675b6d394 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendVenue.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendVenue.kt @@ -1,8 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.* 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.VenueContent @@ -73,3 +75,55 @@ fun Venue.toRequest( replyToMessageId, replyMarkup ) + +suspend fun RequestsExecutor.sendVenue( + chatId: ChatIdentifier, + latitude: Double, + longitude: Double, + title: String, + address: String, + foursquareId: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendVenue( + chatId, latitude, longitude, title, address, foursquareId, disableNotification, replyToMessageId, replyMarkup + ) +) + +suspend fun RequestsExecutor.sendVenue( + chat: Chat, + latitude: Double, + longitude: Double, + title: String, + address: String, + foursquareId: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVenue( + chat.id, latitude, longitude, title, address, foursquareId, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendVenue( + chatId: ChatIdentifier, + venue: Venue, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendVenue( + chatId, venue, disableNotification, replyToMessageId, replyMarkup + ) +) + +suspend fun RequestsExecutor.sendVenue( + chat: Chat, + venue: Venue, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVenue( + chat.id, venue, disableNotification, replyToMessageId, replyMarkup +) From 799eadd7a7ab21a1178747469d884619a2ef6584 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 22:44:26 +0600 Subject: [PATCH 21/53] add send contact extensions --- .../requests/send/SendContact.kt | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendContact.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendContact.kt index 51dff056f3..054ddc68a9 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendContact.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendContact.kt @@ -1,9 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.ReplyingMarkupSendMessageRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* 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.ContactContent @@ -66,3 +68,51 @@ fun Contact.toRequest( replyToMessageId, replyMarkup ) + +suspend fun RequestsExecutor.sendContact( + chatId: ChatIdentifier, + phoneNumber: String, + firstName: String, + lastName: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendContact( + chatId, phoneNumber, firstName, lastName, disableNotification, replyToMessageId, replyMarkup + ) +) + +suspend fun RequestsExecutor.sendContact( + chatId: ChatIdentifier, + contact: Contact, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendContact( + chatId, contact, disableNotification, replyToMessageId, replyMarkup + ) +) + +suspend fun RequestsExecutor.sendContact( + chat: Chat, + phoneNumber: String, + firstName: String, + lastName: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendContact( + chat.id, phoneNumber, firstName, lastName, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendContact( + chat: Chat, + contact: Contact, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendContact( + chat.id, contact, disableNotification, replyToMessageId, replyMarkup +) From f8ffd5fec33b2f2a08da489b0bc17614b467873f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 22:52:10 +0600 Subject: [PATCH 22/53] add send polls extensions --- .../requests/send/polls/SendPoll.kt | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt index 831d874ec7..b68320164f 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt @@ -1,9 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.polls +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.ReplyingMarkupSendMessageRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* 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.PollContent @@ -182,4 +184,66 @@ data class SendQuizPoll( "value is $correctOptionId") } } -} \ No newline at end of file +} + + +suspend fun RequestsExecutor.sendRegularPoll( + chatId: ChatIdentifier, + question: String, + options: List, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + allowMultipleAnswers: Boolean = false, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendRegularPoll( + chatId, question, options, isAnonymous, isClosed, allowMultipleAnswers, disableNotification, replyToMessageId, replyMarkup + ) +) + +suspend fun RequestsExecutor.sendRegularPoll( + chat: Chat, + question: String, + options: List, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + allowMultipleAnswers: Boolean = false, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendRegularPoll( + chat.id, question, options, isAnonymous, isClosed, allowMultipleAnswers, disableNotification, replyToMessageId, replyMarkup +) + + +suspend fun RequestsExecutor.sendQuizPoll( + chatId: ChatIdentifier, + question: String, + options: List, + correctOptionId: Int, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendQuizPoll( + chatId, question, options, correctOptionId, isAnonymous, isClosed, disableNotification, replyToMessageId, replyMarkup + ) +) + +suspend fun RequestsExecutor.sendQuizPoll( + chat: Chat, + question: String, + options: List, + correctOptionId: Int, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll( + chat.id, question, options, correctOptionId, isAnonymous, isClosed, disableNotification, replyToMessageId, replyMarkup +) From cc433d40913daabc25b0b74d7e42f62520f2a73c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 23:06:29 +0600 Subject: [PATCH 23/53] add send bot action extensions --- .../requests/send/SendAction.kt | 100 +++++++++++++++++- .../TelegramBotAPI/types/actions/BotAction.kt | 12 +++ 2 files changed, 111 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendAction.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendAction.kt index 4e94bd44fd..95de49a2ed 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendAction.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendAction.kt @@ -1,8 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendChatMessageRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.actions.BotAction +import com.github.insanusmokrassar.TelegramBotAPI.types.actions.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -22,3 +24,99 @@ data class SendAction( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + + +suspend fun RequestsExecutor.sendBotAction( + chatId: ChatIdentifier, + action: BotAction +) = execute( + SendAction(chatId, action) +) + +suspend fun RequestsExecutor.sendBotAction( + chat: Chat, + action: BotAction +) = sendBotAction(chat.id, action) + + +suspend fun RequestsExecutor.sendActionTyping( + chatId: ChatIdentifier +) = sendBotAction(chatId, TypingAction) + +suspend fun RequestsExecutor.sendActionUploadPhoto( + chatId: ChatIdentifier +) = sendBotAction(chatId, UploadPhotoAction) + +suspend fun RequestsExecutor.sendActionRecordVideo( + chatId: ChatIdentifier +) = sendBotAction(chatId, RecordVideoAction) + +suspend fun RequestsExecutor.sendActionUploadVideo( + chatId: ChatIdentifier +) = sendBotAction(chatId, UploadVideoAction) + +suspend fun RequestsExecutor.sendActionRecordAudio( + chatId: ChatIdentifier +) = sendBotAction(chatId, RecordAudioAction) + +suspend fun RequestsExecutor.sendActionUploadAudio( + chatId: ChatIdentifier +) = sendBotAction(chatId, UploadAudioAction) + +suspend fun RequestsExecutor.sendActionUploadDocument( + chatId: ChatIdentifier +) = sendBotAction(chatId, UploadDocumentAction) + +suspend fun RequestsExecutor.sendActionFindLocation( + chatId: ChatIdentifier +) = sendBotAction(chatId, FindLocationAction) + +suspend fun RequestsExecutor.sendActionRecordVideoNote( + chatId: ChatIdentifier +) = sendBotAction(chatId, RecordVideoNoteAction) + +suspend fun RequestsExecutor.sendActionUploadVideoNote( + chatId: ChatIdentifier +) = sendBotAction(chatId, UploadVideoNoteAction) + + +suspend fun RequestsExecutor.sendActionTyping( + chat: Chat +) = sendBotAction(chat, TypingAction) + +suspend fun RequestsExecutor.sendActionUploadPhoto( + chat: Chat +) = sendBotAction(chat, UploadPhotoAction) + +suspend fun RequestsExecutor.sendActionRecordVideo( + chat: Chat +) = sendBotAction(chat, RecordVideoAction) + +suspend fun RequestsExecutor.sendActionUploadVideo( + chat: Chat +) = sendBotAction(chat, UploadVideoAction) + +suspend fun RequestsExecutor.sendActionRecordAudio( + chat: Chat +) = sendBotAction(chat, RecordAudioAction) + +suspend fun RequestsExecutor.sendActionUploadAudio( + chat: Chat +) = sendBotAction(chat, UploadAudioAction) + +suspend fun RequestsExecutor.sendActionUploadDocument( + chat: Chat +) = sendBotAction(chat, UploadDocumentAction) + +suspend fun RequestsExecutor.sendActionFindLocation( + chat: Chat +) = sendBotAction(chat, FindLocationAction) + +suspend fun RequestsExecutor.sendActionRecordVideoNote( + chat: Chat +) = sendBotAction(chat, RecordVideoNoteAction) + +suspend fun RequestsExecutor.sendActionUploadVideoNote( + chat: Chat +) = sendBotAction(chat, UploadVideoNoteAction) + diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/actions/BotAction.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/actions/BotAction.kt index 8563a874c7..5f0915a211 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/actions/BotAction.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/actions/BotAction.kt @@ -23,6 +23,8 @@ internal object BotActionSerializer: KSerializer { UploadAudioAction.actionName -> UploadAudioAction UploadDocumentAction.actionName -> UploadDocumentAction FindLocationAction.actionName -> FindLocationAction + RecordVideoNoteAction.actionName -> RecordVideoNoteAction + UploadVideoNoteAction.actionName -> UploadVideoNoteAction else -> throw IllegalStateException("Unknown action type: $actionName") } } @@ -71,3 +73,13 @@ object UploadDocumentAction : BotAction() { object FindLocationAction : BotAction() { override val actionName: String = "find_location" } + +@Serializable(BotActionSerializer::class) +object RecordVideoNoteAction : BotAction() { + override val actionName: String = "record_video_note" +} + +@Serializable(BotActionSerializer::class) +object UploadVideoNoteAction : BotAction() { + override val actionName: String = "upload_video_note" +} From b4d0ca507b4164d3cc745bdf65dfaa230da29bfe Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 23:08:13 +0600 Subject: [PATCH 24/53] add get user profile photos extensions --- .../requests/get/GetUserProfilePhotos.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetUserProfilePhotos.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetUserProfilePhotos.kt index f9270a7571..d7061b329f 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetUserProfilePhotos.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetUserProfilePhotos.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.get +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import kotlinx.serialization.* @@ -28,3 +29,19 @@ data class GetUserProfilePhotos( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.getUserProfilePhotos( + userId: UserId, + offset: Int? = null, + limit: Int? = null +) = execute( + GetUserProfilePhotos( + userId, offset, limit + ) +) + +suspend fun RequestsExecutor.getUserProfilePhotos( + user: User, + offset: Int? = null, + limit: Int? = null +) = getUserProfilePhotos(user.id, offset, limit) From be4043f3c21429d1c599f0fb398d9fec51ee9e6f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 23:09:01 +0600 Subject: [PATCH 25/53] fix in RequestsExecutor#getUserProfilePhotos extension --- .../TelegramBotAPI/requests/get/GetUserProfilePhotos.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetUserProfilePhotos.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetUserProfilePhotos.kt index d7061b329f..3aba2e74fc 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetUserProfilePhotos.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetUserProfilePhotos.kt @@ -41,7 +41,7 @@ suspend fun RequestsExecutor.getUserProfilePhotos( ) suspend fun RequestsExecutor.getUserProfilePhotos( - user: User, + user: CommonUser, offset: Int? = null, limit: Int? = null ) = getUserProfilePhotos(user.id, offset, limit) From 86f1e3ea365871b2e894b08b2b3e0fd5ee2f4608 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 23:12:49 +0600 Subject: [PATCH 26/53] add get file info extensions --- .../TelegramBotAPI/requests/get/GetFile.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetFile.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetFile.kt index 54e5e00a1f..7cdc4b0791 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetFile.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/get/GetFile.kt @@ -1,8 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.get +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.files.PathedFile +import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.TelegramMediaFile import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.fileIdField import kotlinx.serialization.* @@ -17,3 +19,13 @@ data class GetFile( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.getFileAdditionalInfo( + fileId: FileId +) = execute( + GetFile(fileId) +) + +suspend fun RequestsExecutor.getFileAdditionalInfo( + file: TelegramMediaFile +) = getFileAdditionalInfo(file.fileId) From 69f81785bfdd69e4d25646e24bbfff3c6aaa096e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 23:15:13 +0600 Subject: [PATCH 27/53] rename RequestsExecutor#setChatPermissions -> RequestsExecutor#setDefaultChatMembersPermissions --- .../requests/chat/modify/SetChatPermissions.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt index 57fa318efb..b365d7fae9 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt @@ -5,7 +5,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -24,12 +23,12 @@ data class SetChatPermissions ( get() = serializer() } -suspend fun RequestsExecutor.setChatPermissions( +suspend fun RequestsExecutor.setDefaultChatMembersPermissions( chatId: ChatIdentifier, permissions: ChatPermissions ) = execute(SetChatPermissions(chatId, permissions)) -suspend fun RequestsExecutor.setChatPermissions( +suspend fun RequestsExecutor.setDefaultChatMembersPermissions( chat: PublicChat, permissions: ChatPermissions -) = setChatPermissions(chat.id, permissions) +) = setDefaultChatMembersPermissions(chat.id, permissions) From 02fa83c92afa1c9734bb15ef8748458ce4196458 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 23:17:55 +0600 Subject: [PATCH 28/53] small refactor in PinChatMessage --- .../TelegramBotAPI/requests/chat/modify/PinChatMessage.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt index ef1f239cad..2996b448d7 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt @@ -42,7 +42,7 @@ suspend fun RequestsExecutor.pinChatMessage( chatId: ChatIdentifier, message: Message, disableNotification: Boolean = false -) = execute(PinChatMessage(chatId, message.messageId, disableNotification)) +) = pinChatMessage(chatId, message.messageId, disableNotification) suspend fun RequestsExecutor.pinChatMessage( chat: PublicChat, From 679f282bd249e503382f01b6d0082adb224bf67e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 23:28:46 +0600 Subject: [PATCH 29/53] refactor delete extensions --- .../TelegramBotAPI/requests/DeleteMessage.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt index 42c8b8bbed..a7df40851a 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt @@ -37,11 +37,9 @@ suspend fun RequestsExecutor.deleteMessage( ) = deleteMessage(chat.id, messageId) suspend fun RequestsExecutor.deleteMessage( - chatId: ChatId, message: Message -) = deleteMessage(chatId, message.messageId) +) = deleteMessage(message.chat, message.messageId) -suspend fun RequestsExecutor.deleteMessage( - chat: Chat, - message: Message -) = deleteMessage(chat.id, message.messageId) +suspend fun Message.delete( + requestsExecutor: RequestsExecutor +) = requestsExecutor.deleteMessage(this) From 28898ea2d4562e6f0707de6a5ff819dd3e10b96b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 23:33:58 +0600 Subject: [PATCH 30/53] add sendSticker extensions --- .../requests/send/media/SendSticker.kt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendSticker.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendSticker.kt index 574e3a5eac..366a2fb3e0 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendSticker.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendSticker.kt @@ -1,10 +1,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.ReplyingMarkupSendMessageRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.MultipartRequestImpl import com.github.insanusmokrassar.TelegramBotAPI.types.* 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.media.StickerContent @@ -64,3 +67,42 @@ data class SendStickerByFile internal constructor( } +suspend fun RequestsExecutor.sendSticker( + chatId: ChatIdentifier, + sticker: FileId, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendStickerByFileId(chatId, sticker, disableNotification, replyToMessageId, replyMarkup) +) + +suspend fun RequestsExecutor.sendSticker( + chatId: ChatIdentifier, + sticker: MultipartFile, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendStickerByFile( + SendStickerByFileId(chatId, null, disableNotification, replyToMessageId, replyMarkup), + sticker + ) +) + +suspend fun RequestsExecutor.sendSticker( + chat: Chat, + sticker: FileId, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendSticker(chat.id, sticker, disableNotification, replyToMessageId, replyMarkup) + +suspend fun RequestsExecutor.sendSticker( + chat: Chat, + sticker: MultipartFile, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendSticker(chat.id, sticker, disableNotification, replyToMessageId, replyMarkup) + From 3a0be49cc5e01499c76ee97241eabfdd6847f538 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 23:35:51 +0600 Subject: [PATCH 31/53] additions in sendSticker --- .../requests/send/media/SendSticker.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendSticker.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendSticker.kt index 366a2fb3e0..b431eec650 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendSticker.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendSticker.kt @@ -8,6 +8,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.Multi import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.files.Sticker 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.media.StickerContent @@ -106,3 +107,21 @@ suspend fun RequestsExecutor.sendSticker( replyMarkup: KeyboardMarkup? = null ) = sendSticker(chat.id, sticker, disableNotification, replyToMessageId, replyMarkup) +suspend fun RequestsExecutor.sendSticker( + chatId: ChatIdentifier, + sticker: Sticker, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendSticker( + chatId, sticker.fileId, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendSticker( + chat: Chat, + sticker: Sticker, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendSticker(chat.id, sticker.fileId, disableNotification, replyToMessageId, replyMarkup) + From 2399dc0d0ade2a537e47853e3529d7af48308073 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 23:38:37 +0600 Subject: [PATCH 32/53] add get sticker set extensions --- .../TelegramBotAPI/requests/get/GetStickerSet.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 41fc2f031a..6e587a7bc6 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 @@ -1,6 +1,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.get +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.files.Sticker import com.github.insanusmokrassar.TelegramBotAPI.types.stickerSetNameField import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.StickerSet import kotlinx.serialization.* @@ -16,3 +18,15 @@ data class GetStickerSet( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.getStickerSet( + name: String +) = execute( + GetStickerSet(name) +) + +suspend fun RequestsExecutor.getStickerSet( + sticker: Sticker +) = execute( + GetStickerSet(sticker.stickerSetName ?: error("Sticker must contains stickerSetName to be correctly used in getStickerSet method")) +) From 269a4dd707b929fd946912f68d365aa6922c25c9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 23:39:57 +0600 Subject: [PATCH 33/53] add upload sticker file extensions --- .../requests/stickers/UploadStickerFile.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/UploadStickerFile.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/UploadStickerFile.kt index 967f3682c6..43fc8b5f5a 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/UploadStickerFile.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/UploadStickerFile.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* @@ -27,3 +28,18 @@ data class UploadStickerFile( override val resultDeserializer: DeserializationStrategy get() = File.serializer() } + + +suspend fun RequestsExecutor.uploadStickerFile( + userId: UserId, + sticker: MultipartFile +) = execute( + UploadStickerFile(userId, sticker) +) + +suspend fun RequestsExecutor.uploadStickerFile( + user: CommonUser, + sticker: MultipartFile +) = execute( + UploadStickerFile(user.id, sticker) +) From 09c623c1d78b0ffc97b777a8589edb1ce97b947a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 23:46:16 +0600 Subject: [PATCH 34/53] add create new sticker set extensions --- .../requests/stickers/CreateNewStickerSet.kt | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStickerSet.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStickerSet.kt index b02b967fc3..e32a92ebeb 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStickerSet.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStickerSet.kt @@ -1,7 +1,9 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.MultipartRequestImpl import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition @@ -51,3 +53,52 @@ data class CreateNewStickerSet internal constructor( override fun method(): String = "createNewStickerSet" } + + +suspend fun RequestsExecutor.createNewStickerSet( + userId: UserId, + name: String, + sticker: FileId, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = execute( + CreateNewStickerSet(userId, name, emojis, sticker, containsMasks, maskPosition) +) + +suspend fun RequestsExecutor.createNewStickerSet( + userId: UserId, + name: String, + sticker: MultipartFile, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = execute( + CommonMultipartFileRequest( + CreateNewStickerSet(userId, name, emojis, null, containsMasks, maskPosition), + mapOf(pngStickerField to sticker) + ) +) + + +suspend fun RequestsExecutor.createNewStickerSet( + user: CommonUser, + name: String, + sticker: FileId, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = createNewStickerSet( + user.id, name, sticker, emojis, containsMasks, maskPosition +) + +suspend fun RequestsExecutor.createNewStickerSet( + user: CommonUser, + name: String, + sticker: MultipartFile, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = createNewStickerSet( + user.id, name, sticker, emojis, containsMasks, maskPosition +) From 945dd05cfda7c0712df6500731ac5bc11282606c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 23:54:14 +0600 Subject: [PATCH 35/53] add add sticker to set and set sticker position in set extensions --- .../requests/stickers/AddStickerToSet.kt | 89 +++++++++++++++++++ .../stickers/SetStickerPositionInSet.kt | 20 +++++ 2 files changed, 109 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStickerToSet.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStickerToSet.kt index 113ad5966e..ac09f673fd 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStickerToSet.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStickerToSet.kt @@ -1,10 +1,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition +import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.StickerSet import kotlinx.serialization.* fun AddStickerToSet( @@ -48,3 +50,90 @@ data class AddStickerToSet internal constructor( override fun method(): String = "addStickerToSet" } + +suspend fun RequestsExecutor.addStickerToSet( + userId: UserId, + stickerSetName: String, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = execute( + AddStickerToSet( + userId, stickerSetName, emojis, sticker, maskPosition + ) +) + +suspend fun RequestsExecutor.addStickerToSet( + userId: UserId, + stickerSetName: String, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = execute( + CommonMultipartFileRequest( + AddStickerToSet( + userId, stickerSetName, emojis, null, maskPosition + ), + mapOf(pngStickerField to sticker) + ) +) + +suspend fun RequestsExecutor.addStickerToSet( + user: CommonUser, + stickerSetName: String, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = addStickerToSet( + user.id, stickerSetName, sticker, emojis, maskPosition +) + +suspend fun RequestsExecutor.addStickerToSet( + user: CommonUser, + stickerSetName: String, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = addStickerToSet( + user.id, stickerSetName, sticker, emojis, maskPosition +) + +suspend fun RequestsExecutor.addStickerToSet( + userId: UserId, + stickerSet: StickerSet, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = addStickerToSet( + userId, stickerSet.name, sticker, emojis, maskPosition +) + +suspend fun RequestsExecutor.addStickerToSet( + userId: UserId, + stickerSet: StickerSet, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = addStickerToSet( + userId, stickerSet.name, sticker, emojis, maskPosition +) + +suspend fun RequestsExecutor.addStickerToSet( + user: CommonUser, + stickerSet: StickerSet, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = addStickerToSet( + user.id, stickerSet.name, sticker, emojis, maskPosition +) + +suspend fun RequestsExecutor.addStickerToSet( + user: CommonUser, + stickerSet: StickerSet, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = addStickerToSet( + user.id, stickerSet.name, sticker, emojis, maskPosition +) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerPositionInSet.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerPositionInSet.kt index cf2fcd7150..90484177cf 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerPositionInSet.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerPositionInSet.kt @@ -1,7 +1,9 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.files.Sticker import com.github.insanusmokrassar.TelegramBotAPI.types.positionField import com.github.insanusmokrassar.TelegramBotAPI.types.stickerField import kotlinx.serialization.* @@ -26,3 +28,21 @@ data class SetStickerPositionInSet( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.setStickerPositionInSet( + sticker: FileId, + position: Int +) = execute( + SetStickerPositionInSet( + sticker, + position + ) +) + +suspend fun RequestsExecutor.setStickerPositionInSet( + sticker: Sticker, + position: Int +) = setStickerPositionInSet( + sticker.fileId, + position +) From dfe5595fd30a8e48e6aa03dbe73c4d58b295c2f8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Feb 2020 23:55:17 +0600 Subject: [PATCH 36/53] add delete sticker from set --- .../requests/stickers/DeleteStickerFromSet.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/DeleteStickerFromSet.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/DeleteStickerFromSet.kt index 91d8cf2ac3..daea8cbf4e 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/DeleteStickerFromSet.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/DeleteStickerFromSet.kt @@ -1,7 +1,9 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.files.Sticker import com.github.insanusmokrassar.TelegramBotAPI.types.stickerField import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -17,3 +19,19 @@ data class DeleteStickerFromSet( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + + + +suspend fun RequestsExecutor.deleteStickerFromSet( + sticker: FileId +) = execute( + DeleteStickerFromSet( + sticker + ) +) + +suspend fun RequestsExecutor.deleteStickerFromSet( + sticker: Sticker +) = deleteStickerFromSet( + sticker.fileId +) From 0dd632eb468aef449cbd34efdec58f2176e2da38 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 00:01:21 +0600 Subject: [PATCH 37/53] add send invoice extensions --- .../requests/send/payments/SendInvoice.kt | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/payments/SendInvoice.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/payments/SendInvoice.kt index 768ddc322f..6367daf221 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/payments/SendInvoice.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/payments/SendInvoice.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.payments import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.* +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup @@ -100,4 +101,50 @@ data class SendInvoice( photoWidth = null photoHeight = null } -} \ No newline at end of file +} + +suspend fun RequestsExecutor.sendInvoice( + chatId: ChatId, + title: String, + description: String, + payload: String, + providerToken: String, + startParameter: StartParameter, + currency: Currency, + prices: List, + providerData: String? = null, + requireName: Boolean = false, + requirePhoneNumber: Boolean = false, + requireEmail: Boolean = false, + requireShippingAddress: Boolean = false, + shouldSendPhoneNumberToProvider: Boolean = false, + shouldSendEmailToProvider: Boolean = false, + priceDependOnShipAddress: Boolean = false, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = execute( + SendInvoice(chatId, title, description, payload, providerToken, startParameter, currency, prices, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, replyMarkup) +) + +suspend fun RequestsExecutor.sendInvoice( + user: CommonUser, + title: String, + description: String, + payload: String, + providerToken: String, + startParameter: StartParameter, + currency: Currency, + prices: List, + providerData: String? = null, + requireName: Boolean = false, + requirePhoneNumber: Boolean = false, + requireEmail: Boolean = false, + requireShippingAddress: Boolean = false, + shouldSendPhoneNumberToProvider: Boolean = false, + shouldSendEmailToProvider: Boolean = false, + priceDependOnShipAddress: Boolean = false, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = sendInvoice(user.id, title, description, payload, providerToken, startParameter, currency, prices, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, replyMarkup) From a846d0031cc6b55799552d78cadfadf0cc057a01 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 00:15:28 +0600 Subject: [PATCH 38/53] updates in sendInvoice and its extensions --- CHANGELOG.md | 3 +++ .../requests/send/payments/SendInvoice.kt | 13 ++++++++---- .../types/message/CommonMessageImpl.kt | 3 ++- .../types/message/RawMessage.kt | 4 ++-- .../message/payments/InvoiceOfPayment.kt | 20 ++++++++++++++++++- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a0e26ee31..7ca5dcc7a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,9 @@ * Now it is possible to get updates by polling with custom executor engine * `CommonMultipartFileRequest` now is internal * Added `LiveLocation` class for more useful tracking live locations +* `InvoiceOfPayment` now is `MessageContent` instead of `PaymentInfo` +* `SendInvoice` now return `ContentMessage` +* `paymentInfo` inside of `CommonMessageImpl` now can be set only to `SuccessfulPaymentInfo` ## 0.22.0 diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/payments/SendInvoice.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/payments/SendInvoice.kt index 6367daf221..8a54257331 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/payments/SendInvoice.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/payments/SendInvoice.kt @@ -5,13 +5,18 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup -import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.PhotoContent +import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.InvoiceOfPayment import com.github.insanusmokrassar.TelegramBotAPI.types.payments.LabeledPrice import com.github.insanusmokrassar.TelegramBotAPI.types.payments.LabeledPricesSerializer import com.github.insanusmokrassar.TelegramBotAPI.types.payments.abstracts.* import kotlinx.serialization.* +private val invoiceMessageSerializer: DeserializationStrategy> + = TelegramBotAPIMessageDeserializationStrategyClass() + /** * @param providerData - JSON-ENCODED FIELD */ @@ -62,10 +67,10 @@ data class SendInvoice( DisableNotification, ReplyMessageId, ReplyMarkup, - SendMessageRequest { + SendMessageRequest> { override fun method(): String = "sendInvoice" - override val resultDeserializer: DeserializationStrategy - get() = TelegramBotAPIMessageDeserializationStrategy + override val resultDeserializer: DeserializationStrategy> + get() = invoiceMessageSerializer override val requestSerializer: SerializationStrategy<*> get() = serializer() diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt index d54fcec119..3dd4192b14 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt @@ -6,6 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMa import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent +import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.SuccessfulPaymentInfo import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.abstracts.PaymentInfo import com.soywiz.klock.DateTime @@ -19,5 +20,5 @@ data class CommonMessageImpl( override val forwardInfo: ForwardInfo?, override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup?, - val paymentInfo: PaymentInfo? + val paymentInfo: SuccessfulPaymentInfo? ) : Message, CommonMessage, FromUserMessage \ No newline at end of file diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt index a900382e94..05877079c7 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt @@ -130,6 +130,7 @@ internal data class RawMessage( location != null -> LocationContent(location) venue != null -> VenueContent(venue) poll != null -> PollContent(poll) + invoice != null -> InvoiceOfPayment(invoice) else -> null } } @@ -175,9 +176,8 @@ internal data class RawMessage( } } - private val paymentInfo: PaymentInfo? by lazy { + private val paymentInfo: SuccessfulPaymentInfo? by lazy { when { - invoice != null -> InvoiceOfPayment(invoice) successful_payment != null -> SuccessfulPaymentInfo(successful_payment) else -> null } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/payments/InvoiceOfPayment.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/payments/InvoiceOfPayment.kt index 7f90a9f438..3c177554af 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/payments/InvoiceOfPayment.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/payments/InvoiceOfPayment.kt @@ -1,8 +1,26 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.payments +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.payments.SendInvoice +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.abstracts.PaymentInfo import com.github.insanusmokrassar.TelegramBotAPI.types.payments.Invoice data class InvoiceOfPayment( val invoice: Invoice -) : PaymentInfo +) : MessageContent { + override fun createResend( + chatId: ChatIdentifier, + disableNotification: Boolean, + replyToMessageId: MessageIdentifier?, + replyMarkup: KeyboardMarkup? + ): Request> { + error("Unfortunately, currently InvoiceOfPayment can not be resend due to requirement of additional parameters," + + " which can't be provided during the call of this method") + } +} From dcfa198c8cca94eda02d1a34d9601e5bc65eff58 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 00:25:24 +0600 Subject: [PATCH 39/53] send game and other extensions --- .../requests/games/SetGameScoreByChatId.kt | 69 +++++++++++++++++++ .../requests/send/games/SendGame.kt | 47 ++++++++++++- 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByChatId.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByChatId.kt index 7cb00e4dc8..36c157a8ec 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByChatId.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByChatId.kt @@ -1,8 +1,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.SetGameScore import com.github.insanusmokrassar.TelegramBotAPI.types.* +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.GameContent import kotlinx.serialization.* @Serializable @@ -23,3 +27,68 @@ data class SetGameScoreByChatId ( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + + +suspend fun RequestsExecutor.setGameScore( + userId: UserId, + score: Long, + chatId: ChatId, + messageId: MessageIdentifier, + force: Boolean = false, + disableEditMessage: Boolean = false +) = execute( + SetGameScoreByChatId(userId, score, chatId, messageId, force, disableEditMessage) +) + +suspend fun RequestsExecutor.setGameScore( + user: CommonUser, + score: Long, + chatId: ChatId, + messageId: MessageIdentifier, + force: Boolean = false, + disableEditMessage: Boolean = false +) = setGameScore( + user.id, score, chatId, messageId, force, disableEditMessage +) + +suspend fun RequestsExecutor.setGameScore( + userId: UserId, + score: Long, + chat: Chat, + messageId: MessageIdentifier, + force: Boolean = false, + disableEditMessage: Boolean = false +) = setGameScore( + userId, score, chat.id, messageId, force, disableEditMessage +) + +suspend fun RequestsExecutor.setGameScore( + user: CommonUser, + score: Long, + chat: Chat, + messageId: MessageIdentifier, + force: Boolean = false, + disableEditMessage: Boolean = false +) = setGameScore( + user.id, score, chat.id, messageId, force, disableEditMessage +) + +suspend fun RequestsExecutor.setGameScore( + userId: UserId, + score: Long, + message: ContentMessage, + force: Boolean = false, + disableEditMessage: Boolean = false +) = setGameScore( + userId, score, message.chat.id, message.messageId, force, disableEditMessage +) + +suspend fun RequestsExecutor.setGameScore( + user: CommonUser, + score: Long, + message: ContentMessage, + force: Boolean = false, + disableEditMessage: Boolean = false +) = setGameScore( + user.id, score, message.chat.id, message.messageId, force, disableEditMessage +) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/games/SendGame.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/games/SendGame.kt index 29edbdd2a6..d254bc29ba 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/games/SendGame.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/games/SendGame.kt @@ -1,9 +1,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.games import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ReplyMarkup +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.games.Game 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.GameContent @@ -31,4 +34,46 @@ data class SendGame ( get() = commonResultDeserializer override val requestSerializer: SerializationStrategy<*> get() = serializer() -} \ No newline at end of file +} + +suspend fun RequestsExecutor.sendGame( + chatId: ChatIdentifier, + gameShortName: String, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendGame( + chatId, gameShortName, disableNotification, replyToMessageId, replyMarkup + ) +) + +suspend fun RequestsExecutor.sendGame( + chat: Chat, + gameShortName: String, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendGame( + chat.id, gameShortName, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendGame( + chatId: ChatIdentifier, + game: Game, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendGame( + chatId, game.title, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendGame( + chat: Chat, + game: Game, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendGame( + chat.id, game.title, disableNotification, replyToMessageId, replyMarkup +) From e7bdc852797f7cbb7af9406431b988edaecbcf16 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 00:29:50 +0600 Subject: [PATCH 40/53] precomplete of games extensions --- .../requests/games/GetGameHighScoresByChat.kt | 51 +++++++++++++++++++ .../GetGameHighScoresByInlineMessageId.kt | 15 ++++++ .../games/SetGameScoreByInlineMessageId.kt | 21 ++++++++ 3 files changed, 87 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByChat.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByChat.kt index d1cd6effd5..ca2f1256ec 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByChat.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByChat.kt @@ -1,8 +1,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.GetGameHighScores import com.github.insanusmokrassar.TelegramBotAPI.types.* +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.GameContent import kotlinx.serialization.* @Serializable @@ -17,3 +21,50 @@ data class GetGameHighScoresByChat ( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + + +suspend fun RequestsExecutor.getGameScore( + userId: UserId, + chatId: ChatId, + messageId: MessageIdentifier +) = execute( + GetGameHighScoresByChat(userId, chatId, messageId) +) + +suspend fun RequestsExecutor.getGameScore( + user: CommonUser, + chatId: ChatId, + messageId: MessageIdentifier +) = getGameScore( + user.id, chatId, messageId +) + +suspend fun RequestsExecutor.getGameScore( + userId: UserId, + chat: Chat, + messageId: MessageIdentifier +) = getGameScore( + userId, chat.id, messageId +) + +suspend fun RequestsExecutor.getGameScore( + user: CommonUser, + chat: Chat, + messageId: MessageIdentifier +) = getGameScore( + user.id, chat.id, messageId +) + +suspend fun RequestsExecutor.getGameScore( + userId: UserId, + message: ContentMessage +) = getGameScore( + userId, message.chat.id, message.messageId +) + +suspend fun RequestsExecutor.getGameScore( + user: CommonUser, + message: ContentMessage +) = getGameScore( + user.id, message.chat.id, message.messageId +) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByInlineMessageId.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByInlineMessageId.kt index 7e35cbce06..c7938b5347 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByInlineMessageId.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByInlineMessageId.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.InlineMessageAction +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.GetGameHighScores import com.github.insanusmokrassar.TelegramBotAPI.types.* import kotlinx.serialization.* @@ -15,3 +16,17 @@ data class GetGameHighScoresByInlineMessageId ( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.getGameScore( + userId: UserId, + inlineMessageId: InlineMessageIdentifier +) = execute( + GetGameHighScoresByInlineMessageId( + userId, inlineMessageId + ) +) + +suspend fun RequestsExecutor.getGameScore( + user: CommonUser, + inlineMessageId: InlineMessageIdentifier +) = getGameScore(user.id, inlineMessageId) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByInlineMessageId.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByInlineMessageId.kt index 23deee5967..9a6794c826 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByInlineMessageId.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByInlineMessageId.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.InlineMessageAction +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.SetGameScore import com.github.insanusmokrassar.TelegramBotAPI.types.* import kotlinx.serialization.* @@ -21,3 +22,23 @@ data class SetGameScoreByInlineMessageId ( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.setGameScore( + userId: UserId, + score: Long, + inlineMessageId: InlineMessageIdentifier, + force: Boolean = false, + disableEditMessage: Boolean = false +) = execute( + SetGameScoreByInlineMessageId( + userId, score, inlineMessageId, force, disableEditMessage + ) +) + +suspend fun RequestsExecutor.setGameScore( + user: CommonUser, + score: Long, + inlineMessageId: InlineMessageIdentifier, + force: Boolean = false, + disableEditMessage: Boolean = false +) = setGameScore(user.id, score, inlineMessageId, force, disableEditMessage) From c7d5fdd2e0a92a05f7448ce4f95c8227f4d7f41b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 00:40:47 +0600 Subject: [PATCH 41/53] fill edit and stop live location methods --- .../TelegramBotAPI/requests/LiveLocation.kt | 42 ++++++--------- .../EditChatMessageLiveLocation.kt | 53 +++++++++++++++++++ .../EditInlineMessageLiveLocation.kt | 17 ++++++ .../StopChatMessageLiveLocation.kt | 24 +++++++++ .../StopInlineMessageLiveLocation.kt | 10 ++++ 5 files changed, 120 insertions(+), 26 deletions(-) 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 a769e86bc1..f3bd84d8d7 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/LiveLocation.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/LiveLocation.kt @@ -1,12 +1,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor -import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation.EditChatMessageLiveLocation -import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation.StopChatMessageLiveLocation +import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation.* 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.message.abstracts.ContentMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.LocationContent import com.soywiz.klock.DateTime import com.soywiz.klock.TimeSpan import io.ktor.utils.io.core.Closeable @@ -16,9 +17,7 @@ private val livePeriodDelayDouble = ((livePeriodLimit.last - 60L) * 1000L).toDou class LiveLocation internal constructor( private val scope: CoroutineScope, private val requestsExecutor: RequestsExecutor, - private val chatId: ChatIdentifier, - private val messageId: MessageIdentifier, - location: Location + initMessage: ContentMessage ) : Closeable { var isClosed: Boolean = false private set @@ -26,8 +25,8 @@ class LiveLocation internal constructor( val leftUntilCloseMillis: TimeSpan get() = autoCloseTime - DateTime.now() private var updateJob: Job? = null - var lastLocation: Location = location - private set(value) { + private var message: ContentMessage = initMessage + set(value) { field = value updateJob ?.cancel() updateJob = scope.launch { @@ -37,9 +36,11 @@ class LiveLocation internal constructor( close() } } + val lastLocation: Location + get() = message.content.location init { - this.lastLocation = location // required to init updateJob + message = initMessage // required to init updateJob } suspend fun updateLocation( @@ -47,15 +48,11 @@ class LiveLocation internal constructor( replyMarkup: InlineKeyboardMarkup? = null ): Location { if (!isClosed) { - lastLocation = requestsExecutor.execute( - EditChatMessageLiveLocation( - chatId, - messageId, - location.latitude, - location.longitude, - replyMarkup - ) - ).content.location + message = requestsExecutor.editLiveLocation( + message, + location, + replyMarkup + ) return lastLocation } else { error("LiveLocation is closed") @@ -69,12 +66,7 @@ class LiveLocation internal constructor( isClosed = true updateJob ?.cancel() scope.launch { - requestsExecutor.execute( - StopChatMessageLiveLocation( - chatId, - messageId - ) - ) + requestsExecutor.stopLiveLocation(message) } } } @@ -103,8 +95,6 @@ suspend fun RequestsExecutor.startLiveLocation( return LiveLocation( scope, this, - chatId, - locationMessage.messageId, - locationMessage.content.location + locationMessage ) } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt index dcdc143392..3be1fe7c8d 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt @@ -1,8 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup +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 @@ -29,3 +31,54 @@ data class EditChatMessageLiveLocation( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.editLiveLocation( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + latitude: Double, + longitude: Double, + replyMarkup: InlineKeyboardMarkup? = null +) = execute( + EditChatMessageLiveLocation( + chatId, messageId, latitude, longitude, replyMarkup + ) +) + +suspend fun RequestsExecutor.editLiveLocation( + chat: Chat, + messageId: MessageIdentifier, + latitude: Double, + longitude: Double, + replyMarkup: InlineKeyboardMarkup? = null +) = editLiveLocation(chat.id, messageId, latitude, longitude, replyMarkup) + +suspend fun RequestsExecutor.editLiveLocation( + message: ContentMessage, + latitude: Double, + longitude: Double, + replyMarkup: InlineKeyboardMarkup? = null +) = editLiveLocation(message.chat, message.messageId, latitude, longitude, replyMarkup) + +suspend fun RequestsExecutor.editLiveLocation( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + location: Location, + replyMarkup: InlineKeyboardMarkup? = null +) = execute( + EditChatMessageLiveLocation( + chatId, messageId, location.latitude, location.longitude, replyMarkup + ) +) + +suspend fun RequestsExecutor.editLiveLocation( + chat: Chat, + messageId: MessageIdentifier, + location: Location, + replyMarkup: InlineKeyboardMarkup? = null +) = editLiveLocation(chat.id, messageId, location.latitude, location.longitude, replyMarkup) + +suspend fun RequestsExecutor.editLiveLocation( + message: ContentMessage, + location: Location, + replyMarkup: InlineKeyboardMarkup? = null +) = editLiveLocation(message.chat, message.messageId, location.latitude, location.longitude, replyMarkup) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/EditInlineMessageLiveLocation.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/EditInlineMessageLiveLocation.kt index 26b974cb3c..5388254674 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/EditInlineMessageLiveLocation.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/EditInlineMessageLiveLocation.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup @@ -20,3 +21,19 @@ data class EditInlineMessageLiveLocation( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.editLiveLocation( + inlineMessageId: InlineMessageIdentifier, + latitude: Double, + longitude: Double, + replyMarkup: InlineKeyboardMarkup? = null +) = execute( + EditInlineMessageLiveLocation( + inlineMessageId, latitude, longitude, replyMarkup + ) +) +suspend fun RequestsExecutor.editLiveLocation( + inlineMessageId: InlineMessageIdentifier, + location: Location, + replyMarkup: InlineKeyboardMarkup? = null +) = editLiveLocation(inlineMessageId, location.latitude, location.longitude, replyMarkup) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/StopChatMessageLiveLocation.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/StopChatMessageLiveLocation.kt index a0f1c3d9fe..4b6243b941 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/StopChatMessageLiveLocation.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/StopChatMessageLiveLocation.kt @@ -1,9 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditChatMessage import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup +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 @@ -26,3 +28,25 @@ data class StopChatMessageLiveLocation( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + + +suspend fun RequestsExecutor.stopLiveLocation( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + replyMarkup: InlineKeyboardMarkup? = null +) = execute( + StopChatMessageLiveLocation( + chatId, messageId, replyMarkup + ) +) + +suspend fun RequestsExecutor.stopLiveLocation( + chat: Chat, + messageId: MessageIdentifier, + replyMarkup: InlineKeyboardMarkup? = null +) = stopLiveLocation(chat.id, messageId, replyMarkup) + +suspend fun RequestsExecutor.stopLiveLocation( + message: ContentMessage, + replyMarkup: InlineKeyboardMarkup? = null +) = stopLiveLocation(message.chat, message.messageId, replyMarkup) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/StopInlineMessageLiveLocation.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/StopInlineMessageLiveLocation.kt index dbe0667ab1..1e4ed274ec 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/StopInlineMessageLiveLocation.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/LiveLocation/StopInlineMessageLiveLocation.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditInlineMessage import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage import com.github.insanusmokrassar.TelegramBotAPI.types.* @@ -17,3 +18,12 @@ data class StopInlineMessageLiveLocation( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +suspend fun RequestsExecutor.stopLiveLocation( + inlineMessageId: InlineMessageIdentifier, + replyMarkup: InlineKeyboardMarkup? = null +) = execute( + StopInlineMessageLiveLocation( + inlineMessageId, replyMarkup + ) +) From e43ad41d2f67d96cae686181c8cf46186f80537a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 00:56:32 +0600 Subject: [PATCH 42/53] 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) + ) +) From 7d0009039f09efb4d4262c78c565bec477c5c501 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 10:12:21 +0600 Subject: [PATCH 43/53] logical fixes --- .../requests/chat/modify/PinChatMessage.kt | 13 +++++-------- .../requests/chat/modify/SetChatPhoto.kt | 6 +++--- .../edit/ReplyMarkup/EditChatMessageReplyMarkup.kt | 9 +-------- .../requests/edit/caption/EditChatMessageCaption.kt | 13 +------------ .../requests/edit/media/EditChatMessageMedia.kt | 10 +--------- .../requests/edit/text/EditChatMessageText.kt | 12 +----------- 6 files changed, 12 insertions(+), 51 deletions(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt index 2996b448d7..95e55c1e11 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt @@ -39,13 +39,10 @@ suspend fun RequestsExecutor.pinChatMessage( ) = pinChatMessage(chat.id, messageId, disableNotification) suspend fun RequestsExecutor.pinChatMessage( - chatId: ChatIdentifier, message: Message, disableNotification: Boolean = false -) = pinChatMessage(chatId, message.messageId, disableNotification) - -suspend fun RequestsExecutor.pinChatMessage( - chat: PublicChat, - message: Message, - disableNotification: Boolean = false -) = pinChatMessage(chat.id, message.messageId, disableNotification) +) = if (message.chat is PublicChat) { + pinChatMessage(message.chat.id, message.messageId, disableNotification) +} else { + error("It is possible to pin messages only in non one-to-one chats") +} diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt index 66104e00fa..5748b64d94 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt @@ -26,12 +26,12 @@ data class SetChatPhoto ( override val paramsJson: JsonObject = toJson(serializer()) } -suspend fun RequestsExecutor.setChatPermissions( +suspend fun RequestsExecutor.setChatPhoto( chatId: ChatIdentifier, photo: MultipartFile ) = execute(SetChatPhoto(chatId, photo)) -suspend fun RequestsExecutor.setChatPermissions( +suspend fun RequestsExecutor.setChatPhoto( chat: PublicChat, photo: MultipartFile -) = setChatPermissions(chat.id, photo) +) = setChatPhoto(chat.id, photo) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditChatMessageReplyMarkup.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditChatMessageReplyMarkup.kt index 69be48676d..faf2077bf9 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditChatMessageReplyMarkup.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditChatMessageReplyMarkup.kt @@ -49,14 +49,7 @@ suspend fun RequestsExecutor.editMessageReplyMarkup( ) = editMessageReplyMarkup(chat.id, messageId, replyMarkup) suspend fun RequestsExecutor.editMessageReplyMarkup( - chatId: ChatId, message: Message, replyMarkup: InlineKeyboardMarkup? = null -) = editMessageReplyMarkup(chatId, message.messageId, replyMarkup) - -suspend fun RequestsExecutor.editMessageReplyMarkup( - chat: Chat, - message: Message, - replyMarkup: InlineKeyboardMarkup? = null -) = editMessageReplyMarkup(chat.id, message.messageId, replyMarkup) +) = editMessageReplyMarkup(message.chat.id, message.messageId, replyMarkup) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt index e3406789bd..bad04096ef 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt @@ -60,21 +60,10 @@ suspend fun RequestsExecutor.editMessageCaption( ) = editMessageCaption(chat.id, messageId, text, parseMode, replyMarkup) suspend fun RequestsExecutor.editMessageCaption( - chatId: ChatId, message: ContentMessage, text: String, parseMode: ParseMode? = null, replyMarkup: InlineKeyboardMarkup? = null ): ContentMessage where T : CaptionedInput, T : MediaContent { - return editMessageCaption(chatId, message.messageId, text, parseMode, replyMarkup) -} - -suspend fun RequestsExecutor.editMessageCaption( - chat: Chat, - message: ContentMessage, - text: String, - parseMode: ParseMode? = null, - replyMarkup: InlineKeyboardMarkup? = null -): ContentMessage where T : CaptionedInput, T : MediaContent { - return editMessageCaption(chat.id, message.messageId, text, parseMode, replyMarkup) + return editMessageCaption(message.chat.id, message.messageId, text, parseMode, replyMarkup) } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt index e01842db23..d9c0f3194c 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt @@ -63,15 +63,7 @@ suspend fun RequestsExecutor.editMessageMedia( ) = editMessageMedia(chat.id, messageId, media, replyMarkup) suspend fun RequestsExecutor.editMessageMedia( - chatId: ChatId, message: ContentMessage, media: InputMedia, replyMarkup: InlineKeyboardMarkup? = null -) = editMessageMedia(chatId, message.messageId, media, replyMarkup) - -suspend fun RequestsExecutor.editMessageMedia( - chat: Chat, - message: ContentMessage, - media: InputMedia, - replyMarkup: InlineKeyboardMarkup? = null -) = editMessageMedia(chat.id, message.messageId, media, replyMarkup) +) = editMessageMedia(message.chat.id, message.messageId, media, replyMarkup) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt index b18c23259e..a64972caa2 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt @@ -59,19 +59,9 @@ suspend fun RequestsExecutor.editMessageText( ) = editMessageText(chat.id, messageId, text, parseMode, disableWebPagePreview, replyMarkup) suspend fun RequestsExecutor.editMessageText( - chatId: ChatId, message: ContentMessage, text: String, parseMode: ParseMode? = null, disableWebPagePreview: Boolean? = null, replyMarkup: InlineKeyboardMarkup? = null -) = editMessageText(chatId, message.messageId, text, parseMode, disableWebPagePreview, replyMarkup) - -suspend fun RequestsExecutor.editMessageText( - chat: Chat, - message: ContentMessage, - text: String, - parseMode: ParseMode? = null, - disableWebPagePreview: Boolean? = null, - replyMarkup: InlineKeyboardMarkup? = null -) = editMessageText(chat.id, message.messageId, text, parseMode, disableWebPagePreview, replyMarkup) \ No newline at end of file +) = editMessageText(message.chat.id, message.messageId, text, parseMode, disableWebPagePreview, replyMarkup) \ No newline at end of file From 9ed1500bee255e96b1e7bbb3420884da84a1df90 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 10:31:22 +0600 Subject: [PATCH 44/53] add additional methods for regular poll --- .../requests/send/polls/SendPoll.kt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt index b68320164f..07aed23c77 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt @@ -202,6 +202,22 @@ suspend fun RequestsExecutor.sendRegularPoll( chatId, question, options, isAnonymous, isClosed, allowMultipleAnswers, disableNotification, replyToMessageId, replyMarkup ) ) +suspend fun RequestsExecutor.sendRegularPoll( + chatId: ChatIdentifier, + poll: RegularPoll, + isClosed: Boolean = false, + question: String = poll.question, + options: List = poll.options.map { it.text }, + isAnonymous: Boolean = poll.isAnonymous, + allowMultipleAnswers: Boolean = poll.allowMultipleAnswers, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendRegularPoll( + chatId, question, options, isAnonymous, isClosed, allowMultipleAnswers, disableNotification, replyToMessageId, replyMarkup + ) +) suspend fun RequestsExecutor.sendRegularPoll( chat: Chat, @@ -217,6 +233,21 @@ suspend fun RequestsExecutor.sendRegularPoll( chat.id, question, options, isAnonymous, isClosed, allowMultipleAnswers, disableNotification, replyToMessageId, replyMarkup ) +suspend fun RequestsExecutor.sendRegularPoll( + chat: Chat, + poll: RegularPoll, + isClosed: Boolean = false, + question: String = poll.question, + options: List = poll.options.map { it.text }, + isAnonymous: Boolean = poll.isAnonymous, + allowMultipleAnswers: Boolean = poll.allowMultipleAnswers, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendRegularPoll( + chat.id, question, options, isAnonymous, isClosed, allowMultipleAnswers, disableNotification, replyToMessageId, replyMarkup +) + suspend fun RequestsExecutor.sendQuizPoll( chatId: ChatIdentifier, From 60a30f972f7518c760b6a6613fa6c44fc8df6517 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 10:33:36 +0600 Subject: [PATCH 45/53] add additional methods for quiz poll --- .../requests/send/polls/SendPoll.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt index 07aed23c77..40795135fd 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt @@ -278,3 +278,35 @@ suspend fun RequestsExecutor.sendQuizPoll( ) = sendQuizPoll( chat.id, question, options, correctOptionId, isAnonymous, isClosed, disableNotification, replyToMessageId, replyMarkup ) + +suspend fun RequestsExecutor.sendQuizPoll( + chatId: ChatIdentifier, + isClosed: Boolean = false, + quizPoll: QuizPoll, + question: String = quizPoll.question, + options: List = quizPoll.options.map { it.text }, + correctOptionId: Int = quizPoll.correctOptionId ?: error("Correct option ID must be provided by income QuizPoll or by developer"), + isAnonymous: Boolean = quizPoll.isAnonymous, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendQuizPoll( + chatId, question, options, correctOptionId, isAnonymous, isClosed, disableNotification, replyToMessageId, replyMarkup + ) +) + +suspend fun RequestsExecutor.sendQuizPoll( + chat: Chat, + isClosed: Boolean = false, + quizPoll: QuizPoll, + question: String = quizPoll.question, + options: List = quizPoll.options.map { it.text }, + correctOptionId: Int = quizPoll.correctOptionId ?: error("Correct option ID must be provided by income QuizPoll or by developer"), + isAnonymous: Boolean = quizPoll.isAnonymous, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll( + chat.id, question, options, correctOptionId, isAnonymous, isClosed, disableNotification, replyToMessageId, replyMarkup +) From 04e4407b96b4e462c0f231926398b0f20a4c4da5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 10:36:31 +0600 Subject: [PATCH 46/53] fill changelog about new actions --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ca5dcc7a9..6705148e18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ * `InvoiceOfPayment` now is `MessageContent` instead of `PaymentInfo` * `SendInvoice` now return `ContentMessage` * `paymentInfo` inside of `CommonMessageImpl` now can be set only to `SuccessfulPaymentInfo` +* Added `RecordVideoNoteAction` and `UploadVideoNoteAction` for `record_video_note` and `upload_video_note` actions ## 0.22.0 From c2c7ac0d1e0d0843a7d2556f6072caf6523758b8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 10:47:35 +0600 Subject: [PATCH 47/53] InvoiceOfPayment is renamed to InvoiceContent --- CHANGELOG.md | 4 ++-- .../requests/send/payments/SendInvoice.kt | 10 ++++------ .../TelegramBotAPI/types/message/RawMessage.kt | 5 ++--- .../{InvoiceOfPayment.kt => InvoiceContent.kt} | 7 ++----- 4 files changed, 10 insertions(+), 16 deletions(-) rename src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/payments/{InvoiceOfPayment.kt => InvoiceContent.kt} (75%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6705148e18..7fb182eb04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,8 +43,8 @@ * Now it is possible to get updates by polling with custom executor engine * `CommonMultipartFileRequest` now is internal * Added `LiveLocation` class for more useful tracking live locations -* `InvoiceOfPayment` now is `MessageContent` instead of `PaymentInfo` -* `SendInvoice` now return `ContentMessage` +* `InvoiceOfPayment` is renamed to `InvoiceContent` and now is `MessageContent` instead of `PaymentInfo` +* `SendInvoice` now return `ContentMessage` * `paymentInfo` inside of `CommonMessageImpl` now can be set only to `SuccessfulPaymentInfo` * Added `RecordVideoNoteAction` and `UploadVideoNoteAction` for `record_video_note` and `upload_video_note` actions diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/payments/SendInvoice.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/payments/SendInvoice.kt index 8a54257331..40d17c9c43 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/payments/SendInvoice.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/payments/SendInvoice.kt @@ -6,15 +6,13 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMe import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* -import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy -import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.PhotoContent -import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.InvoiceOfPayment +import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.InvoiceContent import com.github.insanusmokrassar.TelegramBotAPI.types.payments.LabeledPrice import com.github.insanusmokrassar.TelegramBotAPI.types.payments.LabeledPricesSerializer import com.github.insanusmokrassar.TelegramBotAPI.types.payments.abstracts.* import kotlinx.serialization.* -private val invoiceMessageSerializer: DeserializationStrategy> +private val invoiceMessageSerializer: DeserializationStrategy> = TelegramBotAPIMessageDeserializationStrategyClass() /** @@ -67,9 +65,9 @@ data class SendInvoice( DisableNotification, ReplyMessageId, ReplyMarkup, - SendMessageRequest> { + SendMessageRequest> { override fun method(): String = "sendInvoice" - override val resultDeserializer: DeserializationStrategy> + override val resultDeserializer: DeserializationStrategy> get() = invoiceMessageSerializer override val requestSerializer: SerializationStrategy<*> get() = serializer() diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt index 05877079c7..6b833e32c6 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt @@ -14,9 +14,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Unknow import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.* -import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.InvoiceOfPayment +import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.InvoiceContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.SuccessfulPaymentInfo -import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.abstracts.PaymentInfo import com.github.insanusmokrassar.TelegramBotAPI.types.payments.Invoice import com.github.insanusmokrassar.TelegramBotAPI.types.payments.SuccessfulPayment import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll @@ -130,7 +129,7 @@ internal data class RawMessage( location != null -> LocationContent(location) venue != null -> VenueContent(venue) poll != null -> PollContent(poll) - invoice != null -> InvoiceOfPayment(invoice) + invoice != null -> InvoiceContent(invoice) else -> null } } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/payments/InvoiceOfPayment.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/payments/InvoiceContent.kt similarity index 75% rename from src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/payments/InvoiceOfPayment.kt rename to src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/payments/InvoiceContent.kt index 3c177554af..f40983184a 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/payments/InvoiceOfPayment.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/payments/InvoiceContent.kt @@ -1,17 +1,14 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.payments import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request -import com.github.insanusmokrassar.TelegramBotAPI.requests.send.payments.SendInvoice import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage -import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent -import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.abstracts.PaymentInfo import com.github.insanusmokrassar.TelegramBotAPI.types.payments.Invoice -data class InvoiceOfPayment( +data class InvoiceContent( val invoice: Invoice ) : MessageContent { override fun createResend( @@ -19,7 +16,7 @@ data class InvoiceOfPayment( disableNotification: Boolean, replyToMessageId: MessageIdentifier?, replyMarkup: KeyboardMarkup? - ): Request> { + ): Request> { error("Unfortunately, currently InvoiceOfPayment can not be resend due to requirement of additional parameters," + " which can't be provided during the call of this method") } From fe8c3392fa65a1febc67f951a5f7a314755cbc47 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 10:49:16 +0600 Subject: [PATCH 48/53] Actialize bot action tests --- .../insanusmokrassar/TelegramBotAPI/types/BotActionTests.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/commonTest/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotActionTests.kt b/src/commonTest/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotActionTests.kt index c208576169..a00391b948 100644 --- a/src/commonTest/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotActionTests.kt +++ b/src/commonTest/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotActionTests.kt @@ -26,6 +26,8 @@ class BotActionTests { UploadAudioAction -> example.botAction.actionName UploadDocumentAction -> example.botAction.actionName FindLocationAction -> example.botAction.actionName + RecordVideoNoteAction -> example.botAction.actionName + UploadVideoNoteAction -> example.botAction.actionName } ) } @@ -52,7 +54,9 @@ class BotActionTests { RecordAudioAction.example(), UploadAudioAction.example(), UploadDocumentAction.example(), - FindLocationAction.example() + FindLocationAction.example(), + RecordVideoNoteAction.example(), + UploadVideoNoteAction.example() ).forEach { checkBotActionSerializeDeserialize(it) } From aa333d7c586015b0ca6b402b0ff76699f794df14 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 11:00:21 +0600 Subject: [PATCH 49/53] fill CHANGELOG and update README --- CHANGELOG.md | 1 + README.md | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fb182eb04..12fe9c222a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ * `SendInvoice` now return `ContentMessage` * `paymentInfo` inside of `CommonMessageImpl` now can be set only to `SuccessfulPaymentInfo` * Added `RecordVideoNoteAction` and `UploadVideoNoteAction` for `record_video_note` and `upload_video_note` actions +* For most part of messages was added `RequestsExecutor` extensions for more useful way of usage ## 0.22.0 diff --git a/README.md b/README.md index b2ac7d652a..8936cf96eb 100644 --- a/README.md +++ b/README.md @@ -76,10 +76,10 @@ important objects: Types declare different objects representation. For example, `Chat` for now represented as interface and has several realisations: -* PrivateChat -* GroupChat -* SupergroupChat -* ChannelChat +* `PrivateChat` +* `GroupChat` +* `SupergroupChat` +* `ChannelChat` Instead of common garbage with all information as in original [Chat](https://core.telegram.org/bots/api#chat), here it was separated for more obvious difference between chats types and their possible content. @@ -96,7 +96,14 @@ val requestsExecutor: RequestsExecutor = ... requestsExecutor.execute(GetMe()) ``` -The result type of [GetMe](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt) +Or you can use new syntax: + +```kotlin +val bot: RequestsExecutor = ... +bot.getMe() +``` + +The result type of [GetMe (and getMe extension)](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt) request is [ExtendedBot](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt). @@ -107,31 +114,38 @@ realisation of `RequestsExecutor`, but it is possible, that in future it will be project. How to create `RequestsExecutor`: ```kotlin -val requestsExecutor = KtorRequestsExecutor(TOKEN) +val requestsExecutor = KtorRequestsExecutor( + TelegramAPIUrlsKeeper(TOKEN) +) ``` -Here `KtorRequestsExecutor` - default realisation with Ktor. `TOKEN` is just a token of bot which was retrieved -according to [instruction](https://core.telegram.org/bots#3-how-do-i-create-a-bot). +Here: -Besides, for correct usage of this, you must implement in your project both one of engines for client and server -Ktor libraries: +* `KtorRequestsExecutor` - default realisation with [ktor](https://ktor.io) +* `TelegramAPIUrlsKeeper` - special keeper, which you can save and use for getting files full urls (`resolveFileURL` +extension inside of `PathedFile.kt`) +* `TOKEN` is just a token of bot which was retrieved according to +[instruction](https://core.telegram.org/bots#3-how-do-i-create-a-bot). + +By default, for JVM there is implemented `CIO` client engine, but there is not server engine. Both can be changed like +here: ```groovy dependencies { // ... - implementation "io.ktor:ktor-server-cio:$ktor_version" - implementation "io.ktor:ktor-client-okhttp:$ktor_version" + implementation "io.ktor:ktor-server-cio:$ktor_version" // for implementing of server engine + implementation "io.ktor:ktor-client-okhttp:$ktor_version" // for implementing of additional client engine // ... } ``` -It is able to avoid using of `server` dependency in case if will not be used `Webhook`s. In this case, +You can avoid using of `server` dependency in case if you will not use `Webhook`s. In this case, dependencies list will be simplify: ```groovy dependencies { // ... - implementation "io.ktor:ktor-client-okhttp:$ktor_version" + implementation "io.ktor:ktor-client-okhttp:$ktor_version" // for implementing of additional client engine // ... } ``` From 8fd6a09763df1ecc569480fb5f19bfcb89d0a0ea Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 22:12:18 +0600 Subject: [PATCH 50/53] toInputFile specifying return types --- CHANGELOG.md | 1 + .../TelegramBotAPI/requests/abstracts/InputFile.kt | 2 +- .../TelegramBotAPI/requests/abstracts/InputFileFromJavaFile.kt | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12fe9c222a..c349f873d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ * `paymentInfo` inside of `CommonMessageImpl` now can be set only to `SuccessfulPaymentInfo` * Added `RecordVideoNoteAction` and `UploadVideoNoteAction` for `record_video_note` and `upload_video_note` actions * For most part of messages was added `RequestsExecutor` extensions for more useful way of usage +* `toInputFile` extensions now will return more exact types ## 0.22.0 diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFile.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFile.kt index 6c2f6c96d9..4a7cebba14 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFile.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFile.kt @@ -18,7 +18,7 @@ data class FileId( override val fileId: String ) : InputFile() -fun String.toInputFile(): InputFile = FileId(this) +fun String.toInputFile() = FileId(this) @Serializer(InputFile::class) internal object InputFileSerializer : KSerializer { diff --git a/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFileFromJavaFile.kt b/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFileFromJavaFile.kt index e521ef23e1..99b52b76e6 100644 --- a/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFileFromJavaFile.kt +++ b/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFileFromJavaFile.kt @@ -3,6 +3,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts import com.github.insanusmokrassar.TelegramBotAPI.utils.StorageFile import java.io.File -fun File.toInputFile(): InputFile = MultipartFile( +fun File.toInputFile() = MultipartFile( StorageFile(this) ) From d6bbb0cadc639d7de2039f4402e71b87934ebc7e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 22:36:15 +0600 Subject: [PATCH 51/53] update LiveLocation logic --- .../TelegramBotAPI/requests/LiveLocation.kt | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) 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 657440b45d..14eadb3501 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/LiveLocation.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/LiveLocation.kt @@ -14,36 +14,30 @@ import com.soywiz.klock.TimeSpan import io.ktor.utils.io.core.Closeable import kotlinx.coroutines.* -private val livePeriodDelayDouble = ((livePeriodLimit.last - 60L) * 1000L).toDouble() +private val livePeriodDelayMillis = (livePeriodLimit.last - 60L) * 1000L class LiveLocation internal constructor( - private val scope: CoroutineScope, private val requestsExecutor: RequestsExecutor, + scope: CoroutineScope, + autoCloseTimeDelay: Double, initMessage: ContentMessage ) : Closeable { - var isClosed: Boolean = false - private set - private var autoCloseTime = DateTime.now() + TimeSpan(livePeriodDelayDouble) + private val doWhenClose = { + scope.launch { + requestsExecutor.stopLiveLocation(message) + } + } + private val autoCloseTime = DateTime.now() + TimeSpan(autoCloseTimeDelay) val leftUntilCloseMillis: TimeSpan get() = autoCloseTime - DateTime.now() - private var updateJob: Job? = null + + var isClosed: Boolean = false + private set + get() = field || leftUntilCloseMillis.millisecondsLong < 0L + private var message: ContentMessage = initMessage - set(value) { - field = value - updateJob ?.cancel() - updateJob = scope.launch { - autoCloseTime = DateTime.now() + TimeSpan(livePeriodDelayDouble) - delay(leftUntilCloseMillis.millisecondsLong) - updateJob = null - close() - } - } val lastLocation: Location get() = message.content.location - init { - message = initMessage // required to init updateJob - } - suspend fun updateLocation( location: Location, replyMarkup: InlineKeyboardMarkup? = null @@ -65,10 +59,7 @@ class LiveLocation internal constructor( return } isClosed = true - updateJob ?.cancel() - scope.launch { - requestsExecutor.stopLiveLocation(message) - } + doWhenClose() } } @@ -77,6 +68,7 @@ suspend fun RequestsExecutor.startLiveLocation( chatId: ChatIdentifier, latitude: Double, longitude: Double, + firstTimeUntilCloseMillis: Long = livePeriodDelayMillis, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null @@ -94,8 +86,9 @@ suspend fun RequestsExecutor.startLiveLocation( ) return LiveLocation( - scope, this, + scope, + firstTimeUntilCloseMillis.toDouble(), locationMessage ) } @@ -105,31 +98,34 @@ suspend fun RequestsExecutor.startLiveLocation( chat: Chat, latitude: Double, longitude: Double, + firstTimeUntilCloseMillis: Long = livePeriodDelayMillis, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null ): LiveLocation = startLiveLocation( - scope, chat.id, latitude, longitude, disableNotification, replyToMessageId, replyMarkup + scope, chat.id, latitude, longitude, firstTimeUntilCloseMillis, disableNotification, replyToMessageId, replyMarkup ) suspend fun RequestsExecutor.startLiveLocation( scope: CoroutineScope, chatId: ChatId, location: Location, + firstTimeUntilCloseMillis: Long = livePeriodDelayMillis, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null ): LiveLocation = startLiveLocation( - scope, chatId, location.latitude, location.longitude, disableNotification, replyToMessageId, replyMarkup + scope, chatId, location.latitude, location.longitude, firstTimeUntilCloseMillis, disableNotification, replyToMessageId, replyMarkup ) suspend fun RequestsExecutor.startLiveLocation( scope: CoroutineScope, chat: Chat, location: Location, + firstTimeUntilCloseMillis: Long = livePeriodDelayMillis, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null ): LiveLocation = startLiveLocation( - scope, chat.id, location.latitude, location.longitude, disableNotification, replyToMessageId, replyMarkup + scope, chat.id, location.latitude, location.longitude, firstTimeUntilCloseMillis, disableNotification, replyToMessageId, replyMarkup ) From 0e33b123e9b68afe28c550bccec0b5ce3b8644e9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 22:43:48 +0600 Subject: [PATCH 52/53] additional fixes in live location --- .../TelegramBotAPI/requests/LiveLocation.kt | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) 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 14eadb3501..a285a68e75 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/LiveLocation.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/LiveLocation.kt @@ -13,6 +13,7 @@ import com.soywiz.klock.DateTime import com.soywiz.klock.TimeSpan import io.ktor.utils.io.core.Closeable import kotlinx.coroutines.* +import kotlin.math.ceil private val livePeriodDelayMillis = (livePeriodLimit.last - 60L) * 1000L class LiveLocation internal constructor( @@ -68,17 +69,18 @@ suspend fun RequestsExecutor.startLiveLocation( chatId: ChatIdentifier, latitude: Double, longitude: Double, - firstTimeUntilCloseMillis: Long = livePeriodDelayMillis, + liveTimeMillis: Long = livePeriodDelayMillis, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null ): LiveLocation { + val liveTimeAsDouble = liveTimeMillis.toDouble() val locationMessage = execute( SendLocation( chatId, latitude, longitude, - livePeriodLimit.last.toLong(), + ceil(liveTimeAsDouble / 1000).toLong(), disableNotification, replyToMessageId, replyMarkup @@ -88,7 +90,7 @@ suspend fun RequestsExecutor.startLiveLocation( return LiveLocation( this, scope, - firstTimeUntilCloseMillis.toDouble(), + liveTimeAsDouble, locationMessage ) } @@ -98,34 +100,34 @@ suspend fun RequestsExecutor.startLiveLocation( chat: Chat, latitude: Double, longitude: Double, - firstTimeUntilCloseMillis: Long = livePeriodDelayMillis, + liveTimeMillis: Long = livePeriodDelayMillis, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null ): LiveLocation = startLiveLocation( - scope, chat.id, latitude, longitude, firstTimeUntilCloseMillis, disableNotification, replyToMessageId, replyMarkup + scope, chat.id, latitude, longitude, liveTimeMillis, disableNotification, replyToMessageId, replyMarkup ) suspend fun RequestsExecutor.startLiveLocation( scope: CoroutineScope, chatId: ChatId, location: Location, - firstTimeUntilCloseMillis: Long = livePeriodDelayMillis, + liveTimeMillis: Long = livePeriodDelayMillis, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null ): LiveLocation = startLiveLocation( - scope, chatId, location.latitude, location.longitude, firstTimeUntilCloseMillis, disableNotification, replyToMessageId, replyMarkup + scope, chatId, location.latitude, location.longitude, liveTimeMillis, disableNotification, replyToMessageId, replyMarkup ) suspend fun RequestsExecutor.startLiveLocation( scope: CoroutineScope, chat: Chat, location: Location, - firstTimeUntilCloseMillis: Long = livePeriodDelayMillis, + liveTimeMillis: Long = livePeriodDelayMillis, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null ): LiveLocation = startLiveLocation( - scope, chat.id, location.latitude, location.longitude, firstTimeUntilCloseMillis, disableNotification, replyToMessageId, replyMarkup + scope, chat.id, location.latitude, location.longitude, liveTimeMillis, disableNotification, replyToMessageId, replyMarkup ) From 34f606545ed6c68c69b6f471710f9f5b715639a6 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 22:45:57 +0600 Subject: [PATCH 53/53] additional fixes in live location --- .../TelegramBotAPI/requests/send/SendLocation.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 45ba243ff3..37d88583f4 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 @@ -51,7 +51,7 @@ data class SendLocation( init { if (livePeriod != null && livePeriod !in livePeriodLimit) { - error("Live period for sending location must be in $livePeriodLimit") + error("Live period for sending location must be in $livePeriodLimit, but was $livePeriod") } } }