From 76bbe2a064a21ed6617cac792a27ab7799017365 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 23 Jul 2019 07:24:14 +0800 Subject: [PATCH 01/17] start 0.17.0 --- CHANGELOG.md | 2 ++ build.gradle | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bb5fd249c..38b74d2428 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.17.0 + ## 0.16.0 Bot API 4.3 * `LoginURL` and `LoginURLInlineKeyboardButton` has been added diff --git a/build.gradle b/build.gradle index 3f6ff75d5c..cff9fb47ee 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -project.version = "0.16.1" +project.version = "0.17.0" project.group = "com.github.insanusmokrassar" buildscript { From 8b6947231fa2735211f3a95b6b19f5fbf3c8444e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 23 Jul 2019 07:26:45 +0800 Subject: [PATCH 02/17] "implementation" replaced by "api" in build gradle --- build.gradle | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index cff9fb47ee..bd7283475e 100644 --- a/build.gradle +++ b/build.gradle @@ -30,15 +30,15 @@ repositories { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version" - implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version" - implementation "joda-time:joda-time:$joda_time_version" + api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version" + api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version" + api "joda-time:joda-time:$joda_time_version" - implementation "io.ktor:ktor-client:$ktor_version" - implementation "io.ktor:ktor-client-cio:$ktor_version" + api "io.ktor:ktor-client:$ktor_version" + api "io.ktor:ktor-client-cio:$ktor_version" - implementation "io.ktor:ktor-server:$ktor_version" - implementation "io.ktor:ktor-server-host-common:$ktor_version" + api "io.ktor:ktor-server:$ktor_version" + api "io.ktor:ktor-server-host-common:$ktor_version" } compileKotlin { From 4dba67979df7c2e343795a259fc2b4afc368ecf3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 23 Jul 2019 07:43:32 +0800 Subject: [PATCH 03/17] update dependencies versions --- CHANGELOG.md | 6 ++++++ gradle.properties | 10 +++++----- .../bot/Ktor/base/MultipartRequestCallFactory.kt | 7 ++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38b74d2428..686a1be35a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## 0.17.0 +* Kotlin version `1.3.31` -> `1.3.41` +* Kotlin Coroutines version `1.2.1` -> `1.2.2` +* Kotlin Serialization version `0.11.0` -> `0.11.1` +* Joda Time version `2.10.1` -> `2.10.3` +* Ktor version `1.1.4` -> `1.2.2` + ## 0.16.0 Bot API 4.3 * `LoginURL` and `LoginURLInlineKeyboardButton` has been added diff --git a/gradle.properties b/gradle.properties index e5002968b7..65e5f9842d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,9 @@ kotlin.code.style=official -kotlin_version=1.3.31 -kotlin_coroutines_version=1.2.1 -kotlin_serialisation_runtime_version=0.11.0 -joda_time_version=2.10.1 -ktor_version=1.1.4 +kotlin_version=1.3.41 +kotlin_coroutines_version=1.2.2 +kotlin_serialisation_runtime_version=0.11.1 +joda_time_version=2.10.3 +ktor_version=1.2.2 gradle_bintray_plugin_version=1.8.4 diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/base/MultipartRequestCallFactory.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/base/MultipartRequestCallFactory.kt index c90ba16e95..aa5aad04ad 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/base/MultipartRequestCallFactory.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/base/MultipartRequestCallFactory.kt @@ -3,8 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.utils.mapWithCommonValues import io.ktor.client.HttpClient -import io.ktor.client.request.forms.MultiPartFormDataContent -import io.ktor.client.request.forms.formData +import io.ktor.client.request.forms.* import io.ktor.http.Headers import io.ktor.http.HttpHeaders @@ -22,7 +21,9 @@ class MultipartRequestCallFactory : AbstractRequestCallFactory() { when (value) { is MultipartFile -> append( key, - value.file.asInput(), + InputProvider { + value.file.asInput() + }, Headers.build { append(HttpHeaders.ContentType, value.mimeType) append(HttpHeaders.ContentDisposition, "filename=${value.fileId}") From d8887bb7ff0a0a2955a43315a5bdb52ec4832394 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 23 Jul 2019 07:46:19 +0800 Subject: [PATCH 04/17] RequestsExecutor now is Closeable --- CHANGELOG.md | 2 ++ .../TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt | 4 ++++ .../insanusmokrassar/TelegramBotAPI/bot/RequestsExecutor.kt | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 686a1be35a..54301c46b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ * Joda Time version `2.10.1` -> `2.10.3` * Ktor version `1.1.4` -> `1.2.2` +* `RequestsExecutor` now is `Closeable` + ## 0.16.0 Bot API 4.3 * `LoginURL` and `LoginURLInlineKeyboardButton` has been added diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt index 958b1bd33d..ff1b43eb56 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt @@ -83,4 +83,8 @@ class KtorRequestsExecutor( } } } + + override fun close() { + client.close() + } } diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestsExecutor.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestsExecutor.kt index e2eacbb377..c8e8c52010 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestsExecutor.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestsExecutor.kt @@ -2,8 +2,9 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request +import kotlinx.io.core.Closeable -interface RequestsExecutor { +interface RequestsExecutor : Closeable { @Throws(RequestException::class) suspend fun execute(request: Request): T } \ No newline at end of file From 84ad751792ec61af24c7f422ed0f0de3ff65a47f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 25 Jul 2019 16:25:18 +0800 Subject: [PATCH 05/17] TelegramAPIUrlsKeeper --- CHANGELOG.md | 2 ++ .../bot/BaseRequestsExecutor.kt | 15 ++++++++--- .../bot/Ktor/KtorRequestsExecutor.kt | 26 ++++++++++++++----- .../TelegramBotAPI/types/files/PathedFile.kt | 6 +++++ .../updateshandlers/KtorUpdatesPoller.kt | 23 ++++++++++++++-- .../utils/TelegramAPIUrlsKeeper.kt | 9 +++++++ 6 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/TelegramAPIUrlsKeeper.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 54301c46b3..3eec9b1df7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ * Ktor version `1.1.4` -> `1.2.2` * `RequestsExecutor` now is `Closeable` +* `TelegramAPIUrlsKeeper` was added to provide more comfortable work with file urls and other things +like this ## 0.16.0 Bot API 4.3 diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/BaseRequestsExecutor.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/BaseRequestsExecutor.kt index abaf662aa4..3aef77e43a 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/BaseRequestsExecutor.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/BaseRequestsExecutor.kt @@ -1,8 +1,17 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot +import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper + abstract class BaseRequestsExecutor( - token: String, - hostUrl: String = "https://api.telegram.org" + protected val telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper ) : RequestsExecutor { - protected val baseUrl: String = "$hostUrl/bot$token" + @Deprecated("Deprecated due to new TelegramAPIUrlKeeper API", ReplaceWith("telegramAPIUrlsKeeper.commonAPIUrl")) + protected val baseUrl: String + get() = telegramAPIUrlsKeeper.commonAPIUrl + + @Deprecated("Deprecated due to new TelegramAPIUrlKeeper API") + constructor( + token: String, + hostUrl: String = "https://api.telegram.org" + ) : this (TelegramAPIUrlsKeeper(token, hostUrl)) } \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt index ff1b43eb56..abc0e49fd8 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt @@ -9,6 +9,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.RequestL import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request import com.github.insanusmokrassar.TelegramBotAPI.types.Response import com.github.insanusmokrassar.TelegramBotAPI.types.RetryAfterError +import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper import io.ktor.client.HttpClient import io.ktor.client.call.HttpClientCall import io.ktor.client.engine.HttpClientEngine @@ -17,22 +18,33 @@ import kotlinx.coroutines.delay import kotlinx.serialization.json.Json class KtorRequestsExecutor( - token: String, + telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper, private val client: HttpClient = HttpClient(), - hostUrl: String = "https://api.telegram.org", callsFactories: List = emptyList(), excludeDefaultFactories: Boolean = false, private val requestsLimiter: RequestLimiter = EmptyLimiter, private val jsonFormatter: Json = Json.nonstrict -) : BaseRequestsExecutor(token, hostUrl) { +) : BaseRequestsExecutor(telegramAPIUrlsKeeper) { + + @Deprecated("Deprecated due to new TelegramAPIUrlKeeper API") + constructor( + token: String, + client: HttpClient = HttpClient(), + hostUrl: String = "https://api.telegram.org", + callsFactories: List = emptyList(), + excludeDefaultFactories: Boolean = false, + requestsLimiter: RequestLimiter = EmptyLimiter, + jsonFormatter: Json = Json.nonstrict + ) : this(TelegramAPIUrlsKeeper(token, hostUrl), client, callsFactories, excludeDefaultFactories, requestsLimiter, jsonFormatter) + + @Deprecated("Deprecated due to new TelegramAPIUrlKeeper API") constructor( token: String, engine: HttpClientEngine? = null, hostUrl: String = "https://api.telegram.org" ) : this( - token, - engine ?.let { HttpClient(engine) } ?: HttpClient(), - hostUrl + TelegramAPIUrlsKeeper(token, hostUrl), + engine ?.let { HttpClient(engine) } ?: HttpClient() ) private val callsFactories: List = callsFactories.run { @@ -49,7 +61,7 @@ class KtorRequestsExecutor( for (factory in callsFactories) { call = factory.prepareCall( client, - baseUrl, + telegramAPIUrlsKeeper.commonAPIUrl, request ) if (call != null) { diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/PathedFile.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/PathedFile.kt index e7d48b5823..7ab0ab5a11 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/PathedFile.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/PathedFile.kt @@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.files import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -15,11 +16,16 @@ data class PathedFile( override val fileSize: Long? = null ): TelegramMediaFile +fun TelegramAPIUrlsKeeper.resolveFileURL(file: PathedFile): String = "$fileBaseUrl/${file.filePath}" +inline fun PathedFile.fullUrl(keeper: TelegramAPIUrlsKeeper): String = keeper.resolveFileURL(this) + +@Deprecated("Deprecated due to old API", ReplaceWith("fullUrl(telegramApiUrlsKeeper)")) fun PathedFile.makeFileUrl( botToken: String, apiHost: String = "https://api.telegram.org" ) = "${downloadingFilesBaseUrl(botToken, apiHost)}/$filePath" +@Deprecated("Deprecated due to old API", ReplaceWith("telegramApiUrlsKeeper.fileBaseUrl")) fun downloadingFilesBaseUrl( botToken: String, apiHost: String diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/KtorUpdatesPoller.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/KtorUpdatesPoller.kt index 6c6482f549..2f670113d5 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/KtorUpdatesPoller.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/KtorUpdatesPoller.kt @@ -18,7 +18,7 @@ import io.ktor.client.engine.cio.CIO import kotlinx.coroutines.* fun KtorUpdatesPoller( - token: String, + telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper, timeoutSeconds: Int? = null, oneTimeUpdatesLimit: Int? = null, allowedUpdates: List = ALL_UPDATES_LIST, @@ -26,7 +26,7 @@ fun KtorUpdatesPoller( updatesReceiver: UpdateReceiver ): KtorUpdatesPoller { val executor = KtorRequestsExecutor( - token, + telegramAPIUrlsKeeper, HttpClient( CIO.create { timeoutSeconds ?.let { _ -> @@ -50,6 +50,25 @@ fun KtorUpdatesPoller( ) } +@Deprecated("Deprecated due to new TelegramAPIUrlsKeeper") +fun KtorUpdatesPoller( + token: String, + timeoutSeconds: Int? = null, + oneTimeUpdatesLimit: Int? = null, + allowedUpdates: List = ALL_UPDATES_LIST, + exceptionsHandler: (Exception) -> Boolean = { true }, + updatesReceiver: UpdateReceiver +): KtorUpdatesPoller { + return KtorUpdatesPoller( + TelegramAPIUrlsKeeper(token), + timeoutSeconds, + oneTimeUpdatesLimit, + allowedUpdates, + exceptionsHandler, + updatesReceiver + ) +} + class KtorUpdatesPoller( private val executor: RequestsExecutor, private val timeoutSeconds: Int? = null, diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/TelegramAPIUrlsKeeper.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/TelegramAPIUrlsKeeper.kt new file mode 100644 index 0000000000..2fd7790c31 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/TelegramAPIUrlsKeeper.kt @@ -0,0 +1,9 @@ +package com.github.insanusmokrassar.TelegramBotAPI.utils + +class TelegramAPIUrlsKeeper( + token: String, + hostUrl: String = "https://api.telegram.org" +) { + val commonAPIUrl = "$hostUrl/bot$token" + val fileBaseUrl = "$hostUrl/file/bot$token" +} From cb94a3a38908004a409edcd7d80e2b44d93945d1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Aug 2019 13:25:55 +0600 Subject: [PATCH 06/17] Sticker and StickerSet now with isAnimated field --- CHANGELOG.md | 4 ++++ .../github/insanusmokrassar/TelegramBotAPI/types/Common.kt | 1 + .../insanusmokrassar/TelegramBotAPI/types/files/Sticker.kt | 2 ++ .../TelegramBotAPI/types/stickers/StickerSet.kt | 2 ++ 4 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3eec9b1df7..d16f0b716d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ * `TelegramAPIUrlsKeeper` was added to provide more comfortable work with file urls and other things like this +Changes according to [July 29, 2019 Telegram Bot API update](https://core.telegram.org/bots/api#july-29-2019): + +* `Sticker` and `StickerSet` now have field `isAnimated` + ## 0.16.0 Bot API 4.3 * `LoginURL` and `LoginURLInlineKeyboardButton` has been added diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index d6ce1db4da..9d2bac17a1 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -89,6 +89,7 @@ const val forwardTextField = "forward_text" const val botUsernameField = "bot_username" const val switchInlineQueryCurrentChatField = "switch_inline_query_current_chat" const val switchInlineQueryField = "switch_inline_query" +const val isAnimatedField = "is_animated" const val requestWriteAccessField = "request_write_access" diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/Sticker.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/Sticker.kt index 5cbc60242e..93d9b56272 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/Sticker.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/Sticker.kt @@ -21,6 +21,8 @@ data class Sticker( val emoji: String? = null, @SerialName(stickerSetNameField) val stickerSetName: String? = null, + @SerialName(isAnimatedField) + val isAnimated: Boolean = false, @SerialName(maskPositionField) val maskPosition: MaskPosition? = null, @SerialName(fileSizeField) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/stickers/StickerSet.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/stickers/StickerSet.kt index 85fa4210d5..b36fbc4016 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/stickers/StickerSet.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/stickers/StickerSet.kt @@ -13,6 +13,8 @@ data class StickerSet( val title: String, @SerialName(stickersField) val stickers: List, + @SerialName(isAnimatedField) + val isAnimated: Boolean = false, @SerialName(containsMasksField) val containsMasks: Boolean = false ) From 394bec1805606185dc27135a591bc2122f590312 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Aug 2019 13:46:16 +0600 Subject: [PATCH 07/17] chat permissions adding --- CHANGELOG.md | 1 + .../chat/modify/SetChatPermissions.kt | 19 ++++++++++++++ .../TelegramBotAPI/types/Common.kt | 2 ++ .../types/chat/ChatPermissions.kt | 25 +++++++++++++++++++ .../types/chat/GroupChatImpl.kt | 3 ++- .../TelegramBotAPI/types/chat/RawChat.kt | 10 +++++--- .../types/chat/SupergroupChat.kt | 3 ++- .../types/chat/abstracts/GroupChat.kt | 3 +++ 8 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatPermissions.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index d16f0b716d..807bc25cd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ like this Changes according to [July 29, 2019 Telegram Bot API update](https://core.telegram.org/bots/api#july-29-2019): * `Sticker` and `StickerSet` now have field `isAnimated` +* `ChatPermissions` object was added, `GroupChat` interface got `permissions` field, request `SetChatPermissions` was added ## 0.16.0 Bot API 4.3 diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt new file mode 100644 index 0000000000..3ebe1235b4 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPermissions.kt @@ -0,0 +1,19 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify + +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions +import kotlinx.serialization.* +import kotlinx.serialization.internal.BooleanSerializer + +@Serializable +data class SetChatPermissions ( + @SerialName(chatIdField) + override val chatId: ChatIdentifier, + @SerialName(permissionsField) + val permissions: ChatPermissions +): ChatRequest, SimpleRequest { + override fun method(): String = "setChatPermissions" + override fun resultSerializer(): KSerializer = BooleanSerializer +} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index 9d2bac17a1..cc73690882 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -146,6 +146,7 @@ const val isMemberField = "is_member" const val canSendMessagesField = "can_send_messages" const val canSendMediaMessagesField = "can_send_media_messages" const val canSendOtherMessagesField = "can_send_other_messages" +const val canSendPollsField = "can_send_polls" const val canAddWebPagePreviewsField = "can_add_web_page_previews" const val canBeEditedField = "can_be_edited" @@ -202,6 +203,7 @@ const val certificateField = "certificate" const val questionField = "question" const val optionsField = "options" const val payField = "pay" +const val permissionsField = "permissions" const val pointField = "point" const val xShiftField = "x_shift" diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatPermissions.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatPermissions.kt new file mode 100644 index 0000000000..8441538255 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatPermissions.kt @@ -0,0 +1,25 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat + +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ChatPermissions( + @SerialName(canSendMessagesField) + val canSendMessages: Boolean = false, + @SerialName(canSendMediaMessagesField) + val canSendMediaMessages: Boolean = false, + @SerialName(canSendPollsField) + val canSendPolls: Boolean = false, + @SerialName(canSendOtherMessagesField) + val canSendOtherMessages: Boolean = false, + @SerialName(canAddWebPagePreviewsField) + val canAddWebPagePreviews: Boolean = false, + @SerialName(canChangeInfoField) + val canChangeInfo: Boolean = false, + @SerialName(canInviteUsersField) + val canInviteUsers: Boolean = false, + @SerialName(canPinMessagesField) + val canPinMessages: Boolean = false +) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt index 0b06bf6e64..155f4af834 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt @@ -11,5 +11,6 @@ data class GroupChatImpl( override val allMembersAreAdmins: Boolean, override val inviteLink: String? = null, override val chatPhoto: ChatPhoto? = null, - override val pinnedMessage: RawMessage? = null + override val pinnedMessage: RawMessage? = null, + override val permissions: ChatPermissions? = null ) : GroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt index d7a77e61b0..0a225f1d16 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt @@ -21,7 +21,8 @@ data class RawChat( private val sticker_set_name: String? = null, private val can_set_sticker_set: Boolean? = null, @SerialName("photo") - override val chatPhoto: ChatPhoto? = null + override val chatPhoto: ChatPhoto? = null, + private val permissions: ChatPermissions? = null ) : Chat { fun extractChat(): Chat { return when (type) { @@ -31,7 +32,9 @@ data class RawChat( title, all_members_are_administrators ?: false, invite_link, - chatPhoto + chatPhoto, + pinned_message, + permissions ) "supergroup" -> SupergroupChat( id, @@ -43,7 +46,8 @@ data class RawChat( chatPhoto, pinned_message, sticker_set_name, - can_set_sticker_set ?: false + can_set_sticker_set ?: false, + permissions ) "channel" -> ChannelChat( id, diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt index b310b22b6a..a0b5e35560 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt @@ -15,5 +15,6 @@ data class SupergroupChat( override val chatPhoto: ChatPhoto? = null, override val pinnedMessage: RawMessage? = null, val stickerSetName: String? = null, - val canSetStickerSet: Boolean + val canSetStickerSet: Boolean = false, + override val permissions: ChatPermissions? = null ) : GroupChat, UsernameChat, DescriptionChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt index d3ed57909b..eadc612dd8 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt @@ -1,5 +1,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions + interface GroupChat : PublicChat { val allMembersAreAdmins: Boolean + val permissions: ChatPermissions? } From 6310dceacf30b5f93a2f92ede1af7e470d0bbf92 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Aug 2019 13:48:38 +0600 Subject: [PATCH 08/17] allMembersAreAdmins was removed --- CHANGELOG.md | 1 + .../TelegramBotAPI/types/chat/GroupChatImpl.kt | 1 - .../insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt | 3 --- .../TelegramBotAPI/types/chat/SupergroupChat.kt | 1 - .../TelegramBotAPI/types/chat/abstracts/GroupChat.kt | 1 - 5 files changed, 1 insertion(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 807bc25cd6..50e6d18f9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Changes according to [July 29, 2019 Telegram Bot API update](https://core.telegr * `Sticker` and `StickerSet` now have field `isAnimated` * `ChatPermissions` object was added, `GroupChat` interface got `permissions` field, request `SetChatPermissions` was added +* `GroupChat` object now have no field `allMembersAreAdmins` ## 0.16.0 Bot API 4.3 diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt index 155f4af834..96c9baa4d1 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt @@ -8,7 +8,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage data class GroupChatImpl( override val id: ChatId, override val title: String? = null, - override val allMembersAreAdmins: Boolean, override val inviteLink: String? = null, override val chatPhoto: ChatPhoto? = null, override val pinnedMessage: RawMessage? = null, diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt index 0a225f1d16..f37f545fc9 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt @@ -14,7 +14,6 @@ data class RawChat( private val username: Username? = null, private val first_name: String? = null, private val last_name: String? = null, - private val all_members_are_administrators: Boolean? = null, private val description: String? = null, private val invite_link: String? = null, private val pinned_message: RawMessage? = null, @@ -30,7 +29,6 @@ data class RawChat( "group" -> GroupChatImpl( id, title, - all_members_are_administrators ?: false, invite_link, chatPhoto, pinned_message, @@ -41,7 +39,6 @@ data class RawChat( title, username, description, - all_members_are_administrators ?: false, invite_link, chatPhoto, pinned_message, diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt index a0b5e35560..7ccca5dd8b 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt @@ -10,7 +10,6 @@ data class SupergroupChat( override val title: String? = null, override val username: Username? = null, override val description: String? = null, - override val allMembersAreAdmins: Boolean, override val inviteLink: String? = null, override val chatPhoto: ChatPhoto? = null, override val pinnedMessage: RawMessage? = null, diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt index eadc612dd8..4d33d91fe0 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt @@ -3,6 +3,5 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions interface GroupChat : PublicChat { - val allMembersAreAdmins: Boolean val permissions: ChatPermissions? } From 8fbda09d24d70d76f7c6b4a323821a828c8e4f41 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Aug 2019 14:09:14 +0600 Subject: [PATCH 09/17] chat members fields and restrict chat member request updates --- CHANGELOG.md | 3 +++ .../requests/chat/members/RestrictChatMember.kt | 11 +++-------- .../types/ChatMember/AdministratorChatMemberImpl.kt | 1 + .../types/ChatMember/CreatorChatMember.kt | 4 +++- .../types/ChatMember/KickedChatMember.kt | 1 + .../TelegramBotAPI/types/ChatMember/LeftChatMember.kt | 4 +++- .../types/ChatMember/MemberChatMember.kt | 4 +++- .../TelegramBotAPI/types/ChatMember/RawChatMember.kt | 9 ++++++++- .../types/ChatMember/RestrictedChatMember.kt | 10 ++++++++-- .../{ => abstracts}/AdministratorChatMember.kt | 7 ++----- .../ChatMember/{ => abstracts}/BannedChatMember.kt | 2 +- .../types/ChatMember/{ => abstracts}/ChatMember.kt | 2 +- .../ChatMember/abstracts/SpecialRightsChatMember.kt | 7 +++++++ 13 files changed, 44 insertions(+), 21 deletions(-) rename src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/{ => abstracts}/AdministratorChatMember.kt (64%) rename src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/{ => abstracts}/BannedChatMember.kt (93%) rename src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/{ => abstracts}/ChatMember.kt (92%) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/SpecialRightsChatMember.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 50e6d18f9b..e330b45f62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ Changes according to [July 29, 2019 Telegram Bot API update](https://core.telegr * `Sticker` and `StickerSet` now have field `isAnimated` * `ChatPermissions` object was added, `GroupChat` interface got `permissions` field, request `SetChatPermissions` was added * `GroupChat` object now have no field `allMembersAreAdmins` +* `SpecialRightsChatMember` was added for administrators and restricted members rights union, chat members abstractions +was replaced into `abstracts` package and available permissions was updated +* `RestrictChatMember` request now accept `permissions` object instead of separated permissions ## 0.16.0 Bot API 4.3 diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt index 5179587c6c..aa879b1ff8 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/members/RestrictChatMember.kt @@ -3,6 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.UntilDate import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions import kotlinx.serialization.* import kotlinx.serialization.internal.BooleanSerializer @@ -14,14 +15,8 @@ data class RestrictChatMember( override val userId: UserId, @SerialName(untilDateField) override val untilDate: TelegramDate? = null, - @SerialName(canSendMessagesField) - private val canSendMessages: Boolean? = null, - @SerialName(canSendMediaMessagesField) - private val canSendMediaMessages: Boolean? = null, - @SerialName(canSendOtherMessagesField) - private val canSendOtherMessages: Boolean? = null, - @SerialName(canAddWebPagePreviewsField) - private val canAddWebPagePreviews: Boolean? = null + @SerialName(permissionsField) + val permissions: ChatPermissions ) : ChatMemberRequest, UntilDate { override fun method(): String = "restrictChatMember" override fun resultSerializer(): KSerializer = BooleanSerializer diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/AdministratorChatMemberImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/AdministratorChatMemberImpl.kt index dd0245717d..168b61ff8f 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/AdministratorChatMemberImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/AdministratorChatMemberImpl.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.AdministratorChatMember import com.github.insanusmokrassar.TelegramBotAPI.types.User data class AdministratorChatMemberImpl( diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/CreatorChatMember.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/CreatorChatMember.kt index c6507cdd2a..b00de59489 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/CreatorChatMember.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/CreatorChatMember.kt @@ -1,8 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.AdministratorChatMember import com.github.insanusmokrassar.TelegramBotAPI.types.User -data class CreatorChatMember(override val user: User) : AdministratorChatMember { +data class CreatorChatMember(override val user: User) : + AdministratorChatMember { override val canBeEdited: Boolean = true override val canChangeInfo: Boolean = true override val canPostMessages: Boolean = true diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/KickedChatMember.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/KickedChatMember.kt index 486e30e6da..ad94b7ba24 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/KickedChatMember.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/KickedChatMember.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.BannedChatMember import com.github.insanusmokrassar.TelegramBotAPI.types.TelegramDate import com.github.insanusmokrassar.TelegramBotAPI.types.User diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/LeftChatMember.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/LeftChatMember.kt index 0fbcd3b4b7..aa90a9627b 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/LeftChatMember.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/LeftChatMember.kt @@ -1,5 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMember import com.github.insanusmokrassar.TelegramBotAPI.types.User -data class LeftChatMember(override val user: User) : ChatMember +data class LeftChatMember(override val user: User) : + ChatMember diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/MemberChatMember.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/MemberChatMember.kt index b6ce19920c..7230eef218 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/MemberChatMember.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/MemberChatMember.kt @@ -1,5 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMember import com.github.insanusmokrassar.TelegramBotAPI.types.User -data class MemberChatMember(override val user: User) : ChatMember +data class MemberChatMember(override val user: User) : + ChatMember diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RawChatMember.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RawChatMember.kt index b2037bbb81..85e730212d 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RawChatMember.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RawChatMember.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMember import kotlinx.serialization.* @Serializable @@ -32,6 +33,8 @@ data class RawChatMember( private val canSendMessages: Boolean = false, @SerialName(canSendMediaMessagesField) private val canSendMediaMessages: Boolean = false, + @SerialName(canSendPollsField) + private val canSendPolls: Boolean = false, @SerialName(canSendOtherMessagesField) private val canSendOtherMessages: Boolean = false, @SerialName(canAddWebPagePreviewsField) @@ -60,8 +63,12 @@ data class RawChatMember( isMember, canSendMessages, canSendMediaMessages, + canSendPolls, canSendOtherMessages, - canAddWebPagePreviews + canAddWebPagePreviews, + canChangeInfo, + canInviteUsers, + canPinMessages ) "left" -> LeftChatMember(user) "kicked" -> KickedChatMember( diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RestrictedChatMember.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RestrictedChatMember.kt index a6ab6358bd..1f685f9b1b 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RestrictedChatMember.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RestrictedChatMember.kt @@ -1,5 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.BannedChatMember +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.SpecialRightsChatMember import com.github.insanusmokrassar.TelegramBotAPI.types.TelegramDate import com.github.insanusmokrassar.TelegramBotAPI.types.User @@ -9,6 +11,10 @@ data class RestrictedChatMember( val isMember: Boolean, val canSendMessages: Boolean, val canSendMediaMessages: Boolean, + val canSendPolls: Boolean, val canSendOtherMessages: Boolean, - val canAddWebpagePreviews: Boolean -) : BannedChatMember \ No newline at end of file + val canAddWebpagePreviews: Boolean, + override val canChangeInfo: Boolean, + override val canInviteUsers: Boolean, + override val canPinMessages: Boolean +) : BannedChatMember, SpecialRightsChatMember \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/AdministratorChatMember.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/AdministratorChatMember.kt similarity index 64% rename from src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/AdministratorChatMember.kt rename to src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/AdministratorChatMember.kt index 0f1ec8e402..27bc3e5842 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/AdministratorChatMember.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/AdministratorChatMember.kt @@ -1,13 +1,10 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember +package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts -interface AdministratorChatMember : ChatMember { +interface AdministratorChatMember : SpecialRightsChatMember { val canBeEdited: Boolean - val canChangeInfo: Boolean val canPostMessages: Boolean val canEditMessages: Boolean val canRemoveMessages: Boolean - val canInviteUsers: Boolean val canRestrictMembers: Boolean - val canPinMessages: Boolean val canPromoteMembers: Boolean } \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/BannedChatMember.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/BannedChatMember.kt similarity index 93% rename from src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/BannedChatMember.kt rename to src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/BannedChatMember.kt index 1bf15213b8..7cb1a3f79d 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/BannedChatMember.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/BannedChatMember.kt @@ -1,4 +1,4 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember +package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.UntilDate diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/ChatMember.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/ChatMember.kt similarity index 92% rename from src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/ChatMember.kt rename to src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/ChatMember.kt index 86f70d1bb3..2d6c0b4f41 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/ChatMember.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/ChatMember.kt @@ -1,4 +1,4 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember +package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts import com.github.insanusmokrassar.TelegramBotAPI.types.User diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/SpecialRightsChatMember.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/SpecialRightsChatMember.kt new file mode 100644 index 0000000000..97c51fb5a6 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/abstracts/SpecialRightsChatMember.kt @@ -0,0 +1,7 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts + +interface SpecialRightsChatMember : ChatMember { + val canChangeInfo: Boolean + val canInviteUsers: Boolean + val canPinMessages: Boolean +} From c47c82ac4378f6dd1b05442fd68163c9c07578ed Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Aug 2019 14:15:06 +0600 Subject: [PATCH 10/17] Group chats now have a description --- CHANGELOG.md | 1 + .../insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt | 1 + .../insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt | 1 + .../TelegramBotAPI/types/chat/SupergroupChat.kt | 2 +- .../TelegramBotAPI/types/chat/abstracts/GroupChat.kt | 2 +- 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e330b45f62..1176d6f5cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Changes according to [July 29, 2019 Telegram Bot API update](https://core.telegr * `SpecialRightsChatMember` was added for administrators and restricted members rights union, chat members abstractions was replaced into `abstracts` package and available permissions was updated * `RestrictChatMember` request now accept `permissions` object instead of separated permissions +* All `GroupChat` instances have description ## 0.16.0 Bot API 4.3 diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt index 96c9baa4d1..38e5cd5d7c 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt @@ -8,6 +8,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage data class GroupChatImpl( override val id: ChatId, override val title: String? = null, + override val description: String? = null, override val inviteLink: String? = null, override val chatPhoto: ChatPhoto? = null, override val pinnedMessage: RawMessage? = null, diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt index f37f545fc9..cd00c25e6c 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt @@ -29,6 +29,7 @@ data class RawChat( "group" -> GroupChatImpl( id, title, + description, invite_link, chatPhoto, pinned_message, diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt index 7ccca5dd8b..c32bdd6e7c 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt @@ -16,4 +16,4 @@ data class SupergroupChat( val stickerSetName: String? = null, val canSetStickerSet: Boolean = false, override val permissions: ChatPermissions? = null -) : GroupChat, UsernameChat, DescriptionChat +) : GroupChat, UsernameChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt index 4d33d91fe0..c4c02a2f6e 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt @@ -2,6 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions -interface GroupChat : PublicChat { +interface GroupChat : PublicChat, DescriptionChat { val permissions: ChatPermissions? } From d6bb14e3424734f920d3d620edaf4a76725c823a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Aug 2019 15:15:22 +0600 Subject: [PATCH 11/17] total rework of chats --- CHANGELOG.md | 13 +++- .../bot/exceptions/HandleException.kt | 15 ++++ .../chat/stickers/SetChatStickerSet.kt | 2 +- .../TelegramBotAPI/types/Common.kt | 1 + .../{PrivateChat.kt => ChannelChatImpl.kt} | 15 ++-- .../TelegramBotAPI/types/chat/Chat.kt | 9 --- .../TelegramBotAPI/types/chat/GroupChat.kt | 9 --- .../types/chat/GroupChatImpl.kt | 7 +- .../types/chat/PrivateChatImpl.kt | 11 +++ .../TelegramBotAPI/types/chat/PublicChat.kt | 9 --- .../TelegramBotAPI/types/chat/RawChat.kt | 73 ++++++++++++++----- .../types/chat/SupergroupChat.kt | 19 ----- .../{ChannelChat.kt => SupergroupChatImpl.kt} | 15 ++-- .../{DescriptionChat.kt => ChannelChat.kt} | 4 +- .../types/chat/abstracts/Chat.kt | 1 - .../types/chat/abstracts/GroupChat.kt | 6 +- .../types/chat/abstracts/PrivateChat.kt | 6 ++ .../types/chat/abstracts/PublicChat.kt | 6 +- .../types/chat/abstracts/SuperPublicChat.kt | 3 + .../types/chat/abstracts/SupergroupChat.kt | 3 + .../abstracts/extended/ExtendedChannelChat.kt | 5 ++ .../chat/abstracts/extended/ExtendedChat.kt | 8 ++ .../abstracts/extended/ExtendedGroupChat.kt | 8 ++ .../abstracts/extended/ExtendedPrivateChat.kt | 5 ++ .../abstracts/extended/ExtendedPublicChat.kt | 10 +++ .../extended/ExtendedSupergroupChat.kt | 9 +++ .../chat/extended/ExtendedChannelChatImpl.kt | 15 ++++ .../chat/extended/ExtendedGroupChatImpl.kt | 17 +++++ .../chat/extended/ExtendedPrivateChatImpl.kt | 12 +++ .../extended/ExtendedSupergroupChatImpl.kt | 19 +++++ .../TelegramBotAPI/types/files/Sticker.kt | 2 +- .../types/message/ChannelEventMessage.kt | 3 +- .../types/message/RawMessage.kt | 14 ++-- .../types/message/SupergroupEventMessage.kt | 3 +- 34 files changed, 240 insertions(+), 117 deletions(-) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt rename src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/{PrivateChat.kt => ChannelChatImpl.kt} (53%) delete mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/Chat.kt delete mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt delete mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PublicChat.kt delete mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt rename src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/{ChannelChat.kt => SupergroupChatImpl.kt} (50%) rename src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/{DescriptionChat.kt => ChannelChat.kt} (50%) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PrivateChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SuperPublicChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SupergroupChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChannelChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedGroupChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPrivateChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPublicChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedSupergroupChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 1176d6f5cc..586dbea97f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,16 +2,14 @@ ## 0.17.0 +Libraries updates: + * Kotlin version `1.3.31` -> `1.3.41` * Kotlin Coroutines version `1.2.1` -> `1.2.2` * Kotlin Serialization version `0.11.0` -> `0.11.1` * Joda Time version `2.10.1` -> `2.10.3` * Ktor version `1.1.4` -> `1.2.2` -* `RequestsExecutor` now is `Closeable` -* `TelegramAPIUrlsKeeper` was added to provide more comfortable work with file urls and other things -like this - Changes according to [July 29, 2019 Telegram Bot API update](https://core.telegram.org/bots/api#july-29-2019): * `Sticker` and `StickerSet` now have field `isAnimated` @@ -22,6 +20,13 @@ was replaced into `abstracts` package and available permissions was updated * `RestrictChatMember` request now accept `permissions` object instead of separated permissions * All `GroupChat` instances have description +Other important changes: + +* Totally reworked chats hierarchy. `Extended` abstractions was added for cases when called `GetChat` request +* `RequestsExecutor` now is `Closeable` +* `TelegramAPIUrlsKeeper` was added to provide more comfortable work with file urls and other things +like this + ## 0.16.0 Bot API 4.3 * `LoginURL` and `LoginURLInlineKeyboardButton` has been added diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt new file mode 100644 index 0000000000..9c147a59b5 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt @@ -0,0 +1,15 @@ +package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions + +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.RawChat + +sealed class HandleException ( + message: String +) : IllegalArgumentException( + message +) + +class IllegalChatRawObjectException( + rawChat: RawChat +) : HandleException( + "One of the fields in raw chat object is incorrect" +) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt index 4e0d4519fa..3452572914 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt @@ -11,7 +11,7 @@ data class SetChatStickerSet( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(stickerSetNameField) - val stickerSetName: String + val stickerSetName: StickerSetName ): ChatRequest, SimpleRequest { override fun method(): String = "setChatStickerSet" override fun resultSerializer(): KSerializer = BooleanSerializer diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index cc73690882..2c2cf8c768 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -17,6 +17,7 @@ typealias ShippingOptionIdentifier = String typealias StartParameter = String typealias InlineMessageIdentifier = String typealias PollIdentifier = String +typealias StickerSetName = String val callbackQueryAnswerLength = 0 until 200 val captionLength = 0 until 1024 diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt similarity index 53% rename from src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChat.kt rename to src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt index 0f7f79fd7b..c10fc3ab98 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt @@ -1,13 +1,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.UsernameChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage -data class PrivateChat( +data class ChannelChatImpl( override val id: ChatId, - override val username: Username? = null, - val firstName: String? = null, - val lastName: String? = null, - override val chatPhoto: ChatPhoto? = null -) : Chat, UsernameChat + override val title: String, + override val username: Username? = null +) : ChannelChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/Chat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/Chat.kt deleted file mode 100644 index 9f38f83d41..0000000000 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/Chat.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types.chat - -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat - -@Deprecated( - "Replaced into another package", - ReplaceWith("Chat", "com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat") -) -typealias Chat = Chat \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChat.kt deleted file mode 100644 index 570d671d1a..0000000000 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChat.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types.chat - -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat - -@Deprecated( - "Replaced into another package", - ReplaceWith("GroupChat", "com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat") -) -typealias GroupChat = GroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt index 38e5cd5d7c..4959f2077a 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt @@ -7,10 +7,5 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage data class GroupChatImpl( override val id: ChatId, - override val title: String? = null, - override val description: String? = null, - override val inviteLink: String? = null, - override val chatPhoto: ChatPhoto? = null, - override val pinnedMessage: RawMessage? = null, - override val permissions: ChatPermissions? = null + override val title: String ) : GroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt new file mode 100644 index 0000000000..c8a8f837f1 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt @@ -0,0 +1,11 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat + +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* + +data class PrivateChatImpl( + override val id: ChatId, + override val username: Username? = null, + override val firstName: String = "", + override val lastName: String = "" +) : PrivateChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PublicChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PublicChat.kt deleted file mode 100644 index fbfb55226d..0000000000 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PublicChat.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types.chat - -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat - -@Deprecated( - "Replaced into another package", - ReplaceWith("PublicChat", "com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat") -) -typealias PublicChat = PublicChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt index cd00c25e6c..e04894c535 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt @@ -1,7 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat +import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.IllegalChatRawObjectException import com.github.insanusmokrassar.TelegramBotAPI.types.* 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.chat.extended.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -20,43 +23,75 @@ data class RawChat( private val sticker_set_name: String? = null, private val can_set_sticker_set: Boolean? = null, @SerialName("photo") - override val chatPhoto: ChatPhoto? = null, + private val chatPhoto: ChatPhoto? = null, private val permissions: ChatPermissions? = null ) : Chat { - fun extractChat(): Chat { + private fun extractExtendedChat(): ExtendedChat { return when (type) { - "private" -> PrivateChat(id, username, first_name, last_name, chatPhoto) - "group" -> GroupChatImpl( + "private" -> ExtendedPrivateChatImpl(id, username, first_name ?: "", last_name ?: "", chatPhoto!!) + "group" -> ExtendedGroupChatImpl( id, - title, - description, + title!!, + chatPhoto!!, + description ?: "", invite_link, - chatPhoto, - pinned_message, - permissions + permissions!!, + pinned_message ) - "supergroup" -> SupergroupChat( + "supergroup" -> ExtendedSupergroupChatImpl( id, - title, + title!!, username, - description, + chatPhoto!!, + description ?: "", invite_link, - chatPhoto, + permissions!!, pinned_message, sticker_set_name, - can_set_sticker_set ?: false, - permissions + can_set_sticker_set ?: false ) - "channel" -> ChannelChat( + "channel" -> ExtendedChannelChatImpl( id, - title, + title!!, username, - description, + chatPhoto!!, + description ?: "", invite_link, - chatPhoto, pinned_message ) else -> throw IllegalArgumentException("Unknown type of chat") } } + + private fun extractPreviewChat(): Chat { + return when (type) { + "private" -> PrivateChatImpl(id, username, first_name ?: "", last_name ?: "") + "group" -> GroupChatImpl( + id, + title!! + ) + "supergroup" -> SupergroupChatImpl( + id, + title!!, + username + ) + "channel" -> ChannelChatImpl( + id, + title!!, + username + ) + else -> throw IllegalArgumentException("Unknown type of chat") + } + } + + fun extractChat(): Chat { + return try { + when (chatPhoto) { + null -> extractPreviewChat() + else -> extractExtendedChat() + } + } catch (e: NullPointerException) { + throw IllegalChatRawObjectException(this) + } + } } diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt deleted file mode 100644 index c32bdd6e7c..0000000000 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types.chat - -import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat -import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage - -data class SupergroupChat( - override val id: ChatId, - override val title: String? = null, - override val username: Username? = null, - override val description: String? = null, - override val inviteLink: String? = null, - override val chatPhoto: ChatPhoto? = null, - override val pinnedMessage: RawMessage? = null, - val stickerSetName: String? = null, - val canSetStickerSet: Boolean = false, - override val permissions: ChatPermissions? = null -) : GroupChat, UsernameChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt similarity index 50% rename from src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChat.kt rename to src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt index 598b991822..d492647dd8 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt @@ -2,15 +2,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage -data class ChannelChat( +data class SupergroupChatImpl( override val id: ChatId, - override val title: String? = null, - override val username: Username? = null, - override val description: String? = null, - override val inviteLink: String? = null, - override val chatPhoto: ChatPhoto? = null, - override val pinnedMessage: RawMessage? -) : PublicChat, UsernameChat, DescriptionChat + override val title: String, + override val username: Username? = null +) : SupergroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/DescriptionChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/ChannelChat.kt similarity index 50% rename from src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/DescriptionChat.kt rename to src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/ChannelChat.kt index f572b5fcd5..43c612ac1e 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/DescriptionChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/ChannelChat.kt @@ -1,5 +1,3 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts -interface DescriptionChat : PublicChat { - val description: String? -} +interface ChannelChat : SuperPublicChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt index 7b84aa73b7..2f208fa270 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt @@ -5,5 +5,4 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto interface Chat { val id: ChatId - val chatPhoto: ChatPhoto? } \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt index c4c02a2f6e..06efb55190 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt @@ -1,7 +1,3 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions - -interface GroupChat : PublicChat, DescriptionChat { - val permissions: ChatPermissions? -} +interface GroupChat : PublicChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PrivateChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PrivateChat.kt new file mode 100644 index 0000000000..0c2286f85d --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PrivateChat.kt @@ -0,0 +1,6 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts + +interface PrivateChat : Chat, UsernameChat { + val firstName: String + val lastName: String +} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PublicChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PublicChat.kt index de874bb339..d72876149b 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PublicChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PublicChat.kt @@ -1,9 +1,5 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts -import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage - interface PublicChat : Chat { - val title: String? - val inviteLink: String? - val pinnedMessage: RawMessage? + val title: String } diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SuperPublicChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SuperPublicChat.kt new file mode 100644 index 0000000000..236af28116 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SuperPublicChat.kt @@ -0,0 +1,3 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts + +interface SuperPublicChat : PublicChat, UsernameChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SupergroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SupergroupChat.kt new file mode 100644 index 0000000000..52c0ea464e --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SupergroupChat.kt @@ -0,0 +1,3 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts + +interface SupergroupChat : GroupChat, SuperPublicChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChannelChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChannelChat.kt new file mode 100644 index 0000000000..5601782e7c --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChannelChat.kt @@ -0,0 +1,5 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.ChannelChat + +interface ExtendedChannelChat : ChannelChat, ExtendedPublicChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt new file mode 100644 index 0000000000..5a11195175 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt @@ -0,0 +1,8 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat + +interface ExtendedChat : Chat { + val chatPhoto: ChatPhoto +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedGroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedGroupChat.kt new file mode 100644 index 0000000000..283b89d96b --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedGroupChat.kt @@ -0,0 +1,8 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat + +interface ExtendedGroupChat : GroupChat, ExtendedPublicChat { + val permissions: ChatPermissions +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPrivateChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPrivateChat.kt new file mode 100644 index 0000000000..67e00a46d7 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPrivateChat.kt @@ -0,0 +1,5 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat + +interface ExtendedPrivateChat : PrivateChat, ExtendedChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPublicChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPublicChat.kt new file mode 100644 index 0000000000..5f10a77528 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPublicChat.kt @@ -0,0 +1,10 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage + +interface ExtendedPublicChat : ExtendedChat, PublicChat { + val description: String + val inviteLink: String? + val pinnedMessage: RawMessage? +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedSupergroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedSupergroupChat.kt new file mode 100644 index 0000000000..5dd9f3d8ca --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedSupergroupChat.kt @@ -0,0 +1,9 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.StickerSetName +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat + +interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat { + val stickerSetName: StickerSetName? + val canSetStickerSet: Boolean +} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt new file mode 100644 index 0000000000..66fa32a89b --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt @@ -0,0 +1,15 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChannelChat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage + +data class ExtendedChannelChatImpl( + override val id: ChatId, + override val title: String, + override val username: Username?, + override val chatPhoto: ChatPhoto, + override val description: String, + override val inviteLink: String?, + override val pinnedMessage: RawMessage? +) : ExtendedChannelChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt new file mode 100644 index 0000000000..58ee8695bb --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt @@ -0,0 +1,17 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedGroupChat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage + +data class ExtendedGroupChatImpl( + override val id: ChatId, + override val title: String, + override val chatPhoto: ChatPhoto, + override val description: String, + override val inviteLink: String?, + override val permissions: ChatPermissions, + override val pinnedMessage: RawMessage? +) : ExtendedGroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt new file mode 100644 index 0000000000..3469146856 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt @@ -0,0 +1,12 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedPrivateChat + +data class ExtendedPrivateChatImpl( + override val id: ChatId, + override val username: Username? = null, + override val firstName: String = "", + override val lastName: String = "", + override val chatPhoto: ChatPhoto +) : ExtendedPrivateChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt new file mode 100644 index 0000000000..bd40e28001 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt @@ -0,0 +1,19 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedSupergroupChat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage + +data class ExtendedSupergroupChatImpl( + override val id: ChatId, + override val title: String, + override val username: Username? = null, + override val chatPhoto: ChatPhoto, + override val description: String, + override val inviteLink: String?, + override val permissions: ChatPermissions, + override val pinnedMessage: RawMessage?, + override val stickerSetName: StickerSetName?, + override val canSetStickerSet: Boolean +) : ExtendedSupergroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/Sticker.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/Sticker.kt index 93d9b56272..fd779dad0e 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/Sticker.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/Sticker.kt @@ -20,7 +20,7 @@ data class Sticker( @SerialName(emojiField) val emoji: String? = null, @SerialName(stickerSetNameField) - val stickerSetName: String? = null, + val stickerSetName: StickerSetName? = null, @SerialName(isAnimatedField) val isAnimated: Boolean = false, @SerialName(maskPositionField) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelEventMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelEventMessage.kt index 63fb4df00e..5a08484965 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelEventMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelEventMessage.kt @@ -1,7 +1,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChannelChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChannelChatImpl +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.ChannelChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.ChannelEvent import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ChatEventMessage import org.joda.time.DateTime diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt index 8b76a1d96a..3145aff30a 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt @@ -5,7 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessage import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessageEntitiesSerializer import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.chat.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.files.* import com.github.insanusmokrassar.TelegramBotAPI.types.games.Game import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.* @@ -199,18 +199,18 @@ data class RawMessage( chatEvent ?.let { chatEvent -> when (chat) { - is GroupChat -> GroupEventMessage( - messageId, - chat, - chatEvent as? GroupEvent ?: throwWrongChatEvent(GroupChat::class, chatEvent), - date.asDate - ) is SupergroupChat -> SupergroupEventMessage( messageId, chat, chatEvent as? SupergroupEvent ?: throwWrongChatEvent(SupergroupEvent::class, chatEvent), date.asDate ) + is GroupChat -> GroupEventMessage( + messageId, + chat, + chatEvent as? GroupEvent ?: throwWrongChatEvent(GroupChat::class, chatEvent), + date.asDate + ) is ChannelChat -> ChannelEventMessage( messageId, chat, diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/SupergroupEventMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/SupergroupEventMessage.kt index d767299b35..372be34470 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/SupergroupEventMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/SupergroupEventMessage.kt @@ -1,7 +1,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.SupergroupChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.SupergroupChatImpl +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.SupergroupEvent import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ChatEventMessage import org.joda.time.DateTime From 1f62c8cf9876e2d6ba55c42dd815d93a59c80e31 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Aug 2019 15:41:07 +0600 Subject: [PATCH 12/17] RawChat boilerplate was removed and replaced by serializers --- CHANGELOG.md | 1 + .../bot/exceptions/HandleException.kt | 15 --- .../requests/chat/get/GetChat.kt | 7 +- .../TelegramBotAPI/types/Common.kt | 5 + .../types/chat/ChannelChatImpl.kt | 6 ++ .../types/chat/ChatSerializers.kt | 68 +++++++++++++ .../types/chat/GroupChatImpl.kt | 8 +- .../types/chat/PrivateChatImpl.kt | 7 ++ .../TelegramBotAPI/types/chat/RawChat.kt | 97 ------------------- .../types/chat/SupergroupChatImpl.kt | 6 ++ .../types/chat/abstracts/Chat.kt | 3 + .../chat/abstracts/extended/ExtendedChat.kt | 3 + .../chat/extended/ExtendedChannelChatImpl.kt | 18 +++- .../chat/extended/ExtendedGroupChatImpl.kt | 19 +++- .../chat/extended/ExtendedPrivateChatImpl.kt | 12 ++- .../extended/ExtendedSupergroupChatImpl.kt | 23 ++++- .../types/message/RawMessage.kt | 8 +- 17 files changed, 168 insertions(+), 138 deletions(-) delete mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt delete mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 586dbea97f..98a5d66c83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ was replaced into `abstracts` package and available permissions was updated Other important changes: * Totally reworked chats hierarchy. `Extended` abstractions was added for cases when called `GetChat` request +* `RawChat` boilerplate was removed and replaced by serializers * `RequestsExecutor` now is `Closeable` * `TelegramAPIUrlsKeeper` was added to provide more comfortable work with file urls and other things like this diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt deleted file mode 100644 index 9c147a59b5..0000000000 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions - -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.RawChat - -sealed class HandleException ( - message: String -) : IllegalArgumentException( - message -) - -class IllegalChatRawObjectException( - rawChat: RawChat -) : HandleException( - "One of the fields in raw chat object is incorrect" -) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChat.kt index fdd9ce0bd6..275b772ff4 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChat.kt @@ -3,7 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.RawChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ExtendedChatSerializer +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* @@ -11,7 +12,7 @@ import kotlinx.serialization.* data class GetChat( @SerialName(chatIdField) override val chatId: ChatIdentifier -): ChatRequest, SimpleRequest { +): ChatRequest, SimpleRequest { override fun method(): String = "getChat" - override fun resultSerializer(): KSerializer = RawChat.serializer() + override fun resultSerializer(): KSerializer = ExtendedChatSerializer } diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index 2c2cf8c768..dd07501d98 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -56,6 +56,7 @@ const val lastNameField = "last_name" const val languageCodeField = "language_code" const val textEntitiesField = "text_entities" const val stickerSetNameField = "set_name" +const val stickerSetNameFullField = "sticker_set_name" const val maskPositionField = "mask_position" const val phoneNumberField = "phone_number" const val userIdField = "user_id" @@ -91,6 +92,8 @@ const val botUsernameField = "bot_username" const val switchInlineQueryCurrentChatField = "switch_inline_query_current_chat" const val switchInlineQueryField = "switch_inline_query" const val isAnimatedField = "is_animated" +const val inviteLinkField = "invite_link" +const val pinnedMessageField = "pinned_message" const val requestWriteAccessField = "request_write_access" @@ -149,6 +152,7 @@ const val canSendMediaMessagesField = "can_send_media_messages" const val canSendOtherMessagesField = "can_send_other_messages" const val canSendPollsField = "can_send_polls" const val canAddWebPagePreviewsField = "can_add_web_page_previews" +const val canSetStickerSetField = "can_set_sticker_set" const val canBeEditedField = "can_be_edited" const val canChangeInfoField = "can_change_info" @@ -205,6 +209,7 @@ const val questionField = "question" const val optionsField = "options" const val payField = "pay" const val permissionsField = "permissions" +const val typeField = "type" const val pointField = "point" const val xShiftField = "x_shift" diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt index c10fc3ab98..53a434e3c7 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt @@ -4,9 +4,15 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class ChannelChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(titleField) override val title: String, + @SerialName(usernameField) override val username: Username? = null ) : ChannelChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt new file mode 100644 index 0000000000..4de5303901 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt @@ -0,0 +1,68 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat + +import com.github.insanusmokrassar.TelegramBotAPI.types.* +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.chat.extended.* +import kotlinx.serialization.* +import kotlinx.serialization.internal.StringDescriptor +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonObjectSerializer + +object PreviewChatSerializer : KSerializer { + override val descriptor: SerialDescriptor = StringDescriptor.withName("PreviewChatSerializer") + + override fun deserialize(decoder: Decoder): Chat { + val decodedJson = JsonObjectSerializer.deserialize(decoder) + + val type = decodedJson.getPrimitive(typeField).content + + return when (type) { + "private" -> Json.nonstrict.fromJson(PrivateChatImpl.serializer(), decodedJson) + "group" -> Json.nonstrict.fromJson(GroupChatImpl.serializer(), decodedJson) + "supergroup" -> Json.nonstrict.fromJson(SupergroupChatImpl.serializer(), decodedJson) + "channel" -> Json.nonstrict.fromJson(ChannelChatImpl.serializer(), decodedJson) + else -> throw IllegalArgumentException("Unknown type of chat") + } + } + + override fun serialize(encoder: Encoder, obj: Chat) { + when (obj) { + is ExtendedChat -> ExtendedChatSerializer.serialize(encoder, obj) + is PrivateChatImpl -> PrivateChatImpl.serializer().serialize(encoder, obj) + is GroupChatImpl -> GroupChatImpl.serializer().serialize(encoder, obj) + is SupergroupChatImpl -> SupergroupChatImpl.serializer().serialize(encoder, obj) + is ChannelChatImpl -> ChannelChatImpl.serializer().serialize(encoder, obj) + } + } +} + +object ExtendedChatSerializer : KSerializer { + override val descriptor: SerialDescriptor = StringDescriptor.withName("PreviewChatSerializer") + + override fun deserialize(decoder: Decoder): ExtendedChat { + val decodedJson = JsonObjectSerializer.deserialize(decoder) + + val type = decodedJson.getPrimitive(typeField).content + + return when (type) { + "private" -> Json.nonstrict.fromJson(ExtendedPrivateChatImpl.serializer(), decodedJson) + "group" -> Json.nonstrict.fromJson(ExtendedGroupChatImpl.serializer(), decodedJson) + "supergroup" -> Json.nonstrict.fromJson(ExtendedSupergroupChatImpl.serializer(), decodedJson) + "channel" -> Json.nonstrict.fromJson(ExtendedChannelChatImpl.serializer(), decodedJson) + else -> throw IllegalArgumentException("Unknown type of chat") + } + } + + override fun serialize(encoder: Encoder, obj: ExtendedChat) { + when (obj) { + is ExtendedPrivateChatImpl -> ExtendedPrivateChatImpl.serializer().serialize(encoder, obj) + is ExtendedGroupChatImpl -> ExtendedGroupChatImpl.serializer().serialize(encoder, obj) + is ExtendedSupergroupChatImpl -> ExtendedSupergroupChatImpl.serializer().serialize(encoder, obj) + is ExtendedChannelChatImpl -> ExtendedChannelChatImpl.serializer().serialize(encoder, obj) + } + } +} + + + diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt index 4959f2077a..0f97e79b70 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt @@ -1,11 +1,15 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat -import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId -import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto +import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class GroupChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(titleField) override val title: String ) : GroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt index c8a8f837f1..e335fa4aa0 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt @@ -2,10 +2,17 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class PrivateChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(usernameField) override val username: Username? = null, + @SerialName(firstNameField) override val firstName: String = "", + @SerialName(lastNameField) override val lastName: String = "" ) : PrivateChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt deleted file mode 100644 index e04894c535..0000000000 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt +++ /dev/null @@ -1,97 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types.chat - -import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.IllegalChatRawObjectException -import com.github.insanusmokrassar.TelegramBotAPI.types.* -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.chat.extended.* -import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class RawChat( - override val id: ChatId, - private val type: String, - private val title: String? = null, - private val username: Username? = null, - private val first_name: String? = null, - private val last_name: String? = null, - private val description: String? = null, - private val invite_link: String? = null, - private val pinned_message: RawMessage? = null, - private val sticker_set_name: String? = null, - private val can_set_sticker_set: Boolean? = null, - @SerialName("photo") - private val chatPhoto: ChatPhoto? = null, - private val permissions: ChatPermissions? = null -) : Chat { - private fun extractExtendedChat(): ExtendedChat { - return when (type) { - "private" -> ExtendedPrivateChatImpl(id, username, first_name ?: "", last_name ?: "", chatPhoto!!) - "group" -> ExtendedGroupChatImpl( - id, - title!!, - chatPhoto!!, - description ?: "", - invite_link, - permissions!!, - pinned_message - ) - "supergroup" -> ExtendedSupergroupChatImpl( - id, - title!!, - username, - chatPhoto!!, - description ?: "", - invite_link, - permissions!!, - pinned_message, - sticker_set_name, - can_set_sticker_set ?: false - ) - "channel" -> ExtendedChannelChatImpl( - id, - title!!, - username, - chatPhoto!!, - description ?: "", - invite_link, - pinned_message - ) - else -> throw IllegalArgumentException("Unknown type of chat") - } - } - - private fun extractPreviewChat(): Chat { - return when (type) { - "private" -> PrivateChatImpl(id, username, first_name ?: "", last_name ?: "") - "group" -> GroupChatImpl( - id, - title!! - ) - "supergroup" -> SupergroupChatImpl( - id, - title!!, - username - ) - "channel" -> ChannelChatImpl( - id, - title!!, - username - ) - else -> throw IllegalArgumentException("Unknown type of chat") - } - } - - fun extractChat(): Chat { - return try { - when (chatPhoto) { - null -> extractPreviewChat() - else -> extractExtendedChat() - } - } catch (e: NullPointerException) { - throw IllegalChatRawObjectException(this) - } - } -} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt index d492647dd8..ce53d3bd4f 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt @@ -5,9 +5,15 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class SupergroupChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(titleField) override val title: String, + @SerialName(usernameField) override val username: Username? = null ) : SupergroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt index 2f208fa270..7eead97d8e 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt @@ -2,7 +2,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable +@Serializable(PreviewChatSerializer::class) interface Chat { val id: ChatId } \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt index 5a11195175..24a13a19d1 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt @@ -1,8 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ExtendedChatSerializer import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import kotlinx.serialization.Serializable +@Serializable(ExtendedChatSerializer::class) interface ExtendedChat : Chat { val chatPhoto: ChatPhoto } \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt index 66fa32a89b..7f47b04816 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt @@ -3,13 +3,23 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChannelChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class ExtendedChannelChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(titleField) override val title: String, - override val username: Username?, + @SerialName(usernameField) + override val username: Username? = null, + @SerialName(photoField) override val chatPhoto: ChatPhoto, - override val description: String, - override val inviteLink: String?, - override val pinnedMessage: RawMessage? + @SerialName(descriptionField) + override val description: String = "", + @SerialName(inviteLinkField) + override val inviteLink: String? = null, + @SerialName(pinnedMessageField) + override val pinnedMessage: RawMessage? = null ) : ExtendedChannelChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt index 58ee8695bb..f9990cd24d 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt @@ -1,17 +1,26 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended -import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId -import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto +import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedGroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class ExtendedGroupChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(titleField) override val title: String, + @SerialName(photoField) override val chatPhoto: ChatPhoto, - override val description: String, - override val inviteLink: String?, + @SerialName(permissionsField) override val permissions: ChatPermissions, - override val pinnedMessage: RawMessage? + @SerialName(descriptionField) + override val description: String = "", + @SerialName(inviteLinkField) + override val inviteLink: String? = null, + @SerialName(pinnedMessageField) + override val pinnedMessage: RawMessage? = null ) : ExtendedGroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt index 3469146856..c960d71a08 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt @@ -2,11 +2,19 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedPrivateChat +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class ExtendedPrivateChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(photoField) + override val chatPhoto: ChatPhoto, + @SerialName(usernameField) override val username: Username? = null, + @SerialName(firstNameField) override val firstName: String = "", - override val lastName: String = "", - override val chatPhoto: ChatPhoto + @SerialName(lastNameField) + override val lastName: String = "" ) : ExtendedPrivateChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt index bd40e28001..c781b3ff6c 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt @@ -4,16 +4,29 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedSupergroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class ExtendedSupergroupChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(titleField) override val title: String, + @SerialName(usernameField) override val username: Username? = null, + @SerialName(photoField) override val chatPhoto: ChatPhoto, - override val description: String, - override val inviteLink: String?, + @SerialName(permissionsField) override val permissions: ChatPermissions, - override val pinnedMessage: RawMessage?, - override val stickerSetName: StickerSetName?, - override val canSetStickerSet: Boolean + @SerialName(descriptionField) + override val description: String = "", + @SerialName(inviteLinkField) + override val inviteLink: String? = null, + @SerialName(pinnedMessageField) + override val pinnedMessage: RawMessage? = null, + @SerialName(stickerSetNameFullField) + override val stickerSetName: StickerSetName? = null, + @SerialName(canSetStickerSetField) + override val canSetStickerSet: Boolean = false ) : ExtendedSupergroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt index 3145aff30a..02008dfd76 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt @@ -31,11 +31,11 @@ data class RawMessage( @SerialName(dateField) val date: TelegramDate, @SerialName(chatField) - private val chat: RawChat, + private val chat: Chat, @SerialName(fromField) private val from: User? = null, private val forward_from: User? = null, - private val forward_from_chat: RawChat? = null, + private val forward_from_chat: Chat? = null, private val forward_from_message_id: MessageIdentifier? = null, private val forward_signature: ForwardSignature? = null, private val forward_sender_name: ForwardSenderName? = null, @@ -150,7 +150,7 @@ data class RawMessage( forward_from_chat != null -> ForwardedFromChannelMessage( forward_date, forward_from_message_id ?: throw IllegalStateException("Channel forwarded message must contain message id, but was not"), - forward_from_chat.extractChat(), + forward_from_chat, forward_signature ) forward_from != null -> UserForwardedMessage( @@ -194,8 +194,6 @@ data class RawMessage( @Transient val asMessage: Message by lazy { - val chat = chat.extractChat() - chatEvent ?.let { chatEvent -> when (chat) { From 7e61b77ffe691ff4e8b716d3060286d3da65a4a0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Aug 2019 15:46:31 +0600 Subject: [PATCH 13/17] optimize imports --- .../insanusmokrassar/TelegramBotAPI/bot/UpdatesPoller.kt | 3 ++- .../buttons/InlineKeyboardButtons/InlineKeyboardButton.kt | 3 ++- .../TelegramBotAPI/types/chat/ChannelChatImpl.kt | 4 +--- .../TelegramBotAPI/types/chat/ChatSerializers.kt | 2 +- .../TelegramBotAPI/types/chat/GroupChatImpl.kt | 1 - .../TelegramBotAPI/types/chat/PrivateChatImpl.kt | 2 +- .../TelegramBotAPI/types/chat/SupergroupChatImpl.kt | 3 --- .../TelegramBotAPI/types/chat/abstracts/Chat.kt | 1 - .../TelegramBotAPI/types/message/ChannelEventMessage.kt | 1 - .../TelegramBotAPI/types/message/RawMessage.kt | 1 - .../TelegramBotAPI/types/message/SupergroupEventMessage.kt | 1 - .../types/message/content/media/AudioContent.kt | 1 - .../types/message/content/media/PhotoContent.kt | 3 ++- .../types/message/content/media/VideoContent.kt | 1 - .../types/message/content/media/VoiceContent.kt | 1 - .../MediaGroupUpdates/EditChannelPostMediaGroupUpdate.kt | 1 - .../update/MediaGroupUpdates/EditMessageMediaGroupUpdate.kt | 1 - .../TelegramBotAPI/utils/extensions/UpdatesPolling.kt | 2 +- .../TelegramBotAPI/utils/extensions/Webhooks.kt | 1 - 19 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/UpdatesPoller.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/UpdatesPoller.kt index c80bfa2610..e7e78cb867 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/UpdatesPoller.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/UpdatesPoller.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot -import kotlinx.coroutines.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers import kotlinx.io.core.Closeable interface UpdatesPoller : Closeable { diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt index 26809e7284..d477c11b18 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt @@ -1,7 +1,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons import com.github.insanusmokrassar.TelegramBotAPI.types.* -import kotlinx.serialization.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable @Serializable(InlineKeyboardButtonSerializer::class) sealed class InlineKeyboardButton { diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt index 53a434e3c7..ce5d60655d 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt @@ -1,9 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat -import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.ChannelChat import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt index 4de5303901..521b14e682 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt @@ -1,9 +1,9 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat -import com.github.insanusmokrassar.TelegramBotAPI.types.* 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.chat.extended.* +import com.github.insanusmokrassar.TelegramBotAPI.types.typeField import kotlinx.serialization.* import kotlinx.serialization.internal.StringDescriptor import kotlinx.serialization.json.Json diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt index 0f97e79b70..5a5bf04394 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt @@ -2,7 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat -import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt index e335fa4aa0..6f083135ce 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt @@ -1,7 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt index ce53d3bd4f..44c83a9f82 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt @@ -1,10 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat -import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt index 7eead97d8e..115ef44169 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt @@ -1,7 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId -import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto import com.github.insanusmokrassar.TelegramBotAPI.types.chat.PreviewChatSerializer import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelEventMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelEventMessage.kt index 5a08484965..9631d8183c 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelEventMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelEventMessage.kt @@ -1,7 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChannelChatImpl import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.ChannelChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.ChannelEvent import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ChatEventMessage diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt index 02008dfd76..c2b8e36704 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt @@ -4,7 +4,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessageEntities import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessageEntitiesSerializer import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.files.* import com.github.insanusmokrassar.TelegramBotAPI.types.games.Game diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/SupergroupEventMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/SupergroupEventMessage.kt index 372be34470..cd5c34cdfc 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/SupergroupEventMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/SupergroupEventMessage.kt @@ -1,7 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.SupergroupChatImpl import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.SupergroupEvent import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ChatEventMessage diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/AudioContent.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/AudioContent.kt index 818a3f1764..778498771c 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/AudioContent.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/AudioContent.kt @@ -10,7 +10,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.files.AudioFile import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage -import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/PhotoContent.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/PhotoContent.kt index 919e8751ce..c0589cb9d7 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/PhotoContent.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/PhotoContent.kt @@ -12,7 +12,8 @@ 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.message.RawMessage -import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaCollectionContent +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions data class PhotoContent( diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/VideoContent.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/VideoContent.kt index 765acd5806..2de7f425ba 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/VideoContent.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/VideoContent.kt @@ -11,7 +11,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.files.VideoFile import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage -import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/VoiceContent.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/VoiceContent.kt index c0f84cd2f1..e29db55dee 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/VoiceContent.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/media/VoiceContent.kt @@ -10,7 +10,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.files.VoiceFile import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage -import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/MediaGroupUpdates/EditChannelPostMediaGroupUpdate.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/MediaGroupUpdates/EditChannelPostMediaGroupUpdate.kt index e13ba2a8d7..e2a56e4514 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/MediaGroupUpdates/EditChannelPostMediaGroupUpdate.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/MediaGroupUpdates/EditChannelPostMediaGroupUpdate.kt @@ -3,7 +3,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdate import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage import com.github.insanusmokrassar.TelegramBotAPI.types.update.EditChannelPostUpdate -import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate data class EditChannelPostMediaGroupUpdate( override val origin: EditChannelPostUpdate diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/MediaGroupUpdates/EditMessageMediaGroupUpdate.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/MediaGroupUpdates/EditMessageMediaGroupUpdate.kt index 0801f6c051..be1364dc32 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/MediaGroupUpdates/EditMessageMediaGroupUpdate.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/MediaGroupUpdates/EditMessageMediaGroupUpdate.kt @@ -3,7 +3,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdate import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage import com.github.insanusmokrassar.TelegramBotAPI.types.update.EditMessageUpdate -import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate data class EditMessageMediaGroupUpdate( override val origin: EditMessageUpdate diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPolling.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPolling.kt index 8166e653d4..8ef77a802f 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPolling.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPolling.kt @@ -6,8 +6,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ALL_UPDATES_LIST import com.github.insanusmokrassar.TelegramBotAPI.types.update.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update -import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdatesFilter import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.KtorUpdatesPoller +import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdatesFilter import kotlinx.coroutines.* import java.util.concurrent.Executors diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt index 86011af428..e10e4c9347 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt @@ -11,7 +11,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdatesFilter import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.webhook.WebhookPrivateKeyConfig import com.github.insanusmokrassar.TelegramBotAPI.utils.convertWithMediaGroupUpdates -import com.github.insanusmokrassar.TelegramBotAPI.utils.toSentMediaGroupUpdate import io.ktor.application.call import io.ktor.request.receiveText import io.ktor.response.respond From 9e469c7825dee457bb77274d0d154ef0917cac4f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Aug 2019 17:05:48 +0600 Subject: [PATCH 14/17] fixes in AbstractRequestCallFactory --- .../TelegramBotAPI/bot/Ktor/base/AbstractRequestCallFactory.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/base/AbstractRequestCallFactory.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/base/AbstractRequestCallFactory.kt index 5076d173d2..c924a84bd6 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/base/AbstractRequestCallFactory.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/base/AbstractRequestCallFactory.kt @@ -29,7 +29,6 @@ abstract class AbstractRequestCallFactory : KtorCallFactory { accept(ContentType.Application.Json) body = preparedBody - build() } } From 647d1e79f7da6f5b9c6af9ccdd0fede1b656108f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Aug 2019 17:06:57 +0600 Subject: [PATCH 15/17] ExtendedChat#chatPhoto now is nullable --- .../types/chat/abstracts/extended/ExtendedChat.kt | 2 +- .../types/chat/extended/ExtendedChannelChatImpl.kt | 2 +- .../TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt | 2 +- .../types/chat/extended/ExtendedPrivateChatImpl.kt | 2 +- .../types/chat/extended/ExtendedSupergroupChatImpl.kt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt index 24a13a19d1..c67932e602 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt @@ -7,5 +7,5 @@ import kotlinx.serialization.Serializable @Serializable(ExtendedChatSerializer::class) interface ExtendedChat : Chat { - val chatPhoto: ChatPhoto + val chatPhoto: ChatPhoto? } \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt index 7f47b04816..d1fa0dd594 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt @@ -15,7 +15,7 @@ data class ExtendedChannelChatImpl( @SerialName(usernameField) override val username: Username? = null, @SerialName(photoField) - override val chatPhoto: ChatPhoto, + override val chatPhoto: ChatPhoto? = null, @SerialName(descriptionField) override val description: String = "", @SerialName(inviteLinkField) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt index f9990cd24d..2eb20fc6ca 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt @@ -14,7 +14,7 @@ data class ExtendedGroupChatImpl( @SerialName(titleField) override val title: String, @SerialName(photoField) - override val chatPhoto: ChatPhoto, + override val chatPhoto: ChatPhoto? = null, @SerialName(permissionsField) override val permissions: ChatPermissions, @SerialName(descriptionField) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt index c960d71a08..3ccc572acd 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt @@ -10,7 +10,7 @@ data class ExtendedPrivateChatImpl( @SerialName(idField) override val id: ChatId, @SerialName(photoField) - override val chatPhoto: ChatPhoto, + override val chatPhoto: ChatPhoto? = null, @SerialName(usernameField) override val username: Username? = null, @SerialName(firstNameField) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt index c781b3ff6c..1e352548b2 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt @@ -16,7 +16,7 @@ data class ExtendedSupergroupChatImpl( @SerialName(usernameField) override val username: Username? = null, @SerialName(photoField) - override val chatPhoto: ChatPhoto, + override val chatPhoto: ChatPhoto? = null, @SerialName(permissionsField) override val permissions: ChatPermissions, @SerialName(descriptionField) From 7f7e82bbb07fefa1382c00055d262739fbe25c82 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Aug 2019 17:25:51 +0600 Subject: [PATCH 16/17] bot command entity command extracting fix --- CHANGELOG.md | 2 ++ .../types/MessageEntity/BotCommandMessageEntity.kt | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98a5d66c83..5b3f4a90da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ Other important changes: * Totally reworked chats hierarchy. `Extended` abstractions was added for cases when called `GetChat` request * `RawChat` boilerplate was removed and replaced by serializers +* `BotCommandMessageEntity#command` will not contain `/`/`!` parts and also will cut outside of command begin token (`/` +or `!`) and username token (`@`) or end of command (any space character) * `RequestsExecutor` now is `Closeable` * `TelegramAPIUrlsKeeper` was added to provide more comfortable work with file urls and other things like this diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BotCommandMessageEntity.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BotCommandMessageEntity.kt index cad8a5adfd..2454b2760f 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BotCommandMessageEntity.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BotCommandMessageEntity.kt @@ -3,6 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity import com.github.insanusmokrassar.TelegramBotAPI.utils.commandHTML import com.github.insanusmokrassar.TelegramBotAPI.utils.commandMarkdown +private val commandRegex = Regex("[/!][^@\\s]*") + data class BotCommandMessageEntity( override val offset: Int, override val length: Int, @@ -12,6 +14,6 @@ data class BotCommandMessageEntity( override val asHtmlSource: String = sourceString.commandHTML() val command: String by lazy { - sourceString.substring(1)// skip first symbol like "/" or "!" + commandRegex.find(sourceString) ?.value ?.substring(1) ?: sourceString.substring(1)// skip first symbol like "/" or "!" } } From a7e533d94eb9350bc59587b55610d0a43f3b37b0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Aug 2019 18:03:38 +0600 Subject: [PATCH 17/17] update ktor --- CHANGELOG.md | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b3f4a90da..77d1e75bdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ Libraries updates: * Kotlin Coroutines version `1.2.1` -> `1.2.2` * Kotlin Serialization version `0.11.0` -> `0.11.1` * Joda Time version `2.10.1` -> `2.10.3` -* Ktor version `1.1.4` -> `1.2.2` +* ktor version `1.1.4` -> `1.2.3` Changes according to [July 29, 2019 Telegram Bot API update](https://core.telegram.org/bots/api#july-29-2019): diff --git a/gradle.properties b/gradle.properties index 65e5f9842d..ad7dad97da 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ kotlin_version=1.3.41 kotlin_coroutines_version=1.2.2 kotlin_serialisation_runtime_version=0.11.1 joda_time_version=2.10.3 -ktor_version=1.2.2 +ktor_version=1.2.3 gradle_bintray_plugin_version=1.8.4