From dd4d5cd15d67a95770cdfa4672553ba565561868 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 Nov 2020 22:06:44 +0600 Subject: [PATCH 01/42] start 0.30.0 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69028b1f66..17580ecc8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.30.0 Bot API 5.0 + ## 0.29.4 * `Core`: diff --git a/gradle.properties b/gradle.properties index cfac4de912..4c36a5ebd6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ ktor_version=1.4.1 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.29.4 +library_version=0.30.0 gradle_bintray_plugin_version=1.8.5 github_release_plugin_version=2.2.12 From 6d6c544aaf0704e3cb38668a61a46a48fa4757f6 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 Nov 2020 22:17:17 +0600 Subject: [PATCH 02/42] logout and close --- CHANGELOG.md | 4 +++ .../dev/inmo/tgbotapi/requests/local/Close.kt | 25 +++++++++++++++++++ .../inmo/tgbotapi/requests/local/LogOut.kt | 21 ++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/LogOut.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 17580ecc8a..021369df88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.30.0 Bot API 5.0 +* `Core`: + * Support of `logOut` method (`LogOut` object as a `Request`) + * Support of `close` method (`Close` object as a `Request`) + ## 0.29.4 * `Core`: diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt new file mode 100644 index 0000000000..9e950998f0 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt @@ -0,0 +1,25 @@ +package dev.inmo.tgbotapi.requests.local + +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.Serializable +import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.builtins.serializer + +/** + * Use this method to close the bot instance before moving it from one local server to another. You need to delete the + * webhook before calling this method to ensure that the bot isn't launched again after server restart. The method will + * return error 429 in the first 10 minutes after the bot is launched. + * + * @see io.ktor.client.features.ClientRequestException + */ +@Serializable +object Close : SimpleRequest { + override val requestSerializer: SerializationStrategy<*> + get() = LogOut.serializer() + + override fun method(): String = "close" + + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/LogOut.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/LogOut.kt new file mode 100644 index 0000000000..63eb15993b --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/LogOut.kt @@ -0,0 +1,21 @@ +package dev.inmo.tgbotapi.requests.local + +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +/** + * Use this method to log out from the cloud Bot API server before launching the bot locally. You **must** log out the bot + * before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful + * call, you will not be able to log in again using the same token for 10 minutes + */ +@Serializable +object LogOut : SimpleRequest { + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + override fun method(): String = "logOut" + + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() +} From 86a472e8149b9c899b00d5da733a707a1c7ed1f2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 Nov 2020 22:43:26 +0600 Subject: [PATCH 03/42] SetWebhook updates --- CHANGELOG.md | 8 +++ .../tgbotapi/requests/webhook/SetWebhook.kt | 60 ++++++++++++------- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 2 + 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 021369df88..e29dd5a7be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ * `Core`: * Support of `logOut` method (`LogOut` object as a `Request`) * Support of `close` method (`Close` object as a `Request`) + * `SetWebhook` updates: + * Function `SetWebhook` with `inputFile` has changed this param nullability - `inputFile` now is nullable + * Function `SetWebhook` without `certificate` param now is unavailable. You can use `SetWebhook` with nullable + `inputFile` + * New field `ipAddress`. It works the same as `ip_address` in [setWebhook](https://core.telegram.org/bots/api#setwebhook) + section + * New field `dropPendingUpdates`. It works the same as `drop_pending_updates` in [setWebhook](https://core.telegram.org/bots/api#setwebhook) + section ## 0.29.4 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt index 5dc0f0841a..cc088fe8ca 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt @@ -16,14 +16,18 @@ private fun correctWebhookUrl(sourceUrl: String) = if (sourceUrl.contains("://") fun SetWebhook( url: String, certificate: MultipartFile, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null ): MultipartRequestImpl, Boolean> = MultipartRequestImpl( SetWebhook( correctWebhookUrl(url), - null, + null as String?, + ipAddress, maxAllowedConnections, - allowedUpdates + allowedUpdates, + dropPendingUpdates ), mapOf(certificateField to certificate) ) @@ -31,47 +35,61 @@ fun SetWebhook( fun SetWebhook( url: String, certificate: FileId, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null ): SetWebhook = SetWebhook( correctWebhookUrl(url), certificate.fileId, + ipAddress, maxAllowedConnections, - allowedUpdates + allowedUpdates, + dropPendingUpdates ) +/** + * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update + * for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. + * + * If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the [url], + * e.g. https://www.example.com/. Since nobody else knows your bot's token, you can be pretty sure it's us. + */ @Suppress("USELESS_CAST") fun SetWebhook( url: String, - certificate: InputFile, + certificate: InputFile? = null, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null ): Request = when (certificate) { - is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, maxAllowedConnections, allowedUpdates) - is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, maxAllowedConnections, allowedUpdates) + is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates) + is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates) + null -> SetWebhook(correctWebhookUrl(url), null as String?, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates) } -fun SetWebhook( - url: String, - maxAllowedConnections: Int? = null, - allowedUpdates: List? = null -) = SetWebhook( - correctWebhookUrl(url), - null, - maxAllowedConnections, - allowedUpdates -) - +/** + * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update + * for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. + * + * If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the [url], + * e.g. https://www.example.com/. Since nobody else knows your bot's token, you can be pretty sure it's us. + */ @Serializable data class SetWebhook internal constructor( @SerialName(urlField) val url: String, @SerialName(certificateField) val certificateFile: String? = null, + @SerialName(ipAddressField) + val ipAddress: String? = null, @SerialName(maxAllowedConnectionsField) val maxAllowedConnections: Int? = null, @SerialName(allowedUpdatesField) - val allowedUpdates: List? = null + val allowedUpdates: List? = null, + @SerialName(dropPendingUpdatesField) + val dropPendingUpdates: Boolean? = null ) : DataRequest { override fun method(): String = "setWebhook" override val resultDeserializer: DeserializationStrategy diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 0d3a71a24e..97e8e46d07 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -123,6 +123,7 @@ const val switchPmTextField = "switch_pm_text" const val switchPmParameterField = "switch_pm_parameter" const val maxAllowedConnectionsField = "max_connections" const val allowedUpdatesField = "allowed_updates" +const val dropPendingUpdatesField = "drop_pending_updates" const val hasCustomCertificateField = "has_custom_certificate" const val pendingUpdateCountField = "pending_update_count" const val lastErrorDateField = "last_error_date" @@ -143,6 +144,7 @@ const val inviteLinkField = "invite_link" const val pinnedMessageField = "pinned_message" const val customTitleField = "custom_title" const val optionIdsField = "option_ids" +const val ipAddressField = "ip_address" const val requestContactField = "request_contact" const val requestLocationField = "request_location" From fd1a15cb5d8167a4fbc2d4ac9e25f57e82f49de6 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 Nov 2020 22:46:08 +0600 Subject: [PATCH 04/42] ExtendedPrivateChat#bio --- CHANGELOG.md | 1 + .../src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt | 1 + .../types/chat/abstracts/extended/ExtendedPrivateChat.kt | 4 +++- .../tgbotapi/types/chat/extended/ExtendedPrivateChatImpl.kt | 4 +++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e29dd5a7be..8d81011c81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ section * New field `dropPendingUpdates`. It works the same as `drop_pending_updates` in [setWebhook](https://core.telegram.org/bots/api#setwebhook) section + * New field `ExtendedPrivateChat#bio` ## 0.29.4 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 97e8e46d07..1452412f73 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -247,6 +247,7 @@ const val userField = "user" const val dateField = "date" const val chatField = "chat" const val usernameField = "username" +const val bioField = "bio" const val nameField = "name" const val emailField = "email" const val locationField = "location" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedPrivateChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedPrivateChat.kt index e88ca5fa9f..297c7f3986 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedPrivateChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedPrivateChat.kt @@ -2,4 +2,6 @@ package dev.inmo.tgbotapi.types.chat.abstracts.extended import dev.inmo.tgbotapi.types.chat.abstracts.PrivateChat -interface ExtendedPrivateChat : PrivateChat, ExtendedChat +interface ExtendedPrivateChat : PrivateChat, ExtendedChat { + val bio: String +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedPrivateChatImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedPrivateChatImpl.kt index d507fcfea3..4c1d9702de 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedPrivateChatImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedPrivateChatImpl.kt @@ -16,5 +16,7 @@ data class ExtendedPrivateChatImpl( @SerialName(firstNameField) override val firstName: String = "", @SerialName(lastNameField) - override val lastName: String = "" + override val lastName: String = "", + @SerialName(bioField) + override val bio: String = "" ) : ExtendedPrivateChat From 7a2ecd2dbf1a14f27ddee2cc763c0a980828020f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 Nov 2020 23:10:39 +0600 Subject: [PATCH 05/42] getChat updates completing --- CHANGELOG.md | 4 ++++ .../requests/chat/members/UnbanChatMember.kt | 4 +++- .../dev/inmo/tgbotapi/types/ChatLocation.kt | 18 ++++++++++++++++++ .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 2 ++ .../abstracts/extended/ExtendedChannelChat.kt | 5 ++++- .../extended/ExtendedSupergroupChat.kt | 4 +++- .../chat/extended/ExtendedChannelChatImpl.kt | 4 +++- .../extended/ExtendedSupergroupChatImpl.kt | 6 +++++- 8 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatLocation.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d81011c81..bf21e246f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ * New field `dropPendingUpdates`. It works the same as `drop_pending_updates` in [setWebhook](https://core.telegram.org/bots/api#setwebhook) section * New field `ExtendedPrivateChat#bio` + * New data class `ChatLocation` + * New field `UnbanChatMember#onlyIfBanned` + * New fields `ExtendedChannelChat#linkedGroupChatId` and `ExtendedSupergroupChat#linkedChannelChatId` + * New fields `ExtendedSupergroupChat#location` ## 0.29.4 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/UnbanChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/UnbanChatMember.kt index 6aef8178e3..afe519c847 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/UnbanChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/UnbanChatMember.kt @@ -10,7 +10,9 @@ data class UnbanChatMember( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(userIdField) - override val userId: UserId + override val userId: UserId, + @SerialName(onlyIfBannedField) + val onlyIfBanned: Boolean? = null ) : ChatMemberRequest { override fun method(): String = "unbanChatMember" override val resultDeserializer: DeserializationStrategy diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatLocation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatLocation.kt new file mode 100644 index 0000000000..76c6558d0a --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatLocation.kt @@ -0,0 +1,18 @@ +package dev.inmo.tgbotapi.types + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Represents a location to which a chat is connected. + * + * @see dev.inmo.tgbotapi.requests.chat.get.GetChat + * @see dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedSupergroupChat + */ +@Serializable +data class ChatLocation( + @SerialName(locationField) + val location: Location, + @SerialName(addressField) + val address: String +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 1452412f73..3957c733d5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -102,6 +102,7 @@ const val slowModeDelayField = "slow_mode_delay" const val maskPositionField = "mask_position" const val phoneNumberField = "phone_number" const val userIdField = "user_id" +const val onlyIfBannedField = "only_if_banned" const val containsMasksField = "contains_masks" const val resultIdField = "result_id" const val inlineMessageIdField = "inline_message_id" @@ -145,6 +146,7 @@ const val pinnedMessageField = "pinned_message" const val customTitleField = "custom_title" const val optionIdsField = "option_ids" const val ipAddressField = "ip_address" +const val linkedChatIdField = "linked_chat_id" const val requestContactField = "request_contact" const val requestLocationField = "request_location" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChannelChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChannelChat.kt index 424e9cd9d7..cbda4c68db 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChannelChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChannelChat.kt @@ -1,5 +1,8 @@ package dev.inmo.tgbotapi.types.chat.abstracts.extended +import dev.inmo.tgbotapi.types.ChatId import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat -interface ExtendedChannelChat : ChannelChat, ExtendedPublicChat +interface ExtendedChannelChat : ChannelChat, ExtendedPublicChat { + val linkedGroupChatId: ChatId? +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedSupergroupChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedSupergroupChat.kt index f850ac7601..75ef3df3f6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedSupergroupChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedSupergroupChat.kt @@ -1,10 +1,12 @@ package dev.inmo.tgbotapi.types.chat.abstracts.extended -import dev.inmo.tgbotapi.types.StickerSetName +import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.chat.abstracts.SupergroupChat interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat { val slowModeDelay: Long? val stickerSetName: StickerSetName? val canSetStickerSet: Boolean + val linkedChannelChatId: ChatId? + val location: ChatLocation? } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedChannelChatImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedChannelChatImpl.kt index f7a050628b..d632a1f04d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedChannelChatImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedChannelChatImpl.kt @@ -23,5 +23,7 @@ data class ExtendedChannelChatImpl( override val inviteLink: String? = null, @SerialName(pinnedMessageField) @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) - override val pinnedMessage: Message? = null + override val pinnedMessage: Message? = null, + @SerialName(linkedChatIdField) + override val linkedGroupChatId: ChatId? = null ) : ExtendedChannelChat diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedSupergroupChatImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedSupergroupChatImpl.kt index 1e10877159..df17d30760 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedSupergroupChatImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedSupergroupChatImpl.kt @@ -32,5 +32,9 @@ data class ExtendedSupergroupChatImpl( @SerialName(slowModeDelayField) override val slowModeDelay: Long? = null, @SerialName(canSetStickerSetField) - override val canSetStickerSet: Boolean = false + override val canSetStickerSet: Boolean = false, + @SerialName(linkedChatIdField) + override val linkedChannelChatId: ChatId? = null, + @SerialName(locationField) + override val location: ChatLocation? = null ) : ExtendedSupergroupChat From 179bb66183a2996890c850f6711bf9512883eb4f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 Nov 2020 23:21:25 +0600 Subject: [PATCH 06/42] return SetWebhook without certificate --- CHANGELOG.md | 4 +-- .../tgbotapi/requests/webhook/SetWebhook.kt | 26 +++++++++++++++++-- .../inmo/tgbotapi/types/files/AudioFile.kt | 11 +++++--- .../inmo/tgbotapi/types/files/VideoFile.kt | 11 +++++--- 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf21e246f2..e80f2f6b00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,6 @@ * Support of `logOut` method (`LogOut` object as a `Request`) * Support of `close` method (`Close` object as a `Request`) * `SetWebhook` updates: - * Function `SetWebhook` with `inputFile` has changed this param nullability - `inputFile` now is nullable - * Function `SetWebhook` without `certificate` param now is unavailable. You can use `SetWebhook` with nullable - `inputFile` * New field `ipAddress`. It works the same as `ip_address` in [setWebhook](https://core.telegram.org/bots/api#setwebhook) section * New field `dropPendingUpdates`. It works the same as `drop_pending_updates` in [setWebhook](https://core.telegram.org/bots/api#setwebhook) @@ -18,6 +15,7 @@ * New field `UnbanChatMember#onlyIfBanned` * New fields `ExtendedChannelChat#linkedGroupChatId` and `ExtendedSupergroupChat#linkedChannelChatId` * New fields `ExtendedSupergroupChat#location` + * New fields `AudioFile#fileName` and `VideoFile#fileName` ## 0.29.4 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt index cc088fe8ca..9a2c5a3a0f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt @@ -58,7 +58,7 @@ fun SetWebhook( @Suppress("USELESS_CAST") fun SetWebhook( url: String, - certificate: InputFile? = null, + certificate: InputFile, ipAddress: String? = null, maxAllowedConnections: Int? = null, allowedUpdates: List? = null, @@ -66,9 +66,31 @@ fun SetWebhook( ): Request = when (certificate) { is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates) is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates) - null -> SetWebhook(correctWebhookUrl(url), null as String?, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates) } +/** + * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update + * for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. + * + * If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the [url], + * e.g. https://www.example.com/. Since nobody else knows your bot's token, you can be pretty sure it's us. + */ +@Suppress("USELESS_CAST") +fun SetWebhook( + url: String, + ipAddress: String? = null, + maxAllowedConnections: Int? = null, + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null +): Request = SetWebhook( + correctWebhookUrl(url), + null, + ipAddress, + maxAllowedConnections, + allowedUpdates, + dropPendingUpdates +) + /** * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update * for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt index af686eda9b..554b878069 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt @@ -2,8 +2,7 @@ package dev.inmo.tgbotapi.types.files import dev.inmo.tgbotapi.CommonAbstracts.Performerable import dev.inmo.tgbotapi.requests.abstracts.FileId -import dev.inmo.tgbotapi.types.FileUniqueId -import dev.inmo.tgbotapi.types.fileUniqueIdField +import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.files.abstracts.* import dev.inmo.tgbotapi.utils.MimeType import kotlinx.serialization.SerialName @@ -15,14 +14,20 @@ data class AudioFile( override val fileId: FileId, @SerialName(fileUniqueIdField) override val fileUniqueId: FileUniqueId, + @SerialName(durationField) override val duration: Long? = null, + @SerialName(performerField) override val performer: String? = null, + @SerialName(titleField) override val title: String? = null, + @SerialName(fileNameField) + override val fileName: String? = null, @SerialName(mimeTypeField) override val mimeType: MimeType? = null, @SerialName(fileSizeField) override val fileSize: Long? = null, + @SerialName(thumbField) override val thumb: PhotoSize? = null -) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, TitledMediaFile, Performerable +) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, TitledMediaFile, Performerable fun AudioFile.asVoiceFile() = VoiceFile(fileId, fileUniqueId, duration, mimeType, fileSize) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt index 5780caa07c..da28496110 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt @@ -1,11 +1,10 @@ package dev.inmo.tgbotapi.types.files import dev.inmo.tgbotapi.requests.abstracts.FileId -import dev.inmo.tgbotapi.types.FileUniqueId +import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.types.fileUniqueIdField import dev.inmo.tgbotapi.types.files.abstracts.* import dev.inmo.tgbotapi.utils.MimeType import dev.inmo.tgbotapi.utils.toHtmlCaptions @@ -18,15 +17,21 @@ data class VideoFile( override val fileId: FileId, @SerialName(fileUniqueIdField) override val fileUniqueId: FileUniqueId, + @SerialName(widthField) override val width: Int, + @SerialName(heightField) override val height: Int, + @SerialName(durationField) override val duration: Long? = null, + @SerialName(thumbField) override val thumb: PhotoSize? = null, + @SerialName(fileNameField) + override val fileName: String? = null, @SerialName(mimeTypeField) override val mimeType: MimeType? = null, @SerialName(fileSizeField) override val fileSize: Long? = null -) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile +) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile @Suppress("NOTHING_TO_INLINE") inline fun VideoFile.toInputMediaVideo( From 2a3321600695db1ddce2bc89dab0aece08da5777 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 Nov 2020 23:33:48 +0600 Subject: [PATCH 07/42] disableContentTypeDetection --- CHANGELOG.md | 1 + .../requests/send/media/SendDocument.kt | 28 +++++++++++++++++-- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 1 + .../types/InputMedia/InputMediaDocument.kt | 15 +++++++++- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e80f2f6b00..a11a3fa8db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * New fields `ExtendedChannelChat#linkedGroupChatId` and `ExtendedSupergroupChat#linkedChannelChatId` * New fields `ExtendedSupergroupChat#location` * New fields `AudioFile#fileName` and `VideoFile#fileName` + * New fields `SendDocument#disableContentTypeDetection` and `InputMediaDocument#disableContentTypeDetection` ## 0.29.4 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt index 0b2db11bf8..961d512dc6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt @@ -14,6 +14,15 @@ import dev.inmo.tgbotapi.utils.mapOfNotNull import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* +/** + * Use this method to send general files. On success, the sent [ContentMessage] with [DocumentContent] is returned. + * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. + * + * @param disableContentTypeDetection Disables automatic server-side content type detection for [document] [MultipartFile] + * + * @see ContentMessage + * @see DocumentContent + */ fun SendDocument( chatId: ChatIdentifier, document: InputFile, @@ -22,7 +31,8 @@ fun SendDocument( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, - replyMarkup: KeyboardMarkup? = null + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null ): Request> { val documentAsFileId = (document as? FileId) ?.fileId val documentAsFile = document as? MultipartFile @@ -37,7 +47,8 @@ fun SendDocument( parseMode, disableNotification, replyToMessageId, - replyMarkup + replyMarkup, + disableContentTypeDetection ) return if (documentAsFile == null && thumbAsFile == null) { @@ -53,6 +64,15 @@ fun SendDocument( private val commonResultDeserializer: DeserializationStrategy> = TelegramBotAPIMessageDeserializationStrategyClass() +/** + * Use this method to send general files. On success, the sent [ContentMessage] with [DocumentContent] is returned. + * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. + * + * @param disableContentTypeDetection Disables automatic server-side content type detection for [document] [MultipartFile] + * + * @see ContentMessage + * @see DocumentContent + */ @Serializable data class SendDocumentData internal constructor( @SerialName(chatIdField) @@ -70,7 +90,9 @@ data class SendDocumentData internal constructor( @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, @SerialName(replyMarkupField) - override val replyMarkup: KeyboardMarkup? = null + override val replyMarkup: KeyboardMarkup? = null, + @SerialName(disableContentTypeDetectionField) + val disableContentTypeDetection: Boolean? = null ) : DataRequest>, SendMessageRequest>, ReplyingMarkupSendMessageRequest>, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 3957c733d5..f56da81409 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -86,6 +86,7 @@ const val disableWebPagePreviewField = "disable_web_page_preview" const val disableNotificationField = "disable_notification" const val replyToMessageIdField = "reply_to_message_id" const val replyMarkupField = "reply_markup" +const val disableContentTypeDetectionField = "disable_content_type_detection" const val supportStreamingField = "support_streaming" const val livePeriodField = "live_period" const val isBotField = "is_bot" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt index 465b630c6a..a0fa37b7c0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt @@ -4,19 +4,32 @@ import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField +import dev.inmo.tgbotapi.types.disableContentTypeDetectionField import dev.inmo.tgbotapi.types.files.DocumentFile import dev.inmo.tgbotapi.types.mediaField import kotlinx.serialization.* internal const val documentInputMediaType = "document" +/** + * Represents a general file to be sent. See https://core.telegram.org/bots/api#inputmediadocument + * + * @param disableContentTypeDetection Disables automatic server-side content type detection for files uploaded using + * multipart/form-data. Always used by Telegram system as true, if the document is sent as part of an album. + * + * @see InputFile + * @see MultipartFile + * @see FileId + */ @Serializable data class InputMediaDocument( override val file: InputFile, override val caption: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, - override val thumb: InputFile? = null + override val thumb: InputFile? = null, + @SerialName(disableContentTypeDetectionField) + val disableContentTypeDetection: Boolean? = null ) : InputMedia, DocumentMediaGroupMemberInputMedia, ThumbedInputMedia, CaptionedOutput { override val type: String = documentInputMediaType From 60d5581ec6829eaaa171a6a4ad60187e8f1aa6b8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 Nov 2020 23:38:40 +0600 Subject: [PATCH 08/42] supporting of private chats in pinChatMessage --- CHANGELOG.md | 2 ++ .../extensions/api/chat/modify/PinChatMessage.kt | 9 +++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a11a3fa8db..1e92639cc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ * New fields `ExtendedSupergroupChat#location` * New fields `AudioFile#fileName` and `VideoFile#fileName` * New fields `SendDocument#disableContentTypeDetection` and `InputMediaDocument#disableContentTypeDetection` +* `API`: + * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` ## 0.29.4 diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt index b2c9f7e06b..ea73743556 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt @@ -4,6 +4,7 @@ import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.chat.modify.PinChatMessage import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat import dev.inmo.tgbotapi.types.message.abstracts.Message @@ -14,7 +15,7 @@ suspend fun TelegramBot.pinChatMessage( ) = execute(PinChatMessage(chatId, messageId, disableNotification)) suspend fun TelegramBot.pinChatMessage( - chat: PublicChat, + chat: Chat, messageId: MessageIdentifier, disableNotification: Boolean = false ) = pinChatMessage(chat.id, messageId, disableNotification) @@ -22,8 +23,4 @@ suspend fun TelegramBot.pinChatMessage( suspend fun TelegramBot.pinChatMessage( message: Message, disableNotification: Boolean = false -) = if (message.chat is PublicChat) { - pinChatMessage(message.chat.id, message.messageId, disableNotification) -} else { - error("It is possible to pin messages only in non one-to-one chats") -} +) = pinChatMessage(message.chat.id, message.messageId, disableNotification) From 0886781d61912617d86e21aa81dfb6257d595fa5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 Nov 2020 23:41:19 +0600 Subject: [PATCH 09/42] add docs for PinChatMessage --- .../dev/inmo/tgbotapi/requests/chat/modify/PinChatMessage.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/PinChatMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/PinChatMessage.kt index e3ea186dcc..af3e88920c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/PinChatMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/PinChatMessage.kt @@ -6,6 +6,11 @@ import dev.inmo.tgbotapi.types.* import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer +/** + * Use this method to add a message to the list of pinned messages in a chat. If the chat is not a private chat, the bot + * must be an administrator in the chat for this to work and must have the 'can_pin_messages' admin right in a + * supergroup or 'can_edit_messages' admin right in a channel. + */ @Serializable data class PinChatMessage ( @SerialName(chatIdField) From 159ea6f1ccb46327b63cdbb67c1131e45f222057 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 Nov 2020 23:44:13 +0600 Subject: [PATCH 10/42] UnpinAllChatMessages --- CHANGELOG.md | 2 ++ .../chat/modify/UnpinAllChatMessages.kt | 28 +++++++++++++++++++ .../api/chat/modify/UnpinAllChatMessages.kt | 16 +++++++++++ 3 files changed, 46 insertions(+) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinAllChatMessages.kt create mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinAllChatMessages.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e92639cc9..bebed0c44c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,8 +17,10 @@ * New fields `ExtendedSupergroupChat#location` * New fields `AudioFile#fileName` and `VideoFile#fileName` * New fields `SendDocument#disableContentTypeDetection` and `InputMediaDocument#disableContentTypeDetection` + * New request `UnpinAllChatMessages` * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` + * New extensions `TelegramBot#unpinAllChatMessages` ## 0.29.4 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinAllChatMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinAllChatMessages.kt new file mode 100644 index 0000000000..d5f8da23c3 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinAllChatMessages.kt @@ -0,0 +1,28 @@ +package dev.inmo.tgbotapi.requests.chat.modify + +import dev.inmo.tgbotapi.CommonAbstracts.types.ChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.chatIdField +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +/** + * Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an + * administrator in the chat for this to work and must have the 'can_pin_messages' admin right in a supergroup or + * 'can_edit_messages' admin right in a channel. + * + * @see PinChatMessage + * @see UnpinChatMessage + */ +@Serializable +data class UnpinAllChatMessages( + @SerialName(chatIdField) + override val chatId: ChatIdentifier +): ChatRequest, SimpleRequest { + override fun method(): String = "unpinAllChatMessages" + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinAllChatMessages.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinAllChatMessages.kt new file mode 100644 index 0000000000..2385bda48e --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinAllChatMessages.kt @@ -0,0 +1,16 @@ +package dev.inmo.tgbotapi.extensions.api.chat.modify + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.chat.modify.UnpinAllChatMessages +import dev.inmo.tgbotapi.requests.chat.modify.UnpinChatMessage +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat + +suspend fun TelegramBot.unpinAllChatMessages( + chatId: ChatIdentifier +) = execute(UnpinAllChatMessages(chatId)) + +suspend fun TelegramBot.unpinAllChatMessages( + chat: Chat +) = unpinAllChatMessages(chat.id) From 6a05a7ecab330aef5d348f10a759703bac8b720d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 Nov 2020 23:47:01 +0600 Subject: [PATCH 11/42] add footbal dice animation type --- CHANGELOG.md | 1 + .../kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bebed0c44c..aa450c184c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ * New fields `AudioFile#fileName` and `VideoFile#fileName` * New fields `SendDocument#disableContentTypeDetection` and `InputMediaDocument#disableContentTypeDetection` * New request `UnpinAllChatMessages` + * New dice type `FootballDiceAnimationType` * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt index 74ded7764f..04b1ac0576 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt @@ -26,6 +26,10 @@ object SlotMachineDiceAnimationType : DiceAnimationType() { override val emoji: String = "\uD83C\uDFB0" } @Serializable(DiceAnimationTypeSerializer::class) +object FootballDiceAnimationType : DiceAnimationType() { + override val emoji: String = "⚽" +} +@Serializable(DiceAnimationTypeSerializer::class) data class CustomDiceAnimationType( override val emoji: String ) : DiceAnimationType() @@ -39,6 +43,7 @@ internal object DiceAnimationTypeSerializer : KSerializer { DartsDiceAnimationType.emoji -> DartsDiceAnimationType BasketballDiceAnimationType.emoji -> BasketballDiceAnimationType SlotMachineDiceAnimationType.emoji -> SlotMachineDiceAnimationType + FootballDiceAnimationType.emoji -> FootballDiceAnimationType else -> CustomDiceAnimationType(type) } } From 609a959b99c82ccef973a24a6f269ca1e7cadb0e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 Nov 2020 23:52:22 +0600 Subject: [PATCH 12/42] DiceAnimationType#valueLimits --- CHANGELOG.md | 3 +++ .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 10 +++++--- .../tgbotapi/types/dice/DiceAnimationType.kt | 25 +++++++++++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa450c184c..f39c66dac2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,9 @@ * New fields `SendDocument#disableContentTypeDetection` and `InputMediaDocument#disableContentTypeDetection` * New request `UnpinAllChatMessages` * New dice type `FootballDiceAnimationType` + * Limits for dices has been changed + * `commonDiceResultLimit` has been deprecated + * New field `DiceAnimationType#valueLimits` * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index f56da81409..c113b6be23 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -52,10 +52,14 @@ val inlineQueryAnswerResultsLimit = 0 .. 50 val customTitleLength = 0 .. 16 -val commonDiceResultLimit = 1 .. 6 -@Deprecated("Renamed", ReplaceWith("commonDiceResultLimit", "dev.inmo.tgbotapi.types.commonDiceResultLimit")) +val dartsAndCubeDiceResultLimit = 1 .. 6 +@Deprecated("Renamed", ReplaceWith("dartsAndCubeDiceResultLimit", "dev.inmo.tgbotapi.types.dartsAndCubeDiceResultLimit")) +val commonDiceResultLimit + get() = dartsAndCubeDiceResultLimit +@Deprecated("Renamed", ReplaceWith("dartsAndCubeDiceResultLimit", "dev.inmo.tgbotapi.types.dartsAndCubeDiceResultLimit")) val diceResultLimit - get() = commonDiceResultLimit + get() = dartsAndCubeDiceResultLimit +val basketballAndFootballDiceResultLimit = 1 .. 5 val slotMachineDiceResultLimit = 1 .. 64 val botCommandLengthLimit = 1 .. 32 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt index 04b1ac0576..7a79ba36dd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.dice +import dev.inmo.tgbotapi.types.* import kotlinx.serialization.* import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder @@ -8,31 +9,45 @@ import kotlinx.serialization.encoding.Encoder @Serializable(DiceAnimationTypeSerializer::class) sealed class DiceAnimationType { abstract val emoji: String + abstract val valueLimits: IntRange } @Serializable(DiceAnimationTypeSerializer::class) object CubeDiceAnimationType : DiceAnimationType() { override val emoji: String = "\uD83C\uDFB2" + override val valueLimits: IntRange + get() = dartsAndCubeDiceResultLimit } @Serializable(DiceAnimationTypeSerializer::class) object DartsDiceAnimationType : DiceAnimationType() { override val emoji: String = "\uD83C\uDFAF" + override val valueLimits: IntRange + get() = dartsAndCubeDiceResultLimit } @Serializable(DiceAnimationTypeSerializer::class) object BasketballDiceAnimationType : DiceAnimationType() { override val emoji: String = "\uD83C\uDFC0" -} -@Serializable(DiceAnimationTypeSerializer::class) -object SlotMachineDiceAnimationType : DiceAnimationType() { - override val emoji: String = "\uD83C\uDFB0" + override val valueLimits: IntRange + get() = basketballAndFootballDiceResultLimit } @Serializable(DiceAnimationTypeSerializer::class) object FootballDiceAnimationType : DiceAnimationType() { override val emoji: String = "⚽" + override val valueLimits: IntRange + get() = basketballAndFootballDiceResultLimit +} +@Serializable(DiceAnimationTypeSerializer::class) +object SlotMachineDiceAnimationType : DiceAnimationType() { + override val emoji: String = "\uD83C\uDFB0" + override val valueLimits: IntRange + get() = slotMachineDiceResultLimit } @Serializable(DiceAnimationTypeSerializer::class) data class CustomDiceAnimationType( override val emoji: String -) : DiceAnimationType() +) : DiceAnimationType() { + override val valueLimits: IntRange + get() = error("Custom dice animation type have unknown value limits") +} @Serializer(DiceAnimationType::class) internal object DiceAnimationTypeSerializer : KSerializer { From 201def826ef6cd223e519ceab0cdb3acf48961bf Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Nov 2020 01:12:14 +0600 Subject: [PATCH 13/42] locations updates --- CHANGELOG.md | 18 +++++ .../inmo/tgbotapi/CommonAbstracts/Headed.kt | 7 ++ .../CommonAbstracts/HorizontallyAccured.kt | 7 ++ .../inmo/tgbotapi/CommonAbstracts/Livable.kt | 6 +- .../CommonAbstracts/ProximityAlertable.kt | 7 ++ .../EditChatMessageLiveLocation.kt | 13 ++++ .../EditInlineMessageLiveLocation.kt | 13 ++++ .../edit/abstracts/EditLocationMessage.kt | 7 +- .../tgbotapi/requests/send/SendLocation.kt | 74 ++++++++++++++++++- .../abstracts/PositionedSendMessageRequest.kt | 7 +- .../dev/inmo/tgbotapi/types/ChatLocation.kt | 3 +- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 9 +++ .../LocationChosenInlineResult.kt | 3 +- .../RawChosenInlineResult.kt | 3 +- .../InlineQueryResultLocation.kt | 14 +++- .../InputLocationMessageContent.kt | 13 +++- .../query/LocationInlineQuery.kt | 3 +- .../InlineQueries/query/RawInlineQuery.kt | 3 +- .../dev/inmo/tgbotapi/types/Location.kt | 13 ---- .../inmo/tgbotapi/types/location/Location.kt | 57 ++++++++++++++ .../ChatEvents/ProximityAlertTriggered.kt | 16 ++++ .../inmo/tgbotapi/types/message/RawMessage.kt | 5 ++ .../types/message/content/LocationContent.kt | 34 ++++++--- .../dev/inmo/tgbotapi/types/venue/Venue.kt | 3 +- .../tgbotapi/utils/ThrowErrorWithRange.kt | 6 +- .../tgbotapi/extensions/api/LiveLocation.kt | 13 ++-- .../EditChatMessageLiveLocation.kt | 7 +- .../EditInlineMessageLiveLocation.kt | 4 +- .../extensions/api/send/SendLocation.kt | 7 +- .../tgbotapi/extensions/api/send/SendVenue.kt | 7 +- .../utils/extensions/venue/Foursquare.kt | 3 +- 31 files changed, 315 insertions(+), 70 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Headed.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/HorizontallyAccured.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/ProximityAlertable.kt delete mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Location.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/location/Location.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ProximityAlertTriggered.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index f39c66dac2..69d289ea47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,24 @@ * Limits for dices has been changed * `commonDiceResultLimit` has been deprecated * New field `DiceAnimationType#valueLimits` + * Locations updates: + * New interface `Headed` with property `heading` + * New interface `HorizontallyAccured` with property `horizontalAccuracy` + * New interface `ProximityAlertable` with property `proximityAlertRadius` + * `Location` class has been separated: + * `StaticLocation` for static locations + * `LiveLocation` for live locations + * Property `Livable#livePeriod` now use typealias type `Seconds` (the same by meaning - `Int`) + * `EditLocationMessage` now extends `Locationed`, `HorizontallyAccured`, `ProximityAlertable` and `Headed` interfaces + * New properties in `EditChatMessageLiveLocation`: `horizontalAccuracy`, `heading`, `proximityAlertRadius` + * New properties in `EditInlineMessageLiveLocation`: `horizontalAccuracy`, `heading`, `proximityAlertRadius` + * Main constructor of `SendLocation` now is internal. Instead of that currently available next factories: + * `SendLocation` - sending of static location without live parameters + * `SendStaticLocation` - sending of static location without live parameters + * `SendLiveLocation` - sending of live location with live parameters + * `PositionedSendMessageRequest` now extends `Locationed` + * `LocationContent#createResend` now can create `LiveLocation` + * Support of `ProximityAlertTriggered`. It is `CommonEvent` * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Headed.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Headed.kt new file mode 100644 index 0000000000..629c19c285 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Headed.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.CommonAbstracts + +import dev.inmo.tgbotapi.types.Degrees + +interface Headed { + val heading: Degrees? +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/HorizontallyAccured.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/HorizontallyAccured.kt new file mode 100644 index 0000000000..6f64e012a1 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/HorizontallyAccured.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.CommonAbstracts + +import dev.inmo.tgbotapi.types.Meters + +interface HorizontallyAccured { + val horizontalAccuracy: Meters? +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Livable.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Livable.kt index 228adeb9f8..2eef14eea2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Livable.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Livable.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.CommonAbstracts +import dev.inmo.tgbotapi.types.Seconds + interface Livable { /** - * Period in SECONDS + * Period in [Seconds] */ - val livePeriod: Int? + val livePeriod: Seconds? } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/ProximityAlertable.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/ProximityAlertable.kt new file mode 100644 index 0000000000..413ff99b87 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/ProximityAlertable.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.CommonAbstracts + +import dev.inmo.tgbotapi.types.Meters + +interface ProximityAlertable { + val proximityAlertRadius: Meters? +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt index 0bc1869d0d..ba93fd4206 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt @@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.LocationContent +import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass>() @@ -20,6 +21,12 @@ data class EditChatMessageLiveLocation( override val latitude: Double, @SerialName(longitudeField) override val longitude: Double, + @SerialName(horizontalAccuracyField) + override val horizontalAccuracy: Meters? = null, + @SerialName(headingField) + override val heading: Degrees? = null, + @SerialName(proximityAlertRadiusField) + override val proximityAlertRadius: Meters? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditChatMessage, EditReplyMessage, EditLocationMessage { @@ -28,4 +35,10 @@ data class EditChatMessageLiveLocation( get() = commonResultDeserializer override val requestSerializer: SerializationStrategy<*> get() = serializer() + + init { + if (horizontalAccuracy != null && horizontalAccuracy !in horizontalAccuracyLimit) { + throwRangeError("horizontalAccuracy", horizontalAccuracyLimit, horizontalAccuracy) + } + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditInlineMessageLiveLocation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditInlineMessageLiveLocation.kt index 60bcf9a122..f12c2d522d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditInlineMessageLiveLocation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditInlineMessageLiveLocation.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.requests.edit.LiveLocation import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* @Serializable @@ -13,10 +14,22 @@ data class EditInlineMessageLiveLocation( override val latitude: Double, @SerialName(longitudeField) override val longitude: Double, + @SerialName(horizontalAccuracyField) + override val horizontalAccuracy: Meters? = null, + @SerialName(headingField) + override val heading: Degrees? = null, + @SerialName(proximityAlertRadiusField) + override val proximityAlertRadius: Meters? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditInlineMessage, EditReplyMessage, EditLocationMessage { override fun method(): String = "editMessageLiveLocation" override val requestSerializer: SerializationStrategy<*> get() = serializer() + + init { + if (horizontalAccuracy != null && horizontalAccuracy !in horizontalAccuracyLimit) { + throwRangeError("horizontalAccuracy", horizontalAccuracyLimit, horizontalAccuracy) + } + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditLocationMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditLocationMessage.kt index b41276c47d..853d39ee5b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditLocationMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditLocationMessage.kt @@ -1,6 +1,5 @@ package dev.inmo.tgbotapi.requests.edit.abstracts -interface EditLocationMessage { - val latitude: Double - val longitude: Double -} +import dev.inmo.tgbotapi.CommonAbstracts.* + +interface EditLocationMessage : Locationed, HorizontallyAccured, ProximityAlertable, Headed diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendLocation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendLocation.kt index 9a765ca175..ef44f81ab0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendLocation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendLocation.kt @@ -1,19 +1,74 @@ package dev.inmo.tgbotapi.requests.send +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.LocationContent +import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* private val commonResultDeserializer: DeserializationStrategy> = TelegramBotAPIMessageDeserializationStrategyClass() +fun SendLocation( + chatId: ChatIdentifier, + latitude: Double, + longitude: Double, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = SendLocation( + chatId, + latitude, + longitude, + null, + null, + null, + null, + disableNotification, + replyToMessageId, + replyMarkup +) + +fun SendStaticLocation( + chatId: ChatIdentifier, + latitude: Double, + longitude: Double, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = SendLocation(chatId, latitude, longitude, disableNotification, replyToMessageId, replyMarkup) + +fun SendLiveLocation( + chatId: ChatIdentifier, + latitude: Double, + longitude: Double, + livePeriod: Seconds, + horizontalAccuracy: Meters? = null, + heading: Degrees? = null, + proximityAlertRadius: Meters? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = SendLocation( + chatId, + latitude, + longitude, + livePeriod, + horizontalAccuracy, + heading, + proximityAlertRadius, + disableNotification, + replyToMessageId, + replyMarkup +) + @Serializable -data class SendLocation( +data class SendLocation internal constructor( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(latitudeField) @@ -21,7 +76,13 @@ data class SendLocation( @SerialName(longitudeField) override val longitude: Double, @SerialName(livePeriodField) - val livePeriod: Long? = null, + override val livePeriod: Seconds? = null, + @SerialName(horizontalAccuracyField) + override val horizontalAccuracy: Meters? = null, + @SerialName(headingField) + override val heading: Degrees? = null, + @SerialName(proximityAlertRadiusField) + override val proximityAlertRadius: Meters? = null, @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) @@ -30,7 +91,11 @@ data class SendLocation( override val replyMarkup: KeyboardMarkup? = null ) : SendMessageRequest>, ReplyingMarkupSendMessageRequest>, - PositionedSendMessageRequest> + PositionedSendMessageRequest>, + HorizontallyAccured, + Livable, + ProximityAlertable, + Headed { override fun method(): String = "sendLocation" override val resultDeserializer: DeserializationStrategy> @@ -42,5 +107,8 @@ data class SendLocation( if (livePeriod != null && livePeriod !in livePeriodLimit) { error("Live period for sending location must be in $livePeriodLimit, but was $livePeriod") } + if (horizontalAccuracy != null && horizontalAccuracy !in horizontalAccuracyLimit) { + throwRangeError("horizontalAccuracy", horizontalAccuracyLimit, horizontalAccuracy) + } } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/PositionedSendMessageRequest.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/PositionedSendMessageRequest.kt index e2823f307e..533d2b515d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/PositionedSendMessageRequest.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/PositionedSendMessageRequest.kt @@ -1,6 +1,5 @@ package dev.inmo.tgbotapi.requests.send.abstracts -interface PositionedSendMessageRequest: SendMessageRequest { - val latitude: Double - val longitude: Double -} \ No newline at end of file +import dev.inmo.tgbotapi.CommonAbstracts.Locationed + +interface PositionedSendMessageRequest: SendMessageRequest, Locationed \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatLocation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatLocation.kt index 76c6558d0a..3d24f1eb8f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatLocation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatLocation.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types +import dev.inmo.tgbotapi.types.location.StaticLocation import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -12,7 +13,7 @@ import kotlinx.serialization.Serializable @Serializable data class ChatLocation( @SerialName(locationField) - val location: Location, + val location: StaticLocation, @SerialName(addressField) val address: String ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index c113b6be23..76ec3d21c3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -28,6 +28,12 @@ typealias FoursquareType = String typealias Seconds = Int typealias LongSeconds = Long +typealias Meters = Float +typealias Degrees = Int + +val degreesLimit = 1 .. 360 +val horizontalAccuracyLimit = 0F .. 1500F + val getUpdatesLimit = 1 .. 100 val callbackQueryAnswerLength = 0 until 200 val captionLength = 0 .. 1024 @@ -93,6 +99,7 @@ const val replyMarkupField = "reply_markup" const val disableContentTypeDetectionField = "disable_content_type_detection" const val supportStreamingField = "support_streaming" const val livePeriodField = "live_period" +const val proximityAlertRadiusField = "proximity_alert_radius" const val isBotField = "is_bot" const val firstNameField = "first_name" const val lastNameField = "last_name" @@ -152,6 +159,7 @@ const val customTitleField = "custom_title" const val optionIdsField = "option_ids" const val ipAddressField = "ip_address" const val linkedChatIdField = "linked_chat_id" +const val horizontalAccuracyField = "horizontal_accuracy" const val requestContactField = "request_contact" const val requestLocationField = "request_location" @@ -249,6 +257,7 @@ const val heightField = "height" const val lengthField = "length" const val latitudeField = "latitude" const val longitudeField = "longitude" +const val headingField = "heading" const val fromField = "from" const val userField = "user" const val dateField = "date" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/LocationChosenInlineResult.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/LocationChosenInlineResult.kt index 92623a6402..16324e7e85 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/LocationChosenInlineResult.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/LocationChosenInlineResult.kt @@ -2,11 +2,12 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.ChosenInlineResult +import dev.inmo.tgbotapi.types.location.StaticLocation data class LocationChosenInlineResult( override val resultId: InlineQueryIdentifier, override val user: User, - val location: Location, + val location: StaticLocation, override val inlineMessageId: InlineMessageIdentifier?, override val query: String ) : ChosenInlineResult diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt index 4900c189b4..4db078be40 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.ChosenInlineResult +import dev.inmo.tgbotapi.types.location.StaticLocation import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -14,7 +15,7 @@ internal data class RawChosenInlineResult( @SerialName(queryField) val query: String, @SerialName(locationField) - val location: Location? = null, + val location: StaticLocation? = null, @SerialName(inlineMessageIdField) val inlineMessageId: InlineMessageIdentifier? = null ) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultLocation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultLocation.kt index e7eebe43ab..5b6d19776f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultLocation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultLocation.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.Livable -import dev.inmo.tgbotapi.CommonAbstracts.Locationed +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent @@ -17,10 +16,16 @@ data class InlineQueryResultLocation( override val latitude: Double, @SerialName(longitudeField) override val longitude: Double, + @SerialName(horizontalAccuracyField) + override val horizontalAccuracy: Meters? = null, @SerialName(titleField) override val title: String, @SerialName(livePeriodField) - override val livePeriod: Int? = null, + override val livePeriod: Seconds? = null, + @SerialName(headingField) + override val heading: Degrees? = null, + @SerialName(proximityAlertRadiusField) + override val proximityAlertRadius: Meters? = null, @SerialName(thumbUrlField) override val thumbUrl: String? = null, @SerialName(thumbWidthField) @@ -33,7 +38,10 @@ data class InlineQueryResultLocation( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResult, Locationed, + HorizontallyAccured, Livable, + ProximityAlertable, + Headed, TitledInlineQueryResult, WithInputMessageContentInlineQueryResult, ThumbedInlineQueryResult, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputLocationMessageContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputLocationMessageContent.kt index 9096ab0eac..eda3152abf 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputLocationMessageContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputLocationMessageContent.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent -import dev.inmo.tgbotapi.CommonAbstracts.Livable -import dev.inmo.tgbotapi.CommonAbstracts.Locationed +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import kotlinx.serialization.SerialName @@ -13,6 +12,12 @@ data class InputLocationMessageContent( override val latitude: Double, @SerialName(longitudeField) override val longitude: Double, + @SerialName(horizontalAccuracyField) + override val horizontalAccuracy: Meters? = null, @SerialName(livePeriodField) - override val livePeriod: Int? = null -) : Locationed, Livable, InputMessageContent \ No newline at end of file + override val livePeriod: Seconds? = null, + @SerialName(headingField) + override val heading: Degrees? = null, + @SerialName(proximityAlertRadiusField) + override val proximityAlertRadius: Meters? = null +) : Locationed, HorizontallyAccured, ProximityAlertable, Livable, Headed, InputMessageContent \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt index 260eb39cc2..cc0cd4772d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt @@ -2,11 +2,12 @@ package dev.inmo.tgbotapi.types.InlineQueries.query import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InlineQuery +import dev.inmo.tgbotapi.types.location.StaticLocation data class LocationInlineQuery( override val id: InlineQueryIdentifier, override val from: User, override val query: String, override val offset: String, - val location: Location + val location: StaticLocation ) : InlineQuery diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt index 2d15827909..2b4473486a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.query import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.location.StaticLocation import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -15,7 +16,7 @@ internal data class RawInlineQuery( @SerialName(offsetField) val offset: String, @SerialName(locationField) - val location: Location? = null + val location: StaticLocation? = null ) { val asInlineQuery by lazy { location ?.let { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Location.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Location.kt deleted file mode 100644 index 0571bfaf1e..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Location.kt +++ /dev/null @@ -1,13 +0,0 @@ -package dev.inmo.tgbotapi.types - -import dev.inmo.tgbotapi.CommonAbstracts.Locationed -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class Location( - @SerialName(longitudeField) - override val longitude: Double, - @SerialName(latitudeField) - override val latitude: Double -) : Locationed diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/location/Location.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/location/Location.kt new file mode 100644 index 0000000000..b8b9878429 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/location/Location.kt @@ -0,0 +1,57 @@ +package dev.inmo.tgbotapi.types.location + +import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.utils.nonstrictJsonFormat +import kotlinx.serialization.* +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.JsonNull +import kotlinx.serialization.json.JsonObject + +@Serializable(LocationSerializer::class) +sealed class Location : Locationed, HorizontallyAccured + +@Serializable +data class StaticLocation( + @SerialName(longitudeField) + override val longitude: Double, + @SerialName(latitudeField) + override val latitude: Double, + @SerialName(horizontalAccuracyField) + override val horizontalAccuracy: Meters? = null +) : Location() + +@Serializable +data class LiveLocation( + @SerialName(longitudeField) + override val longitude: Double, + @SerialName(latitudeField) + override val latitude: Double, + @SerialName(horizontalAccuracyField) + override val horizontalAccuracy: Meters? = null, + @SerialName(livePeriodField) + override val livePeriod: Seconds, + @SerialName(headingField) + override val heading: Degrees? = null, + @SerialName(proximityAlertRadiusField) + override val proximityAlertRadius: Meters? = null +) : Location(), Livable, ProximityAlertable, Headed + +@Serializer(Location::class) +object LocationSerializer : KSerializer { + override fun deserialize(decoder: Decoder): Location = JsonObject.serializer().deserialize(decoder).let { + if (it.containsKey(livePeriodField) && it[livePeriodField] != JsonNull) { + nonstrictJsonFormat.decodeFromJsonElement(LiveLocation.serializer(), it) + } else { + nonstrictJsonFormat.decodeFromJsonElement(StaticLocation.serializer(), it) + } + } + + override fun serialize(encoder: Encoder, value: Location) { + when (value) { + is StaticLocation -> StaticLocation.serializer().serialize(encoder, value) + is LiveLocation -> LiveLocation.serializer().serialize(encoder, value) + } + } +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ProximityAlertTriggered.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ProximityAlertTriggered.kt new file mode 100644 index 0000000000..557908240a --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ProximityAlertTriggered.kt @@ -0,0 +1,16 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent +import kotlinx.serialization.Serializable + +/** + * This object represents the content of a service message, sent whenever a user in the chat triggers a proximity alert + * set by another user. + */ +@Serializable +data class ProximityAlertTriggered( + val traveler: User, + val watcher: User, + val distance: Meters +) : CommonEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 5f6991b77a..e771b4cdc1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -8,6 +8,9 @@ import dev.inmo.tgbotapi.types.chat.abstracts.* import dev.inmo.tgbotapi.types.dice.Dice import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.games.RawGame +import dev.inmo.tgbotapi.types.location.Location +import dev.inmo.tgbotapi.types.message.ChatEvents.ProximityAlertTriggered +import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.abstracts.Message @@ -86,6 +89,7 @@ internal data class RawMessage( // passport property private val passport_data: Unit? = null, + private val proximity_alert_triggered: ProximityAlertTriggered? = null, private val reply_markup: InlineKeyboardMarkup? = null ) { @@ -180,6 +184,7 @@ internal data class RawMessage( ) channel_chat_created -> ChannelChatCreated() pinned_message != null -> PinnedMessage(pinned_message.asMessage) + proximity_alert_triggered != null -> proximity_alert_triggered else -> null } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt index 81f41ef536..f7a8750028 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt @@ -1,9 +1,10 @@ package dev.inmo.tgbotapi.types.message.content import dev.inmo.tgbotapi.requests.abstracts.Request -import dev.inmo.tgbotapi.requests.send.SendLocation +import dev.inmo.tgbotapi.requests.send.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup +import dev.inmo.tgbotapi.types.location.* import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent @@ -15,13 +16,26 @@ data class LocationContent( disableNotification: Boolean, replyToMessageId: MessageIdentifier?, replyMarkup: KeyboardMarkup? - ): Request> = SendLocation( - chatId, - location.latitude, - location.longitude, - null, - disableNotification, - replyToMessageId, - replyMarkup - ) + ): Request> = when (location) { + is StaticLocation -> SendStaticLocation( + chatId, + location.latitude, + location.longitude, + disableNotification, + replyToMessageId, + replyMarkup + ) + is LiveLocation -> SendLiveLocation( + chatId, + location.latitude, + location.longitude, + location.livePeriod, + location.horizontalAccuracy, + location.heading, + location.proximityAlertRadius, + disableNotification, + replyToMessageId, + replyMarkup + ) + } } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt index 415a00e963..6482709d5c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt @@ -3,13 +3,14 @@ package dev.inmo.tgbotapi.types.venue import dev.inmo.tgbotapi.CommonAbstracts.CommonVenueData import dev.inmo.tgbotapi.CommonAbstracts.Locationed import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.location.StaticLocation import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class Venue( @SerialName(locationField) - val location: Location, + val location: StaticLocation, @SerialName(titleField) override val title: String, @SerialName(addressField) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/ThrowErrorWithRange.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/ThrowErrorWithRange.kt index 88c9946627..03d00bc88b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/ThrowErrorWithRange.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/ThrowErrorWithRange.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.utils -internal fun throwRangeError( +internal fun > throwRangeError( valueName: String, - range: IntRange, - actualValue: Int + range: ClosedRange, + actualValue: T ): Nothing = error("$valueName must be in range $range, but was $actualValue") diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocation.kt index c480c38fe1..960993c312 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocation.kt @@ -13,6 +13,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.content.LocationContent import com.soywiz.klock.DateTime import com.soywiz.klock.TimeSpan +import dev.inmo.tgbotapi.types.location.StaticLocation import io.ktor.utils.io.core.Closeable import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch @@ -39,13 +40,13 @@ class LiveLocation internal constructor( get() = field || leftUntilCloseMillis.millisecondsLong < 0L private var message: ContentMessage = initMessage - val lastLocation: Location + val lastLocation: StaticLocation get() = message.content.location suspend fun updateLocation( - location: Location, + location: StaticLocation, replyMarkup: InlineKeyboardMarkup? = null - ): Location { + ): StaticLocation { if (!isClosed) { message = requestsExecutor.editLiveLocation( message, @@ -114,7 +115,7 @@ suspend fun TelegramBot.startLiveLocation( suspend fun TelegramBot.startLiveLocation( scope: CoroutineScope, chatId: ChatId, - location: Location, + location: StaticLocation, liveTimeMillis: Long = defaultLivePeriodDelayMillis, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -126,7 +127,7 @@ suspend fun TelegramBot.startLiveLocation( suspend fun TelegramBot.startLiveLocation( scope: CoroutineScope, chat: Chat, - location: Location, + location: StaticLocation, liveTimeMillis: Long = defaultLivePeriodDelayMillis, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -148,7 +149,7 @@ suspend inline fun TelegramBot.replyWithLiveLocation( suspend inline fun TelegramBot.replyWithLiveLocation( to: Message, scope: CoroutineScope, - location: Location, + location: StaticLocation, liveTimeMillis: Long = defaultLivePeriodDelayMillis, disableNotification: Boolean = false, replyMarkup: KeyboardMarkup? = null diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt index 29b62ec4ff..f17ba6b8aa 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt @@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.requests.edit.LiveLocation.EditChatMessageLiveLocation import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.LocationContent @@ -38,7 +39,7 @@ suspend fun TelegramBot.editLiveLocation( suspend fun TelegramBot.editLiveLocation( chatId: ChatIdentifier, messageId: MessageIdentifier, - location: Location, + location: StaticLocation, replyMarkup: InlineKeyboardMarkup? = null ) = execute( EditChatMessageLiveLocation( @@ -49,12 +50,12 @@ suspend fun TelegramBot.editLiveLocation( suspend fun TelegramBot.editLiveLocation( chat: Chat, messageId: MessageIdentifier, - location: Location, + location: StaticLocation, replyMarkup: InlineKeyboardMarkup? = null ) = editLiveLocation(chat.id, messageId, location.latitude, location.longitude, replyMarkup) suspend fun TelegramBot.editLiveLocation( message: ContentMessage, - location: Location, + location: StaticLocation, replyMarkup: InlineKeyboardMarkup? = null ) = editLiveLocation(message.chat, message.messageId, location.latitude, location.longitude, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt index fc0520b248..a518941806 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.extensions.api.edit.LiveLocation import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.edit.LiveLocation.EditInlineMessageLiveLocation import dev.inmo.tgbotapi.types.InlineMessageIdentifier -import dev.inmo.tgbotapi.types.Location +import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup suspend fun TelegramBot.editLiveLocation( @@ -18,6 +18,6 @@ suspend fun TelegramBot.editLiveLocation( ) suspend fun TelegramBot.editLiveLocation( inlineMessageId: InlineMessageIdentifier, - location: Location, + location: StaticLocation, replyMarkup: InlineKeyboardMarkup? = null ) = editLiveLocation(inlineMessageId, location.latitude, location.longitude, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt index b67be97035..a9abc0c4cb 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt @@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.requests.send.SendLocation import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.message.abstracts.Message suspend fun TelegramBot.sendLocation( @@ -27,7 +28,7 @@ suspend fun TelegramBot.sendLocation( suspend fun TelegramBot.sendLocation( chatId: ChatIdentifier, - location: Location, + location: StaticLocation, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null @@ -58,7 +59,7 @@ suspend fun TelegramBot.sendLocation( suspend fun TelegramBot.sendLocation( chat: Chat, - location: Location, + location: StaticLocation, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null @@ -88,7 +89,7 @@ suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply( to: Message, - location: Location, + location: StaticLocation, disableNotification: Boolean = false, replyMarkup: KeyboardMarkup? = null ) = sendLocation( diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt index 08495ad015..e05b942a9b 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt @@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.requests.send.SendVenue import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.venue.Venue @@ -40,7 +41,7 @@ suspend fun TelegramBot.sendVenue( suspend fun TelegramBot.sendVenue( chatId: ChatIdentifier, - location: Location, + location: StaticLocation, title: String, address: String, foursquareId: String? = null, @@ -53,7 +54,7 @@ suspend fun TelegramBot.sendVenue( suspend fun TelegramBot.sendVenue( chat: Chat, - location: Location, + location: StaticLocation, title: String, address: String, foursquareId: String? = null, @@ -101,7 +102,7 @@ suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply( to: Message, - location: Location, + location: StaticLocation, title: String, address: String, foursquareId: String? = null, diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt index 091c0fec86..3651bb2581 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.extensions.utils.extensions.venue import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.venue.Venue import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -11,7 +12,7 @@ val Venue.foursquare: Foursquare? } fun Venue( - location: Location, + location: StaticLocation, title: String, address: String, foursquare: Foursquare From 53b8cc462543ac1e634f15f63afce3dce5786d41 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Nov 2020 01:15:03 +0600 Subject: [PATCH 14/42] update pollQuestionTextLength --- CHANGELOG.md | 1 + .../src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69d289ea47..da3402c380 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ * `PositionedSendMessageRequest` now extends `Locationed` * `LocationContent#createResend` now can create `LiveLocation` * Support of `ProximityAlertTriggered`. It is `CommonEvent` + * Property `pollQuestionTextLength` now have maximum up to `300` * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 76ec3d21c3..fb2b899d5c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -49,7 +49,7 @@ val invoiceDescriptionLimit = 1 until 256 val invoicePayloadBytesLimit = 1 until 128 val pollOptionTextLength = 1 .. 100 -val pollQuestionTextLength = 1 until 256 +val pollQuestionTextLength = 1 .. 300 val pollOptionsLimit = 2 .. 10 val livePeriodLimit = 60 .. 86400 From 0a73dfb79952632df6fa5726f5b6394ecf1e7814 Mon Sep 17 00:00:00 2001 From: madhead Date: Thu, 5 Nov 2020 01:56:36 +0300 Subject: [PATCH 15/42] Fix #184: Anonymous Admins: support for is_anonymous flag --- CHANGELOG.md | 2 ++ .../tgbotapi/types/ChatMember/AdministratorChatMemberImpl.kt | 1 + .../dev/inmo/tgbotapi/types/ChatMember/CreatorChatMember.kt | 1 + .../dev/inmo/tgbotapi/types/ChatMember/RawChatMember.kt | 5 ++++- .../types/ChatMember/abstracts/AdministratorChatMember.kt | 1 + 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da3402c380..e301b4e153 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,8 @@ * `LocationContent#createResend` now can create `LiveLocation` * Support of `ProximityAlertTriggered`. It is `CommonEvent` * Property `pollQuestionTextLength` now have maximum up to `300` + * Anonymous Admins: + * New field `AdministratorChatMember#isAnonymous` * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/AdministratorChatMemberImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/AdministratorChatMemberImpl.kt index d4f9727948..3b734ef904 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/AdministratorChatMemberImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/AdministratorChatMemberImpl.kt @@ -14,5 +14,6 @@ data class AdministratorChatMemberImpl( override val canRestrictMembers: Boolean, override val canPinMessages: Boolean, override val canPromoteMembers: Boolean, + override val isAnonymous: Boolean, override val customTitle: String? ) : AdministratorChatMember diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/CreatorChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/CreatorChatMember.kt index 153679d274..af981b2312 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/CreatorChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/CreatorChatMember.kt @@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.types.User data class CreatorChatMember( override val user: User, + override val isAnonymous: Boolean, override val customTitle: String? ) : AdministratorChatMember { override val canBeEdited: Boolean = true diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/RawChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/RawChatMember.kt index 5e7e9875a7..4f8bd51b66 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/RawChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/RawChatMember.kt @@ -40,12 +40,14 @@ internal data class RawChatMember( private val canSendOtherMessages: Boolean = false, @SerialName(canAddWebPagePreviewsField) private val canAddWebPagePreviews: Boolean = false, + @SerialName(isAnonymousField) + private val isAnonymous: Boolean = false, @SerialName(customTitleField) private val customTitle: String? = null ) { val asChatMember: ChatMember by lazy { when (status) { - "creator" -> CreatorChatMember(user, customTitle) + "creator" -> CreatorChatMember(user, isAnonymous, customTitle) "administrator" -> AdministratorChatMemberImpl( user, canBeEdited, @@ -57,6 +59,7 @@ internal data class RawChatMember( canRestrictMembers, canPinMessages, canPromoteMembers, + isAnonymous, customTitle ) "member" -> MemberChatMember(user) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt index 8b7e7cc18e..ba3bb2ac00 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt @@ -7,5 +7,6 @@ interface AdministratorChatMember : SpecialRightsChatMember { val canRemoveMessages: Boolean val canRestrictMembers: Boolean val canPromoteMembers: Boolean + val isAnonymous: Boolean val customTitle: String? } \ No newline at end of file From ff34b23777b9652301e0d35e951b7049e77d6ce8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Nov 2020 12:39:59 +0600 Subject: [PATCH 16/42] implementation of sender_chat and author_signature --- CHANGELOG.md | 15 ++++ ...hannelMessage.kt => ChannelMessageImpl.kt} | 13 +++- .../tgbotapi/types/message/GroupMessages.kt | 49 ++++++++++++ ...onMessageImpl.kt => PrivateMessageImpl.kt} | 10 ++- .../inmo/tgbotapi/types/message/RawMessage.kt | 75 ++++++++++++++----- .../types/message/abstracts/ChannelMessage.kt | 12 +++ .../types/message/abstracts/GroupMessages.kt | 19 +++++ .../types/message/abstracts/PrivateMessage.kt | 6 ++ .../types/message/abstracts/PublicMessage.kt | 9 +++ .../types/message/abstracts/SignedMessage.kt | 7 ++ .../abstracts/WithSenderChatMessage.kt | 7 ++ 11 files changed, 196 insertions(+), 26 deletions(-) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/{ChannelMessage.kt => ChannelMessageImpl.kt} (62%) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/{CommonMessageImpl.kt => PrivateMessageImpl.kt} (75%) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelMessage.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateMessage.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PublicMessage.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/SignedMessage.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/WithSenderChatMessage.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index e301b4e153..20119d562a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.30.0 Bot API 5.0 +**THIS UPDATE CONTAINS A LOT OF BREAKING CHANGES. PLEASE, BE CAREFUL ON UPGRADING OF YOUR PROJECT** + * `Core`: * Support of `logOut` method (`LogOut` object as a `Request`) * Support of `close` method (`Close` object as a `Request`) @@ -43,6 +45,19 @@ * Property `pollQuestionTextLength` now have maximum up to `300` * Anonymous Admins: * New field `AdministratorChatMember#isAnonymous` + * Several new interfaces of messages: + * `SignedMessage` - any message which possibly have `authorSignature` + * `WithSenderChatMessage` - any message which have `senderChat`. Property `senderChat` is not-nullable due to + separation of implementators + * `PublicMessage` - all channel messages have property `val chat: PublicChat` instead of common `val chat: Chat` + * `ChannelMessage` - all channel messages have property `val chat: ChannelChat` instead of common `val chat: Chat` + * Old `ChannelMessage` was safely renamed to `ChannelMessageImpl` (old name was set as typealias and deprecated) + * `GroupMessage` - all group messages have property `val chat: GroupChat` instead of common `val chat: Chat` + * `FromChannelGroupMessage` - instances should have property `val channel: ChannelChat` + * `AnonymousGroupMessage` - instances may have setup property `authorSignature` + * `CommonGroupMessage` - just common message + * `PrivateMessage` - works like previous `CommonMessageImpl` + * Previous `CommonMessageImpl` safely renamed to `PrivateMessageImpl` * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessageImpl.kt similarity index 62% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessage.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessageImpl.kt index bc4e26c60e..2be816b343 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessageImpl.kt @@ -7,10 +7,12 @@ import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage import com.soywiz.klock.DateTime +import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat +import dev.inmo.tgbotapi.types.message.abstracts.ChannelMessage -data class ChannelMessage( +data class ChannelMessageImpl( override val messageId: MessageIdentifier, - override val chat: Chat, + override val chat: ChannelChat, override val content: T, override val date: DateTime, override val editDate: DateTime?, @@ -18,5 +20,8 @@ data class ChannelMessage( override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup?, override val senderBot: CommonBot?, - val authorSignature: AuthorSignature? -) : PossiblySentViaBotCommonMessage + override val authorSignature: AuthorSignature? +) : ChannelMessage + +@Deprecated("Renamed", ReplaceWith("ChannelMessageImpl", "dev.inmo.tgbotapi.types.message.ChannelMessageImpl")) +typealias ChannelMessage = ChannelMessageImpl diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt new file mode 100644 index 0000000000..62baeffa7a --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt @@ -0,0 +1,49 @@ +package dev.inmo.tgbotapi.types.message + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent +import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage +import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo +import com.soywiz.klock.DateTime +import dev.inmo.tgbotapi.types.chat.abstracts.* +import dev.inmo.tgbotapi.types.message.abstracts.* + +data class FromChannelGroupMessageImpl( + override val chat: GroupChat, + override val channel: ChannelChat, + override val messageId: MessageIdentifier, + override val date: DateTime, + override val forwardInfo: ForwardInfo?, + override val editDate: DateTime?, + override val replyTo: Message?, + override val replyMarkup: InlineKeyboardMarkup?, + override val content: T, + override val senderBot: CommonBot?, + override val authorSignature: AuthorSignature? +) : FromChannelGroupMessage + +data class AnonymousGroupMessageImpl( + override val chat: GroupChat, + override val messageId: MessageIdentifier, + override val date: DateTime, + override val forwardInfo: ForwardInfo?, + override val editDate: DateTime?, + override val replyTo: Message?, + override val replyMarkup: InlineKeyboardMarkup?, + override val content: T, + override val senderBot: CommonBot?, + override val authorSignature: AuthorSignature? +) : AnonymousGroupMessage + +data class CommonGroupMessageImpl( + override val chat: GroupChat, + override val messageId: MessageIdentifier, + override val date: DateTime, + override val forwardInfo: ForwardInfo?, + override val editDate: DateTime?, + override val replyTo: Message?, + override val replyMarkup: InlineKeyboardMarkup?, + override val content: T, + override val senderBot: CommonBot? +) : CommonGroupMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt similarity index 75% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMessageImpl.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt index b0f51180ea..99dae3d350 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMessageImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt @@ -3,14 +3,13 @@ package dev.inmo.tgbotapi.types.message import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat -import dev.inmo.tgbotapi.types.message.abstracts.FromUserMessage -import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo import com.soywiz.klock.DateTime +import dev.inmo.tgbotapi.types.message.abstracts.* -data class CommonMessageImpl( +data class PrivateMessageImpl( override val messageId: MessageIdentifier, override val user: User, override val chat: Chat, @@ -22,4 +21,7 @@ data class CommonMessageImpl( override val replyMarkup: InlineKeyboardMarkup?, override val senderBot: CommonBot?, val paymentInfo: SuccessfulPaymentInfo? -) : PossiblySentViaBotCommonMessage, FromUserMessage \ No newline at end of file +) : PrivateMessage + +@Deprecated("Renamed", ReplaceWith("PrivateMessageImpl", "dev.inmo.tgbotapi.types.message.PrivateMessageImpl")) +typealias CommonMessageImpl = PrivateMessageImpl diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index e771b4cdc1..0424ecd0b7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -10,7 +10,6 @@ import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.games.RawGame import dev.inmo.tgbotapi.types.location.Location import dev.inmo.tgbotapi.types.message.ChatEvents.ProximityAlertTriggered -import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.abstracts.Message @@ -31,14 +30,11 @@ import kotlin.reflect.KClass // TODO:: add PassportData type @Serializable internal data class RawMessage( - @SerialName(messageIdField) val messageId: MessageIdentifier, - @SerialName(dateField) val date: TelegramDate, - @SerialName(chatField) private val chat: Chat, - @SerialName(fromField) private val from: User? = null, + private val sender_chat: PublicChat? = null, private val forward_from: User? = null, private val forward_from_chat: Chat? = null, private val forward_from_message_id: MessageIdentifier? = null, @@ -258,19 +254,61 @@ internal data class RawMessage( ) } } ?: when (chat) { - is ChannelChat -> ChannelMessage( - messageId, - chat, - content, - date.asDate, - edit_date?.asDate, - forwarded, - reply_to_message?.asMessage, - reply_markup, - via_bot, - author_signature - ) - else -> CommonMessageImpl( + is PublicChat -> when (chat) { + is ChannelChat -> ChannelMessageImpl( + messageId, + chat, + content, + date.asDate, + edit_date?.asDate, + forwarded, + reply_to_message?.asMessage, + reply_markup, + via_bot, + author_signature + ) + is GroupChat -> when (sender_chat) { + is ChannelChat -> FromChannelGroupMessageImpl( + chat, + sender_chat, + messageId, + date.asDate, + forwarded, + edit_date ?.asDate, + reply_to_message ?.asMessage, + reply_markup, + content, + via_bot, + author_signature + ) + is GroupChat -> AnonymousGroupMessageImpl( + chat, + messageId, + date.asDate, + forwarded, + edit_date ?.asDate, + reply_to_message ?.asMessage, + reply_markup, + content, + via_bot, + author_signature + ) + null -> CommonGroupMessageImpl( + chat, + messageId, + date.asDate, + forwarded, + edit_date ?.asDate, + reply_to_message ?.asMessage, + reply_markup, + content, + via_bot + ) + else -> error("Currently in groups supported only fields \"sender_chat\" with channel, group or null, but was $sender_chat") + } + else -> error("Unknown type of public chat: $chat") + } + is PrivateChat -> PrivateMessageImpl( messageId, from ?: error("Was detected common message, but owner (sender) of the message was not found"), chat, @@ -283,6 +321,7 @@ internal data class RawMessage( via_bot, paymentInfo ) + else -> error("Unknown type of chat: $chat") } } ?: error("Was not found supported type of data") } catch (e: Exception) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelMessage.kt new file mode 100644 index 0000000000..b30ace047c --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelMessage.kt @@ -0,0 +1,12 @@ +package dev.inmo.tgbotapi.types.message.abstracts + +import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat +import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent +import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage + +interface ChannelMessage : PossiblySentViaBotCommonMessage, SignedMessage, WithSenderChatMessage { + override val chat: ChannelChat + override val senderChat: ChannelChat + get() = chat +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt new file mode 100644 index 0000000000..c97eb604a2 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt @@ -0,0 +1,19 @@ +package dev.inmo.tgbotapi.types.message.abstracts + +import dev.inmo.tgbotapi.types.chat.abstracts.* +import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent + +interface GroupMessage : PublicMessage { + override val chat: GroupChat +} + +interface FromChannelGroupMessage : GroupMessage, SignedMessage, WithSenderChatMessage { + val channel: ChannelChat + override val senderChat: ChannelChat + get() = channel +} +interface AnonymousGroupMessage : GroupMessage, SignedMessage, WithSenderChatMessage { + override val senderChat: GroupChat + get() = chat +} +interface CommonGroupMessage : GroupMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateMessage.kt new file mode 100644 index 0000000000..f57d2ce731 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateMessage.kt @@ -0,0 +1,6 @@ +package dev.inmo.tgbotapi.types.message.abstracts + +import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent +import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage + +interface PrivateMessage : PossiblySentViaBotCommonMessage, FromUserMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PublicMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PublicMessage.kt new file mode 100644 index 0000000000..1ab4b3786c --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PublicMessage.kt @@ -0,0 +1,9 @@ +package dev.inmo.tgbotapi.types.message.abstracts + +import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat +import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent +import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage + +interface PublicMessage : PossiblySentViaBotCommonMessage { + override val chat: PublicChat +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/SignedMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/SignedMessage.kt new file mode 100644 index 0000000000..18aabe8616 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/SignedMessage.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.message.abstracts + +import dev.inmo.tgbotapi.types.AuthorSignature + +interface SignedMessage : Message { + val authorSignature: AuthorSignature? +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/WithSenderChatMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/WithSenderChatMessage.kt new file mode 100644 index 0000000000..55147cd92a --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/WithSenderChatMessage.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.message.abstracts + +import dev.inmo.tgbotapi.types.chat.abstracts.Chat + +interface WithSenderChatMessage { + val senderChat: Chat +} \ No newline at end of file From f835167f6618f9f80d6a2f1e2d90e6639e44c52a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Nov 2020 12:47:14 +0600 Subject: [PATCH 17/42] isAnonymous support --- CHANGELOG.md | 1 + .../inmo/tgbotapi/requests/chat/members/PromoteChatMember.kt | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20119d562a..a49e7c4a3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ * `CommonGroupMessage` - just common message * `PrivateMessage` - works like previous `CommonMessageImpl` * Previous `CommonMessageImpl` safely renamed to `PrivateMessageImpl` + * New property `PromoteChatMember#isAnonymous` * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/PromoteChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/PromoteChatMember.kt index 0489a54374..b878b0cd6a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/PromoteChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/PromoteChatMember.kt @@ -14,6 +14,8 @@ data class PromoteChatMember( override val userId: UserId, @SerialName(untilDateField) override val untilDate: TelegramDate? = null, + @SerialName(isAnonymousField) + private val isAnonymous: Boolean? = null, @SerialName(canChangeInfoField) private val canChangeInfo: Boolean? = null, @SerialName(canPostMessagesField) From eb879963f803730fdce1a39c26b820628845a936 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Nov 2020 12:48:44 +0600 Subject: [PATCH 18/42] isAnonymous support in api --- CHANGELOG.md | 1 + .../extensions/api/chat/members/PromoteChatMember.kt | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a49e7c4a3d..cffb8bce66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` + * Extensions `TelegramBot#promoteChatMember` got `isAnonymous` parameter ## 0.29.4 diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/PromoteChatMember.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/PromoteChatMember.kt index 8ef88449ad..e3f1dc9721 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/PromoteChatMember.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/PromoteChatMember.kt @@ -9,6 +9,7 @@ suspend fun TelegramBot.promoteChatMember( chatId: ChatIdentifier, userId: UserId, untilDate: TelegramDate? = null, + isAnonymous: Boolean? = null, canChangeInfo: Boolean? = null, canPostMessages: Boolean? = null, canEditMessages: Boolean? = null, @@ -22,6 +23,7 @@ suspend fun TelegramBot.promoteChatMember( chatId, userId, untilDate, + isAnonymous, canChangeInfo, canPostMessages, canEditMessages, @@ -37,6 +39,7 @@ suspend fun TelegramBot.promoteChatMember( chat: PublicChat, userId: UserId, untilDate: TelegramDate? = null, + isAnonymous: Boolean? = null, canChangeInfo: Boolean? = null, canPostMessages: Boolean? = null, canEditMessages: Boolean? = null, @@ -49,6 +52,7 @@ suspend fun TelegramBot.promoteChatMember( chat.id, userId, untilDate, + isAnonymous, canChangeInfo, canPostMessages, canEditMessages, @@ -63,6 +67,7 @@ suspend fun TelegramBot.promoteChatMember( chatId: ChatId, user: User, untilDate: TelegramDate? = null, + isAnonymous: Boolean? = null, canChangeInfo: Boolean? = null, canPostMessages: Boolean? = null, canEditMessages: Boolean? = null, @@ -75,6 +80,7 @@ suspend fun TelegramBot.promoteChatMember( chatId, user.id, untilDate, + isAnonymous, canChangeInfo, canPostMessages, canEditMessages, @@ -89,6 +95,7 @@ suspend fun TelegramBot.promoteChatMember( chat: PublicChat, user: User, untilDate: TelegramDate? = null, + isAnonymous: Boolean? = null, canChangeInfo: Boolean? = null, canPostMessages: Boolean? = null, canEditMessages: Boolean? = null, @@ -101,6 +108,7 @@ suspend fun TelegramBot.promoteChatMember( chat.id, user.id, untilDate, + isAnonymous, canChangeInfo, canPostMessages, canEditMessages, From c0e81b1d6dc26b7d0b652bddff7163514f657d2a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Nov 2020 16:53:26 +0600 Subject: [PATCH 19/42] partially complete rewriting of things according to #189 --- .../tgbotapi/CommonAbstracts/Explained.kt | 8 ++- .../tgbotapi/CommonAbstracts/TextSource.kt | 1 + .../inmo/tgbotapi/CommonAbstracts/Texted.kt | 32 +++++++++ .../edit/abstracts/EditTextChatMessage.kt | 7 +- .../edit/caption/EditChatMessageCaption.kt | 40 ++++++++++- .../edit/caption/EditInlineMessageCaption.kt | 37 +++++++++- .../requests/edit/text/EditChatMessageText.kt | 44 +++++++++++- .../edit/text/EditInlineMessageText.kt | 41 ++++++++++- .../tgbotapi/requests/send/SendMessage.kt | 49 ++++++++++++- .../abstracts/TextableSendMessageRequest.kt | 7 +- .../requests/send/media/SendAnimation.kt | 53 ++++++++++++++ .../tgbotapi/requests/send/media/SendAudio.kt | 54 +++++++++++++- .../requests/send/media/SendDocument.kt | 58 +++++++++++++++ .../tgbotapi/requests/send/media/SendPhoto.kt | 37 ++++++++++ .../tgbotapi/requests/send/media/SendVideo.kt | 55 +++++++++++++++ .../requests/send/media/SendVideoNote.kt | 17 ----- .../tgbotapi/requests/send/media/SendVoice.kt | 45 ++++++++++++ .../tgbotapi/requests/send/polls/SendPoll.kt | 70 ++++++++++++++++++- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 2 + .../types/InputMedia/InputMediaAnimation.kt | 42 +++++++++-- .../types/InputMedia/InputMediaAudio.kt | 43 ++++++++++-- .../types/InputMedia/InputMediaDocument.kt | 35 ++++++++-- .../types/InputMedia/InputMediaPhoto.kt | 29 ++++++-- .../types/InputMedia/InputMediaVideo.kt | 35 +++++++++- .../InputMedia/MediaGroupMemberInputMedia.kt | 6 +- .../types/MessageEntity/RawMessageEntity.kt | 17 ++++- 26 files changed, 800 insertions(+), 64 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt index ef79db3bb2..dd1e659658 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt @@ -7,10 +7,16 @@ interface Explained { val explanation: String? } -interface ExplainedOutput : Explained { +interface ParsableExplainedOutput : Explained { val parseMode: ParseMode? } +interface EntitiesExplainedOutput : Explained { + val entities: List? +} + +interface ExplainedOutput : ParsableExplainedOutput, EntitiesExplainedOutput + interface ExplainedInput : Explained { /** * Not full list of entities. This list WILL NOT contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt index 95bbd565b8..c652a3aac8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt @@ -21,3 +21,4 @@ data class TextPart( ) fun List.justTextSources() = map { it.source } +fun List.makeString() = joinToString("") { it.source } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt new file mode 100644 index 0000000000..b28b796591 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt @@ -0,0 +1,32 @@ +package dev.inmo.tgbotapi.CommonAbstracts + +import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.utils.fullListOfSubSource + +interface Texted { + val text: String? +} + +interface ParsableOutput : Texted { + val parseMode: ParseMode? +} + +interface EntitiesOutput : Texted { + val entities: List? +} + +interface TextedOutput : ParsableOutput, EntitiesOutput + +interface TextedInput : Texted { + /** + * Not full list of entities. This list WILL NOT contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] + * @see [CaptionedInput.fullEntitiesList] + */ + val textEntities: List +} + +/** + * Convert its [TextedInput.textEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource] + * with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] + */ +fun TextedInput.fullEntitiesList(): FullTextSourcesList = text ?.fullListOfSubSource(textEntities) ?.map { it.source } ?: emptyList() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditTextChatMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditTextChatMessage.kt index 0c09216c1f..286695eaa3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditTextChatMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditTextChatMessage.kt @@ -1,8 +1,7 @@ package dev.inmo.tgbotapi.requests.edit.abstracts -import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput -interface EditTextChatMessage { - val text: String - val parseMode: ParseMode? +interface EditTextChatMessage : TextedOutput { + override val text: String } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt index ac53971139..9317cb1755 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt @@ -1,8 +1,12 @@ package dev.inmo.tgbotapi.requests.edit.caption +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.requests.edit.media.MediaContentMessageResultDeserializer import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -12,8 +16,37 @@ import kotlinx.serialization.* const val editMessageCaptionMethod = "editMessageCaption" +fun EditChatMessageCaption( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + text: String, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = EditChatMessageCaption( + chatId, + messageId, + text, + parseMode, + null, + replyMarkup +) + +fun EditChatMessageCaption( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null +) = EditChatMessageCaption( + chatId, + messageId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + replyMarkup +) + @Serializable -data class EditChatMessageCaption( +data class EditChatMessageCaption internal constructor( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(messageIdField) @@ -22,9 +55,14 @@ data class EditChatMessageCaption( override val text: String, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditChatMessage, EditTextChatMessage, EditReplyMessage { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text) ?.justTextSources() + } override fun method(): String = editMessageCaptionMethod override val resultDeserializer: DeserializationStrategy> diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt index 4cd418ab54..4603e9a7a3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt @@ -1,23 +1,58 @@ package dev.inmo.tgbotapi.requests.edit.caption +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.* +fun EditInlineMessageCaption( + inlineMessageId: InlineMessageIdentifier, + text: String, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = EditInlineMessageCaption( + inlineMessageId, + text, + parseMode, + null, + replyMarkup +) + +fun EditInlineMessageCaption( + inlineMessageId: InlineMessageIdentifier, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null +) = EditInlineMessageCaption( + inlineMessageId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + replyMarkup +) + @Serializable -data class EditInlineMessageCaption( +data class EditInlineMessageCaption internal constructor( @SerialName(inlineMessageIdField) override val inlineMessageId: InlineMessageIdentifier, @SerialName(captionField) override val text: String, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditInlineMessage, EditTextChatMessage, EditReplyMessage { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text) ?.justTextSources() + } + override fun method(): String = editMessageCaptionMethod override val requestSerializer: SerializationStrategy<*> get() = serializer() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt index b327d18645..873fdc567c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt @@ -1,8 +1,12 @@ package dev.inmo.tgbotapi.requests.edit.text +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.requests.send.TextContentMessageResultDeserializer import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -12,8 +16,41 @@ import kotlinx.serialization.* const val editMessageTextMethod = "editMessageText" +fun EditChatMessageText( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = EditChatMessageText( + chatId, + messageId, + text, + parseMode, + null, + disableWebPagePreview, + replyMarkup +) + +fun EditChatMessageText( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = EditChatMessageText( + chatId, + messageId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + disableWebPagePreview, + replyMarkup +) + @Serializable -data class EditChatMessageText( +data class EditChatMessageText internal constructor( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(messageIdField) @@ -22,11 +59,16 @@ data class EditChatMessageText( override val text: String, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(entitiesField) + private val rawEntities: List? = null, @SerialName(disableWebPagePreviewField) override val disableWebPagePreview: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditChatMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text) ?.justTextSources() + } override fun method(): String = editMessageTextMethod override val resultDeserializer: DeserializationStrategy> diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt index 00a714fa55..1b9ea92c95 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt @@ -1,26 +1,65 @@ package dev.inmo.tgbotapi.requests.edit.text +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.requests.edit.media.editMessageMediaMethod import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.* +fun EditInlineMessageText( + inlineMessageId: InlineMessageIdentifier, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = EditInlineMessageText( + inlineMessageId, + text, + parseMode, + null, + disableWebPagePreview, + replyMarkup +) + +fun EditInlineMessageText( + inlineMessageId: InlineMessageIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = EditInlineMessageText( + inlineMessageId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + disableWebPagePreview, + replyMarkup +) + @Serializable -data class EditInlineMessageText( +data class EditInlineMessageText internal constructor( @SerialName(inlineMessageIdField) override val inlineMessageId: InlineMessageIdentifier, @SerialName(textField) override val text: String, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(entitiesField) + private val rawEntities: List? = null, @SerialName(disableWebPagePreviewField) override val disableWebPagePreview: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditInlineMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + override fun method(): String = editMessageMediaMethod override val requestSerializer: SerializationStrategy<*> get() = serializer() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt index f6b8ef20e0..4a87e596c6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt @@ -1,8 +1,12 @@ package dev.inmo.tgbotapi.requests.send +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.CommonAbstracts.types.DisableWebPagePreview import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -15,14 +19,53 @@ import kotlinx.serialization.* internal val TextContentMessageResultDeserializer: DeserializationStrategy> = TelegramBotAPIMessageDeserializationStrategyClass() +fun SendTextMessage( + chatId: ChatIdentifier, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = SendTextMessage( + chatId, + text, + parseMode, + null, + disableWebPagePreview, + disableNotification, + replyToMessageId, + replyMarkup +) + +fun SendTextMessage( + chatId: ChatIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = SendTextMessage( + chatId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + disableWebPagePreview, + disableNotification, + replyToMessageId, + replyMarkup +) + @Serializable -data class SendTextMessage( +data class SendTextMessage internal constructor( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(textField) override val text: String, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(entitiesField) + private val rawEntities: List? = null, @SerialName(disableWebPagePreviewField) override val disableWebPagePreview: Boolean? = null, @SerialName(disableNotificationField) @@ -36,6 +79,10 @@ data class SendTextMessage( TextableSendMessageRequest>, DisableWebPagePreview { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text) ?.justTextSources() + } + init { if (text.length !in textLength) { throwRangeError("Text length", textLength, text.length) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/TextableSendMessageRequest.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/TextableSendMessageRequest.kt index 078c94f326..e77f2d321d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/TextableSendMessageRequest.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/TextableSendMessageRequest.kt @@ -1,8 +1,5 @@ package dev.inmo.tgbotapi.requests.send.abstracts -import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput -interface TextableSendMessageRequest: SendMessageRequest { - val text: String? - val parseMode: ParseMode? -} \ No newline at end of file +interface TextableSendMessageRequest: SendMessageRequest, TextedOutput diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt index de4578c8d0..012d556ec6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt @@ -1,9 +1,13 @@ package dev.inmo.tgbotapi.requests.send.media +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -38,6 +42,49 @@ fun SendAnimation( thumbAsFileId, caption, parseMode, + null, + duration, + width, + height, + disableNotification, + replyToMessageId, + replyMarkup + ) + + return if (animationAsFile == null && thumbAsFile == null) { + data + } else { + MultipartRequestImpl( + data, + SendAnimationFiles(animationAsFile, thumbAsFile) + ) + } +} + +fun SendAnimation( + chatId: ChatIdentifier, + animation: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +): Request> { + val animationAsFileId = (animation as? FileId) ?.fileId + val animationAsFile = animation as? MultipartFile + val thumbAsFileId = (thumb as? FileId) ?.fileId + val thumbAsFile = thumb as? MultipartFile + + val data = SendAnimationData( + chatId, + animationAsFileId, + thumbAsFileId, + entities.makeString(), + null, + entities.toRawMessageEntities(), duration, width, height, @@ -71,6 +118,8 @@ data class SendAnimationData internal constructor( override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(durationField) override val duration: Long? = null, @SerialName(widthField) @@ -91,6 +140,10 @@ data class SendAnimationData internal constructor( DuratedSendMessageRequest>, SizedSendMessageRequest> { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + init { text ?.let { if (it.length !in captionLength) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt index dd06aa2faf..4dce2c6736 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt @@ -1,10 +1,13 @@ package dev.inmo.tgbotapi.requests.send.media -import dev.inmo.tgbotapi.CommonAbstracts.Performerable +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -39,6 +42,49 @@ fun SendAudio( thumbAsFileId, caption, parseMode, + null, + duration, + performer, + title, + disableNotification, + replyToMessageId, + replyMarkup + ) + + return if (audioAsFile == null && thumbAsFile == null) { + data + } else { + MultipartRequestImpl( + data, + SendAudioFiles(audioAsFile, thumbAsFile) + ) + } +} + +fun SendAudio( + chatId: ChatIdentifier, + audio: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +): Request> { + val audioAsFileId = (audio as? FileId) ?.fileId + val audioAsFile = audio as? MultipartFile + val thumbAsFileId = (thumb as? FileId) ?.fileId + val thumbAsFile = thumb as? MultipartFile + + val data = SendAudioData( + chatId, + audioAsFileId, + thumbAsFileId, + entities.makeString(), + null, + entities.toRawMessageEntities(), duration, performer, title, @@ -72,6 +118,8 @@ data class SendAudioData internal constructor( override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(durationField) override val duration: Long? = null, @SerialName(performerField) @@ -93,6 +141,10 @@ data class SendAudioData internal constructor( DuratedSendMessageRequest>, Performerable { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + init { text ?.let { if (it.length !in captionLength) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt index 961d512dc6..72a0fed603 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt @@ -1,9 +1,13 @@ package dev.inmo.tgbotapi.requests.send.media +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -45,6 +49,54 @@ fun SendDocument( thumbAsFileId, caption, parseMode, + null, + disableNotification, + replyToMessageId, + replyMarkup, + disableContentTypeDetection + ) + + return if (documentAsFile == null && thumbAsFile == null) { + data + } else { + MultipartRequestImpl( + data, + SendDocumentFiles(documentAsFile, thumbAsFile) + ) + } +} + +/** + * Use this method to send general files. On success, the sent [ContentMessage] with [DocumentContent] is returned. + * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. + * + * @param disableContentTypeDetection Disables automatic server-side content type detection for [document] [MultipartFile] + * + * @see ContentMessage + * @see DocumentContent + */ +fun SendDocument( + chatId: ChatIdentifier, + document: InputFile, + thumb: InputFile? = null, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +): Request> { + val documentAsFileId = (document as? FileId) ?.fileId + val documentAsFile = document as? MultipartFile + val thumbAsFileId = (thumb as? FileId) ?.fileId + val thumbAsFile = thumb as? MultipartFile + + val data = SendDocumentData( + chatId, + documentAsFileId, + thumbAsFileId, + entities.makeString(), + null, + entities.toRawMessageEntities(), disableNotification, replyToMessageId, replyMarkup, @@ -85,6 +137,8 @@ data class SendDocumentData internal constructor( override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) @@ -99,6 +153,10 @@ data class SendDocumentData internal constructor( TextableSendMessageRequest>, ThumbedSendMessageRequest> { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + init { text ?.let { if (it.length !in captionLength) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt index 5ffd41caf2..a526b06704 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt @@ -1,9 +1,13 @@ package dev.inmo.tgbotapi.requests.send.media +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -27,6 +31,33 @@ fun SendPhoto( (photo as? FileId) ?.fileId, caption, parseMode, + null, + disableNotification, + replyToMessageId, + replyMarkup + ) + return data.photo ?.let { + data + } ?: MultipartRequestImpl( + data, + SendPhotoFiles(photo as MultipartFile) + ) +} + +fun SendPhoto( + chatId: ChatIdentifier, + photo: InputFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +): Request> { + val data = SendPhotoData( + chatId, + (photo as? FileId) ?.fileId, + entities.makeString(), + null, + entities.toRawMessageEntities(), disableNotification, replyToMessageId, replyMarkup @@ -52,6 +83,8 @@ data class SendPhotoData internal constructor( override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) @@ -63,6 +96,10 @@ data class SendPhotoData internal constructor( ReplyingMarkupSendMessageRequest>, TextableSendMessageRequest> { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + init { text ?.let { if (it.length !in captionLength) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt index 3c2ba65bd3..3640d60adb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt @@ -1,9 +1,13 @@ package dev.inmo.tgbotapi.requests.send.media +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -39,6 +43,51 @@ fun SendVideo( thumbAsFileId, caption, parseMode, + null, + duration, + width, + height, + supportStreaming, + disableNotification, + replyToMessageId, + replyMarkup + ) + + return if (videoAsFile == null && thumbAsFile == null) { + data + } else { + MultipartRequestImpl( + data, + SendVideoFiles(videoAsFile, thumbAsFile) + ) + } +} + +fun SendVideo( + chatId: ChatIdentifier, + video: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + supportStreaming: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +): Request> { + val videoAsFileId = (video as? FileId) ?.fileId + val videoAsFile = video as? MultipartFile + val thumbAsFileId = (thumb as? FileId) ?.fileId + val thumbAsFile = thumb as? MultipartFile + + val data = SendVideoData( + chatId, + videoAsFileId, + thumbAsFileId, + entities.makeString(), + null, + entities.toRawMessageEntities(), duration, width, height, @@ -73,6 +122,8 @@ data class SendVideoData internal constructor( override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(durationField) override val duration: Long? = null, @SerialName(widthField) @@ -95,6 +146,10 @@ data class SendVideoData internal constructor( DuratedSendMessageRequest>, SizedSendMessageRequest> { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + init { text ?.let { if (it.length !in captionLength) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt index 66376e093b..9664f7ec61 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt @@ -18,8 +18,6 @@ fun SendVideoNote( chatId: ChatIdentifier, videoNote: InputFile, thumb: InputFile? = null, - caption: String? = null, - parseMode: ParseMode? = null, duration: Long? = null, size: Int? = null, // in documentation - length (size of video side) disableNotification: Boolean = false, @@ -35,8 +33,6 @@ fun SendVideoNote( chatId, videoNoteAsFileId, thumbAsFileId, - caption, - parseMode, duration, size, disableNotification, @@ -65,10 +61,6 @@ data class SendVideoNoteData internal constructor( val videoNote: String? = null, @SerialName(thumbField) override val thumb: String? = null, - @SerialName(captionField) - override val text: String? = null, - @SerialName(parseModeField) - override val parseMode: ParseMode? = null, @SerialName(durationField) override val duration: Long? = null, @SerialName(lengthField) @@ -82,7 +74,6 @@ data class SendVideoNoteData internal constructor( ) : DataRequest>, SendMessageRequest>, ReplyingMarkupSendMessageRequest>, - TextableSendMessageRequest>, ThumbedSendMessageRequest>, DuratedSendMessageRequest>, SizedSendMessageRequest> @@ -90,14 +81,6 @@ data class SendVideoNoteData internal constructor( override val height: Int? get() = width - init { - text ?.let { - if (it.length !in captionLength) { - throwRangeError("Caption length", captionLength, it.length) - } - } - } - override fun method(): String = "sendVideoNote" override val resultDeserializer: DeserializationStrategy> get() = commonResultDeserializer diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt index 1429239446..34962d6079 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt @@ -1,9 +1,13 @@ package dev.inmo.tgbotapi.requests.send.media +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -32,6 +36,41 @@ fun SendVoice( voiceAsFileId, caption, parseMode, + null, + duration, + disableNotification, + replyToMessageId, + replyMarkup + ) + + return if (voiceAsFile == null) { + data + } else { + MultipartRequestImpl( + data, + SendVoiceFiles(voiceAsFile) + ) + } +} + +fun SendVoice( + chatId: ChatIdentifier, + voice: InputFile, + entities: List, + duration: Long? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +): Request> { + val voiceAsFileId = (voice as? FileId) ?.fileId + val voiceAsFile = voice as? MultipartFile + + val data = SendVoiceData( + chatId, + voiceAsFileId, + entities.makeString(), + null, + entities.toRawMessageEntities(), duration, disableNotification, replyToMessageId, @@ -61,6 +100,8 @@ data class SendVoiceData internal constructor( override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(durationField) override val duration: Long? = null, @SerialName(disableNotificationField) @@ -75,6 +116,10 @@ data class SendVoiceData internal constructor( TextableSendMessageRequest>, DuratedSendMessageRequest> { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + init { text ?.let { if (it.length !in captionLength) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt index 7ded492c21..9001b208e8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt @@ -14,6 +14,9 @@ import dev.inmo.tgbotapi.types.polls.* import dev.inmo.tgbotapi.utils.fullListOfSubSource import dev.inmo.tgbotapi.utils.toMarkdownV2Captions import com.soywiz.klock.DateTime +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import kotlinx.serialization.* private val commonResultDeserializer: DeserializationStrategy> = TelegramBotAPIMessageDeserializationStrategyClass() @@ -85,8 +88,7 @@ fun Poll.createRequest( correctOptionId, isAnonymous, isClosed, - explanation ?.fullListOfSubSource(explanationEntities) ?.justTextSources() ?.toMarkdownV2Captions() ?.firstOrNull(), - MarkdownV2, + fullEntitiesList(), scheduledCloseInfo, disableNotification, replyToMessageId, @@ -186,8 +188,65 @@ data class SendRegularPoll( } } +fun SendQuizPoll( + chatId: ChatIdentifier, + question: String, + options: List, + correctOptionId: Int, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + explanation: String? = null, + parseMode: ParseMode? = null, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = SendQuizPoll( + chatId, + question, + options, + correctOptionId, + isAnonymous, + isClosed, + explanation, + parseMode, + null, + closeInfo, + disableNotification, + replyToMessageId, + replyMarkup +) + +fun SendQuizPoll( + chatId: ChatIdentifier, + question: String, + options: List, + correctOptionId: Int, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + entities: List, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = SendQuizPoll( + chatId, + question, + options, + correctOptionId, + isAnonymous, + isClosed, + entities.makeString(), + null, + entities.toRawMessageEntities(), + closeInfo, + disableNotification, + replyToMessageId, + replyMarkup +) + @Serializable -data class SendQuizPoll( +data class SendQuizPoll internal constructor( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(questionField) @@ -204,6 +263,8 @@ data class SendQuizPoll( override val explanation: String? = null, @SerialName(explanationParseModeField) override val parseMode: ParseMode? = null, + @SerialName(explanationEntitiesField) + private val rawEntities: List? = null, @Transient override val closeInfo: ScheduledCloseInfo? = null, @SerialName(disableNotificationField) @@ -216,6 +277,9 @@ data class SendQuizPoll( override val type: String = quizPollType override val requestSerializer: SerializationStrategy<*> get() = serializer() + override val entities: List? by lazy { + rawEntities ?.asTextParts(explanation ?: return@lazy null) ?.justTextSources() + } @SerialName(openPeriodField) override val openPeriod: LongSeconds? diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index fb2b899d5c..cdcbb62785 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -108,6 +108,7 @@ const val canJoinGroupsField = "can_join_groups" const val canReadAllGroupMessagesField = "can_read_all_group_messages" const val supportInlineQueriesField = "supports_inline_queries" const val textEntitiesField = "text_entities" +const val entitiesField = "entities" const val stickerSetNameField = "set_name" const val stickerSetNameFullField = "sticker_set_name" const val slowModeDelayField = "slow_mode_delay" @@ -147,6 +148,7 @@ const val totalVoterCountField = "total_voter_count" const val correctOptionIdField = "correct_option_id" const val allowsMultipleAnswersField = "allows_multiple_answers" const val isAnonymousField = "is_anonymous" +const val captionEntitiesField = "caption_entities" const val loginUrlField = "login_url" const val forwardTextField = "forward_text" const val botUsernameField = "bot_username" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt index c56a9044f3..0f71ff5def 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt @@ -1,25 +1,57 @@ package dev.inmo.tgbotapi.types.InputMedia -import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField -import dev.inmo.tgbotapi.types.mediaField import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InputMediaAnimation( + file: InputFile, + text: String? = null, + parseMode: ParseMode? = null, + width: Int? = null, + height: Int? = null, + duration: Long? = null, + thumb: InputFile? = null +) = InputMediaAnimation(file, text, parseMode, null, width, height, duration, thumb) + +fun InputMediaAnimation( + file: InputFile, + entities: List, + width: Int? = null, + height: Int? = null, + duration: Long? = null, + thumb: InputFile? = null +) = InputMediaAnimation(file, entities.makeString(), null, entities.toRawMessageEntities(), width, height, duration, thumb) + @Serializable -data class InputMediaAnimation( +data class InputMediaAnimation internal constructor( override val file: InputFile, - override val caption: String? = null, + @SerialName(captionField) + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, override val width: Int? = null, override val height: Int? = null, override val duration: Long? = null, override val thumb: InputFile? = null -) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, CaptionedOutput { +) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, TextedOutput, CaptionedOutput { override val type: String = "animation" + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text @SerialName(mediaField) override val media: String diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt index 1c3b547428..738da6a829 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt @@ -1,30 +1,61 @@ package dev.inmo.tgbotapi.types.InputMedia -import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput -import dev.inmo.tgbotapi.CommonAbstracts.Performerable +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.files.AudioFile import dev.inmo.tgbotapi.types.files.PhotoSize -import dev.inmo.tgbotapi.types.mediaField import dev.inmo.tgbotapi.types.message.content.media.AudioContent import kotlinx.serialization.* internal const val audioInputMediaType = "audio" +fun InputMediaAudio( + file: InputFile, + entities: List, + duration: Long? = null, + performer: String? = null, + title: String? = null, + thumb: InputFile? = null +) = InputMediaAudio( + file, entities.makeString(), null, entities.toRawMessageEntities(), duration, performer, title, thumb +) + +fun InputMediaAudio( + file: InputFile, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + performer: String? = null, + title: String? = null, + thumb: InputFile? = null +) = InputMediaAudio( + file, text, parseMode, null, duration, performer, title, thumb +) + @Serializable -data class InputMediaAudio( +data class InputMediaAudio internal constructor( override val file: InputFile, - override val caption: String? = null, + @SerialName(captionField) + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, override val duration: Long? = null, override val performer: String? = null, override val title: String? = null, override val thumb: InputFile? = null -) : InputMedia, AudioMediaGroupMemberInputMedia, DuratedInputMedia, ThumbedInputMedia, TitledInputMedia, CaptionedOutput, Performerable { +) : InputMedia, AudioMediaGroupMemberInputMedia, DuratedInputMedia, ThumbedInputMedia, TitledInputMedia, Performerable { override val type: String = audioInputMediaType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt index a0fa37b7c0..81cc43a069 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt @@ -1,16 +1,33 @@ package dev.inmo.tgbotapi.types.InputMedia -import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField -import dev.inmo.tgbotapi.types.disableContentTypeDetectionField import dev.inmo.tgbotapi.types.files.DocumentFile -import dev.inmo.tgbotapi.types.mediaField import kotlinx.serialization.* internal const val documentInputMediaType = "document" +fun InputMediaDocument( + file: InputFile, + caption: String? = null, + parseMode: ParseMode? = null, + thumb: InputFile? = null, + disableContentTypeDetection: Boolean? = null +) = InputMediaDocument(file, caption, parseMode, null, thumb, disableContentTypeDetection) + +fun InputMediaDocument( + file: InputFile, + entities: List, + thumb: InputFile? = null, + disableContentTypeDetection: Boolean? = null +) = InputMediaDocument(file, entities.makeString(), null, entities.toRawMessageEntities(), thumb, disableContentTypeDetection) + /** * Represents a general file to be sent. See https://core.telegram.org/bots/api#inputmediadocument * @@ -22,16 +39,22 @@ internal const val documentInputMediaType = "document" * @see FileId */ @Serializable -data class InputMediaDocument( +data class InputMediaDocument internal constructor( override val file: InputFile, - override val caption: String? = null, + @SerialName(captionField) + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, override val thumb: InputFile? = null, @SerialName(disableContentTypeDetectionField) val disableContentTypeDetection: Boolean? = null -) : InputMedia, DocumentMediaGroupMemberInputMedia, ThumbedInputMedia, CaptionedOutput { +) : InputMedia, DocumentMediaGroupMemberInputMedia, ThumbedInputMedia { override val type: String = documentInputMediaType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt index 32a5c1b482..e921b51508 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt @@ -1,24 +1,45 @@ package dev.inmo.tgbotapi.types.InputMedia +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.files.PhotoSize -import dev.inmo.tgbotapi.types.mediaField import kotlinx.serialization.* import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonObject internal const val photoInputMediaType = "photo" +fun InputMediaPhoto( + file: InputFile, + text: String? = null, + parseMode: ParseMode? = null +) = InputMediaPhoto(file, text, parseMode, null) + +fun InputMediaPhoto( + file: InputFile, + entities: List +) = InputMediaPhoto(file, entities.makeString(), null, entities.toRawMessageEntities()) + @Serializable -data class InputMediaPhoto( +data class InputMediaPhoto internal constructor( override val file: InputFile, - override val caption: String? = null, + @SerialName(captionField) + override val text: String? = null, @SerialName(parseModeField) - override val parseMode: ParseMode? = null + override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null ) : InputMedia, VisualMediaGroupMemberInputMedia { override val type: String = photoInputMediaType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt index 302a1579d3..d6a6c46bcd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt @@ -1,26 +1,55 @@ package dev.inmo.tgbotapi.types.InputMedia +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField -import dev.inmo.tgbotapi.types.mediaField import kotlinx.serialization.* import kotlinx.serialization.json.JsonElement internal const val videoInputMediaType = "video" +fun InputMediaVideo( + file: InputFile, + text: String? = null, + parseMode: ParseMode? = null, + width: Int? = null, + height: Int? = null, + duration: Long? = null, + thumb: InputFile? = null +) = InputMediaVideo(file, text, parseMode, null, width, height, duration, thumb) + +fun InputMediaVideo( + file: InputFile, + entities: List, + width: Int? = null, + height: Int? = null, + duration: Long? = null, + thumb: InputFile? = null +) = InputMediaVideo(file, entities.makeString(), null, entities.toRawMessageEntities(), width, height, duration, thumb) + @Serializable -data class InputMediaVideo( +data class InputMediaVideo internal constructor ( override val file: InputFile, - override val caption: String? = null, + @SerialName(captionField) + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, override val width: Int? = null, override val height: Int? = null, override val duration: Long? = null, override val thumb: InputFile? = null ) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, VisualMediaGroupMemberInputMedia { override val type: String = videoInputMediaType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMedia.kt index 83965179f8..ebb1b2291c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMedia.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMedia.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InputMedia import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import kotlinx.serialization.* import kotlinx.serialization.json.* @@ -15,7 +16,10 @@ internal fun T.buildArguments(withSerializer: SerializationStrategy) = ar ) @Serializable(MediaGroupMemberInputMediaSerializer::class) -interface MediaGroupMemberInputMedia : InputMedia, CaptionedOutput { +interface MediaGroupMemberInputMedia : InputMedia, CaptionedOutput, TextedOutput { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text fun serialize(format: StringFormat): String } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt index 942e6d1704..610a384682 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.MessageEntity -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.utils.shiftSourcesToTheLeft @@ -83,7 +82,7 @@ internal fun createTextPart(from: String, entities: RawMessageEntities): List.asRawMessageEntities() = mapNotNull { +internal fun List.asRawMessageEntities(): List = mapNotNull { val source = it.source when (source) { is MentionTextSource -> RawMessageEntity("mention", it.range.first, it.range.last - it.range.first) @@ -105,6 +104,18 @@ internal fun List.asRawMessageEntities() = mapNotNull { } } +internal fun List.toRawMessageEntities(): List { + var i = 0 + return map { + TextPart( + i until it.source.length, + it + ).also { + i = it.range.last + 1 + } + }.asRawMessageEntities() +} + internal fun RawMessageEntities.asTextParts(sourceString: String): List = createTextPart(sourceString, this) internal typealias RawMessageEntities = List From a5982ac88123759dc60caf12cb1f272a7719dd6d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Nov 2020 18:00:40 +0600 Subject: [PATCH 20/42] partially restructurize InlineQueryResult and several its implementators --- .../InlineQueryResultVideoCachedImpl.kt | 34 +++++++++++++- .../InlineQueryResultVideoImpl.kt | 44 ++++++++++++++++++- .../InlineQueryResultVoiceCachedImpl.kt | 32 +++++++++++++- .../InlineQueryResultVoiceImpl.kt | 44 ++++++++++++++++++- .../audio/InlineQueryResultAudioCommon.kt | 8 +++- .../InlineQueryResultDocumentCommon.kt | 8 +++- .../results/gif/InlineQueryResultGifCommon.kt | 8 +++- .../InlineQueryResultMpeg4GifCommon.kt | 8 +++- .../photo/InlineQueryResultPhotoCommon.kt | 8 +++- .../video/InlineQueryResultVideoCommon.kt | 8 +++- .../voice/InlineQueryResultVoiceCommon.kt | 8 +++- 11 files changed, 195 insertions(+), 15 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt index c5368ae68f..3ca7511514 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt @@ -1,18 +1,43 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.InlineQueryResultVideoCached import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.inlineQueryResultVideoType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultVideoCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String, + description: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVideoCachedImpl(id, fileId, title, description, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultVideoCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String, + description: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVideoCachedImpl(id, fileId, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultVideoCachedImpl( +data class InlineQueryResultVideoCachedImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(videoFileIdField) @@ -22,13 +47,18 @@ data class InlineQueryResultVideoCachedImpl( @SerialName(descriptionField) override val description: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultVideoCached { override val type: String = inlineQueryResultVideoType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt index 63ca03891b..2e6262cbec 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt @@ -1,9 +1,13 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.InlineQueryResultVideo import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.inlineQueryResultVideoType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -12,8 +16,39 @@ import dev.inmo.tgbotapi.utils.MimeType import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultVideoImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + mimeType: MimeType, + title: String, + width: Int? = null, + height: Int? = null, + duration: Int? = null, + description: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVideoImpl(id, url, thumbUrl, mimeType, title, width, height, duration, description, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultVideoImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + mimeType: MimeType, + title: String, + width: Int? = null, + height: Int? = null, + duration: Int? = null, + description: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVideoImpl(id, url, thumbUrl, mimeType, title, width, height, duration, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultVideoImpl( +data class InlineQueryResultVideoImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(videoUrlField) @@ -33,13 +68,18 @@ data class InlineQueryResultVideoImpl( @SerialName(descriptionField) override val description: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultVideo { override val type: String = inlineQueryResultVideoType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt index e840e1f444..ee2d540148 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt @@ -1,18 +1,41 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.InlineQueryResultVoiceCached import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.inlineQueryResultVoiceType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultVoiceCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVoiceCachedImpl(id, fileId, title, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultVoiceCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVoiceCachedImpl(id, fileId, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultVoiceCachedImpl( +data class InlineQueryResultVoiceCachedImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(voiceFileIdField) @@ -20,13 +43,18 @@ data class InlineQueryResultVoiceCachedImpl( @SerialName(titleField) override val title: String, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultVoiceCached { override val type: String = inlineQueryResultVoiceType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt index 7a8f85efc6..f507bcc0d9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt @@ -1,17 +1,52 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.InlineQueryResultVoice import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.inlineQueryResultVoiceType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultVoiceImpl( + id: InlineQueryIdentifier, + url: String, + title: String, + duration: Int? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVoiceImpl( + id, + url, + title, + duration, + text, + parseMode, + null, + replyMarkup, + inputMessageContent +) + +fun InlineQueryResultVoiceImpl( + id: InlineQueryIdentifier, + url: String, + title: String, + duration: Int? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVoiceImpl(id, url, title, duration, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultVoiceImpl( +data class InlineQueryResultVoiceImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(voiceUrlField) @@ -21,13 +56,18 @@ data class InlineQueryResultVoiceImpl( @SerialName(voiceDurationField) override val duration: Int? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultVoice { override val type: String = inlineQueryResultVoiceType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/audio/InlineQueryResultAudioCommon.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/audio/InlineQueryResultAudioCommon.kt index 4d044cb2fa..b27d04396d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/audio/InlineQueryResultAudioCommon.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/audio/InlineQueryResultAudioCommon.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.WithInputMessageContentInlineQueryResult @@ -8,4 +9,9 @@ const val inlineQueryResultAudioType = "audio" interface InlineQueryResultAudioCommon : InlineQueryResult, CaptionedOutput, - WithInputMessageContentInlineQueryResult + TextedOutput, + WithInputMessageContentInlineQueryResult { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/document/InlineQueryResultDocumentCommon.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/document/InlineQueryResultDocumentCommon.kt index 6000638253..fa51b3e0e0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/document/InlineQueryResultDocumentCommon.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/document/InlineQueryResultDocumentCommon.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.* const val inlineQueryResultDocumentType = "document" @@ -9,4 +10,9 @@ interface InlineQueryResultDocumentCommon : InlineQueryResult, TitledInlineQueryResult, DescribedInlineQueryResult, CaptionedOutput, - WithInputMessageContentInlineQueryResult + TextedOutput, + WithInputMessageContentInlineQueryResult { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/gif/InlineQueryResultGifCommon.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/gif/InlineQueryResultGifCommon.kt index 6c64ec21b0..95e5f14480 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/gif/InlineQueryResultGifCommon.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/gif/InlineQueryResultGifCommon.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.* const val inlineQueryResultGifType = "gif" @@ -8,4 +9,9 @@ const val inlineQueryResultGifType = "gif" interface InlineQueryResultGifCommon : InlineQueryResult, OptionallyTitledInlineQueryResult, CaptionedOutput, - WithInputMessageContentInlineQueryResult + TextedOutput, + WithInputMessageContentInlineQueryResult { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/mpeg4gif/InlineQueryResultMpeg4GifCommon.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/mpeg4gif/InlineQueryResultMpeg4GifCommon.kt index f8649eb7b8..69b4e5b88c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/mpeg4gif/InlineQueryResultMpeg4GifCommon.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/mpeg4gif/InlineQueryResultMpeg4GifCommon.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.* const val inlineQueryResultMpeg4GifType = "mpeg4_gif" @@ -8,4 +9,9 @@ const val inlineQueryResultMpeg4GifType = "mpeg4_gif" interface InlineQueryResultMpeg4GifCommon : InlineQueryResult, OptionallyTitledInlineQueryResult, CaptionedOutput, - WithInputMessageContentInlineQueryResult + TextedOutput, + WithInputMessageContentInlineQueryResult { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/photo/InlineQueryResultPhotoCommon.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/photo/InlineQueryResultPhotoCommon.kt index b65989092d..1f33a3a9b9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/photo/InlineQueryResultPhotoCommon.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/photo/InlineQueryResultPhotoCommon.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.* const val inlineQueryResultPhotoType = "photo" @@ -9,4 +10,9 @@ interface InlineQueryResultPhotoCommon : InlineQueryResult, OptionallyTitledInlineQueryResult, DescribedInlineQueryResult, CaptionedOutput, - WithInputMessageContentInlineQueryResult + TextedOutput, + WithInputMessageContentInlineQueryResult { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/video/InlineQueryResultVideoCommon.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/video/InlineQueryResultVideoCommon.kt index a82aecbd03..a015faac61 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/video/InlineQueryResultVideoCommon.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/video/InlineQueryResultVideoCommon.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.* const val inlineQueryResultVideoType = "video" @@ -9,4 +10,9 @@ interface InlineQueryResultVideoCommon : InlineQueryResult, TitledInlineQueryResult, DescribedInlineQueryResult, CaptionedOutput, - WithInputMessageContentInlineQueryResult + TextedOutput, + WithInputMessageContentInlineQueryResult { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/voice/InlineQueryResultVoiceCommon.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/voice/InlineQueryResultVoiceCommon.kt index 8ff23d5ea3..0bb3dee55b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/voice/InlineQueryResultVoiceCommon.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/voice/InlineQueryResultVoiceCommon.kt @@ -1,11 +1,17 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.* const val inlineQueryResultVoiceType = "voice" interface InlineQueryResultVoiceCommon : InlineQueryResult, CaptionedOutput, + TextedOutput, WithInputMessageContentInlineQueryResult, - TitledInlineQueryResult + TitledInlineQueryResult { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text +} From d5e283e7ba9d4a2cd6df413a08dd99f8259733a2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Nov 2020 20:18:16 +0600 Subject: [PATCH 21/42] Update all classes which must have "entities"/"caption_entities" fields (#189) --- CHANGELOG.md | 1 + .../InlineQueryResultAudioCachedImpl.kt | 30 ++++++++++++- .../InlineQueryResultAudioImpl.kt | 36 +++++++++++++++- .../InlineQueryResultDocumentCachedImpl.kt | 34 ++++++++++++++- .../InlineQueryResultDocumentImpl.kt | 42 ++++++++++++++++++- .../InlineQueryResultGifCachedImpl.kt | 32 +++++++++++++- .../InlineQueryResultGifImpl.kt | 42 ++++++++++++++++++- .../InlineQueryResultMpeg4GifCachedImpl.kt | 32 +++++++++++++- .../InlineQueryResultMpeg4GifImpl.kt | 42 ++++++++++++++++++- .../InlineQueryResultPhotoCachedImpl.kt | 33 ++++++++++++++- .../InlineQueryResultPhotoImpl.kt | 40 +++++++++++++++++- .../InputTextMessageContent.kt | 40 +++++++++++++++--- 12 files changed, 378 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cffb8bce66..9b70a1718e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,7 @@ * `PrivateMessage` - works like previous `CommonMessageImpl` * Previous `CommonMessageImpl` safely renamed to `PrivateMessageImpl` * New property `PromoteChatMember#isAnonymous` + * Update all classes which must have `entities`/`caption_entities` fields * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt index 7d478397ec..cccb0b8fb6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt @@ -1,30 +1,56 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.InlineQueryResultAudioCached import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.inlineQueryResultAudioType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultAudioCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultAudioCachedImpl(id, fileId, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultAudioCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultAudioCachedImpl(id, fileId, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultAudioCachedImpl( +data class InlineQueryResultAudioCachedImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(audioFileIdField) override val fileId: FileId, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultAudioCached { override val type: String = inlineQueryResultAudioType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt index e009ab8f66..38474be80b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt @@ -1,17 +1,44 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.InlineQueryResultAudio import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.inlineQueryResultAudioType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultAudioImpl( + id: InlineQueryIdentifier, + url: String, + title: String, + performer: String? = null, + duration: Int? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultAudioImpl(id, url, title, performer, duration, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultAudioImpl( + id: InlineQueryIdentifier, + url: String, + title: String, + performer: String? = null, + duration: Int? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultAudioImpl(id, url, title, performer, duration, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultAudioImpl( +data class InlineQueryResultAudioImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(audioUrlField) @@ -23,13 +50,18 @@ data class InlineQueryResultAudioImpl( @SerialName(audioDurationField) override val duration: Int? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultAudio { override val type: String = inlineQueryResultAudioType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt index 85b4cb2644..6d278f49e6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt @@ -1,18 +1,43 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.InlineQueryResultDocumentCached import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.inlineQueryResultDocumentType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultDocumentCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String, + description: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultDocumentCachedImpl(id, fileId, title, description, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultDocumentCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String, + description: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultDocumentCachedImpl(id, fileId, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultDocumentCachedImpl( +data class InlineQueryResultDocumentCachedImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(documentFileIdField) @@ -22,13 +47,18 @@ data class InlineQueryResultDocumentCachedImpl( @SerialName(descriptionField) override val description: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultDocumentCached { override val type: String = inlineQueryResultDocumentType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt index 4043852c3c..83eff31242 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt @@ -1,9 +1,13 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.InlineQueryResultDocument import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.inlineQueryResultDocumentType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -12,8 +16,37 @@ import dev.inmo.tgbotapi.utils.MimeType import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultDocumentImpl( + id: InlineQueryIdentifier, + url: String, + title: String, + mimeType: MimeType, + thumbUrl: String? = null, + thumbWidth: Int? = null, + thumbHeight: Int? = null, + description: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultDocumentImpl(id, url, title, mimeType, thumbUrl, thumbWidth, thumbHeight, description, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultDocumentImpl( + id: InlineQueryIdentifier, + url: String, + title: String, + mimeType: MimeType, + thumbUrl: String? = null, + thumbWidth: Int? = null, + thumbHeight: Int? = null, + description: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultDocumentImpl(id, url, title, mimeType, thumbUrl, thumbWidth, thumbHeight, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultDocumentImpl( +data class InlineQueryResultDocumentImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(documentUrlField) @@ -31,13 +64,18 @@ data class InlineQueryResultDocumentImpl( @SerialName(descriptionField) override val description: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultDocument { override val type: String = inlineQueryResultDocumentType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt index 091cc13c2a..97de40174a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt @@ -1,18 +1,41 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.InlineQueryResultGifCached import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.inlineQueryResultGifType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultGifCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultGifCachedImpl(id, fileId, title, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultGifCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultGifCachedImpl(id, fileId, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultGifCachedImpl( +data class InlineQueryResultGifCachedImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(gifFileIdField) @@ -20,13 +43,18 @@ data class InlineQueryResultGifCachedImpl( @SerialName(titleField) override val title: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultGifCached { override val type: String = inlineQueryResultGifType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt index afb8b7215d..ca613abfec 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt @@ -1,9 +1,13 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.InlineQueryResultGif import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.inlineQueryResultGifType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -11,8 +15,37 @@ import dev.inmo.tgbotapi.utils.MimeType import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultGifImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + thumbMimeType: MimeType? = null, + width: Int? = null, + height: Int? = null, + duration: Int? = null, + title: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultGifImpl(id, url, thumbUrl, thumbMimeType, width, height, duration, title, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultGifImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + thumbMimeType: MimeType? = null, + width: Int? = null, + height: Int? = null, + duration: Int? = null, + title: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultGifImpl(id, url, thumbUrl, thumbMimeType, width, height, duration, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultGifImpl( +data class InlineQueryResultGifImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(gifUrlField) @@ -30,15 +63,20 @@ data class InlineQueryResultGifImpl( @SerialName(titleField) override val title: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultGif { override val type: String = inlineQueryResultGifType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } init { if (thumbMimeType != null && thumbMimeType !in telegramInlineModeGifPermittedMimeTypes) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt index 014664fca9..bdf0c15817 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt @@ -1,18 +1,41 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.InlineQueryResultMpeg4GifCached import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.inlineQueryResultMpeg4GifType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultMpeg4GifCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultMpeg4GifCachedImpl(id, fileId, title, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultMpeg4GifCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultMpeg4GifCachedImpl(id, fileId, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultMpeg4GifCachedImpl( +data class InlineQueryResultMpeg4GifCachedImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(mpeg4GifFileIdField) @@ -20,13 +43,18 @@ data class InlineQueryResultMpeg4GifCachedImpl( @SerialName(titleField) override val title: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultMpeg4GifCached { override val type: String = inlineQueryResultMpeg4GifType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt index 206016a70f..5f77b70629 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt @@ -1,9 +1,13 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.InlineQueryResultMpeg4Gif import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.inlineQueryResultMpeg4GifType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -11,8 +15,37 @@ import dev.inmo.tgbotapi.utils.MimeType import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultMpeg4GifImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + thumbMimeType: MimeType? = null, + width: Int? = null, + height: Int? = null, + duration: Int? = null, + title: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultMpeg4GifImpl(id, url, thumbUrl, thumbMimeType, width, height, duration, title, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultMpeg4GifImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + thumbMimeType: MimeType? = null, + width: Int? = null, + height: Int? = null, + duration: Int? = null, + title: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultMpeg4GifImpl(id, url, thumbUrl, thumbMimeType, width, height, duration, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultMpeg4GifImpl( +data class InlineQueryResultMpeg4GifImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(mpeg4GifUrlField) @@ -30,15 +63,20 @@ data class InlineQueryResultMpeg4GifImpl( @SerialName(titleField) override val title: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultMpeg4Gif { override val type: String = inlineQueryResultMpeg4GifType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } init { if (thumbMimeType != null && thumbMimeType !in telegramInlineModeGifPermittedMimeTypes) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt index 270fa12fa9..3318691b35 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt @@ -1,18 +1,42 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.InlineQueryResultPhotoCached import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.inlineQueryResultPhotoType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultPhotoCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String? = null, + description: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultPhotoCachedImpl(id, fileId, title, description, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultPhotoCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String? = null, + description: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultPhotoCachedImpl(id, fileId, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultPhotoCachedImpl( +data class InlineQueryResultPhotoCachedImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(photoFileIdField) @@ -22,13 +46,18 @@ data class InlineQueryResultPhotoCachedImpl( @SerialName(descriptionField) override val description: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultPhotoCached { override val type: String = inlineQueryResultPhotoType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt index bd35faee26..54173109ea 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt @@ -1,17 +1,48 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.InlineQueryResultPhoto import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.inlineQueryResultPhotoType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultPhotoImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + width: Int? = null, + height: Int? = null, + title: String? = null, + description: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultPhotoImpl(id, url, thumbUrl, width, height, title, description, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultPhotoImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + width: Int? = null, + height: Int? = null, + title: String? = null, + description: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultPhotoImpl(id, url, thumbUrl, width, height, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultPhotoImpl( +data class InlineQueryResultPhotoImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(photoUrlField) @@ -27,13 +58,18 @@ data class InlineQueryResultPhotoImpl( @SerialName(descriptionField) override val description: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultPhoto { override val type: String = inlineQueryResultPhotoType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt index 698608c632..2cee36978c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt @@ -1,21 +1,49 @@ package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent -import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.CommonAbstracts.types.DisableWebPagePreview +import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField -import dev.inmo.tgbotapi.types.disableWebPagePreviewField -import dev.inmo.tgbotapi.types.messageTextField import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +/** + * Represents the [InputMessageContent] of a text message to be sent as the result of an inline query. + */ +fun InputTextMessageContent( + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null +) = InputTextMessageContent(text, parseMode, null, disableWebPagePreview) + +/** + * Represents the [InputMessageContent] of a text message to be sent as the result of an inline query. + */ +fun InputTextMessageContent( + entities: List, + disableWebPagePreview: Boolean? = null +) = InputTextMessageContent(entities.makeString(), null, entities.toRawMessageEntities(), disableWebPagePreview) + @Serializable -data class InputTextMessageContent( +data class InputTextMessageContent internal constructor( @SerialName(messageTextField) - override val caption: String, + override val text: String, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(entitiesField) + private val rawEntities: List? = null, @SerialName(disableWebPagePreviewField) override val disableWebPagePreview: Boolean? = null -) : CaptionedOutput, DisableWebPagePreview, InputMessageContent \ No newline at end of file +) : CaptionedOutput, TextedOutput, DisableWebPagePreview, InputMessageContent { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text + override val entities: List? by lazy { + rawEntities ?.asTextParts(text) ?.justTextSources() + } +} \ No newline at end of file From 6bdefb6f8fca738b87c1d4c275f3f5ae4b2959e9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Nov 2020 20:27:45 +0600 Subject: [PATCH 22/42] new request CopyMessage (#187) --- CHANGELOG.md | 1 + .../tgbotapi/requests/send/CopyMessage.kt | 77 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b70a1718e..1514790204 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ * Previous `CommonMessageImpl` safely renamed to `PrivateMessageImpl` * New property `PromoteChatMember#isAnonymous` * Update all classes which must have `entities`/`caption_entities` fields + * New request `CopyMessage` * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt new file mode 100644 index 0000000000..685d526ddc --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt @@ -0,0 +1,77 @@ +package dev.inmo.tgbotapi.requests.send + +import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.types.MessageAction +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextParts +import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.types.ParseMode.parseModeField +import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup +import dev.inmo.tgbotapi.types.message.abstracts.* +import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass +import kotlinx.serialization.* + +private val ResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass>() + +fun CopyMessage( + fromChatId: ChatIdentifier, + toChatId: ChatIdentifier, + messageId: MessageIdentifier, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = CopyMessage(fromChatId, toChatId, messageId, text, parseMode, null, disableNotification, replyToMessageId, replyMarkup) + +fun CopyMessage( + fromChatId: ChatIdentifier, + toChatId: ChatIdentifier, + messageId: MessageIdentifier, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = CopyMessage(fromChatId, toChatId, messageId, entities.makeString(), null, entities.toRawMessageEntities(), disableNotification, replyToMessageId, replyMarkup) + +@Serializable +data class CopyMessage internal constructor( + @SerialName(fromChatIdField) + val fromChatId: ChatIdentifier, + @SerialName(chatIdField) + val toChatId: ChatIdentifier, + @SerialName(messageIdField) + override val messageId: MessageIdentifier, + @SerialName(captionField) + override val text: String? = null, + @SerialName(parseModeField) + override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, + @SerialName(disableNotificationField) + override val disableNotification: Boolean = false, + @SerialName(replyToMessageIdField) + override val replyToMessageId: MessageIdentifier? = null, + @SerialName(replyMarkupField) + override val replyMarkup: KeyboardMarkup? = null +): SimpleRequest>, + ReplyingMarkupSendMessageRequest>, + MessageAction, + TextedOutput { + override val chatId: ChatIdentifier + get() = fromChatId + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + + override fun method(): String = "copyMessage" + + override val resultDeserializer: DeserializationStrategy> + get() = ResultDeserializer + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} From 765caefc3211944b6d60fd20e533d4cfcf25c57c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Nov 2020 21:33:11 +0600 Subject: [PATCH 23/42] implementation of allow sending without reply (#191) --- .../CommonAbstracts/types/ReplyMessageId.kt | 1 + .../tgbotapi/requests/send/CopyMessage.kt | 8 ++++-- .../tgbotapi/requests/send/SendContact.kt | 6 +++++ .../inmo/tgbotapi/requests/send/SendDice.kt | 2 ++ .../tgbotapi/requests/send/SendLocation.kt | 9 ++++++- .../tgbotapi/requests/send/SendMessage.kt | 6 +++++ .../inmo/tgbotapi/requests/send/SendVenue.kt | 6 +++++ .../tgbotapi/requests/send/games/SendGame.kt | 2 ++ .../requests/send/media/SendAnimation.kt | 6 +++++ .../tgbotapi/requests/send/media/SendAudio.kt | 6 +++++ .../requests/send/media/SendDocument.kt | 6 +++++ .../requests/send/media/SendMediaGroup.kt | 25 ++++++++++++------- .../tgbotapi/requests/send/media/SendPhoto.kt | 6 +++++ .../requests/send/media/SendSticker.kt | 4 +++ .../tgbotapi/requests/send/media/SendVideo.kt | 6 +++++ .../requests/send/media/SendVideoNote.kt | 4 +++ .../tgbotapi/requests/send/media/SendVoice.kt | 6 +++++ .../requests/send/payments/SendInvoice.kt | 2 ++ .../tgbotapi/requests/send/polls/SendPoll.kt | 13 ++++++++++ .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 1 + 20 files changed, 113 insertions(+), 12 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/types/ReplyMessageId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/types/ReplyMessageId.kt index 4acaca76f2..3321882208 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/types/ReplyMessageId.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/types/ReplyMessageId.kt @@ -4,4 +4,5 @@ import dev.inmo.tgbotapi.types.MessageIdentifier interface ReplyMessageId { val replyToMessageId: MessageIdentifier? + val allowSendingWithoutReply: Boolean? } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt index 685d526ddc..e9b6f55a1a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt @@ -25,8 +25,9 @@ fun CopyMessage( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = CopyMessage(fromChatId, toChatId, messageId, text, parseMode, null, disableNotification, replyToMessageId, replyMarkup) +) = CopyMessage(fromChatId, toChatId, messageId, text, parseMode, null, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) fun CopyMessage( fromChatId: ChatIdentifier, @@ -35,8 +36,9 @@ fun CopyMessage( entities: List, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = CopyMessage(fromChatId, toChatId, messageId, entities.makeString(), null, entities.toRawMessageEntities(), disableNotification, replyToMessageId, replyMarkup) +) = CopyMessage(fromChatId, toChatId, messageId, entities.makeString(), null, entities.toRawMessageEntities(), disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) @Serializable data class CopyMessage internal constructor( @@ -56,6 +58,8 @@ data class CopyMessage internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ): SimpleRequest>, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendContact.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendContact.kt index 2124808ed7..77613e5d93 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendContact.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendContact.kt @@ -26,6 +26,8 @@ data class SendContact( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendMessageRequest>, @@ -36,6 +38,7 @@ data class SendContact( contact: Contact, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): this( chatId, @@ -44,6 +47,7 @@ data class SendContact( contact.lastName, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -58,11 +62,13 @@ fun Contact.toRequest( chatId: ChatIdentifier, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): SendContact = SendContact( chatId, this, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendDice.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendDice.kt index 248984de66..8347737808 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendDice.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendDice.kt @@ -24,6 +24,8 @@ data class SendDice( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : ReplyingMarkupSendMessageRequest>, ReplyMessageId, DisableNotification { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendLocation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendLocation.kt index ef44f81ab0..69da7631dc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendLocation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendLocation.kt @@ -20,6 +20,7 @@ fun SendLocation( longitude: Double, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = SendLocation( chatId, @@ -31,6 +32,7 @@ fun SendLocation( null, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -40,8 +42,9 @@ fun SendStaticLocation( longitude: Double, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = SendLocation(chatId, latitude, longitude, disableNotification, replyToMessageId, replyMarkup) +) = SendLocation(chatId, latitude, longitude, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) fun SendLiveLocation( chatId: ChatIdentifier, @@ -53,6 +56,7 @@ fun SendLiveLocation( proximityAlertRadius: Meters? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = SendLocation( chatId, @@ -64,6 +68,7 @@ fun SendLiveLocation( proximityAlertRadius, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -87,6 +92,8 @@ data class SendLocation internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendMessageRequest>, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt index 4a87e596c6..229c2e05f4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt @@ -26,6 +26,7 @@ fun SendTextMessage( disableWebPagePreview: Boolean? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = SendTextMessage( chatId, @@ -35,6 +36,7 @@ fun SendTextMessage( disableWebPagePreview, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -44,6 +46,7 @@ fun SendTextMessage( disableWebPagePreview: Boolean? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = SendTextMessage( chatId, @@ -53,6 +56,7 @@ fun SendTextMessage( disableWebPagePreview, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -72,6 +76,8 @@ data class SendTextMessage internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendMessageRequest>, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt index 81cc758590..63be242277 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt @@ -30,6 +30,8 @@ data class SendVenue( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendMessageRequest>, @@ -42,6 +44,7 @@ data class SendVenue( venue: Venue, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): this( chatId, @@ -52,6 +55,7 @@ data class SendVenue( venue.foursquareId, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -66,11 +70,13 @@ fun Venue.toRequest( chatId: ChatIdentifier, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): SendVenue = SendVenue( chatId, this, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/games/SendGame.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/games/SendGame.kt index 8c901e5e5e..7f49e410fe 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/games/SendGame.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/games/SendGame.kt @@ -22,6 +22,8 @@ data class SendGame ( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendMessageRequest>, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt index 012d556ec6..ecb6ef0650 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt @@ -29,6 +29,7 @@ fun SendAnimation( height: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val animationAsFileId = (animation as? FileId) ?.fileId @@ -48,6 +49,7 @@ fun SendAnimation( height, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -71,6 +73,7 @@ fun SendAnimation( height: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val animationAsFileId = (animation as? FileId) ?.fileId @@ -90,6 +93,7 @@ fun SendAnimation( height, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -130,6 +134,8 @@ data class SendAnimationData internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : DataRequest>, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt index 4dce2c6736..8bfd85918d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt @@ -29,6 +29,7 @@ fun SendAudio( title: String? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val audioAsFileId = (audio as? FileId) ?.fileId @@ -48,6 +49,7 @@ fun SendAudio( title, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -71,6 +73,7 @@ fun SendAudio( title: String? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val audioAsFileId = (audio as? FileId) ?.fileId @@ -90,6 +93,7 @@ fun SendAudio( title, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -130,6 +134,8 @@ data class SendAudioData internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : DataRequest>, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt index 72a0fed603..806fa73d2b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt @@ -35,6 +35,7 @@ fun SendDocument( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null, disableContentTypeDetection: Boolean? = null ): Request> { @@ -52,6 +53,7 @@ fun SendDocument( null, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup, disableContentTypeDetection ) @@ -82,6 +84,7 @@ fun SendDocument( entities: List, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null, disableContentTypeDetection: Boolean? = null ): Request> { @@ -99,6 +102,7 @@ fun SendDocument( entities.toRawMessageEntities(), disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup, disableContentTypeDetection ) @@ -143,6 +147,8 @@ data class SendDocumentData internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null, @SerialName(disableContentTypeDetectionField) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt index c49a398ec4..42602bdd00 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt @@ -22,7 +22,8 @@ fun SendMediaGroup( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ): Request> { if (media.size !in mediaCountInMediaGroup) { throwRangeError("Count of members in media group", mediaCountInMediaGroup, media.size) @@ -43,7 +44,8 @@ fun SendMediaGroup( chatId, media, disableNotification, - replyToMessageId + replyToMessageId, + allowSendingWithoutReply ) return if (files.isEmpty()) { @@ -66,8 +68,9 @@ inline fun SendPlaylist( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null -) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId) + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply) /** * Use this method to be sure that you are correctly sending documents media group @@ -79,8 +82,9 @@ inline fun SendDocumentsGroup( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null -) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId) + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply) /** * Use this method to be sure that you are correctly sending visual media group @@ -93,8 +97,9 @@ inline fun SendVisualMediaGroup( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null -) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId) + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply) private val messagesListSerializer: KSerializer> = ListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass()) @@ -107,7 +112,9 @@ data class SendMediaGroupData internal constructor( @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) - override val replyToMessageId: MessageIdentifier? = null + override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null ) : DataRequest>, SendMessageRequest> { @SerialName(mediaField) private val convertedMedia: String diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt index a526b06704..eb7564219c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt @@ -24,6 +24,7 @@ fun SendPhoto( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val data = SendPhotoData( @@ -34,6 +35,7 @@ fun SendPhoto( null, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) return data.photo ?.let { @@ -50,6 +52,7 @@ fun SendPhoto( entities: List, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val data = SendPhotoData( @@ -60,6 +63,7 @@ fun SendPhoto( entities.toRawMessageEntities(), disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) return data.photo ?.let { @@ -89,6 +93,8 @@ data class SendPhotoData internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : DataRequest>, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendSticker.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendSticker.kt index afa7f152d5..e19140ba51 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendSticker.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendSticker.kt @@ -17,12 +17,14 @@ fun SendSticker( sticker: InputFile, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> = SendStickerByFileId( chatId, sticker as? FileId, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ).let { when (sticker) { @@ -44,6 +46,8 @@ data class SendStickerByFileId internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendMessageRequest>, ReplyingMarkupSendMessageRequest> { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt index 3640d60adb..9dfa699f34 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt @@ -30,6 +30,7 @@ fun SendVideo( supportStreaming: Boolean? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val videoAsFileId = (video as? FileId) ?.fileId @@ -50,6 +51,7 @@ fun SendVideo( supportStreaming, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -74,6 +76,7 @@ fun SendVideo( supportStreaming: Boolean? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val videoAsFileId = (video as? FileId) ?.fileId @@ -94,6 +97,7 @@ fun SendVideo( supportStreaming, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -136,6 +140,8 @@ data class SendVideoData internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : DataRequest>, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt index 9664f7ec61..3751531c32 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt @@ -22,6 +22,7 @@ fun SendVideoNote( size: Int? = null, // in documentation - length (size of video side) disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val videoNoteAsFileId = (videoNote as? FileId) ?.fileId @@ -37,6 +38,7 @@ fun SendVideoNote( size, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -69,6 +71,8 @@ data class SendVideoNoteData internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : DataRequest>, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt index 34962d6079..e856b5247e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt @@ -26,6 +26,7 @@ fun SendVoice( duration: Long? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val voiceAsFileId = (voice as? FileId) ?.fileId @@ -40,6 +41,7 @@ fun SendVoice( duration, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -60,6 +62,7 @@ fun SendVoice( duration: Long? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val voiceAsFileId = (voice as? FileId) ?.fileId @@ -74,6 +77,7 @@ fun SendVoice( duration, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -108,6 +112,8 @@ data class SendVoiceData internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : DataRequest>, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/payments/SendInvoice.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/payments/SendInvoice.kt index ef21eb0930..af6bc6e0da 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/payments/SendInvoice.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/payments/SendInvoice.kt @@ -57,6 +57,8 @@ data class SendInvoice( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : Currencied, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt index 9001b208e8..fed5aac521 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt @@ -66,6 +66,7 @@ fun Poll.createRequest( chatId: ChatIdentifier, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = when (this) { is RegularPoll -> SendRegularPoll( @@ -78,6 +79,7 @@ fun Poll.createRequest( scheduledCloseInfo, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) is QuizPoll -> correctOptionId ?.let { correctOptionId -> @@ -92,6 +94,7 @@ fun Poll.createRequest( scheduledCloseInfo, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) } ?: SendRegularPoll( @@ -104,6 +107,7 @@ fun Poll.createRequest( scheduledCloseInfo, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) is UnknownPollType -> SendRegularPoll( @@ -116,6 +120,7 @@ fun Poll.createRequest( scheduledCloseInfo, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) } @@ -167,6 +172,8 @@ data class SendRegularPoll( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendPoll() { @@ -200,6 +207,7 @@ fun SendQuizPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = SendQuizPoll( chatId, @@ -214,6 +222,7 @@ fun SendQuizPoll( closeInfo, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -228,6 +237,7 @@ fun SendQuizPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = SendQuizPoll( chatId, @@ -242,6 +252,7 @@ fun SendQuizPoll( closeInfo, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -271,6 +282,8 @@ data class SendQuizPoll internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendPoll(), ExplainedOutput { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index cdcbb62785..201243caea 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -95,6 +95,7 @@ const val fromChatIdField = "from_chat_id" const val disableWebPagePreviewField = "disable_web_page_preview" const val disableNotificationField = "disable_notification" const val replyToMessageIdField = "reply_to_message_id" +const val allowSendingWithoutReplyField = "allow_sending_without_reply" const val replyMarkupField = "reply_markup" const val disableContentTypeDetectionField = "disable_content_type_detection" const val supportStreamingField = "support_streaming" From 98d7b9c6512adb47c1d4ef83a56d421b39e79b41 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Nov 2020 21:42:31 +0600 Subject: [PATCH 24/42] update coroutines :) --- CHANGELOG.md | 3 +++ gradle.properties | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1514790204..306345a0ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ **THIS UPDATE CONTAINS A LOT OF BREAKING CHANGES. PLEASE, BE CAREFUL ON UPGRADING OF YOUR PROJECT** +* `Common`: + * `Version`: + * `Coroutine`: `1.4.0` -> `1.4.1` * `Core`: * Support of `logOut` method (`LogOut` object as a `Request`) * Support of `close` method (`Close` object as a `Request`) diff --git a/gradle.properties b/gradle.properties index 4c36a5ebd6..e73cbad343 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ kotlin.incremental=true kotlin.incremental.js=true kotlin_version=1.4.10 -kotlin_coroutines_version=1.4.0 +kotlin_coroutines_version=1.4.1 kotlin_serialisation_runtime_version=1.0.1 klock_version=1.12.1 uuid_version=0.2.2 From 99bb8d6e0d56b1b41182888400488afcfa749a15 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Nov 2020 23:48:23 +0600 Subject: [PATCH 25/42] update extnsions.api --- CHANGELOG.md | 1 + .../EditChatMessageLiveLocation.kt | 1 + .../dev/inmo/tgbotapi/requests/local/Close.kt | 2 +- .../tgbotapi/requests/send/polls/SendPoll.kt | 2 + .../query/LocationInlineQuery.kt | 3 +- .../InlineQueries/query/RawInlineQuery.kt | 3 +- .../types/message/content/ContactContent.kt | 3 +- .../types/message/content/DiceContent.kt | 2 + .../types/message/content/GameContent.kt | 2 + .../types/message/content/LocationContent.kt | 4 + .../types/message/content/PollContent.kt | 2 + .../types/message/content/TextContent.kt | 6 + .../types/message/content/VenueContent.kt | 3 +- .../content/abstracts/ResendableContent.kt | 4 +- .../message/content/media/AnimationContent.kt | 2 + .../message/content/media/AudioContent.kt | 2 + .../message/content/media/DocumentContent.kt | 2 + .../message/content/media/PhotoContent.kt | 2 + .../message/content/media/StickerContent.kt | 2 + .../message/content/media/VideoContent.kt | 2 + .../message/content/media/VideoNoteContent.kt | 13 +- .../message/content/media/VoiceContent.kt | 2 + .../types/message/payments/InvoiceContent.kt | 1 + .../dev/inmo/tgbotapi/extensions/api/Close.kt | 7 + ...iveLocation.kt => LiveLocationProvider.kt} | 124 ++++++++++++--- .../inmo/tgbotapi/extensions/api/LogOut.kt | 6 + .../api/chat/members/UnbanChatMember.kt | 20 ++- .../EditChatMessageLiveLocation.kt | 28 ++-- .../EditInlineMessageLiveLocation.kt | 13 +- .../edit/caption/EditChatMessageCaption.kt | 25 +++ .../edit/caption/EditInlineMessageCaption.kt | 7 + .../api/edit/text/EditChatMessageText.kt | 28 +++- .../api/edit/text/EditInlineMessageText.kt | 8 + .../extensions/api/send/CopyMessage.kt | 150 ++++++++++++++++++ .../extensions/api/send/SendContact.kt | 16 +- .../tgbotapi/extensions/api/send/SendDice.kt | 9 +- .../extensions/api/send/SendLocation.kt | 37 ++++- .../extensions/api/send/SendMessage.kt | 76 ++++++++- .../tgbotapi/extensions/api/send/SendVenue.kt | 27 ++-- .../extensions/api/send/games/SendGame.kt | 21 ++- .../api/send/media/SendAnimation.kt | 140 +++++++++++++++- .../extensions/api/send/media/SendAudio.kt | 119 +++++++++++++- .../extensions/api/send/media/SendDocument.kt | 137 ++++++++++++++-- .../api/send/media/SendMediaGroup.kt | 66 +++++--- .../extensions/api/send/media/SendPhoto.kt | 99 +++++++++++- .../extensions/api/send/media/SendSticker.kt | 21 ++- .../extensions/api/send/media/SendVideo.kt | 117 +++++++++++++- .../api/send/media/SendVideoNote.kt | 36 ++--- .../extensions/api/send/media/SendVoice.kt | 105 +++++++++++- .../api/send/payments/SendInvoice.kt | 9 +- .../extensions/api/send/polls/SendPoll.kt | 138 ++++++++++++++-- .../extensions/api/webhook/SetWebhookInfo.kt | 18 ++- 52 files changed, 1468 insertions(+), 205 deletions(-) create mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/Close.kt rename tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/{LiveLocation.kt => LiveLocationProvider.kt} (58%) create mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LogOut.kt create mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessage.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 306345a0ab..48d33221d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ * New property `PromoteChatMember#isAnonymous` * Update all classes which must have `entities`/`caption_entities` fields * New request `CopyMessage` + * New extension `List#makeString` for more comfortable work with new api with entities * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt index ba93fd4206..e1a1688d4e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.requests.edit.LiveLocation import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.types.location.LiveLocation import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.LocationContent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt index 9e950998f0..2c6d7ed618 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt @@ -16,7 +16,7 @@ import kotlinx.serialization.builtins.serializer @Serializable object Close : SimpleRequest { override val requestSerializer: SerializationStrategy<*> - get() = LogOut.serializer() + get() = serializer() override fun method(): String = "close" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt index fed5aac521..5df2ae268b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt @@ -46,6 +46,7 @@ fun SendPoll( isClosed: Boolean = false, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = SendRegularPoll( chatId, @@ -53,6 +54,7 @@ fun SendPoll( options, isAnonymous, isClosed, + allowSendingWithoutReply = allowSendingWithoutReply, disableNotification = disableNotification, replyToMessageId = replyToMessageId, replyMarkup = replyMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt index cc0cd4772d..de8d573a25 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.query import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InlineQuery +import dev.inmo.tgbotapi.types.location.Location import dev.inmo.tgbotapi.types.location.StaticLocation data class LocationInlineQuery( @@ -9,5 +10,5 @@ data class LocationInlineQuery( override val from: User, override val query: String, override val offset: String, - val location: StaticLocation + val location: Location ) : InlineQuery diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt index 2b4473486a..edfa1b5abc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.query import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.location.Location import dev.inmo.tgbotapi.types.location.StaticLocation import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -16,7 +17,7 @@ internal data class RawInlineQuery( @SerialName(offsetField) val offset: String, @SerialName(locationField) - val location: StaticLocation? = null + val location: Location? = null ) { val asInlineQuery by lazy { location ?.let { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/ContactContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/ContactContent.kt index 8802c91830..20d0c73370 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/ContactContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/ContactContent.kt @@ -14,8 +14,9 @@ data class ContactContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendContact( - chatId, contact, disableNotification, replyToMessageId, replyMarkup + chatId, contact, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DiceContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DiceContent.kt index c287d15281..891f848d56 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DiceContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DiceContent.kt @@ -16,12 +16,14 @@ data class DiceContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendDice( chatId, dice.animationType, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/GameContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/GameContent.kt index a58505616b..5e7b21f9d9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/GameContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/GameContent.kt @@ -16,12 +16,14 @@ data class GameContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendGame( chatId, game.title, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt index f7a8750028..12afc0b413 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt @@ -7,7 +7,9 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.location.* import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent +import kotlinx.serialization.Serializable +@Serializable data class LocationContent( val location: Location ) : MessageContent { @@ -23,6 +25,7 @@ data class LocationContent( location.longitude, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) is LiveLocation -> SendLiveLocation( @@ -35,6 +38,7 @@ data class LocationContent( location.proximityAlertRadius, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PollContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PollContent.kt index 074d7d7896..ddb139e0d6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PollContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PollContent.kt @@ -16,11 +16,13 @@ data class PollContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = poll.createRequest( chatId, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt index 270a6bab3e..33cc9c3319 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt @@ -24,6 +24,7 @@ data class TextContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendTextMessage( chatId, @@ -32,6 +33,7 @@ data class TextContent( false, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -39,11 +41,13 @@ data class TextContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): List>> = createResends( chatId, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup, HTMLParseMode ) @@ -52,6 +56,7 @@ data class TextContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup?, parseMode: ParseMode = HTMLParseMode ): List>> = when (parseMode) { @@ -66,6 +71,7 @@ data class TextContent( false, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VenueContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VenueContent.kt index 9b662e8133..60a355afe1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VenueContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VenueContent.kt @@ -16,8 +16,9 @@ data class VenueContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendVenue( - chatId, venue, disableNotification, replyToMessageId, replyMarkup + chatId, venue, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/ResendableContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/ResendableContent.kt index 8707e351ee..f0b1993573 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/ResendableContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/ResendableContent.kt @@ -11,6 +11,7 @@ interface ResendableContent { chatId: ChatIdentifier, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request @@ -18,6 +19,7 @@ interface ResendableContent { chatId: ChatIdentifier, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null - ): List> = listOf(createResend(chatId, disableNotification, replyToMessageId, replyMarkup)) + ): List> = listOf(createResend(chatId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup)) } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt index 2d5c4b8ca8..c7b1f6c662 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt @@ -27,6 +27,7 @@ data class AnimationContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendAnimation( chatId, @@ -39,6 +40,7 @@ data class AnimationContent( media.height, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt index e662354d3a..287fd39bb0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt @@ -24,6 +24,7 @@ data class AudioContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendAudio( chatId, @@ -36,6 +37,7 @@ data class AudioContent( media.title, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt index f69c415813..737b73d82b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt @@ -26,6 +26,7 @@ data class DocumentContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendDocument( chatId, @@ -35,6 +36,7 @@ data class DocumentContent( HTMLParseMode, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt index de7b9eb17a..6582fd1bb3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt @@ -26,6 +26,7 @@ data class PhotoContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendPhoto( chatId, @@ -34,6 +35,7 @@ data class PhotoContent( HTMLParseMode, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt index 68c5edc783..7b0ab518e2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt @@ -17,12 +17,14 @@ data class StickerContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendSticker( chatId, media.fileId, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt index 1049043f37..eacb96d6bf 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt @@ -27,6 +27,7 @@ data class VideoContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendVideo( chatId, @@ -40,6 +41,7 @@ data class VideoContent( null, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt index 4957e19853..df414aee2b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt @@ -18,26 +18,17 @@ data class VideoNoteContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? - ): Request> = createResend(chatId, null, null, disableNotification, replyToMessageId, replyMarkup) - - fun createResend( - chatId: ChatIdentifier, - caption: String?, - parseMode: ParseMode? = null, - disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null, - replyMarkup: KeyboardMarkup? = null ): Request> = SendVideoNote( chatId, media.fileId, media.thumb ?.fileId, - caption, - parseMode, media.duration, media.width, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt index 1aa62d14ef..1d2b2dd4ce 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt @@ -25,6 +25,7 @@ data class VoiceContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendVoice( chatId, @@ -34,6 +35,7 @@ data class VoiceContent( media.duration, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/InvoiceContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/InvoiceContent.kt index 35341e8dc5..b7dcca1c12 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/InvoiceContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/InvoiceContent.kt @@ -15,6 +15,7 @@ data class InvoiceContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> { error("Unfortunately, currently InvoiceOfPayment can not be resend due to requirement of additional parameters," + diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/Close.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/Close.kt new file mode 100644 index 0000000000..14a613d890 --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/Close.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.extensions.api + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.local.Close + +@Suppress("unused") +suspend inline fun TelegramBot.close() = execute(Close) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt similarity index 58% rename from tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocation.kt rename to tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt index 960993c312..28edcf6741 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt @@ -3,7 +3,6 @@ package dev.inmo.tgbotapi.extensions.api import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.extensions.api.edit.LiveLocation.editLiveLocation import dev.inmo.tgbotapi.extensions.api.edit.LiveLocation.stopLiveLocation -import dev.inmo.tgbotapi.requests.send.SendLocation import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -13,14 +12,15 @@ import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.content.LocationContent import com.soywiz.klock.DateTime import com.soywiz.klock.TimeSpan -import dev.inmo.tgbotapi.types.location.StaticLocation +import dev.inmo.tgbotapi.requests.send.SendLiveLocation +import dev.inmo.tgbotapi.types.location.* import io.ktor.utils.io.core.Closeable import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import kotlin.math.ceil val defaultLivePeriodDelayMillis = (livePeriodLimit.last - 60L) * 1000L -class LiveLocation internal constructor( +class LiveLocationProvider internal constructor( private val requestsExecutor: TelegramBot, scope: CoroutineScope, autoCloseTimeDelay: Double, @@ -40,13 +40,13 @@ class LiveLocation internal constructor( get() = field || leftUntilCloseMillis.millisecondsLong < 0L private var message: ContentMessage = initMessage - val lastLocation: StaticLocation - get() = message.content.location + val lastLocation: LiveLocation + get() = message.content.location as LiveLocation suspend fun updateLocation( - location: StaticLocation, + location: LiveLocation, replyMarkup: InlineKeyboardMarkup? = null - ): StaticLocation { + ): LiveLocation { if (!isClosed) { message = requestsExecutor.editLiveLocation( message, @@ -74,24 +74,32 @@ suspend fun TelegramBot.startLiveLocation( latitude: Double, longitude: Double, liveTimeMillis: Long = defaultLivePeriodDelayMillis, + initHorizontalAccuracy: Meters? = null, + initHeading: Degrees? = null, + initProximityAlertRadius: Meters? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -): LiveLocation { +): LiveLocationProvider { val liveTimeAsDouble = liveTimeMillis.toDouble() val locationMessage = execute( - SendLocation( + SendLiveLocation( chatId, latitude, longitude, - ceil(liveTimeAsDouble / 1000).toLong(), + ceil(liveTimeAsDouble / 1000).toInt(), + initHorizontalAccuracy, + initHeading, + initProximityAlertRadius, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) ) - return LiveLocation( + return LiveLocationProvider( this, scope, liveTimeAsDouble, @@ -105,11 +113,26 @@ suspend fun TelegramBot.startLiveLocation( latitude: Double, longitude: Double, liveTimeMillis: Long = defaultLivePeriodDelayMillis, + initHorizontalAccuracy: Meters? = null, + initHeading: Degrees? = null, + initProximityAlertRadius: Meters? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -): LiveLocation = startLiveLocation( - scope, chat.id, latitude, longitude, liveTimeMillis, disableNotification, replyToMessageId, replyMarkup +): LiveLocationProvider = startLiveLocation( + scope, + chat.id, + latitude, + longitude, + liveTimeMillis, + initHorizontalAccuracy, + initHeading, + initProximityAlertRadius, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup ) suspend fun TelegramBot.startLiveLocation( @@ -117,11 +140,26 @@ suspend fun TelegramBot.startLiveLocation( chatId: ChatId, location: StaticLocation, liveTimeMillis: Long = defaultLivePeriodDelayMillis, + initHorizontalAccuracy: Meters? = null, + initHeading: Degrees? = null, + initProximityAlertRadius: Meters? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -): LiveLocation = startLiveLocation( - scope, chatId, location.latitude, location.longitude, liveTimeMillis, disableNotification, replyToMessageId, replyMarkup +): LiveLocationProvider = startLiveLocation( + scope, + chatId, + location.latitude, + location.longitude, + liveTimeMillis, + initHorizontalAccuracy, + initHeading, + initProximityAlertRadius, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup ) suspend fun TelegramBot.startLiveLocation( @@ -129,11 +167,26 @@ suspend fun TelegramBot.startLiveLocation( chat: Chat, location: StaticLocation, liveTimeMillis: Long = defaultLivePeriodDelayMillis, + initHorizontalAccuracy: Meters? = null, + initHeading: Degrees? = null, + initProximityAlertRadius: Meters? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -): LiveLocation = startLiveLocation( - scope, chat.id, location.latitude, location.longitude, liveTimeMillis, disableNotification, replyToMessageId, replyMarkup +): LiveLocationProvider = startLiveLocation( + scope, + chat.id, + location.latitude, + location.longitude, + liveTimeMillis, + initHorizontalAccuracy, + initHeading, + initProximityAlertRadius, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup ) suspend inline fun TelegramBot.replyWithLiveLocation( @@ -142,15 +195,48 @@ suspend inline fun TelegramBot.replyWithLiveLocation( latitude: Double, longitude: Double, liveTimeMillis: Long = defaultLivePeriodDelayMillis, + initHorizontalAccuracy: Meters? = null, + initHeading: Degrees? = null, + initProximityAlertRadius: Meters? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = startLiveLocation(scope, to.chat, latitude, longitude, liveTimeMillis, disableNotification, to.messageId, replyMarkup) +) = startLiveLocation( + scope, + to.chat, + latitude, + longitude, + liveTimeMillis, + initHorizontalAccuracy, + initHeading, + initProximityAlertRadius, + disableNotification, + to.messageId, + allowSendingWithoutReply, + replyMarkup +) suspend inline fun TelegramBot.replyWithLiveLocation( to: Message, scope: CoroutineScope, location: StaticLocation, liveTimeMillis: Long = defaultLivePeriodDelayMillis, + initHorizontalAccuracy: Meters? = null, + initHeading: Degrees? = null, + initProximityAlertRadius: Meters? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = startLiveLocation(scope, to.chat, location, liveTimeMillis, disableNotification, to.messageId, replyMarkup) +) = startLiveLocation( + scope, + to.chat, + location, + liveTimeMillis, + initHorizontalAccuracy, + initHeading, + initProximityAlertRadius, + disableNotification, + to.messageId, + allowSendingWithoutReply, + replyMarkup +) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LogOut.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LogOut.kt new file mode 100644 index 0000000000..23d5c8daeb --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LogOut.kt @@ -0,0 +1,6 @@ +package dev.inmo.tgbotapi.extensions.api + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.local.LogOut + +suspend inline fun TelegramBot.logOut() = execute(LogOut) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/UnbanChatMember.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/UnbanChatMember.kt index 74719e7281..5b98415738 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/UnbanChatMember.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/UnbanChatMember.kt @@ -7,21 +7,25 @@ import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat suspend fun TelegramBot.unbanChatMember( chatId: ChatIdentifier, - userId: UserId -) = execute(UnbanChatMember(chatId, userId)) + userId: UserId, + onlyIfBanned: Boolean? = null +) = execute(UnbanChatMember(chatId, userId, onlyIfBanned)) suspend fun TelegramBot.unbanChatMember( chat: PublicChat, - userId: UserId -) = unbanChatMember(chat.id, userId) + userId: UserId, + onlyIfBanned: Boolean? = null +) = unbanChatMember(chat.id, userId, onlyIfBanned) suspend fun TelegramBot.unbanChatMember( chatId: ChatId, - user: User -) = unbanChatMember(chatId, user.id) + user: User, + onlyIfBanned: Boolean? = null +) = unbanChatMember(chatId, user.id, onlyIfBanned) suspend fun TelegramBot.unbanChatMember( chat: PublicChat, - user: User -) = unbanChatMember(chat.id, user.id) + user: User, + onlyIfBanned: Boolean? = null +) = unbanChatMember(chat.id, user.id, onlyIfBanned) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt index f17ba6b8aa..894fa27df1 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt @@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.requests.edit.LiveLocation.EditChatMessageLiveLocation import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.location.LiveLocation import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.LocationContent @@ -14,10 +15,13 @@ suspend fun TelegramBot.editLiveLocation( messageId: MessageIdentifier, latitude: Double, longitude: Double, + horizontalAccuracy: Meters? = null, + heading: Degrees? = null, + proximityAlertRadius: Meters? = null, replyMarkup: InlineKeyboardMarkup? = null ) = execute( EditChatMessageLiveLocation( - chatId, messageId, latitude, longitude, replyMarkup + chatId, messageId, latitude, longitude, horizontalAccuracy, heading, proximityAlertRadius, replyMarkup ) ) @@ -26,36 +30,42 @@ suspend fun TelegramBot.editLiveLocation( messageId: MessageIdentifier, latitude: Double, longitude: Double, + horizontalAccuracy: Meters? = null, + heading: Degrees? = null, + proximityAlertRadius: Meters? = null, replyMarkup: InlineKeyboardMarkup? = null -) = editLiveLocation(chat.id, messageId, latitude, longitude, replyMarkup) +) = editLiveLocation(chat.id, messageId, latitude, longitude, horizontalAccuracy, heading, proximityAlertRadius, replyMarkup) suspend fun TelegramBot.editLiveLocation( message: ContentMessage, latitude: Double, longitude: Double, + horizontalAccuracy: Meters? = null, + heading: Degrees? = null, + proximityAlertRadius: Meters? = null, replyMarkup: InlineKeyboardMarkup? = null -) = editLiveLocation(message.chat, message.messageId, latitude, longitude, replyMarkup) +) = editLiveLocation(message.chat, message.messageId, latitude, longitude, horizontalAccuracy, heading, proximityAlertRadius, replyMarkup) suspend fun TelegramBot.editLiveLocation( chatId: ChatIdentifier, messageId: MessageIdentifier, - location: StaticLocation, + location: LiveLocation, replyMarkup: InlineKeyboardMarkup? = null ) = execute( EditChatMessageLiveLocation( - chatId, messageId, location.latitude, location.longitude, replyMarkup + chatId, messageId, location.latitude, location.longitude, location.horizontalAccuracy, location.heading, location.proximityAlertRadius, replyMarkup ) ) suspend fun TelegramBot.editLiveLocation( chat: Chat, messageId: MessageIdentifier, - location: StaticLocation, + location: LiveLocation, replyMarkup: InlineKeyboardMarkup? = null -) = editLiveLocation(chat.id, messageId, location.latitude, location.longitude, replyMarkup) +) = editLiveLocation(chat.id, messageId, location.latitude, location.longitude, location.horizontalAccuracy, location.heading, location.proximityAlertRadius, replyMarkup) suspend fun TelegramBot.editLiveLocation( message: ContentMessage, - location: StaticLocation, + location: LiveLocation, replyMarkup: InlineKeyboardMarkup? = null -) = editLiveLocation(message.chat, message.messageId, location.latitude, location.longitude, replyMarkup) +) = editLiveLocation(message.chat, message.messageId, location.latitude, location.longitude, location.horizontalAccuracy, location.heading, location.proximityAlertRadius, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt index a518941806..141d8220ee 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt @@ -2,22 +2,27 @@ package dev.inmo.tgbotapi.extensions.api.edit.LiveLocation import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.edit.LiveLocation.EditInlineMessageLiveLocation -import dev.inmo.tgbotapi.types.InlineMessageIdentifier +import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.types.location.LiveLocation +import kotlinx.serialization.SerialName suspend fun TelegramBot.editLiveLocation( inlineMessageId: InlineMessageIdentifier, latitude: Double, longitude: Double, + horizontalAccuracy: Meters? = null, + heading: Degrees? = null, + proximityAlertRadius: Meters? = null, replyMarkup: InlineKeyboardMarkup? = null ) = execute( EditInlineMessageLiveLocation( - inlineMessageId, latitude, longitude, replyMarkup + inlineMessageId, latitude, longitude, horizontalAccuracy, heading, proximityAlertRadius, replyMarkup ) ) suspend fun TelegramBot.editLiveLocation( inlineMessageId: InlineMessageIdentifier, - location: StaticLocation, + location: LiveLocation, replyMarkup: InlineKeyboardMarkup? = null -) = editLiveLocation(inlineMessageId, location.latitude, location.longitude, replyMarkup) +) = editLiveLocation(inlineMessageId, location.latitude, location.longitude, location.horizontalAccuracy, location.heading, location.proximityAlertRadius, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditChatMessageCaption.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditChatMessageCaption.kt index 3ee1097691..1becc8e0d3 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditChatMessageCaption.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditChatMessageCaption.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.extensions.api.edit.caption import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.edit.caption.EditChatMessageCaption import dev.inmo.tgbotapi.types.ChatIdentifier @@ -37,3 +38,27 @@ suspend fun TelegramBot.editMessageCaption( ): ContentMessage where T : CaptionedInput, T : MediaContent { return editMessageCaption(message.chat.id, message.messageId, text, parseMode, replyMarkup) } + +suspend fun TelegramBot.editMessageCaption( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null +) = execute( + EditChatMessageCaption(chatId, messageId, entities, replyMarkup) +) + +suspend fun TelegramBot.editMessageCaption( + chat: Chat, + messageId: MessageIdentifier, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageCaption(chat.id, messageId, entities, replyMarkup) + +suspend fun TelegramBot.editMessageCaption( + message: ContentMessage, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null +): ContentMessage where T : CaptionedInput, T : MediaContent { + return editMessageCaption(message.chat.id, message.messageId, entities, replyMarkup) +} diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditInlineMessageCaption.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditInlineMessageCaption.kt index 29ca66bfbb..00df5eea1e 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditInlineMessageCaption.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditInlineMessageCaption.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.edit.caption +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.edit.caption.EditInlineMessageCaption import dev.inmo.tgbotapi.types.InlineMessageIdentifier @@ -12,3 +13,9 @@ suspend fun TelegramBot.editMessageCaption( parseMode: ParseMode? = null, replyMarkup: InlineKeyboardMarkup? = null ) = execute(EditInlineMessageCaption(inlineMessageId, text, parseMode, replyMarkup)) + +suspend fun TelegramBot.editMessageCaption( + inlineMessageId: InlineMessageIdentifier, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null +) = execute(EditInlineMessageCaption(inlineMessageId, entities, replyMarkup)) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditChatMessageText.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditChatMessageText.kt index 811a5f33d0..1e9f460310 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditChatMessageText.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditChatMessageText.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.edit.text +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.edit.text.EditChatMessageText import dev.inmo.tgbotapi.types.ChatIdentifier @@ -36,4 +37,29 @@ suspend fun TelegramBot.editMessageText( parseMode: ParseMode? = null, disableWebPagePreview: Boolean? = null, replyMarkup: InlineKeyboardMarkup? = null -) = editMessageText(message.chat.id, message.messageId, text, parseMode, disableWebPagePreview, replyMarkup) \ No newline at end of file +) = editMessageText(message.chat.id, message.messageId, text, parseMode, disableWebPagePreview, replyMarkup) + +suspend fun TelegramBot.editMessageText( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = execute( + EditChatMessageText(chatId, messageId, entities, disableWebPagePreview, replyMarkup) +) + +suspend fun TelegramBot.editMessageText( + chat: Chat, + messageId: MessageIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageText(chat.id, messageId, entities, disableWebPagePreview, replyMarkup) + +suspend fun TelegramBot.editMessageText( + message: ContentMessage, + entities: List, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageText(message.chat.id, message.messageId, entities, disableWebPagePreview, replyMarkup) \ No newline at end of file diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditInlineMessageText.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditInlineMessageText.kt index e21c30c03c..f100fa861e 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditInlineMessageText.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditInlineMessageText.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.edit.text +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.edit.text.EditInlineMessageText import dev.inmo.tgbotapi.types.InlineMessageIdentifier @@ -13,3 +14,10 @@ suspend fun TelegramBot.editMessageText( disableWebPagePreview: Boolean? = null, replyMarkup: InlineKeyboardMarkup? = null ) = execute(EditInlineMessageText(inlineMessageId, text, parseMode, disableWebPagePreview, replyMarkup)) + +suspend fun TelegramBot.editMessageText( + inlineMessageId: InlineMessageIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = execute(EditInlineMessageText(inlineMessageId, entities, disableWebPagePreview, replyMarkup)) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessage.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessage.kt new file mode 100644 index 0000000000..73874634de --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessage.kt @@ -0,0 +1,150 @@ +package dev.inmo.tgbotapi.extensions.api.send + +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.send.CopyMessage +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup +import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.message.abstracts.Message + +suspend inline fun TelegramBot.copyMessage( + fromChatId: ChatIdentifier, + toChatId: ChatIdentifier, + messageId: MessageIdentifier, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + CopyMessage(fromChatId, toChatId, messageId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) + +suspend inline fun TelegramBot.copyMessage( + fromChat: Chat, + toChatId: ChatIdentifier, + messageId: MessageIdentifier, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(fromChat.id, toChatId, messageId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + fromChatId: ChatIdentifier, + toChat: Chat, + messageId: MessageIdentifier, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(fromChatId, toChat.id, messageId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + fromChat: Chat, + toChat: Chat, + messageId: MessageIdentifier, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(fromChat.id, toChat.id, messageId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + toChatId: ChatIdentifier, + message: Message, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(message.chat, toChatId, message.messageId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + toChat: Chat, + message: Message, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(message.chat, toChat, message.messageId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + + +suspend inline fun TelegramBot.copyMessage( + fromChatId: ChatIdentifier, + toChatId: ChatIdentifier, + messageId: MessageIdentifier, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + CopyMessage(fromChatId, toChatId, messageId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) + +suspend inline fun TelegramBot.copyMessage( + fromChat: Chat, + toChatId: ChatIdentifier, + messageId: MessageIdentifier, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(fromChat.id, toChatId, messageId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + fromChatId: ChatIdentifier, + toChat: Chat, + messageId: MessageIdentifier, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(fromChatId, toChat.id, messageId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + fromChat: Chat, + toChat: Chat, + messageId: MessageIdentifier, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(fromChat.id, toChat.id, messageId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + toChatId: ChatIdentifier, + message: Message, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(message.chat, toChatId, message.messageId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + toChat: Chat, + message: Message, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(message.chat, toChat, message.messageId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendContact.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendContact.kt index 9b0f05be68..7edf1423e4 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendContact.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendContact.kt @@ -14,10 +14,11 @@ suspend fun TelegramBot.sendContact( lastName: String? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendContact( - chatId, phoneNumber, firstName, lastName, disableNotification, replyToMessageId, replyMarkup + chatId, phoneNumber, firstName, lastName, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) ) @@ -26,10 +27,11 @@ suspend fun TelegramBot.sendContact( contact: Contact, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendContact( - chatId, contact, disableNotification, replyToMessageId, replyMarkup + chatId, contact, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) ) @@ -40,9 +42,10 @@ suspend fun TelegramBot.sendContact( lastName: String? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendContact( - chat.id, phoneNumber, firstName, lastName, disableNotification, replyToMessageId, replyMarkup + chat.id, phoneNumber, firstName, lastName, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendContact( @@ -50,9 +53,10 @@ suspend fun TelegramBot.sendContact( contact: Contact, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendContact( - chat.id, contact, disableNotification, replyToMessageId, replyMarkup + chat.id, contact, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend inline fun TelegramBot.reply( @@ -61,6 +65,7 @@ suspend inline fun TelegramBot.reply( firstName: String, lastName: String? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendContact( to.chat, @@ -69,6 +74,7 @@ suspend inline fun TelegramBot.reply( lastName, disableNotification, to.messageId, + allowSendingWithoutReply, replyMarkup ) @@ -76,11 +82,13 @@ suspend inline fun TelegramBot.reply( to: Message, contact: Contact, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendContact( to.chat, contact, disableNotification, to.messageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendDice.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendDice.kt index b6afbe4374..250f55d88a 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendDice.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendDice.kt @@ -14,9 +14,10 @@ suspend fun TelegramBot.sendDice( animationType: DiceAnimationType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( - SendDice(chatId, animationType, disableNotification, replyToMessageId, replyMarkup) + SendDice(chatId, animationType, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) suspend fun TelegramBot.sendDice( @@ -24,12 +25,14 @@ suspend fun TelegramBot.sendDice( animationType: DiceAnimationType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendDice(chat.id, animationType, disableNotification, replyToMessageId, replyMarkup) +) = sendDice(chat.id, animationType, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, animationType: DiceAnimationType? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendDice(to.chat, animationType, disableNotification, to.messageId, replyMarkup) +) = sendDice(to.chat, animationType, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt index a9abc0c4cb..0442d77149 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.extensions.api.send import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.send.SendLocation +import dev.inmo.tgbotapi.requests.send.SendStaticLocation import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat @@ -16,7 +17,7 @@ suspend fun TelegramBot.sendLocation( replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null ) = execute( - SendLocation( + SendStaticLocation( chatId, latitude, longitude, @@ -72,6 +73,40 @@ suspend fun TelegramBot.sendLocation( replyMarkup ) +suspend fun TelegramBot.sendStaticLocation( + chatId: ChatIdentifier, + latitude: Double, + longitude: Double, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendLocation(chatId, latitude, longitude, disableNotification, replyToMessageId, replyMarkup) + +suspend fun TelegramBot.sendStaticLocation( + chatId: ChatIdentifier, + location: StaticLocation, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendLocation(chatId, location.latitude, location.longitude, disableNotification, replyToMessageId, replyMarkup) + +suspend fun TelegramBot.sendStaticLocation( + chat: Chat, + latitude: Double, + longitude: Double, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendLocation(chat.id, latitude, longitude, disableNotification, replyToMessageId, replyMarkup) + +suspend fun TelegramBot.sendStaticLocation( + chat: Chat, + location: StaticLocation, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendLocation(chat.id, location.latitude, location.longitude, disableNotification, replyToMessageId, replyMarkup) + suspend inline fun TelegramBot.reply( to: Message, latitude: Double, diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendMessage.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendMessage.kt index 2519f6597c..ccfae79987 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendMessage.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendMessage.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.send.SendTextMessage import dev.inmo.tgbotapi.types.ChatIdentifier @@ -16,9 +17,10 @@ suspend fun TelegramBot.sendMessage( disableWebPagePreview: Boolean? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( - SendTextMessage(chatId, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup) + SendTextMessage(chatId, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) suspend fun TelegramBot.sendTextMessage( @@ -28,9 +30,10 @@ suspend fun TelegramBot.sendTextMessage( disableWebPagePreview: Boolean? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendMessage( - chatId, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup + chatId, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendMessage( @@ -40,8 +43,9 @@ suspend fun TelegramBot.sendMessage( disableWebPagePreview: Boolean? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendMessage(chat.id, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup) +) = sendMessage(chat.id, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendTextMessage( @@ -51,8 +55,54 @@ suspend fun TelegramBot.sendTextMessage( disableWebPagePreview: Boolean? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendTextMessage(chat.id, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup) +) = sendTextMessage(chat.id, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend fun TelegramBot.sendMessage( + chatId: ChatIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendTextMessage(chatId, entities, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) + +suspend fun TelegramBot.sendTextMessage( + chatId: ChatIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendMessage( + chatId, entities, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup +) + +suspend fun TelegramBot.sendMessage( + chat: Chat, + entities: List, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendMessage(chat.id, entities, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + + +suspend fun TelegramBot.sendTextMessage( + chat: Chat, + entities: List, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendTextMessage(chat.id, entities, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, @@ -60,6 +110,7 @@ suspend inline fun TelegramBot.reply( parseMode: ParseMode? = null, disableWebPagePreview: Boolean? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendTextMessage( to.chat, @@ -68,5 +119,22 @@ suspend inline fun TelegramBot.reply( disableWebPagePreview, disableNotification, to.messageId, + allowSendingWithoutReply, + replyMarkup +) +suspend inline fun TelegramBot.reply( + to: Message, + entities: List, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendTextMessage( + to.chat, + entities, + disableWebPagePreview, + disableNotification, + to.messageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt index e05b942a9b..ce34bf4e0b 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt @@ -18,10 +18,11 @@ suspend fun TelegramBot.sendVenue( foursquareId: String? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendVenue( - chatId, latitude, longitude, title, address, foursquareId, disableNotification, replyToMessageId, replyMarkup + chatId, latitude, longitude, title, address, foursquareId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) ) @@ -34,9 +35,10 @@ suspend fun TelegramBot.sendVenue( foursquareId: String? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chat.id, latitude, longitude, title, address, foursquareId, disableNotification, replyToMessageId, replyMarkup + chat.id, latitude, longitude, title, address, foursquareId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendVenue( @@ -47,9 +49,10 @@ suspend fun TelegramBot.sendVenue( foursquareId: String? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chatId, location.latitude, location.longitude, title, address, foursquareId, disableNotification, replyToMessageId, replyMarkup + chatId, location.latitude, location.longitude, title, address, foursquareId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendVenue( @@ -60,9 +63,10 @@ suspend fun TelegramBot.sendVenue( foursquareId: String? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chat.id, location.latitude, location.longitude, title, address, foursquareId, disableNotification, replyToMessageId, replyMarkup + chat.id, location.latitude, location.longitude, title, address, foursquareId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendVenue( @@ -70,10 +74,11 @@ suspend fun TelegramBot.sendVenue( venue: Venue, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendVenue( - chatId, venue, disableNotification, replyToMessageId, replyMarkup + chatId, venue, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) ) @@ -82,9 +87,10 @@ suspend fun TelegramBot.sendVenue( venue: Venue, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chat.id, venue, disableNotification, replyToMessageId, replyMarkup + chat.id, venue, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend inline fun TelegramBot.reply( @@ -95,9 +101,10 @@ suspend inline fun TelegramBot.reply( address: String, foursquareId: String? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - to.chat, latitude, longitude, title, address, foursquareId, disableNotification, to.messageId, replyMarkup + to.chat, latitude, longitude, title, address, foursquareId, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup ) suspend inline fun TelegramBot.reply( @@ -107,16 +114,18 @@ suspend inline fun TelegramBot.reply( address: String, foursquareId: String? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - to.chat, location, title, address, foursquareId, disableNotification, to.messageId, replyMarkup + to.chat, location, title, address, foursquareId, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup ) suspend inline fun TelegramBot.reply( to: Message, venue: Venue, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - to.chat, venue, disableNotification, to.messageId, replyMarkup + to.chat, venue, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/games/SendGame.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/games/SendGame.kt index 82d17237b7..bc95b64ca3 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/games/SendGame.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/games/SendGame.kt @@ -14,10 +14,11 @@ suspend fun TelegramBot.sendGame( gameShortName: String, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendGame( - chatId, gameShortName, disableNotification, replyToMessageId, replyMarkup + chatId, gameShortName, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) ) @@ -26,9 +27,10 @@ suspend fun TelegramBot.sendGame( gameShortName: String, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendGame( - chat.id, gameShortName, disableNotification, replyToMessageId, replyMarkup + chat.id, gameShortName, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendGame( @@ -36,9 +38,10 @@ suspend fun TelegramBot.sendGame( game: Game, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendGame( - chatId, game.title, disableNotification, replyToMessageId, replyMarkup + chatId, game.title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendGame( @@ -46,32 +49,36 @@ suspend fun TelegramBot.sendGame( game: Game, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendGame( - chat.id, game.title, disableNotification, replyToMessageId, replyMarkup + chat.id, game.title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend inline fun TelegramBot.replyWithGame( to: Message, gameShortName: String, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendGame( - to.chat, gameShortName, disableNotification, to.messageId, replyMarkup + to.chat, gameShortName, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup ) suspend inline fun TelegramBot.replyWithGame( to: Message, game: Game, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendGame( - to.chat, game.title, disableNotification, to.messageId, replyMarkup + to.chat, game.title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup ) suspend inline fun TelegramBot.reply( to: Message, game: Game, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithGame(to, game, disableNotification, replyMarkup) +) = replyWithGame(to, game, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt index 79f9ee41ab..95a4c4bcdc 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send.media +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendAnimation @@ -22,6 +23,7 @@ suspend fun TelegramBot.sendAnimation( height: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendAnimation( @@ -35,6 +37,7 @@ suspend fun TelegramBot.sendAnimation( height, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) ) @@ -49,9 +52,10 @@ suspend fun TelegramBot.sendAnimation( height: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendAnimation( - chatId, animation.fileId, animation.thumb ?.fileId, text, parseMode, duration, width, height, disableNotification, replyToMessageId, replyMarkup + chatId, animation.fileId, animation.thumb ?.fileId, text, parseMode, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendAnimation( @@ -65,8 +69,9 @@ suspend fun TelegramBot.sendAnimation( height: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(chat.id, animation, thumb, text, parseMode, duration, width, height, disableNotification, replyToMessageId, replyMarkup) +) = sendAnimation(chat.id, animation, thumb, text, parseMode, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendAnimation( chat: Chat, @@ -78,8 +83,9 @@ suspend fun TelegramBot.sendAnimation( height: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(chat.id, animation, text, parseMode, duration, width, height, disableNotification, replyToMessageId, replyMarkup) +) = sendAnimation(chat.id, animation, text, parseMode, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithAnimation( to: Message, @@ -91,6 +97,7 @@ suspend inline fun TelegramBot.replyWithAnimation( width: Int? = null, height: Int? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendAnimation( to.chat, @@ -103,6 +110,7 @@ suspend inline fun TelegramBot.replyWithAnimation( height, disableNotification, to.messageId, + allowSendingWithoutReply, replyMarkup ) @@ -115,8 +123,9 @@ suspend inline fun TelegramBot.replyWithAnimation( width: Int? = null, height: Int? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(to.chat, animation, text, parseMode, duration, width, height, disableNotification, to.messageId, replyMarkup) +) = sendAnimation(to.chat, animation, text, parseMode, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, @@ -127,5 +136,126 @@ suspend inline fun TelegramBot.reply( width: Int? = null, height: Int? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithAnimation(to, animation, text, parseMode, duration, width, height, disableNotification, replyMarkup) +) = replyWithAnimation(to, animation, text, parseMode, duration, width, height, disableNotification, allowSendingWithoutReply, replyMarkup) + + +suspend fun TelegramBot.sendAnimation( + chatId: ChatIdentifier, + animation: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendAnimation( + chatId, + animation, + thumb, + entities, + duration, + width, + height, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) +) + +suspend fun TelegramBot.sendAnimation( + chatId: ChatIdentifier, + animation: AnimationFile, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation( + chatId, animation.fileId, animation.thumb ?.fileId, entities, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup +) + +suspend fun TelegramBot.sendAnimation( + chat: Chat, + animation: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation(chat.id, animation, thumb, entities, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend fun TelegramBot.sendAnimation( + chat: Chat, + animation: AnimationFile, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation(chat.id, animation, entities, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithAnimation( + to: Message, + animation: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation( + to.chat, + animation, + thumb, + entities, + duration, + width, + height, + disableNotification, + to.messageId, + allowSendingWithoutReply, + replyMarkup +) + +suspend inline fun TelegramBot.replyWithAnimation( + to: Message, + animation: AnimationFile, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation(to.chat, animation, entities, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + animation: AnimationFile, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithAnimation(to, animation, entities, duration, width, height, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt index 0c9596f1f0..ce100da778 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send.media +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendAudio @@ -23,6 +24,7 @@ suspend fun TelegramBot.sendAudio( title: String? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendAudio( @@ -36,6 +38,7 @@ suspend fun TelegramBot.sendAudio( title, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) ) @@ -51,8 +54,9 @@ suspend fun TelegramBot.sendAudio( title: String? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAudio(chat.id, audio, thumb, text, parseMode, duration, performer, title, disableNotification, replyToMessageId, replyMarkup) +) = sendAudio(chat.id, audio, thumb, text, parseMode, duration, performer, title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendAudio( chatId: ChatIdentifier, @@ -62,8 +66,9 @@ suspend fun TelegramBot.sendAudio( title: String? = audio.title, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAudio(chatId, audio.fileId, audio.thumb ?.fileId, text, parseMode, audio.duration, audio.performer, title, disableNotification, replyToMessageId, replyMarkup) +) = sendAudio(chatId, audio.fileId, audio.thumb ?.fileId, text, parseMode, audio.duration, audio.performer, title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendAudio( chat: Chat, @@ -73,8 +78,9 @@ suspend fun TelegramBot.sendAudio( title: String? = audio.title, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAudio(chat.id, audio, text, parseMode, title, disableNotification, replyToMessageId, replyMarkup) +) = sendAudio(chat.id, audio, text, parseMode, title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithAudio( to: Message, @@ -86,8 +92,9 @@ suspend inline fun TelegramBot.replyWithAudio( performer: String? = null, title: String? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAudio(to.chat, audio, thumb, text, parseMode, duration, performer, title, disableNotification, to.messageId, replyMarkup) +) = sendAudio(to.chat, audio, thumb, text, parseMode, duration, performer, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithAudio( to: Message, @@ -96,8 +103,9 @@ suspend inline fun TelegramBot.replyWithAudio( parseMode: ParseMode? = null, title: String? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAudio(to.chat, audio, text, parseMode, title, disableNotification, to.messageId, replyMarkup) +) = sendAudio(to.chat, audio, text, parseMode, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, @@ -106,5 +114,104 @@ suspend inline fun TelegramBot.reply( parseMode: ParseMode? = null, title: String? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithAudio(to, audio, text, parseMode, title, disableNotification, replyMarkup) +) = replyWithAudio(to, audio, text, parseMode, title, disableNotification, allowSendingWithoutReply, replyMarkup) + + +suspend inline fun TelegramBot.sendAudio( + chatId: ChatIdentifier, + audio: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendAudio( + chatId, + audio, + thumb, + entities, + duration, + performer, + title, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) +) + +suspend inline fun TelegramBot.sendAudio( + chat: Chat, + audio: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio(chat.id, audio, thumb, entities, duration, performer, title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.sendAudio( + chatId: ChatIdentifier, + audio: AudioFile, + entities: List, + title: String? = audio.title, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio(chatId, audio.fileId, audio.thumb ?.fileId, entities, audio.duration, audio.performer, title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.sendAudio( + chat: Chat, + audio: AudioFile, + entities: List, + title: String? = audio.title, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio(chat.id, audio, entities, title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithAudio( + to: Message, + audio: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio(to.chat, audio, thumb, entities, duration, performer, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithAudio( + to: Message, + audio: AudioFile, + entities: List, + title: String? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio(to.chat, audio, entities, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + audio: AudioFile, + entities: List, + title: String? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithAudio(to, audio, entities, title, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendDocument.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendDocument.kt index a1fca68afa..1fab4cc11b 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendDocument.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendDocument.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send.media +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendDocument @@ -19,7 +20,9 @@ suspend fun TelegramBot.sendDocument( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, - replyMarkup: KeyboardMarkup? = null + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null ) = execute( SendDocument( chatId, @@ -29,7 +32,9 @@ suspend fun TelegramBot.sendDocument( parseMode, disableNotification, replyToMessageId, - replyMarkup + allowSendingWithoutReply, + replyMarkup, + disableContentTypeDetection ) ) @@ -41,8 +46,10 @@ suspend fun TelegramBot.sendDocument( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, - replyMarkup: KeyboardMarkup? = null -) = sendDocument(chat.id, document, thumb, text, parseMode, disableNotification, replyToMessageId, replyMarkup) + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(chat.id, document, thumb, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) suspend fun TelegramBot.sendDocument( chatId: ChatIdentifier, @@ -51,9 +58,11 @@ suspend fun TelegramBot.sendDocument( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, - replyMarkup: KeyboardMarkup? = null + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null ) = sendDocument( - chatId, document.fileId, document.thumb ?.fileId, text, parseMode, disableNotification, replyToMessageId, replyMarkup + chatId, document.fileId, document.thumb ?.fileId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection ) suspend fun TelegramBot.sendDocument( @@ -63,8 +72,10 @@ suspend fun TelegramBot.sendDocument( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, - replyMarkup: KeyboardMarkup? = null -) = sendDocument(chat.id, document, text, parseMode, disableNotification, replyToMessageId, replyMarkup) + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(chat.id, document, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) suspend inline fun TelegramBot.replyWithDocument( to: Message, @@ -73,8 +84,10 @@ suspend inline fun TelegramBot.replyWithDocument( text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, - replyMarkup: KeyboardMarkup? = null -) = sendDocument(to.chat, document, thumb, text, parseMode, disableNotification, to.messageId, replyMarkup) + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(to.chat, document, thumb, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) suspend inline fun TelegramBot.replyWithDocument( to: Message, @@ -82,8 +95,10 @@ suspend inline fun TelegramBot.replyWithDocument( text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, - replyMarkup: KeyboardMarkup? = null -) = sendDocument(to.chat, document, text, parseMode, disableNotification, to.messageId, replyMarkup) + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(to.chat, document, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) suspend inline fun TelegramBot.reply( to: Message, @@ -91,5 +106,99 @@ suspend inline fun TelegramBot.reply( text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, - replyMarkup: KeyboardMarkup? = null -) = replyWithDocument(to, document, text, parseMode, disableNotification, replyMarkup) + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = replyWithDocument(to, document, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + + +suspend inline fun TelegramBot.sendDocument( + chatId: ChatIdentifier, + document: InputFile, + thumb: InputFile? = null, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = execute( + SendDocument( + chatId, + document, + thumb, + entities, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup, + disableContentTypeDetection + ) +) + +suspend inline fun TelegramBot.sendDocument( + chat: Chat, + document: InputFile, + thumb: InputFile? = null, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(chat.id, document, thumb, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + +suspend inline fun TelegramBot.sendDocument( + chatId: ChatIdentifier, + document: DocumentFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument( + chatId, document.fileId, document.thumb ?.fileId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection +) + +suspend inline fun TelegramBot.sendDocument( + chat: Chat, + document: DocumentFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(chat.id, document, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + +suspend inline fun TelegramBot.replyWithDocument( + to: Message, + document: InputFile, + thumb: InputFile? = null, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(to.chat, document, thumb, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + +suspend inline fun TelegramBot.replyWithDocument( + to: Message, + document: DocumentFile, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(to.chat, document, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + +suspend inline fun TelegramBot.reply( + to: Message, + document: DocumentFile, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = replyWithDocument(to, document, entities, disableNotification, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt index 03e5d13e3d..6a115897b8 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt @@ -17,10 +17,11 @@ suspend fun TelegramBot.sendMediaGroup( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = execute( SendMediaGroup( - chatId, media, disableNotification, replyToMessageId + chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) ) @@ -32,9 +33,10 @@ suspend fun TelegramBot.sendMediaGroup( chat: Chat, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = sendMediaGroup( - chat.id, media, disableNotification, replyToMessageId + chat.id, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) /** @@ -44,10 +46,11 @@ suspend fun TelegramBot.sendPlaylist( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = execute( SendPlaylist( - chatId, media, disableNotification, replyToMessageId + chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) ) @@ -58,9 +61,10 @@ suspend fun TelegramBot.sendPlaylist( chat: Chat, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = sendPlaylist( - chat.id, media, disableNotification, replyToMessageId + chat.id, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) /** @@ -70,10 +74,11 @@ suspend fun TelegramBot.sendDocumentsGroup( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = execute( SendDocumentsGroup( - chatId, media, disableNotification, replyToMessageId + chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) ) @@ -84,9 +89,10 @@ suspend fun TelegramBot.sendDocumentsGroup( chat: Chat, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = sendDocumentsGroup( - chat.id, media, disableNotification, replyToMessageId + chat.id, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) /** @@ -96,10 +102,11 @@ suspend fun TelegramBot.sendVisualMediaGroup( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = execute( SendVisualMediaGroup( - chatId, media, disableNotification, replyToMessageId + chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) ) @@ -110,37 +117,44 @@ suspend fun TelegramBot.sendVisualMediaGroup( chat: Chat, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = sendVisualMediaGroup( - chat.id, media, disableNotification, replyToMessageId + chat.id, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) +@RiskFeature(rawSendingMediaGroupsWarning) suspend inline fun TelegramBot.replyWithMediaGroup( to: Message, media: List, - disableNotification: Boolean = false -) = sendMediaGroup(to.chat, media, disableNotification, to.messageId) + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = sendMediaGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) suspend inline fun TelegramBot.replyWithPlaylist( to: Message, media: List, - disableNotification: Boolean = false -) = sendPlaylist(to.chat, media, disableNotification, to.messageId) + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = sendPlaylist(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) suspend inline fun TelegramBot.replyWithDocumentsGroup( to: Message, media: List, - disableNotification: Boolean = false -) = sendDocumentsGroup(to.chat, media, disableNotification, to.messageId) + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = sendDocumentsGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) suspend inline fun TelegramBot.replyWithVisualMediaGroup( to: Message, media: List, - disableNotification: Boolean = false -) = sendVisualMediaGroup(to.chat, media, disableNotification, to.messageId) + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = sendVisualMediaGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) suspend inline fun TelegramBot.reply( to: Message, media: List, - disableNotification: Boolean = false -) = replyWithMediaGroup(to, media, disableNotification) + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = replyWithMediaGroup(to, media, disableNotification, allowSendingWithoutReply) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt index 6f12590f0d..d4ee9ed59d 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send.media +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendPhoto @@ -19,6 +20,7 @@ suspend fun TelegramBot.sendPhoto( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendPhoto( @@ -28,6 +30,7 @@ suspend fun TelegramBot.sendPhoto( parseMode, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) ) @@ -39,8 +42,9 @@ suspend fun TelegramBot.sendPhoto( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat.id, fileId, caption, parseMode, disableNotification, replyToMessageId, replyMarkup) +) = sendPhoto(chat.id, fileId, caption, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendPhoto( chatId: ChatIdentifier, @@ -49,8 +53,9 @@ suspend fun TelegramBot.sendPhoto( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), caption, parseMode, disableNotification, replyToMessageId, replyMarkup) +) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), caption, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendPhoto( chat: Chat, @@ -59,8 +64,9 @@ suspend fun TelegramBot.sendPhoto( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat.id, photo, caption, parseMode, disableNotification, replyToMessageId, replyMarkup) +) = sendPhoto(chat.id, photo, caption, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithPhoto( to: Message, @@ -68,8 +74,9 @@ suspend inline fun TelegramBot.replyWithPhoto( caption: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, fileId, caption, parseMode, disableNotification, to.messageId, replyMarkup) +) = sendPhoto(to.chat, fileId, caption, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithPhoto( to: Message, @@ -77,8 +84,9 @@ suspend inline fun TelegramBot.replyWithPhoto( caption: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, photo, caption, parseMode, disableNotification, to.messageId, replyMarkup) +) = sendPhoto(to.chat, photo, caption, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, @@ -86,5 +94,84 @@ suspend inline fun TelegramBot.reply( caption: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithPhoto(to, photo, caption, parseMode, disableNotification, replyMarkup) +) = replyWithPhoto(to, photo, caption, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) + + +suspend inline fun TelegramBot.sendPhoto( + chatId: ChatIdentifier, + fileId: InputFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendPhoto( + chatId, + fileId, + entities, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) +) + +suspend inline fun TelegramBot.sendPhoto( + chat: Chat, + fileId: InputFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto(chat.id, fileId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.sendPhoto( + chatId: ChatIdentifier, + photo: Photo, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.sendPhoto( + chat: Chat, + photo: Photo, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto(chat.id, photo, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithPhoto( + to: Message, + fileId: InputFile, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto(to.chat, fileId, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithPhoto( + to: Message, + photo: Photo, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto(to.chat, photo, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + photo: Photo, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithPhoto(to, photo, entities, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt index 9e4b7aad50..9f7cac00f5 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt @@ -15,9 +15,10 @@ suspend fun TelegramBot.sendSticker( sticker: InputFile, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( - SendSticker(chatId, sticker, disableNotification, replyToMessageId, replyMarkup) + SendSticker(chatId, sticker, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) suspend fun TelegramBot.sendSticker( @@ -25,42 +26,48 @@ suspend fun TelegramBot.sendSticker( sticker: InputFile, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendSticker(chat.id, sticker, disableNotification, replyToMessageId, replyMarkup) +) = sendSticker(chat.id, sticker, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendSticker( chatId: ChatIdentifier, sticker: Sticker, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendSticker(chatId, sticker.fileId, disableNotification, replyToMessageId, replyMarkup) +) = sendSticker(chatId, sticker.fileId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendSticker( chat: Chat, sticker: Sticker, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendSticker(chat, sticker.fileId, disableNotification, replyToMessageId, replyMarkup) +) = sendSticker(chat, sticker.fileId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithSticker( to: Message, sticker: InputFile, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendSticker(to.chat, sticker, disableNotification, to.messageId, replyMarkup) +) = sendSticker(to.chat, sticker, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithSticker( to: Message, sticker: Sticker, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendSticker(to.chat, sticker, disableNotification, to.messageId, replyMarkup) +) = sendSticker(to.chat, sticker, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, sticker: Sticker, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithSticker(to, sticker, disableNotification, replyMarkup) +) = replyWithSticker(to, sticker, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt index c58d9ca661..962b265ace 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send.media +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendVideo @@ -22,6 +23,7 @@ suspend fun TelegramBot.sendVideo( height: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendVideo( @@ -36,6 +38,7 @@ suspend fun TelegramBot.sendVideo( null, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) ) @@ -47,8 +50,9 @@ suspend fun TelegramBot.sendVideo( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chatId, video.fileId, video.thumb ?.fileId, text, parseMode, video.duration, video.width, video.height, disableNotification, replyToMessageId, replyMarkup) +) = sendVideo(chatId, video.fileId, video.thumb ?.fileId, text, parseMode, video.duration, video.width, video.height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendVideo( chat: Chat, @@ -61,8 +65,9 @@ suspend fun TelegramBot.sendVideo( height: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chat.id, video, thumb, text, parseMode, duration, width, height, disableNotification, replyToMessageId, replyMarkup) +) = sendVideo(chat.id, video, thumb, text, parseMode, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendVideo( @@ -72,8 +77,9 @@ suspend fun TelegramBot.sendVideo( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chat.id, video, text, parseMode, disableNotification, replyToMessageId, replyMarkup) +) = sendVideo(chat.id, video, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithVideo( to: Message, @@ -85,8 +91,9 @@ suspend inline fun TelegramBot.replyWithVideo( width: Int? = null, height: Int? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(to.chat, video, thumb, text, parseMode, duration, width, height, disableNotification, to.messageId, replyMarkup) +) = sendVideo(to.chat, video, thumb, text, parseMode, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithVideo( to: Message, @@ -94,8 +101,9 @@ suspend inline fun TelegramBot.replyWithVideo( text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(to.chat, video, text, parseMode, disableNotification, to.messageId, replyMarkup) +) = sendVideo(to.chat, video, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, @@ -103,5 +111,102 @@ suspend inline fun TelegramBot.reply( text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithVideo(to, video, text, parseMode, disableNotification, replyMarkup) +) = replyWithVideo(to, video, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) + + +suspend inline fun TelegramBot.sendVideo( + chatId: ChatIdentifier, + video: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendVideo( + chatId, + video, + thumb, + entities, + duration, + width, + height, + null, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) +) + +suspend inline fun TelegramBot.sendVideo( + chatId: ChatIdentifier, + video: VideoFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo(chatId, video.fileId, video.thumb ?.fileId, entities, video.duration, video.width, video.height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.sendVideo( + chat: Chat, + video: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo(chat.id, video, thumb, entities, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + + +suspend inline fun TelegramBot.sendVideo( + chat: Chat, + video: VideoFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo(chat.id, video, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithVideo( + to: Message, + video: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo(to.chat, video, thumb, entities, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithVideo( + to: Message, + video: VideoFile, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo(to.chat, video, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + video: VideoFile, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithVideo(to, video, entities, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt index 7eb6b9f4a5..1e335a9ec2 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt @@ -16,24 +16,22 @@ suspend fun TelegramBot.sendVideoNote( chatId: ChatIdentifier, videoNote: InputFile, thumb: InputFile? = null, - text: String? = null, - parseMode: ParseMode? = null, duration: Long? = null, size: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendVideoNote( chatId, videoNote, thumb, - text, - parseMode, duration, size, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) ) @@ -41,64 +39,58 @@ suspend fun TelegramBot.sendVideoNote( suspend fun TelegramBot.sendVideoNote( chatId: ChatIdentifier, videoNote: VideoNoteFile, - text: String? = null, - parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVideoNote( - chatId, videoNote.fileId, videoNote.thumb ?.fileId, text, parseMode, videoNote.duration, videoNote.width, disableNotification, replyToMessageId, replyMarkup + chatId, videoNote.fileId, videoNote.thumb ?.fileId, videoNote.duration, videoNote.width, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendVideoNote( chat: Chat, videoNote: InputFile, thumb: InputFile? = null, - text: String? = null, - parseMode: ParseMode? = null, duration: Long? = null, size: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideoNote(chat.id, videoNote, thumb, text, parseMode, duration, size, disableNotification, replyToMessageId, replyMarkup) +) = sendVideoNote(chat.id, videoNote, thumb, duration, size, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendVideoNote( chat: Chat, videoNote: VideoNoteFile, - text: String? = null, - parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideoNote(chat.id, videoNote, text, parseMode, disableNotification, replyToMessageId, replyMarkup) +) = sendVideoNote(chat.id, videoNote, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithVideoNote( to: Message, videoNote: InputFile, thumb: InputFile? = null, - text: String? = null, - parseMode: ParseMode? = null, duration: Long? = null, size: Int? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideoNote(to.chat, videoNote, thumb, text, parseMode, duration, size, disableNotification, to.messageId, replyMarkup) +) = sendVideoNote(to.chat, videoNote, thumb, duration, size, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithVideoNote( to: Message, videoNote: VideoNoteFile, - text: String? = null, - parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideoNote(to.chat, videoNote, text, parseMode, disableNotification, to.messageId, replyMarkup) +) = sendVideoNote(to.chat, videoNote, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, videoNote: VideoNoteFile, - text: String? = null, - parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithVideoNote(to, videoNote, text, parseMode, disableNotification, replyMarkup) +) = replyWithVideoNote(to, videoNote, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt index 68c63a91fe..197000a8a5 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send.media +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendVoice @@ -20,6 +21,7 @@ suspend fun TelegramBot.sendVoice( duration: Long? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendVoice( @@ -30,6 +32,7 @@ suspend fun TelegramBot.sendVoice( duration, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) ) @@ -42,8 +45,9 @@ suspend fun TelegramBot.sendVoice( duration: Long? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVoice(chat.id, voice, text, parseMode, duration, disableNotification, replyToMessageId, replyMarkup) +) = sendVoice(chat.id, voice, text, parseMode, duration, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendVoice( chatId: ChatIdentifier, @@ -52,9 +56,10 @@ suspend fun TelegramBot.sendVoice( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVoice( - chatId, voice.fileId, text, parseMode, voice.duration, disableNotification, replyToMessageId, replyMarkup + chatId, voice.fileId, text, parseMode, voice.duration, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendVoice( @@ -64,8 +69,9 @@ suspend fun TelegramBot.sendVoice( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVoice(chat.id, voice, text, parseMode, disableNotification, replyToMessageId, replyMarkup) +) = sendVoice(chat.id, voice, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithVoice( to: Message, @@ -74,8 +80,9 @@ suspend inline fun TelegramBot.replyWithVoice( parseMode: ParseMode? = null, duration: Long? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVoice(to.chat, voice, text, parseMode, duration, disableNotification, to.messageId, replyMarkup) +) = sendVoice(to.chat, voice, text, parseMode, duration, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithVoice( to: Message, @@ -83,8 +90,9 @@ suspend inline fun TelegramBot.replyWithVoice( text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVoice(to.chat, voice, text, parseMode, disableNotification, to.messageId, replyMarkup) +) = sendVoice(to.chat, voice, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, @@ -92,5 +100,90 @@ suspend inline fun TelegramBot.reply( text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithVoice(to, voice, text, parseMode, disableNotification, replyMarkup) +) = replyWithVoice(to, voice, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) + + +suspend inline fun TelegramBot.sendVoice( + chatId: ChatIdentifier, + voice: InputFile, + entities: List, + duration: Long? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendVoice( + chatId, + voice, + entities, + duration, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) +) + +suspend inline fun TelegramBot.sendVoice( + chat: Chat, + voice: InputFile, + entities: List, + duration: Long? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice(chat.id, voice, entities, duration, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.sendVoice( + chatId: ChatIdentifier, + voice: VoiceFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice( + chatId, voice.fileId, entities, voice.duration, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup +) + +suspend inline fun TelegramBot.sendVoice( + chat: Chat, + voice: VoiceFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice(chat.id, voice, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithVoice( + to: Message, + voice: InputFile, + entities: List, + duration: Long? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice(to.chat, voice, entities, duration, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithVoice( + to: Message, + voice: VoiceFile, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice(to.chat, voice, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + voice: VoiceFile, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithVoice(to, voice, entities, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/payments/SendInvoice.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/payments/SendInvoice.kt index ee04707a50..3af85856f1 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/payments/SendInvoice.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/payments/SendInvoice.kt @@ -27,9 +27,10 @@ suspend fun TelegramBot.sendInvoice( priceDependOnShipAddress: Boolean = false, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: InlineKeyboardMarkup? = null ) = execute( - SendInvoice(chatId, title, description, payload, providerToken, startParameter, currency, prices, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, replyMarkup) + SendInvoice(chatId, title, description, payload, providerToken, startParameter, currency, prices, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) suspend fun TelegramBot.sendInvoice( @@ -51,8 +52,9 @@ suspend fun TelegramBot.sendInvoice( priceDependOnShipAddress: Boolean = false, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: InlineKeyboardMarkup? = null -) = sendInvoice(user.id, title, description, payload, providerToken, startParameter, currency, prices, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, replyMarkup) +) = sendInvoice(user.id, title, description, payload, providerToken, startParameter, currency, prices, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithInvoice( to: Message, @@ -72,5 +74,6 @@ suspend inline fun TelegramBot.replyWithInvoice( shouldSendEmailToProvider: Boolean = false, priceDependOnShipAddress: Boolean = false, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: InlineKeyboardMarkup? = null -) = sendInvoice(to.chat.id, title, description, payload, providerToken, startParameter, currency, prices, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, to.messageId, replyMarkup) +) = sendInvoice(to.chat.id, title, description, payload, providerToken, startParameter, currency, prices, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendPoll.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendPoll.kt index 674214eef0..d95c63c464 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendPoll.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendPoll.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send.polls +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.send.polls.SendQuizPoll import dev.inmo.tgbotapi.requests.send.polls.SendRegularPoll @@ -21,10 +22,11 @@ suspend fun TelegramBot.sendRegularPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendRegularPoll( - chatId, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, replyMarkup + chatId, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) ) suspend fun TelegramBot.sendRegularPoll( @@ -38,8 +40,9 @@ suspend fun TelegramBot.sendRegularPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendRegularPoll(chatId, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, replyMarkup) +) = sendRegularPoll(chatId, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendRegularPoll( chat: Chat, @@ -51,9 +54,10 @@ suspend fun TelegramBot.sendRegularPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendRegularPoll( - chat.id, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, replyMarkup + chat.id, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendRegularPoll( @@ -67,9 +71,10 @@ suspend fun TelegramBot.sendRegularPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendRegularPoll( - chat.id, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, replyMarkup + chat.id, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) @@ -85,10 +90,11 @@ suspend fun TelegramBot.sendQuizPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendQuizPoll( - chatId, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, replyMarkup + chatId, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) ) @@ -104,9 +110,10 @@ suspend fun TelegramBot.sendQuizPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendQuizPoll( - chat.id, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, replyMarkup + chat.id, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendQuizPoll( @@ -122,9 +129,10 @@ suspend fun TelegramBot.sendQuizPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendQuizPoll( - chatId, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, replyMarkup + chatId, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendQuizPoll( @@ -140,9 +148,83 @@ suspend fun TelegramBot.sendQuizPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendQuizPoll( - chat.id, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, replyMarkup + chat.id, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup +) + + +suspend inline fun TelegramBot.sendQuizPoll( + chatId: ChatIdentifier, + question: String, + options: List, + correctOptionId: Int, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + entities: List, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendQuizPoll( + chatId, question, options, correctOptionId, isAnonymous, isClosed, entities, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup + ) +) + +suspend inline fun TelegramBot.sendQuizPoll( + chat: Chat, + question: String, + options: List, + correctOptionId: Int, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + entities: List, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll( + chat.id, question, options, correctOptionId, isAnonymous, isClosed, entities, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup +) + +suspend inline fun TelegramBot.sendQuizPoll( + chatId: ChatIdentifier, + isClosed: Boolean = false, + quizPoll: QuizPoll, + question: String = quizPoll.question, + options: List = quizPoll.options.map { it.text }, + correctOptionId: Int = quizPoll.correctOptionId ?: error("Correct option ID must be provided by income QuizPoll or by developer"), + isAnonymous: Boolean = quizPoll.isAnonymous, + entities: List, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll( + chatId, question, options, correctOptionId, isAnonymous, isClosed, entities, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup +) + +suspend inline fun TelegramBot.sendQuizPoll( + chat: Chat, + isClosed: Boolean = false, + quizPoll: QuizPoll, + question: String = quizPoll.question, + options: List = quizPoll.options.map { it.text }, + correctOptionId: Int = quizPoll.correctOptionId ?: error("Correct option ID must be provided by income QuizPoll or by developer"), + isAnonymous: Boolean = quizPoll.isAnonymous, + entities: List, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll( + chat.id, question, options, correctOptionId, isAnonymous, isClosed, entities, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend inline fun TelegramBot.replyWithRegularPoll( @@ -154,8 +236,9 @@ suspend inline fun TelegramBot.replyWithRegularPoll( allowMultipleAnswers: Boolean = false, closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendRegularPoll(to.chat, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, to.messageId, replyMarkup) +) = sendRegularPoll(to.chat, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithRegularPoll( to: Message, @@ -167,8 +250,9 @@ suspend inline fun TelegramBot.replyWithRegularPoll( allowMultipleAnswers: Boolean = poll.allowMultipleAnswers, closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendRegularPoll(to.chat, poll, isClosed, question, options, isAnonymous, allowMultipleAnswers, closeInfo, disableNotification, to.messageId, replyMarkup) +) = sendRegularPoll(to.chat, poll, isClosed, question, options, isAnonymous, allowMultipleAnswers, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithQuizPoll( to: Message, @@ -181,8 +265,9 @@ suspend inline fun TelegramBot.replyWithQuizPoll( parseMode: ParseMode? = null, closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendQuizPoll(to.chat, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, to.messageId, replyMarkup) +) = sendQuizPoll(to.chat, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithQuizPoll( to: Message, @@ -196,6 +281,35 @@ suspend inline fun TelegramBot.replyWithQuizPoll( parseMode: ParseMode? = null, closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, explanation, parseMode, closeInfo, disableNotification, to.messageId, replyMarkup) +) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, explanation, parseMode, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +suspend inline fun TelegramBot.replyWithQuizPoll( + to: Message, + question: String, + options: List, + correctOptionId: Int, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + entities: List, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll(to.chat, question, options, correctOptionId, isAnonymous, isClosed, entities, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithQuizPoll( + to: Message, + isClosed: Boolean = false, + quizPoll: QuizPoll, + question: String = quizPoll.question, + options: List = quizPoll.options.map { it.text }, + correctOptionId: Int = quizPoll.correctOptionId ?: error("Correct option ID must be provided by income QuizPoll or by developer"), + isAnonymous: Boolean = quizPoll.isAnonymous, + entities: List, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, entities, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/webhook/SetWebhookInfo.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/webhook/SetWebhookInfo.kt index 375d22301c..bf2730daae 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/webhook/SetWebhookInfo.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/webhook/SetWebhookInfo.kt @@ -10,11 +10,13 @@ import dev.inmo.tgbotapi.requests.webhook.SetWebhook */ suspend fun TelegramBot.setWebhookInfo( url: String, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null ) = execute( SetWebhook( - url, maxAllowedConnections, allowedUpdates + url, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates ) ) @@ -24,11 +26,13 @@ suspend fun TelegramBot.setWebhookInfo( suspend fun TelegramBot.setWebhookInfo( url: String, certificate: FileId, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null ) = execute( SetWebhook( - url, certificate, maxAllowedConnections, allowedUpdates + url, certificate, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates ) ) @@ -38,10 +42,12 @@ suspend fun TelegramBot.setWebhookInfo( suspend fun TelegramBot.setWebhookInfo( url: String, certificate: MultipartFile, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null ) = execute( SetWebhook( - url, certificate, maxAllowedConnections, allowedUpdates + url, certificate, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates ) ) From bf1e353615c646ac77f1688f67ca9439ede35882 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 6 Nov 2020 00:05:05 +0600 Subject: [PATCH 26/42] fix build --- .../kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt | 5 +++-- .../inmo/tgbotapi/types/message/content/LocationContent.kt | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt index f2bea226f2..41be71b854 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt @@ -23,5 +23,6 @@ data class VoiceFile( fun VoiceFile.asAudioFile( performer: String? = null, - title: String? = null -) = AudioFile(fileId, fileUniqueId, duration, performer, title, mimeType, fileSize) + title: String? = null, + fileName: String? = null +) = AudioFile(fileId, fileUniqueId, duration, performer, title, fileName, mimeType, fileSize) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt index 12afc0b413..c9632e6a77 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt @@ -17,6 +17,7 @@ data class LocationContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = when (location) { is StaticLocation -> SendStaticLocation( From 3b1803e8513b42f8f5429849cf3ee51f68c5ebcd Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 6 Nov 2020 00:12:14 +0600 Subject: [PATCH 27/42] remove deprecations --- .../tgbotapi/bot/Ktor/KtorRequestsExecutor.kt | 1 - .../base/DownloadFileRequestCallFactory.kt | 5 +-- .../EditChatMessageLiveLocation.kt | 1 - .../edit/caption/EditChatMessageCaption.kt | 2 - .../edit/caption/EditInlineMessageCaption.kt | 2 - .../requests/edit/text/EditChatMessageText.kt | 2 - .../edit/text/EditInlineMessageText.kt | 2 - .../dev/inmo/tgbotapi/requests/local/Close.kt | 4 +- .../tgbotapi/requests/send/CopyMessage.kt | 4 +- .../tgbotapi/requests/send/SendMessage.kt | 2 - .../requests/send/media/SendAnimation.kt | 2 - .../tgbotapi/requests/send/media/SendAudio.kt | 2 - .../requests/send/media/SendDocument.kt | 2 - .../requests/send/media/SendMediaGroup.kt | 1 - .../tgbotapi/requests/send/media/SendPhoto.kt | 2 - .../tgbotapi/requests/send/media/SendVideo.kt | 2 - .../requests/send/media/SendVideoNote.kt | 3 -- .../tgbotapi/requests/send/media/SendVoice.kt | 2 - .../tgbotapi/requests/send/polls/SendPoll.kt | 9 +--- .../dev/inmo/tgbotapi/types/ChatIdentifier.kt | 3 +- .../types/ChatMember/abstracts/ChatMember.kt | 3 +- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 3 -- .../InlineQueryResultAudioCachedImpl.kt | 2 - .../InlineQueryResultAudioImpl.kt | 2 - .../InlineQueryResultDocumentCachedImpl.kt | 2 - .../InlineQueryResultDocumentImpl.kt | 2 - .../InlineQueryResultGifCachedImpl.kt | 2 - .../InlineQueryResultGifImpl.kt | 2 - .../InlineQueryResultMpeg4GifCachedImpl.kt | 2 - .../InlineQueryResultMpeg4GifImpl.kt | 2 - .../InlineQueryResultPhotoCachedImpl.kt | 1 - .../InlineQueryResultPhotoImpl.kt | 2 - .../InlineQueryResultVideoCachedImpl.kt | 2 - .../InlineQueryResultVideoImpl.kt | 2 - .../InlineQueryResultVoiceCachedImpl.kt | 2 - .../InlineQueryResultVoiceImpl.kt | 2 - .../InputTextMessageContent.kt | 2 - .../query/LocationInlineQuery.kt | 4 +- .../InlineQueries/query/RawInlineQuery.kt | 1 - .../types/InputMedia/InputMediaAnimation.kt | 5 +-- .../types/InputMedia/InputMediaAudio.kt | 7 +--- .../types/InputMedia/InputMediaDocument.kt | 2 - .../types/InputMedia/InputMediaPhoto.kt | 7 +--- .../types/InputMedia/InputMediaVideo.kt | 6 +-- .../InputMedia/MediaGroupMemberInputMedia.kt | 2 +- .../types/InputMedia/ThumbedInputMedia.kt | 13 ------ .../InlineKeyboardButtonSerializer.kt | 6 ++- .../tgbotapi/types/chat/ChatSerializers.kt | 3 +- .../inmo/tgbotapi/types/files/VideoFile.kt | 2 - .../types/message/ChannelEventMessage.kt | 2 +- .../types/message/ChannelMediaGroupMessage.kt | 2 +- .../types/message/ChannelMessageImpl.kt | 8 ++-- .../ChatEvents/ProximityAlertTriggered.kt | 3 +- .../types/message/CommonGroupEventMessage.kt | 2 +- .../types/message/CommonMediaGroupMessage.kt | 2 +- .../message/CommonSupergroupEventMessage.kt | 2 +- .../tgbotapi/types/message/GroupMessages.kt | 9 ++-- .../types/message/PrivateMessageImpl.kt | 6 +-- .../inmo/tgbotapi/types/message/RawMessage.kt | 2 - .../types/message/abstracts/ChannelMessage.kt | 1 - .../types/message/abstracts/GroupMessages.kt | 3 +- .../types/message/abstracts/Message.kt | 2 +- .../types/message/content/LocationContent.kt | 6 ++- .../message/content/media/AudioContent.kt | 7 ++-- .../message/content/media/DocumentContent.kt | 8 ++-- .../message/content/media/PhotoContent.kt | 8 ++-- .../message/content/media/VideoContent.kt | 4 -- .../message/content/media/VideoNoteContent.kt | 1 - .../dev/inmo/tgbotapi/types/polls/Poll.kt | 7 ++-- .../inmo/tgbotapi/utils/StringFormatting.kt | 3 +- .../utils/extensions/ReceiveChannel.kt | 42 ------------------- .../inmo/tgbotapi/types/TelegramDateTests.kt | 2 +- .../dev/inmo/tgbotapi/utils/MimeTypeActual.kt | 5 ++- .../dev/inmo/tgbotapi/utils/MimeTypeActual.kt | 2 +- .../extensions/api/LiveLocationProvider.kt | 9 ++-- .../api/chat/modify/PinChatMessage.kt | 1 - .../api/chat/modify/UnpinAllChatMessages.kt | 2 - .../EditChatMessageLiveLocation.kt | 1 - .../EditInlineMessageLiveLocation.kt | 2 - .../extensions/api/send/SendLocation.kt | 4 +- .../tgbotapi/extensions/api/send/SendVenue.kt | 3 +- .../extensions/api/send/media/SendAudio.kt | 1 - .../api/send/media/SendVideoNote.kt | 2 - .../extensions/api/send/media/SendVoice.kt | 1 - .../utils/shortcuts/PollCloseShortcuts.kt | 4 +- .../utils/updates/CommandsFilters.kt | 2 +- .../InlineQueryUpdatesConversations.kt | 2 +- .../inmo/tgbotapi/types/files/PathedFile.kt | 1 - 88 files changed, 85 insertions(+), 235 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt index 909f3a72ad..780c39992a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt @@ -10,7 +10,6 @@ import dev.inmo.tgbotapi.types.Response import dev.inmo.tgbotapi.utils.* import io.ktor.client.HttpClient import io.ktor.client.features.* -import io.ktor.client.statement.HttpStatement import io.ktor.client.statement.readText import kotlinx.serialization.json.Json diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt index 80a11d0912..05d3874332 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt @@ -1,15 +1,12 @@ package dev.inmo.tgbotapi.bot.Ktor.base import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory -import dev.inmo.tgbotapi.bot.RequestsExecutor import dev.inmo.tgbotapi.requests.DownloadFile import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper import dev.inmo.tgbotapi.utils.handleSafely import io.ktor.client.HttpClient -import io.ktor.client.request.* -import io.ktor.client.statement.* -import io.ktor.http.HttpMethod +import io.ktor.client.request.get import kotlinx.serialization.json.Json object DownloadFileRequestCallFactory : KtorCallFactory { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt index e1a1688d4e..ba93fd4206 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt @@ -3,7 +3,6 @@ package dev.inmo.tgbotapi.requests.edit.LiveLocation import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup -import dev.inmo.tgbotapi.types.location.LiveLocation import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.LocationContent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt index 9317cb1755..617970f108 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt @@ -5,8 +5,6 @@ import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.requests.edit.media.MediaContentMessageResultDeserializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt index 4603e9a7a3..20145b3939 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt @@ -4,8 +4,6 @@ import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt index 873fdc567c..a0f37f90b3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt @@ -5,8 +5,6 @@ import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.requests.send.TextContentMessageResultDeserializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt index 1b9ea92c95..2e0be3eafe 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt @@ -5,8 +5,6 @@ import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.requests.edit.media.editMessageMediaMethod import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt index 2c6d7ed618..9f1bea26bf 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt @@ -1,9 +1,7 @@ package dev.inmo.tgbotapi.requests.local import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest -import kotlinx.serialization.DeserializationStrategy -import kotlinx.serialization.Serializable -import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer /** diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt index e9b6f55a1a..a690f6e71b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt @@ -6,12 +6,10 @@ import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup -import dev.inmo.tgbotapi.types.message.abstracts.* +import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import kotlinx.serialization.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt index 229c2e05f4..c36219778c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt @@ -5,8 +5,6 @@ import dev.inmo.tgbotapi.CommonAbstracts.types.DisableWebPagePreview import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt index ecb6ef0650..4e58cc23a4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt @@ -6,8 +6,6 @@ import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt index 8bfd85918d..82e15305a9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt @@ -6,8 +6,6 @@ import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt index 806fa73d2b..6a515be8a4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt @@ -6,8 +6,6 @@ import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt index 42602bdd00..df4a949fa1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt @@ -9,7 +9,6 @@ import dev.inmo.tgbotapi.types.InputMedia.* import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializerClass import dev.inmo.tgbotapi.utils.* -import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.json.buildJsonArray diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt index eb7564219c..c492456f31 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt @@ -6,8 +6,6 @@ import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt index 9dfa699f34..52e7ae8ba3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt @@ -6,8 +6,6 @@ import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt index 3751531c32..94d5b710fb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt @@ -4,14 +4,11 @@ import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.media.VideoNoteContent import dev.inmo.tgbotapi.utils.mapOfNotNull -import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* fun SendVideoNote( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt index e856b5247e..69e6d0f756 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt @@ -6,8 +6,6 @@ import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt index 5df2ae268b..5c2784e85d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt @@ -1,22 +1,17 @@ package dev.inmo.tgbotapi.requests.send.polls +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2 +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.PollContent import dev.inmo.tgbotapi.types.polls.* -import dev.inmo.tgbotapi.utils.fullListOfSubSource -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions -import com.soywiz.klock.DateTime -import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import kotlinx.serialization.* private val commonResultDeserializer: DeserializationStrategy> = TelegramBotAPIMessageDeserializationStrategyClass() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt index 2babc7b429..813ac70c44 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt @@ -3,7 +3,8 @@ package dev.inmo.tgbotapi.types import kotlinx.serialization.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import kotlinx.serialization.json.* +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.longOrNull @Serializable(ChatIdentifierSerializer::class) sealed class ChatIdentifier diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/ChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/ChatMember.kt index b0d0a88171..21d8324165 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/ChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/ChatMember.kt @@ -2,7 +2,8 @@ package dev.inmo.tgbotapi.types.ChatMember.abstracts import dev.inmo.tgbotapi.types.ChatMember.RawChatMember import dev.inmo.tgbotapi.types.User -import kotlinx.serialization.* +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 201243caea..5f17f8e6b8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -60,9 +60,6 @@ val customTitleLength = 0 .. 16 val dartsAndCubeDiceResultLimit = 1 .. 6 @Deprecated("Renamed", ReplaceWith("dartsAndCubeDiceResultLimit", "dev.inmo.tgbotapi.types.dartsAndCubeDiceResultLimit")) -val commonDiceResultLimit - get() = dartsAndCubeDiceResultLimit -@Deprecated("Renamed", ReplaceWith("dartsAndCubeDiceResultLimit", "dev.inmo.tgbotapi.types.dartsAndCubeDiceResultLimit")) val diceResultLimit get() = dartsAndCubeDiceResultLimit val basketballAndFootballDiceResultLimit = 1 .. 5 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt index cccb0b8fb6..30f23487c8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt @@ -7,8 +7,6 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.inlineQueryResultAudioType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt index 38474be80b..f4221fae20 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt @@ -6,8 +6,6 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.inlineQueryResultAudioType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt index 6d278f49e6..2b7bd33291 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt @@ -7,8 +7,6 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.inlineQueryResultDocumentType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt index 83eff31242..bca7294ef3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt @@ -6,8 +6,6 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.inlineQueryResultDocumentType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt index 97de40174a..a65dd530ac 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt @@ -7,8 +7,6 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.inlineQueryResultGifType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt index ca613abfec..d282045d62 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt @@ -6,8 +6,6 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.inlineQueryResultGifType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt index bdf0c15817..d7726fa700 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt @@ -7,8 +7,6 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.inlineQueryResultMpeg4GifType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt index 5f77b70629..9b07306447 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt @@ -6,8 +6,6 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.inlineQueryResultMpeg4GifType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt index 3318691b35..942fb9039a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt @@ -7,7 +7,6 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.inlineQueryResultPhotoType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt index 54173109ea..332a2ce09c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt @@ -6,8 +6,6 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.inlineQueryResultPhotoType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt index 3ca7511514..8fe16705c5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt @@ -7,8 +7,6 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.inlineQueryResultVideoType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt index 2e6262cbec..e055c7f468 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt @@ -6,8 +6,6 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.inlineQueryResultVideoType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt index ee2d540148..e5e236120d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt @@ -7,8 +7,6 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.inlineQueryResultVoiceType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt index f507bcc0d9..02c4189ed8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt @@ -6,8 +6,6 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.inlineQueryResultVoiceType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt index 2cee36978c..9a2d74746b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt @@ -5,8 +5,6 @@ import dev.inmo.tgbotapi.CommonAbstracts.types.DisableWebPagePreview import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import kotlinx.serialization.SerialName diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt index de8d573a25..fe94c7e34d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt @@ -1,9 +1,9 @@ package dev.inmo.tgbotapi.types.InlineQueries.query -import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InlineQuery +import dev.inmo.tgbotapi.types.InlineQueryIdentifier +import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.location.Location -import dev.inmo.tgbotapi.types.location.StaticLocation data class LocationInlineQuery( override val id: InlineQueryIdentifier, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt index edfa1b5abc..eaf43fca71 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt @@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.types.InlineQueries.query import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.location.Location -import dev.inmo.tgbotapi.types.location.StaticLocation import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt index 0f71ff5def..5eb5e61c8e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt @@ -1,11 +1,10 @@ package dev.inmo.tgbotapi.types.InputMedia import dev.inmo.tgbotapi.CommonAbstracts.* -import dev.inmo.tgbotapi.requests.abstracts.* +import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import kotlinx.serialization.SerialName diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt index 738da6a829..01d416f485 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt @@ -1,16 +1,13 @@ package dev.inmo.tgbotapi.types.InputMedia import dev.inmo.tgbotapi.CommonAbstracts.* -import dev.inmo.tgbotapi.requests.abstracts.* +import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.files.AudioFile -import dev.inmo.tgbotapi.types.files.PhotoSize -import dev.inmo.tgbotapi.types.message.content.media.AudioContent import kotlinx.serialization.* internal const val audioInputMediaType = "audio" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt index 81cc43a069..a448046867 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt @@ -4,8 +4,6 @@ import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.files.DocumentFile diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt index e921b51508..345d60b117 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt @@ -1,17 +1,14 @@ package dev.inmo.tgbotapi.types.InputMedia import dev.inmo.tgbotapi.CommonAbstracts.* -import dev.inmo.tgbotapi.requests.abstracts.* +import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.files.PhotoSize import kotlinx.serialization.* -import kotlinx.serialization.json.JsonElement -import kotlinx.serialization.json.JsonObject internal const val photoInputMediaType = "photo" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt index d6a6c46bcd..f7907dd023 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt @@ -1,15 +1,13 @@ package dev.inmo.tgbotapi.types.InputMedia import dev.inmo.tgbotapi.CommonAbstracts.* -import dev.inmo.tgbotapi.requests.abstracts.* +import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import kotlinx.serialization.* -import kotlinx.serialization.json.JsonElement internal const val videoInputMediaType = "video" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMedia.kt index ebb1b2291c..7e63cc915b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMedia.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMedia.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.types.InputMedia import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import kotlinx.serialization.* -import kotlinx.serialization.json.* +import kotlinx.serialization.json.Json internal val argumentsFormatter by lazy { Json { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/ThumbedInputMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/ThumbedInputMedia.kt index 1bda788bf4..d2b51c84b1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/ThumbedInputMedia.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/ThumbedInputMedia.kt @@ -1,20 +1,7 @@ package dev.inmo.tgbotapi.types.InputMedia import dev.inmo.tgbotapi.requests.abstracts.* -import dev.inmo.tgbotapi.types.thumbField -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable interface ThumbedInputMedia : InputMedia { val thumb: InputFile? - @Serializable - @SerialName(thumbField) - @Deprecated("Will be removed due to useless state") - val thumbMedia: String? - get() = thumb ?.let { - when (it) { - is FileId -> it.fileId - is MultipartFile -> it.fileId.toInputMediaFileAttachmentName() - } - } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt index 8a3ab256e0..c8a3be6343 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt @@ -2,11 +2,13 @@ package dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.utils.nonstrictJsonFormat -import kotlinx.serialization.* +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import kotlinx.serialization.json.* +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonObject internal object InlineKeyboardButtonSerializer : KSerializer { @InternalSerializationApi diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatSerializers.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatSerializers.kt index 053e640183..23a27339a0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatSerializers.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatSerializers.kt @@ -6,7 +6,8 @@ import dev.inmo.tgbotapi.types.chat.abstracts.UnknownChatType import dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedChat import dev.inmo.tgbotapi.types.chat.extended.* import dev.inmo.tgbotapi.utils.nonstrictJsonFormat -import kotlinx.serialization.* +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.serializer import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt index da28496110..eebd6ea018 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt @@ -3,11 +3,9 @@ package dev.inmo.tgbotapi.types.files import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo -import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.files.abstracts.* import dev.inmo.tgbotapi.utils.MimeType -import dev.inmo.tgbotapi.utils.toHtmlCaptions import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelEventMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelEventMessage.kt index d0cbd5cf4b..ce972e7d52 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelEventMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelEventMessage.kt @@ -1,10 +1,10 @@ package dev.inmo.tgbotapi.types.message +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChannelEvent import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage -import com.soywiz.klock.DateTime data class ChannelEventMessage( override val messageId: MessageIdentifier, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt index d77100871f..70d670d41e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.message +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.MediaGroupIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -7,7 +8,6 @@ import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent -import com.soywiz.klock.DateTime data class ChannelMediaGroupMessage( override val messageId: MessageIdentifier, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessageImpl.kt index 2be816b343..ba28d6c5ba 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessageImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessageImpl.kt @@ -1,14 +1,12 @@ package dev.inmo.tgbotapi.types.message +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup -import dev.inmo.tgbotapi.types.chat.abstracts.Chat -import dev.inmo.tgbotapi.types.message.abstracts.Message -import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent -import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage -import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat import dev.inmo.tgbotapi.types.message.abstracts.ChannelMessage +import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent data class ChannelMessageImpl( override val messageId: MessageIdentifier, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ProximityAlertTriggered.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ProximityAlertTriggered.kt index 557908240a..e502522020 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ProximityAlertTriggered.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ProximityAlertTriggered.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.message.ChatEvents -import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.Meters +import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonGroupEventMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonGroupEventMessage.kt index 6117b923c7..d55134b6c5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonGroupEventMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonGroupEventMessage.kt @@ -1,11 +1,11 @@ package dev.inmo.tgbotapi.types.message +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent import dev.inmo.tgbotapi.types.message.abstracts.GroupEventMessage -import com.soywiz.klock.DateTime @Deprecated("Renamed", ReplaceWith("CommonGroupEventMessage")) typealias GroupEventMessage = CommonGroupEventMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt index 248f7da715..2694c7d187 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt @@ -1,11 +1,11 @@ package dev.inmo.tgbotapi.types.message +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.message.abstracts.* import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent -import com.soywiz.klock.DateTime data class CommonMediaGroupMessage( override val messageId: MessageIdentifier, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonSupergroupEventMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonSupergroupEventMessage.kt index 36e218907f..f5a382888e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonSupergroupEventMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonSupergroupEventMessage.kt @@ -1,11 +1,11 @@ package dev.inmo.tgbotapi.types.message +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.chat.abstracts.SupergroupChat import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent import dev.inmo.tgbotapi.types.message.abstracts.SupergroupEventMessage -import com.soywiz.klock.DateTime @Deprecated("Renamed", ReplaceWith("CommonSupergroupEventMessage")) typealias SupergroupEventMessage = CommonSupergroupEventMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt index 62baeffa7a..8a72fc3393 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt @@ -1,13 +1,12 @@ package dev.inmo.tgbotapi.types.message +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup -import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent -import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage -import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo -import com.soywiz.klock.DateTime -import dev.inmo.tgbotapi.types.chat.abstracts.* +import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat +import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat import dev.inmo.tgbotapi.types.message.abstracts.* +import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent data class FromChannelGroupMessageImpl( override val chat: GroupChat, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt index 99dae3d350..232fb6a88a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt @@ -1,13 +1,13 @@ package dev.inmo.tgbotapi.types.message +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.PrivateMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent -import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo -import com.soywiz.klock.DateTime -import dev.inmo.tgbotapi.types.message.abstracts.* data class PrivateMessageImpl( override val messageId: MessageIdentifier, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 0424ecd0b7..f218311a4a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -9,7 +9,6 @@ import dev.inmo.tgbotapi.types.dice.Dice import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.games.RawGame import dev.inmo.tgbotapi.types.location.Location -import dev.inmo.tgbotapi.types.message.ChatEvents.ProximityAlertTriggered import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.abstracts.Message @@ -23,7 +22,6 @@ import dev.inmo.tgbotapi.types.payments.Invoice import dev.inmo.tgbotapi.types.payments.SuccessfulPayment import dev.inmo.tgbotapi.types.polls.Poll import dev.inmo.tgbotapi.types.venue.Venue -import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlin.reflect.KClass diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelMessage.kt index b30ace047c..2ef124d5b1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelMessage.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat -import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt index c97eb604a2..0338591bcb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.message.abstracts -import dev.inmo.tgbotapi.types.chat.abstracts.* +import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat +import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent interface GroupMessage : PublicMessage { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/Message.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/Message.kt index 2d45b0dba1..3bf616a482 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/Message.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/Message.kt @@ -1,9 +1,9 @@ package dev.inmo.tgbotapi.types.message.abstracts +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.message.RawMessage -import com.soywiz.klock.DateTime import kotlinx.serialization.* import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt index c9632e6a77..36c5d90f35 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.types.message.content import dev.inmo.tgbotapi.requests.abstracts.Request -import dev.inmo.tgbotapi.requests.send.* -import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.requests.send.SendLiveLocation +import dev.inmo.tgbotapi.requests.send.SendStaticLocation +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.location.* import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt index 287fd39bb0..3e93231ffc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt @@ -4,16 +4,15 @@ import dev.inmo.tgbotapi.CommonAbstracts.TextPart import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendAudio import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.* +import dev.inmo.tgbotapi.types.InputMedia.InputMediaAudio +import dev.inmo.tgbotapi.types.InputMedia.toInputMediaAudio import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode -import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2 import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.AudioFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.content.abstracts.* +import dev.inmo.tgbotapi.types.message.content.abstracts.AudioMediaGroupContent import dev.inmo.tgbotapi.utils.toHtmlCaptions -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions data class AudioContent( override val media: AudioFile, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt index 737b73d82b..21975585e6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt @@ -5,17 +5,17 @@ import dev.inmo.tgbotapi.CommonAbstracts.TextPart import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendDocument import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.* +import dev.inmo.tgbotapi.types.InputMedia.InputMediaDocument +import dev.inmo.tgbotapi.types.InputMedia.toInputMediaDocument import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode -import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2 import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.DocumentFile import dev.inmo.tgbotapi.types.files.asDocumentFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.content.abstracts.* +import dev.inmo.tgbotapi.types.message.content.abstracts.DocumentMediaGroupContent +import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent import dev.inmo.tgbotapi.utils.toHtmlCaptions -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions data class DocumentContent( override val media: DocumentFile, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt index 6582fd1bb3..958477102a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt @@ -4,16 +4,16 @@ import dev.inmo.tgbotapi.CommonAbstracts.TextPart import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendPhoto import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.* +import dev.inmo.tgbotapi.types.InputMedia.InputMediaPhoto +import dev.inmo.tgbotapi.types.InputMedia.toInputMediaPhoto import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode -import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2 import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.content.abstracts.* +import dev.inmo.tgbotapi.types.message.content.abstracts.MediaCollectionContent +import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent import dev.inmo.tgbotapi.utils.toHtmlCaptions -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions data class PhotoContent( override val mediaCollection: Photo, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt index eacb96d6bf..9931dee306 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt @@ -5,18 +5,14 @@ import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendVideo import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo -import dev.inmo.tgbotapi.types.InputMedia.MediaGroupMemberInputMedia import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode -import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2 import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.VideoFile import dev.inmo.tgbotapi.types.files.toInputMediaVideo import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent import dev.inmo.tgbotapi.utils.toHtmlCaptions -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions data class VideoContent( override val media: VideoFile, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt index df414aee2b..848e6bb1e9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt @@ -5,7 +5,6 @@ import dev.inmo.tgbotapi.requests.send.media.SendVideoNote import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo import dev.inmo.tgbotapi.types.MessageIdentifier -import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.VideoNoteFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/Poll.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/Poll.kt index 4cfdfe19c3..709fc5c9fe 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/Poll.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/Poll.kt @@ -1,11 +1,12 @@ package dev.inmo.tgbotapi.types.polls -import dev.inmo.tgbotapi.CommonAbstracts.* +import com.soywiz.klock.DateTime +import com.soywiz.klock.TimeSpan +import dev.inmo.tgbotapi.CommonAbstracts.ExplainedInput +import dev.inmo.tgbotapi.CommonAbstracts.TextPart import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.utils.nonstrictJsonFormat -import com.soywiz.klock.DateTime -import com.soywiz.klock.TimeSpan import kotlinx.serialization.* import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StringFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StringFormatting.kt index d9a079d9c6..abe06bf13a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StringFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StringFormatting.kt @@ -1,7 +1,8 @@ package dev.inmo.tgbotapi.utils -import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.ParseMode.* +import dev.inmo.tgbotapi.types.UserId +import dev.inmo.tgbotapi.types.link import dev.inmo.tgbotapi.utils.extensions.* const val markdownBoldControl = "*" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/ReceiveChannel.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/ReceiveChannel.kt index 4094709bce..d936e4764c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/ReceiveChannel.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/ReceiveChannel.kt @@ -11,48 +11,6 @@ private sealed class DebounceAction { private data class AddValue(override val value: T) : DebounceAction() private data class RemoveJob(override val value: T, val job: Job) : DebounceAction() -@Deprecated("Unused and will be removed in next major release") -fun ReceiveChannel.debounceByValue( - delayMillis: Long, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default), - resultBroadcastChannelCapacity: Int = 32 -): ReceiveChannel { - val outChannel = Channel(resultBroadcastChannelCapacity) - val values = HashMap() - - val channel = Channel>(Channel.UNLIMITED) - scope.launch { - for (action in channel) { - when (action) { - is AddValue -> { - val msg = action.value - values[msg] ?.cancel() - lateinit var job: Job - job = launch { - delay(delayMillis) - - outChannel.send(msg) - channel.send(RemoveJob(msg, job)) - } - values[msg] = job - } - is RemoveJob -> if (values[action.value] == action.job) { - values.remove(action.value) - } - } - - } - } - - scope.launch { - for (msg in this@debounceByValue) { - channel.send(AddValue(msg)) - } - } - - return outChannel -} - typealias AccumulatedValues = Pair> fun ReceiveChannel>.accumulateByKey( diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TelegramDateTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TelegramDateTests.kt index 77bd43f636..7ac90e6b71 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TelegramDateTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TelegramDateTests.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.types -import dev.inmo.tgbotapi.TestsJsonFormat import com.soywiz.klock.DateTime +import dev.inmo.tgbotapi.TestsJsonFormat import kotlinx.serialization.Serializable import kotlin.test.Test import kotlin.test.assertEquals diff --git a/tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt b/tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt index e668a64f14..ce99122dfa 100644 --- a/tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt +++ b/tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt @@ -1,8 +1,9 @@ package dev.inmo.tgbotapi.utils -import kotlinx.serialization.* -import org.w3c.dom.get import kotlinx.browser.window +import kotlinx.serialization.Serializable +import kotlinx.serialization.Transient +import org.w3c.dom.get @Serializable(MimeTypeSerializer::class) actual class MimeType( diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt index 95a7ba5c9a..3617b5180f 100644 --- a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt @@ -1,6 +1,6 @@ package dev.inmo.tgbotapi.utils -import kotlinx.serialization.* +import kotlinx.serialization.Serializable @Serializable(MimeTypeSerializer::class) actual class MimeType( diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt index 28edcf6741..683fa940b2 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt @@ -1,19 +1,20 @@ package dev.inmo.tgbotapi.extensions.api +import com.soywiz.klock.DateTime +import com.soywiz.klock.TimeSpan import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.extensions.api.edit.LiveLocation.editLiveLocation import dev.inmo.tgbotapi.extensions.api.edit.LiveLocation.stopLiveLocation +import dev.inmo.tgbotapi.requests.send.SendLiveLocation import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.location.LiveLocation +import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.content.LocationContent -import com.soywiz.klock.DateTime -import com.soywiz.klock.TimeSpan -import dev.inmo.tgbotapi.requests.send.SendLiveLocation -import dev.inmo.tgbotapi.types.location.* import io.ktor.utils.io.core.Closeable import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt index ea73743556..9a1977cc07 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt @@ -5,7 +5,6 @@ import dev.inmo.tgbotapi.requests.chat.modify.PinChatMessage import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.chat.abstracts.Chat -import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat import dev.inmo.tgbotapi.types.message.abstracts.Message suspend fun TelegramBot.pinChatMessage( diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinAllChatMessages.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinAllChatMessages.kt index 2385bda48e..3faa707bf9 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinAllChatMessages.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinAllChatMessages.kt @@ -2,10 +2,8 @@ package dev.inmo.tgbotapi.extensions.api.chat.modify import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.chat.modify.UnpinAllChatMessages -import dev.inmo.tgbotapi.requests.chat.modify.UnpinChatMessage import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.chat.abstracts.Chat -import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat suspend fun TelegramBot.unpinAllChatMessages( chatId: ChatIdentifier diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt index 894fa27df1..2548f015a2 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt @@ -6,7 +6,6 @@ import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.location.LiveLocation -import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.LocationContent diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt index 141d8220ee..9540b6a658 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt @@ -3,10 +3,8 @@ package dev.inmo.tgbotapi.extensions.api.edit.LiveLocation import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.edit.LiveLocation.EditInlineMessageLiveLocation import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.location.LiveLocation -import kotlinx.serialization.SerialName suspend fun TelegramBot.editLiveLocation( inlineMessageId: InlineMessageIdentifier, diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt index 0442d77149..7a98d1b72e 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt @@ -1,9 +1,9 @@ package dev.inmo.tgbotapi.extensions.api.send import dev.inmo.tgbotapi.bot.TelegramBot -import dev.inmo.tgbotapi.requests.send.SendLocation import dev.inmo.tgbotapi.requests.send.SendStaticLocation -import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.location.StaticLocation diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt index ce34bf4e0b..e23e7554e6 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt @@ -2,7 +2,8 @@ package dev.inmo.tgbotapi.extensions.api.send import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.send.SendVenue -import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.location.StaticLocation diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt index ce100da778..e6cfab19f9 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt @@ -9,7 +9,6 @@ import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat -import dev.inmo.tgbotapi.types.files.AnimationFile import dev.inmo.tgbotapi.types.files.AudioFile import dev.inmo.tgbotapi.types.message.abstracts.Message diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt index 1e335a9ec2..7bebc92be5 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt @@ -5,10 +5,8 @@ import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendVideoNote import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier -import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat -import dev.inmo.tgbotapi.types.files.VideoFile import dev.inmo.tgbotapi.types.files.VideoNoteFile import dev.inmo.tgbotapi.types.message.abstracts.Message diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt index 197000a8a5..21b87b0e66 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt @@ -9,7 +9,6 @@ import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat -import dev.inmo.tgbotapi.types.files.AudioFile import dev.inmo.tgbotapi.types.files.VoiceFile import dev.inmo.tgbotapi.types.message.abstracts.Message diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/PollCloseShortcuts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/PollCloseShortcuts.kt index 61169cc7f5..3a1e40f55f 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/PollCloseShortcuts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/PollCloseShortcuts.kt @@ -1,11 +1,11 @@ package dev.inmo.tgbotapi.extensions.utils.shortcuts +import com.soywiz.klock.DateTime +import com.soywiz.klock.TimeSpan import dev.inmo.tgbotapi.types.LongSeconds import dev.inmo.tgbotapi.types.Seconds import dev.inmo.tgbotapi.types.polls.ApproximateScheduledCloseInfo import dev.inmo.tgbotapi.types.polls.ExactScheduledCloseInfo -import com.soywiz.klock.DateTime -import com.soywiz.klock.TimeSpan fun closePollExactAt( dateTime: DateTime diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/CommandsFilters.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/CommandsFilters.kt index 69f4bc69f0..6d553cf32e 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/CommandsFilters.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/CommandsFilters.kt @@ -9,7 +9,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.types.message.content.fullEntitiesList import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate -import kotlinx.coroutines.flow.* +import kotlinx.coroutines.flow.Flow /** * Convert incoming [dev.inmo.tgbotapi.types.message.abstracts.ContentMessage.content] of diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/InlineQueryUpdatesConversations.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/InlineQueryUpdatesConversations.kt index 635d677f95..ab324e7771 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/InlineQueryUpdatesConversations.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/InlineQueryUpdatesConversations.kt @@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.types.InlineQueries.query.BaseInlineQuery import dev.inmo.tgbotapi.types.InlineQueries.query.LocationInlineQuery import dev.inmo.tgbotapi.types.UpdateIdentifier import dev.inmo.tgbotapi.types.update.InlineQueryUpdate -import kotlinx.coroutines.flow.* +import kotlinx.coroutines.flow.Flow /** * @return Mapped [Flow] with [Pair]s. [Pair.first] in this pair will be [UpdateIdentifier]. It could be useful in diff --git a/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/files/PathedFile.kt b/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/files/PathedFile.kt index 90be566896..2c70dd1c2b 100644 --- a/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/files/PathedFile.kt +++ b/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/files/PathedFile.kt @@ -1,6 +1,5 @@ package dev.inmo.tgbotapi.types.files -import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper import java.io.File import java.io.FileOutputStream From e45f9cf46ae6827f6309911309d9f4a666a5654d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 6 Nov 2020 00:37:56 +0600 Subject: [PATCH 28/42] return serialname for messageId in RawMessage --- .../kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index f218311a4a..f9aa545c75 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -22,12 +22,14 @@ import dev.inmo.tgbotapi.types.payments.Invoice import dev.inmo.tgbotapi.types.payments.SuccessfulPayment import dev.inmo.tgbotapi.types.polls.Poll import dev.inmo.tgbotapi.types.venue.Venue +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlin.reflect.KClass // TODO:: add PassportData type @Serializable internal data class RawMessage( + @SerialName(messageIdField) val messageId: MessageIdentifier, val date: TelegramDate, private val chat: Chat, From 00a75801a8448c18bc26cbaa632db7d416fff57d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 6 Nov 2020 01:14:48 +0600 Subject: [PATCH 29/42] fixes --- .../tgbotapi/requests/send/CopyMessage.kt | 10 +++--- .../types/MessageEntity/RawMessageEntity.kt | 33 ++++++++++--------- .../dev/inmo/tgbotapi/types/MessageId.kt | 24 ++++++++++++++ .../inmo/tgbotapi/types/message/RawMessage.kt | 5 +-- 4 files changed, 48 insertions(+), 24 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageId.kt diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt index a690f6e71b..817ff9ba0c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt @@ -13,8 +13,6 @@ import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import kotlinx.serialization.* -private val ResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass>() - fun CopyMessage( fromChatId: ChatIdentifier, toChatId: ChatIdentifier, @@ -60,8 +58,8 @@ data class CopyMessage internal constructor( override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null -): SimpleRequest>, - ReplyingMarkupSendMessageRequest>, +): SimpleRequest, + ReplyingMarkupSendMessageRequest, MessageAction, TextedOutput { override val chatId: ChatIdentifier @@ -72,8 +70,8 @@ data class CopyMessage internal constructor( override fun method(): String = "copyMessage" - override val resultDeserializer: DeserializationStrategy> - get() = ResultDeserializer + override val resultDeserializer: DeserializationStrategy + get() = MessageIdSerializer override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt index 610a384682..a91ee59882 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt @@ -84,22 +84,23 @@ internal fun createTextPart(from: String, entities: RawMessageEntities): List.asRawMessageEntities(): List = mapNotNull { val source = it.source + val length = it.range.last - it.range.first + 1 when (source) { - is MentionTextSource -> RawMessageEntity("mention", it.range.first, it.range.last - it.range.first) - is HashTagTextSource -> RawMessageEntity("hashtag", it.range.first, it.range.last - it.range.first) - is CashTagTextSource -> RawMessageEntity("cashtag", it.range.first, it.range.last - it.range.first) - is BotCommandTextSource -> RawMessageEntity("bot_command", it.range.first, it.range.last - it.range.first) - is URLTextSource -> RawMessageEntity("url", it.range.first, it.range.last - it.range.first) - is EMailTextSource -> RawMessageEntity("email", it.range.first, it.range.last - it.range.first) - is PhoneNumberTextSource -> RawMessageEntity("phone_number", it.range.first, it.range.last - it.range.first) - is BoldTextSource -> RawMessageEntity("bold", it.range.first, it.range.last - it.range.first) - is ItalicTextSource -> RawMessageEntity("italic", it.range.first, it.range.last - it.range.first) - is CodeTextSource -> RawMessageEntity("code", it.range.first, it.range.last - it.range.first) - is PreTextSource -> RawMessageEntity("pre", it.range.first, it.range.last - it.range.first, language = source.language) - is TextLinkTextSource -> RawMessageEntity("text_link", it.range.first, it.range.last - it.range.first, source.url) - is TextMentionTextSource -> RawMessageEntity("text_mention", it.range.first, it.range.last - it.range.first, user = source.user) - is UnderlineTextSource -> RawMessageEntity("underline", it.range.first, it.range.last - it.range.first) - is StrikethroughTextSource -> RawMessageEntity("strikethrough", it.range.first, it.range.last - it.range.first) + is MentionTextSource -> RawMessageEntity("mention", it.range.first, length) + is HashTagTextSource -> RawMessageEntity("hashtag", it.range.first, length) + is CashTagTextSource -> RawMessageEntity("cashtag", it.range.first, length) + is BotCommandTextSource -> RawMessageEntity("bot_command", it.range.first, length) + is URLTextSource -> RawMessageEntity("url", it.range.first, length) + is EMailTextSource -> RawMessageEntity("email", it.range.first, length) + is PhoneNumberTextSource -> RawMessageEntity("phone_number", it.range.first, length) + is BoldTextSource -> RawMessageEntity("bold", it.range.first, length) + is ItalicTextSource -> RawMessageEntity("italic", it.range.first, length) + is CodeTextSource -> RawMessageEntity("code", it.range.first, length) + is PreTextSource -> RawMessageEntity("pre", it.range.first, length, language = source.language) + is TextLinkTextSource -> RawMessageEntity("text_link", it.range.first, length, source.url) + is TextMentionTextSource -> RawMessageEntity("text_mention", it.range.first, length, user = source.user) + is UnderlineTextSource -> RawMessageEntity("underline", it.range.first, length) + is StrikethroughTextSource -> RawMessageEntity("strikethrough", it.range.first, length) else -> null } } @@ -108,7 +109,7 @@ internal fun List.toRawMessageEntities(): List { var i = 0 return map { TextPart( - i until it.source.length, + i until (i + it.source.length), it ).also { i = it.range.last + 1 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageId.kt new file mode 100644 index 0000000000..d8c73228f7 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageId.kt @@ -0,0 +1,24 @@ +package dev.inmo.tgbotapi.types + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.* + +object MessageIdSerializer : KSerializer { + override val descriptor: SerialDescriptor = JsonObject.serializer().descriptor + + override fun deserialize(decoder: Decoder): MessageIdentifier = JsonObject.serializer().deserialize(decoder)[messageIdField]!!.jsonPrimitive.long + + override fun serialize(encoder: Encoder, value: MessageIdentifier) { + JsonObject.serializer().serialize( + encoder, + JsonObject( + mapOf( + messageIdField to JsonPrimitive(value) + ) + ) + ) + } +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index f9aa545c75..55504c97e8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -22,6 +22,7 @@ import dev.inmo.tgbotapi.types.payments.Invoice import dev.inmo.tgbotapi.types.payments.SuccessfulPayment import dev.inmo.tgbotapi.types.polls.Poll import dev.inmo.tgbotapi.types.venue.Venue +import dev.inmo.tgbotapi.utils.fullListOfSubSource import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlin.reflect.KClass @@ -91,11 +92,11 @@ internal data class RawMessage( ) { private val content: MessageContent? by lazy { val adaptedCaptionEntities = caption ?.let { - caption_entities ?.asTextParts(caption) + it.fullListOfSubSource(caption_entities ?.asTextParts(caption) ?: emptyList()) } ?: emptyList() when { - text != null -> TextContent(text, entities ?.asTextParts(text) ?: emptyList()) + text != null -> TextContent(text, text.fullListOfSubSource(entities ?.asTextParts(text) ?: emptyList())) audio != null -> AudioContent( audio, caption, From c7259e7699ca9a2d58410a4ccb47332351d3e272 Mon Sep 17 00:00:00 2001 From: madhead Date: Thu, 5 Nov 2020 02:26:52 +0300 Subject: [PATCH 30/42] Fix #175: Support for message_id field in unpinChatMessage method --- CHANGELOG.md | 1 + .../requests/chat/modify/UnpinChatMessage.kt | 6 +++++- .../api/chat/modify/UnpinChatMessage.kt | 17 +++++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48d33221d4..edb9298979 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ * New fields `AudioFile#fileName` and `VideoFile#fileName` * New fields `SendDocument#disableContentTypeDetection` and `InputMediaDocument#disableContentTypeDetection` * New request `UnpinAllChatMessages` + * New parameter for `unpinChatMessage` method: `messageId` * New dice type `FootballDiceAnimationType` * Limits for dices has been changed * `commonDiceResultLimit` has been deprecated diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinChatMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinChatMessage.kt index 456d0649b9..868559b16d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinChatMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinChatMessage.kt @@ -3,14 +3,18 @@ package dev.inmo.tgbotapi.requests.chat.modify import dev.inmo.tgbotapi.CommonAbstracts.types.ChatRequest import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.chatIdField +import dev.inmo.tgbotapi.types.messageIdField import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer @Serializable data class UnpinChatMessage( @SerialName(chatIdField) - override val chatId: ChatIdentifier + override val chatId: ChatIdentifier, + @SerialName(messageIdField) + val messageId: MessageIdentifier? = null ): ChatRequest, SimpleRequest { override fun method(): String = "unpinChatMessage" override val resultDeserializer: DeserializationStrategy diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt index de540d19d3..ada3cc7b95 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt @@ -3,12 +3,21 @@ package dev.inmo.tgbotapi.extensions.api.chat.modify import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.chat.modify.UnpinChatMessage import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat +import dev.inmo.tgbotapi.types.message.abstracts.Message suspend fun TelegramBot.unpinChatMessage( - chatId: ChatIdentifier -) = execute(UnpinChatMessage(chatId)) + chatId: ChatIdentifier, + messageId: MessageIdentifier? = null +) = execute(UnpinChatMessage(chatId, messageId)) suspend fun TelegramBot.unpinChatMessage( - chat: PublicChat -) = unpinChatMessage(chat.id) + chat: Chat, + messageId: MessageIdentifier? = null +) = unpinChatMessage(chat.id, messageId) + +suspend fun TelegramBot.unpinChatMessage( + message: Message +) = unpinChatMessage(message.chat.id, message.messageId) From 824fa9ba0903ea8aa24f5420fd9b21be573d9ac1 Mon Sep 17 00:00:00 2001 From: madhead Date: Thu, 5 Nov 2020 19:13:43 +0300 Subject: [PATCH 31/42] Fix #190: Support for Google Places values in venue-related methods and types --- CHANGELOG.md | 1 + .../CommonAbstracts/CommonVenueData.kt | 11 +- .../inmo/tgbotapi/requests/send/SendVenue.kt | 31 ++-- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 4 + .../InlineQueryResultVenue.kt | 8 +- .../InputVenueMessageContent.kt | 8 +- .../dev/inmo/tgbotapi/types/venue/Venue.kt | 6 +- .../tgbotapi/extensions/api/send/SendVenue.kt | 139 ++++++++++++++++-- .../utils/extensions/venue/Foursquare.kt | 4 +- .../utils/extensions/venue/Google.kt | 27 ++++ 10 files changed, 204 insertions(+), 35 deletions(-) create mode 100644 tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Google.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index edb9298979..9c8621af44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ * Update all classes which must have `entities`/`caption_entities` fields * New request `CopyMessage` * New extension `List#makeString` for more comfortable work with new api with entities + * Support for Google Places identifiers for venues * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt index 6ee7716366..f3361259d1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt @@ -1,8 +1,15 @@ package dev.inmo.tgbotapi.CommonAbstracts +import dev.inmo.tgbotapi.types.FoursquareId +import dev.inmo.tgbotapi.types.FoursquareType +import dev.inmo.tgbotapi.types.GooglePlaceId +import dev.inmo.tgbotapi.types.GooglePlaceType + interface CommonVenueData : Titled { override val title: String val address: String - val foursquareId: String? - val foursquareType: String? // TODO:: Rewrite with enum or interface + val foursquareId: FoursquareId? + val foursquareType: FoursquareType? // TODO:: Rewrite with enum or interface + val googlePlaceId: GooglePlaceId? + val googlePlaceType: GooglePlaceType? } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt index 63be242277..fe0c5f2825 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt @@ -25,7 +25,13 @@ data class SendVenue( @SerialName(addressField) val address: String, @SerialName(foursquareIdField) - val foursquareId: String? = null, + val foursquareId: FoursquareId? = null, + @SerialName(foursquareTypeField) + val foursquareType: FoursquareType? = null, + @SerialName(googlePlaceIdField) + val googlePlaceId: GooglePlaceId? = null, + @SerialName(googlePlaceTypeField) + val googlePlaceType: GooglePlaceType? = null, @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) @@ -47,16 +53,19 @@ data class SendVenue( allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): this( - chatId, - venue.location.latitude, - venue.location.longitude, - venue.title, - venue.address, - venue.foursquareId, - disableNotification, - replyToMessageId, - allowSendingWithoutReply, - replyMarkup + chatId = chatId, + latitude = venue.location.latitude, + longitude = venue.location.longitude, + title = venue.title, + address = venue.address, + foursquareId = venue.foursquareId, + foursquareType = venue.foursquareType, + googlePlaceId = venue.googlePlaceId, + googlePlaceType = venue.googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) override fun method(): String = "sendVenue" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 5f17f8e6b8..af9fb30db5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -24,6 +24,8 @@ typealias FileUniqueId = String typealias DiceResult = Int typealias FoursquareId = String typealias FoursquareType = String +typealias GooglePlaceId = String +typealias GooglePlaceType = String typealias Seconds = Int typealias LongSeconds = Long @@ -126,6 +128,8 @@ const val showAlertField = "show_alert" const val cachedTimeField = "cached_time" const val foursquareIdField = "foursquare_id" const val foursquareTypeField = "foursquare_type" +const val googlePlaceIdField = "google_place_id" +const val googlePlaceTypeField = "google_place_type" const val untilDateField = "until_date" const val errorMessageField = "error_message" const val messageTextField = "message_text" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVenue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVenue.kt index 30ec5796f2..e514afb1dd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVenue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVenue.kt @@ -22,9 +22,13 @@ data class InlineQueryResultVenue( @SerialName(addressField) override val address: String, @SerialName(foursquareIdField) - override val foursquareId: String? = null, + override val foursquareId: FoursquareId? = null, @SerialName(foursquareTypeField) - override val foursquareType: String? = null, + override val foursquareType: FoursquareType? = null, + @SerialName(googlePlaceIdField) + override val googlePlaceId: GooglePlaceId? = null, + @SerialName(googlePlaceTypeField) + override val googlePlaceType: GooglePlaceType? = null, @SerialName(thumbUrlField) override val thumbUrl: String? = null, @SerialName(thumbWidthField) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputVenueMessageContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputVenueMessageContent.kt index f8be7df0c5..e744c10404 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputVenueMessageContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputVenueMessageContent.kt @@ -18,7 +18,11 @@ data class InputVenueMessageContent( @SerialName(addressField) override val address: String, @SerialName(foursquareIdField) - override val foursquareId: String? = null, + override val foursquareId: FoursquareId? = null, @SerialName(foursquareTypeField) - override val foursquareType: String? = null + override val foursquareType: FoursquareType? = null, + @SerialName(googlePlaceIdField) + override val googlePlaceId: GooglePlaceId? = null, + @SerialName(googlePlaceTypeField) + override val googlePlaceType: GooglePlaceType? = null ) : Locationed, CommonVenueData, InputMessageContent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt index 6482709d5c..b27c18e1e7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt @@ -18,5 +18,9 @@ data class Venue( @SerialName(foursquareIdField) override val foursquareId: FoursquareId? = null, @SerialName(foursquareTypeField) - override val foursquareType: FoursquareType? = null + override val foursquareType: FoursquareType? = null, + @SerialName(googlePlaceIdField) + override val googlePlaceId: GooglePlaceId? = null, + @SerialName(googlePlaceTypeField) + override val googlePlaceType: GooglePlaceType? = null ) : CommonVenueData, Locationed by location diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt index e23e7554e6..31cabb0734 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt @@ -3,6 +3,10 @@ package dev.inmo.tgbotapi.extensions.api.send import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.send.SendVenue import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.FoursquareId +import dev.inmo.tgbotapi.types.FoursquareType +import dev.inmo.tgbotapi.types.GooglePlaceId +import dev.inmo.tgbotapi.types.GooglePlaceType import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat @@ -16,14 +20,29 @@ suspend fun TelegramBot.sendVenue( longitude: Double, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendVenue( - chatId, latitude, longitude, title, address, foursquareId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup + chatId = chatId, + latitude = latitude, + longitude = longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) ) @@ -33,13 +52,28 @@ suspend fun TelegramBot.sendVenue( longitude: Double, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chat.id, latitude, longitude, title, address, foursquareId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup + chatId = chat.id, + latitude = latitude, + longitude = longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend fun TelegramBot.sendVenue( @@ -47,13 +81,28 @@ suspend fun TelegramBot.sendVenue( location: StaticLocation, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chatId, location.latitude, location.longitude, title, address, foursquareId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup + chatId = chatId, + latitude = location.latitude, + longitude = location.longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend fun TelegramBot.sendVenue( @@ -61,13 +110,28 @@ suspend fun TelegramBot.sendVenue( location: StaticLocation, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chat.id, location.latitude, location.longitude, title, address, foursquareId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup + chatId = chat.id, + latitude = location.latitude, + longitude = location.longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend fun TelegramBot.sendVenue( @@ -79,7 +143,12 @@ suspend fun TelegramBot.sendVenue( replyMarkup: KeyboardMarkup? = null ) = execute( SendVenue( - chatId, venue, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup + chatId = chatId, + venue = venue, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) ) @@ -91,7 +160,12 @@ suspend fun TelegramBot.sendVenue( allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chat.id, venue, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup + chatId = chat.id, + venue = venue, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend inline fun TelegramBot.reply( @@ -100,12 +174,27 @@ suspend inline fun TelegramBot.reply( longitude: Double, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - to.chat, latitude, longitude, title, address, foursquareId, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup + chat = to.chat, + latitude = latitude, + longitude = longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = to.messageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend inline fun TelegramBot.reply( @@ -113,12 +202,27 @@ suspend inline fun TelegramBot.reply( location: StaticLocation, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - to.chat, location, title, address, foursquareId, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup + chat = to.chat, + latitude = location.latitude, + longitude = location.longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = to.messageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend inline fun TelegramBot.reply( @@ -128,5 +232,10 @@ suspend inline fun TelegramBot.reply( allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - to.chat, venue, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup + chat = to.chat, + venue = venue, + disableNotification = disableNotification, + replyToMessageId = to.messageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt index 3651bb2581..66283981a9 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt @@ -7,7 +7,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable val Venue.foursquare: Foursquare? - get() = foursquareId ?.let { + get() = foursquareId?.let { Foursquare(it, foursquareType) } @@ -16,7 +16,7 @@ fun Venue( title: String, address: String, foursquare: Foursquare -) = Venue(location, title, address, foursquare.id, foursquare.type) +) = Venue(location, title, address, foursquareId = foursquare.id, foursquareType = foursquare.type) @Serializable data class Foursquare( diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Google.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Google.kt new file mode 100644 index 0000000000..04ea6a6c62 --- /dev/null +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Google.kt @@ -0,0 +1,27 @@ +package dev.inmo.tgbotapi.extensions.utils.extensions.venue + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.location.StaticLocation +import dev.inmo.tgbotapi.types.venue.Venue +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +val Venue.googlePlace: GooglePlace? + get() = googlePlaceId?.let { + GooglePlace(it, googlePlaceType) + } + +fun Venue( + location: StaticLocation, + title: String, + address: String, + googlePlace: GooglePlace +) = Venue(location, title, address, googlePlaceId = googlePlace.id, googlePlaceType = googlePlace.type) + +@Serializable +data class GooglePlace( + @SerialName(googlePlaceIdField) + val id: GooglePlaceId, + @SerialName(googlePlaceTypeField) + val type: GooglePlaceType? = null +) From c89aa7b9ba1fa258e6079cc3a2dbda141ae467c0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 6 Nov 2020 12:07:46 +0600 Subject: [PATCH 32/42] telegramBot improvements --- CHANGELOG.md | 3 +++ .../tgbotapi/utils/TelegramAPIUrlsKeeper.kt | 4 ++- .../tgbotapi/extensions/api/BotExtensions.kt | 27 ++++++++++++++----- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c8621af44..bc1f8e980d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,9 @@ * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` * Extensions `TelegramBot#promoteChatMember` got `isAnonymous` parameter + * All old api methods has been actualized to their analogs in `Core` + * All `telegramBot` with `token: String` got `apiUrl` parameter + * Factory `telegramBotWithCustomClientConfig` has been renamed to `telegramBot` ## 0.29.4 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper.kt index f6876dbe8e..1e8770804d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.utils +const val telegramBotAPIDefaultUrl = "https://api.telegram.org" + class TelegramAPIUrlsKeeper( token: String, - hostUrl: String = "https://api.telegram.org" + hostUrl: String = telegramBotAPIDefaultUrl ) { val commonAPIUrl = "$hostUrl/bot$token" val fileBaseUrl = "$hostUrl/file/bot$token" diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt index 18f9d0e72e..2300eeaba3 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.api import dev.inmo.tgbotapi.bot.Ktor.KtorRequestsExecutor import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper +import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl import io.ktor.client.HttpClient import io.ktor.client.HttpClientConfig import io.ktor.client.engine.HttpClientEngine @@ -46,24 +47,35 @@ fun telegramBotWithCustomClientConfig( * Allows to create bot using bot [token] */ fun telegramBot( - token: String -): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token)) + token: String, + apiUrl: String = telegramBotAPIDefaultUrl +): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token, apiUrl)) /** * Allows to create bot using bot [token] and already prepared [client] */ fun telegramBot( token: String, - client: HttpClient -): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token), client) + client: HttpClient, + apiUrl: String = telegramBotAPIDefaultUrl +): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), client) /** * Allows to create bot using bot [token] and configure [HttpClient] using [clientConfig] */ -fun telegramBotWithCustomClientConfig( +fun telegramBot( token: String, + apiUrl: String = telegramBotAPIDefaultUrl, clientConfig: HttpClientConfig<*>.() -> Unit -): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token), clientConfig) +): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token, apiUrl), clientConfig) + +@Suppress("NOTHING_TO_INLINE") +@Deprecated("Renamed", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot")) +inline fun telegramBotWithCustomClientConfig( + token: String, + apiUrl: String = telegramBotAPIDefaultUrl, + noinline clientConfig: HttpClientConfig<*>.() -> Unit +) = telegramBot(token, apiUrl, clientConfig) /** * Allows to create bot using bot [token] and specify [HttpClientEngine] by passing [clientEngine] param and optionally @@ -72,5 +84,6 @@ fun telegramBotWithCustomClientConfig( fun telegramBot( token: String, clientEngine: HttpClientEngine, + apiUrl: String = telegramBotAPIDefaultUrl, clientConfig: HttpClientConfig<*>.() -> Unit = {} -): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token), clientEngine, clientConfig) +): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token, apiUrl), clientEngine, clientConfig) From 6ec0fcadd2f8f3819edceca55124f0e90953afc0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 6 Nov 2020 12:29:51 +0600 Subject: [PATCH 33/42] rewrite telegramBot functions --- .../tgbotapi/extensions/api/BotExtensions.kt | 140 +++++++++++++----- 1 file changed, 99 insertions(+), 41 deletions(-) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt index 2300eeaba3..f3f02d62a2 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt @@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl import io.ktor.client.HttpClient import io.ktor.client.HttpClientConfig -import io.ktor.client.engine.HttpClientEngine +import io.ktor.client.engine.* /** * Allows to create bot using bot [urlsKeeper] and already prepared [client] @@ -19,14 +19,108 @@ fun telegramBot( client ) +/** + * Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngineFactory] by passing [clientFactory] param and optionally + * configure it with [clientConfig] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + urlsKeeper: TelegramAPIUrlsKeeper, + clientFactory: HttpClientEngineFactory, + noinline clientConfig: HttpClientConfig.() -> Unit = {} +) = telegramBot( + urlsKeeper, + HttpClient(clientFactory, clientConfig) +) + /** * Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngine] by passing [clientEngine] param and optionally * configure [HttpClient] using [clientConfig] */ +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + urlsKeeper: TelegramAPIUrlsKeeper, + clientEngine: HttpClientEngine, + noinline clientConfig: HttpClientConfig<*>.() -> Unit = {} +) = telegramBot( + urlsKeeper, + HttpClient(clientEngine, clientConfig) +) + +/** + * Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngine] by configuring [HttpClient] using + * [clientConfig] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + urlsKeeper: TelegramAPIUrlsKeeper, + noinline clientConfig: HttpClientConfig<*>.() -> Unit +) = telegramBot( + urlsKeeper, + HttpClient(clientConfig) +) + +/** + * Allows to create bot using bot [token], [apiUrl] (for custom api servers) and already prepared [client] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + token: String, + apiUrl: String = telegramBotAPIDefaultUrl, + client: HttpClient = HttpClient() +): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), client) + +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + token: String, + clientFactory: HttpClientEngineFactory, + apiUrl: String = telegramBotAPIDefaultUrl, + noinline clientConfig: HttpClientConfig.() -> Unit = {} +) = telegramBot( + TelegramAPIUrlsKeeper(token, apiUrl), + clientFactory, + clientConfig +) + +/** + * Allows to create bot using bot [token] and specify [HttpClientEngine] by passing [clientEngine] param and optionally + * configure [HttpClient] using [clientConfig] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + token: String, + clientEngine: HttpClientEngine, + apiUrl: String = telegramBotAPIDefaultUrl, + noinline clientConfig: HttpClientConfig<*>.() -> Unit = {} +) = telegramBot( + TelegramAPIUrlsKeeper(token, apiUrl), + clientEngine, + clientConfig +) + +/** + * Allows to create bot using bot [token] and [apiUrl] and specify [HttpClientEngine] by configuring [HttpClient] using + * [clientConfig] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + token: String, + apiUrl: String = telegramBotAPIDefaultUrl, + noinline clientConfig: HttpClientConfig<*>.() -> Unit = {} +) = telegramBot( + TelegramAPIUrlsKeeper(token, apiUrl), + clientConfig +) + +/** + * Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngine] by passing [clientEngine] param and optionally + * configure [HttpClient] using [clientConfig] + */ +@Deprecated("Will be removed in next releases", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot")) fun telegramBotWithCustomClientConfig( urlsKeeper: TelegramAPIUrlsKeeper, clientEngine: HttpClientEngine, - clientConfig: HttpClientConfig<*>.() -> Unit = {} + clientConfig: HttpClientConfig<*>.() -> Unit ): TelegramBot = telegramBot( urlsKeeper, HttpClient(clientEngine, clientConfig) @@ -35,55 +129,19 @@ fun telegramBotWithCustomClientConfig( /** * Allows to create bot using bot [urlsKeeper] and optionally configure [HttpClient] using [clientConfig] */ +@Deprecated("Will be removed in next releases", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot")) fun telegramBotWithCustomClientConfig( urlsKeeper: TelegramAPIUrlsKeeper, - clientConfig: HttpClientConfig<*>.() -> Unit = {} + clientConfig: HttpClientConfig<*>.() -> Unit ): TelegramBot = telegramBot( urlsKeeper, HttpClient(clientConfig) ) -/** - * Allows to create bot using bot [token] - */ -fun telegramBot( - token: String, - apiUrl: String = telegramBotAPIDefaultUrl -): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token, apiUrl)) - -/** - * Allows to create bot using bot [token] and already prepared [client] - */ -fun telegramBot( - token: String, - client: HttpClient, - apiUrl: String = telegramBotAPIDefaultUrl -): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), client) - -/** - * Allows to create bot using bot [token] and configure [HttpClient] using [clientConfig] - */ -fun telegramBot( - token: String, - apiUrl: String = telegramBotAPIDefaultUrl, - clientConfig: HttpClientConfig<*>.() -> Unit -): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token, apiUrl), clientConfig) - @Suppress("NOTHING_TO_INLINE") @Deprecated("Renamed", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot")) inline fun telegramBotWithCustomClientConfig( token: String, apiUrl: String = telegramBotAPIDefaultUrl, noinline clientConfig: HttpClientConfig<*>.() -> Unit -) = telegramBot(token, apiUrl, clientConfig) - -/** - * Allows to create bot using bot [token] and specify [HttpClientEngine] by passing [clientEngine] param and optionally - * configure [HttpClient] using [clientConfig] - */ -fun telegramBot( - token: String, - clientEngine: HttpClientEngine, - apiUrl: String = telegramBotAPIDefaultUrl, - clientConfig: HttpClientConfig<*>.() -> Unit = {} -): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token, apiUrl), clientEngine, clientConfig) +) = telegramBot(token, apiUrl = apiUrl, clientConfig = clientConfig) From ee6f0f3d5d8c7e1f77eb41947b44ef4e9078944c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 6 Nov 2020 12:59:55 +0600 Subject: [PATCH 34/42] add separation of text sources --- CHANGELOG.md | 4 ++ .../tgbotapi/CommonAbstracts/TextSource.kt | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc1f8e980d..bf0baa7cd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,10 @@ * New request `CopyMessage` * New extension `List#makeString` for more comfortable work with new api with entities * Support for Google Places identifiers for venues + * New extensions for text sources separating: + * `List#separateForMessage` + * `List#separateForCaption` + * `List#separateForText` * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt index c652a3aac8..fbf2541d6e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt @@ -1,5 +1,8 @@ package dev.inmo.tgbotapi.CommonAbstracts +import dev.inmo.tgbotapi.types.captionLength +import dev.inmo.tgbotapi.types.textLength + typealias FullTextSourcesList = List typealias FullTextPartsList = List @@ -22,3 +25,47 @@ data class TextPart( fun List.justTextSources() = map { it.source } fun List.makeString() = joinToString("") { it.source } +fun List.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List> { + if (isEmpty()) { + return emptyList() + } + + val resultList = mutableListOf>(mutableListOf()) + var currentPartLength = 0 + val maxSize = limit.last + 1 + + for (current in this) { + if (current.source.length > maxSize) { + error("Currently unsupported parts with size more than target one-message parts (${current.source.length} > ${maxSize})") + } + + if (currentPartLength + current.source.length > maxSize) { + if (numberOfParts == null || numberOfParts < resultList.size) { + resultList.add(mutableListOf()) + currentPartLength = 0 + } else { + break + } + } + + resultList.last().add(current) + currentPartLength += current.source.length + } + + return resultList +} + +/** + * This method will prepare [TextSource]s list for messages. Remember, that first part will be separated with + * [captionLength] and all others with + */ +fun List.separateForCaption(): List> { + val captionPart = separateForMessage(captionLength, 1).first() + return listOf(captionPart) + minus(captionPart).separateForMessage(textLength) +} + +/** + * This method will prepare [TextSource]s list for messages with [textLength] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun List.separateForText(): List> = separateForMessage(textLength) From 6665b6ef036a317e4cf32dfa99e739a2a7ed08c5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 6 Nov 2020 14:37:13 +0600 Subject: [PATCH 35/42] reorganize text sources and text parts --- .../tgbotapi/CommonAbstracts/TextSource.kt | 5 + .../types/MessageEntity/RawMessageEntity.kt | 99 +++++++++++-------- .../textsources/BoldTextSource.kt | 12 ++- .../textsources/BotCommandTextSource.kt | 10 +- .../textsources/CashTagTextSource.kt | 6 +- .../textsources/EMailTextSource.kt | 6 +- .../textsources/HashTagTextSource.kt | 10 +- .../textsources/ItalicTextSource.kt | 6 +- .../textsources/MentionTextSource.kt | 10 +- .../textsources/PhoneNumberTextSource.kt | 6 +- .../textsources/StrikethroughTextSource.kt | 6 +- .../textsources/TextMentionTextSource.kt | 6 +- .../textsources/UnderlineTextSource.kt | 6 +- .../inmo/tgbotapi/types/message/RawMessage.kt | 4 +- .../utils/MultilevelTextSourceFormatting.kt | 39 ++++---- .../MessageEntity/TextPartsCreatingTests.kt | 85 ++++------------ 16 files changed, 133 insertions(+), 183 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt index fbf2541d6e..9113ee5c18 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.CommonAbstracts +import dev.inmo.tgbotapi.types.MessageEntity.toTextParts import dev.inmo.tgbotapi.types.captionLength import dev.inmo.tgbotapi.types.textLength @@ -15,7 +16,10 @@ interface TextSource { interface MultilevelTextSource : TextSource { + @Deprecated("Will be removed in near major release") val textParts: List + get() = textParts(0) + val textSources: List } data class TextPart( @@ -25,6 +29,7 @@ data class TextPart( fun List.justTextSources() = map { it.source } fun List.makeString() = joinToString("") { it.source } +fun MultilevelTextSource.textParts(offset: Int): List = textSources.toTextParts(offset) fun List.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List> { if (isEmpty()) { return emptyList() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt index a91ee59882..ce48f51baa 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.types.MessageEntity import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.types.User +import dev.inmo.tgbotapi.utils.fullListOfSubSource import dev.inmo.tgbotapi.utils.shiftSourcesToTheLeft import kotlinx.serialization.Serializable @@ -16,26 +17,29 @@ internal data class RawMessageEntity( val language: String? = null ) -internal fun RawMessageEntity.asTextParts(source: String, subParts: List): List { - val sourceSubstring = source.substring(offset, offset + length) +internal fun RawMessageEntity.asTextParts( + source: String, + subParts: List +): List { + val sourceSubstring: String = source.substring(offset, offset + length) val range = offset until (offset + length) - val shiftedSubParts = subParts.shiftSourcesToTheLeft(offset) + val shiftedSubSources = sourceSubstring.fullListOfSubSource(subParts.shiftSourcesToTheLeft(offset)).justTextSources() return when (type) { - "mention" -> MentionTextSource(sourceSubstring, shiftedSubParts) - "hashtag" -> HashTagTextSource(sourceSubstring, shiftedSubParts) - "cashtag" -> CashTagTextSource(sourceSubstring, shiftedSubParts) - "bot_command" -> BotCommandTextSource(sourceSubstring, shiftedSubParts) + "mention" -> MentionTextSource(sourceSubstring, shiftedSubSources) + "hashtag" -> HashTagTextSource(sourceSubstring, shiftedSubSources) + "cashtag" -> CashTagTextSource(sourceSubstring, shiftedSubSources) + "bot_command" -> BotCommandTextSource(sourceSubstring, shiftedSubSources) "url" -> URLTextSource(sourceSubstring) - "email" -> EMailTextSource(sourceSubstring, shiftedSubParts) - "phone_number" -> PhoneNumberTextSource(sourceSubstring, shiftedSubParts) - "bold" -> BoldTextSource(sourceSubstring, shiftedSubParts) - "italic" -> ItalicTextSource(sourceSubstring, shiftedSubParts) + "email" -> EMailTextSource(sourceSubstring, shiftedSubSources) + "phone_number" -> PhoneNumberTextSource(sourceSubstring, shiftedSubSources) + "bold" -> BoldTextSource(sourceSubstring, shiftedSubSources) + "italic" -> ItalicTextSource(sourceSubstring, shiftedSubSources) "code" -> CodeTextSource(sourceSubstring) "pre" -> PreTextSource(sourceSubstring, language) "text_link" -> TextLinkTextSource(sourceSubstring, url ?: throw IllegalStateException("URL must not be null for text link")) - "text_mention" -> TextMentionTextSource(sourceSubstring, user ?: throw IllegalStateException("User must not be null for text mention"), shiftedSubParts) - "underline" -> UnderlineTextSource(sourceSubstring, shiftedSubParts) - "strikethrough" -> StrikethroughTextSource(sourceSubstring, shiftedSubParts) + "text_mention" -> TextMentionTextSource(sourceSubstring, user ?: throw IllegalStateException("User must not be null for text mention"), shiftedSubSources) + "underline" -> UnderlineTextSource(sourceSubstring, shiftedSubSources) + "strikethrough" -> StrikethroughTextSource(sourceSubstring, shiftedSubSources) else -> RegularTextSource(sourceSubstring) }.let { val part = TextPart(range, it) @@ -47,7 +51,7 @@ internal fun RawMessageEntity.asTextParts(source: String, subParts: List { +internal fun createTextPart(originalFullString: String, entities: RawMessageEntities): List { val mutableEntities = entities.toMutableList() mutableEntities.sortBy { it.offset } val resultList = mutableListOf() @@ -73,8 +77,8 @@ internal fun createTextPart(from: String, entities: RawMessageEntities): List.asRawMessageEntities(): List = mapNotNull { - val source = it.source - val length = it.range.last - it.range.first + 1 - when (source) { - is MentionTextSource -> RawMessageEntity("mention", it.range.first, length) - is HashTagTextSource -> RawMessageEntity("hashtag", it.range.first, length) - is CashTagTextSource -> RawMessageEntity("cashtag", it.range.first, length) - is BotCommandTextSource -> RawMessageEntity("bot_command", it.range.first, length) - is URLTextSource -> RawMessageEntity("url", it.range.first, length) - is EMailTextSource -> RawMessageEntity("email", it.range.first, length) - is PhoneNumberTextSource -> RawMessageEntity("phone_number", it.range.first, length) - is BoldTextSource -> RawMessageEntity("bold", it.range.first, length) - is ItalicTextSource -> RawMessageEntity("italic", it.range.first, length) - is CodeTextSource -> RawMessageEntity("code", it.range.first, length) - is PreTextSource -> RawMessageEntity("pre", it.range.first, length, language = source.language) - is TextLinkTextSource -> RawMessageEntity("text_link", it.range.first, length, source.url) - is TextMentionTextSource -> RawMessageEntity("text_mention", it.range.first, length, user = source.user) - is UnderlineTextSource -> RawMessageEntity("underline", it.range.first, length) - is StrikethroughTextSource -> RawMessageEntity("strikethrough", it.range.first, length) - else -> null +internal fun TextPart.asRawMessageEntities(): List { + val source = source + val length = range.last - range.first + 1 + + return listOfNotNull( + when (source) { + is MentionTextSource -> RawMessageEntity("mention", range.first, length) + is HashTagTextSource -> RawMessageEntity("hashtag", range.first, length) + is CashTagTextSource -> RawMessageEntity("cashtag", range.first, length) + is BotCommandTextSource -> RawMessageEntity("bot_command", range.first, length) + is URLTextSource -> RawMessageEntity("url", range.first, length) + is EMailTextSource -> RawMessageEntity("email", range.first, length) + is PhoneNumberTextSource -> RawMessageEntity("phone_number", range.first, length) + is BoldTextSource -> RawMessageEntity("bold", range.first, length) + is ItalicTextSource -> RawMessageEntity("italic", range.first, length) + is CodeTextSource -> RawMessageEntity("code", range.first, length) + is PreTextSource -> RawMessageEntity("pre", range.first, length, language = source.language) + is TextLinkTextSource -> RawMessageEntity("text_link", range.first, length, source.url) + is TextMentionTextSource -> RawMessageEntity("text_mention", range.first, length, user = source.user) + is UnderlineTextSource -> RawMessageEntity("underline", range.first, length) + is StrikethroughTextSource -> RawMessageEntity("strikethrough", range.first, length) + else -> null + } + ) + if (source is MultilevelTextSource) { + source.textParts(range.first).asRawMessageEntities() + } else { + emptyList() } } -internal fun List.toRawMessageEntities(): List { - var i = 0 +internal fun List.asRawMessageEntities(): List = flatMap { it.asRawMessageEntities() } + +internal fun List.toTextParts(preOffset: Int = 0): List { + var i = preOffset return map { TextPart( i until (i + it.source.length), @@ -114,9 +127,13 @@ internal fun List.toRawMessageEntities(): List { ).also { i = it.range.last + 1 } - }.asRawMessageEntities() + } } -internal fun RawMessageEntities.asTextParts(sourceString: String): List = createTextPart(sourceString, this) +internal fun List.toRawMessageEntities(): List = toTextParts().asRawMessageEntities() + +internal fun RawMessageEntities.asTextParts(sourceString: String): List = sourceString.fullListOfSubSource( + createTextPart(sourceString, this) +) internal typealias RawMessageEntities = List diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt index b5c2823022..882f2df3ea 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt @@ -1,15 +1,19 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.types.MessageEntity.toTextParts import dev.inmo.tgbotapi.utils.* class BoldTextSource( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asMarkdownSource: String by lazy { source.boldMarkdown() } override val asMarkdownV2Source: String by lazy { boldMarkdownV2() } override val asHtmlSource: String by lazy { boldHTML() } } + +@Suppress("NOTHING_TO_INLINE") +inline fun bold(text: String) = BoldTextSource(text, emptyList()) +@Suppress("NOTHING_TO_INLINE") +inline fun bold(parts: List) = BoldTextSource(parts.makeString(), parts) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt index eb95d69313..44a8be5e94 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt @@ -1,24 +1,18 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* private val commandRegex = Regex("[/!][^@\\s]*") class BotCommandTextSource( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { val command: String by lazy { commandRegex.find(source) ?.value ?.substring(1) ?: source.substring(1)// skip first symbol like "/" or "!" } - override val textParts: List by lazy { - command.fullListOfSubSource( - textParts.shiftSourcesToTheLeft(1) - ) - } override val asMarkdownSource: String by lazy { source.commandMarkdown() } override val asMarkdownV2Source: String by lazy { commandMarkdownV2() } override val asHtmlSource: String by lazy { commandHTML() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt index 13e490b753..b421977893 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt @@ -1,14 +1,12 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* class CashTagTextSource( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asMarkdownSource: String by lazy { source.cashTagMarkdown() } override val asMarkdownV2Source: String by lazy { cashTagMarkdownV2() } override val asHtmlSource: String by lazy { cashTagHTML() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt index f5c7450238..b4355986bf 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt @@ -1,14 +1,12 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* class EMailTextSource( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asMarkdownSource: String by lazy { source.emailMarkdown() } override val asMarkdownV2Source: String by lazy { emailMarkdownV2(source) } override val asHtmlSource: String by lazy { emailHTML(source) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt index 2cd398ad47..4ff9ddd98a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* private val String.withoutSharp @@ -13,13 +12,8 @@ private val String.withoutSharp class HashTagTextSource( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { - source.withoutSharp.fullListOfSubSource( - textParts.shiftSourcesToTheLeft(1) - ) - } override val asMarkdownSource: String by lazy { source.hashTagMarkdown() } override val asMarkdownV2Source: String by lazy { hashTagMarkdownV2() } override val asHtmlSource: String by lazy { hashTagHTML() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt index 0c8ed6fa61..d142936213 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt @@ -1,14 +1,12 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* class ItalicTextSource( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asMarkdownSource: String by lazy { source.italicMarkdown() } override val asMarkdownV2Source: String by lazy { italicMarkdownV2() } override val asHtmlSource: String by lazy { italicHTML() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt index bd3ef1efa4..f3251eea49 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* private val String.withoutCommercialAt @@ -13,13 +12,8 @@ private val String.withoutCommercialAt class MentionTextSource( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { - source.withoutCommercialAt.fullListOfSubSource( - textParts.shiftSourcesToTheLeft(1) - ) - } override val asMarkdownSource: String by lazy { source.mentionMarkdown() } override val asMarkdownV2Source: String by lazy { mentionMarkdownV2() } override val asHtmlSource: String by lazy { mentionHTML() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt index 6aabef80fa..c3c697ee73 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt @@ -1,14 +1,12 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* class PhoneNumberTextSource( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asMarkdownSource: String by lazy { source.phoneMarkdown() } override val asMarkdownV2Source: String by lazy { phoneMarkdownV2() } override val asHtmlSource: String by lazy { phoneHTML() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt index 63ec29c07f..0d34b23f2a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt @@ -1,14 +1,12 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* class StrikethroughTextSource( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asHtmlSource: String by lazy { strikethroughHTML() } override val asMarkdownV2Source: String by lazy { strikethroughMarkdownV2() } override val asMarkdownSource: String by lazy { source.strikethroughMarkdown() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt index 5109236b1b..f71cb532dc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt @@ -1,16 +1,14 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.utils.* class TextMentionTextSource( override val source: String, val user: User, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asMarkdownSource: String by lazy { source.textMentionMarkdown(user.id) } override val asMarkdownV2Source: String by lazy { textMentionMarkdownV2(user.id) } override val asHtmlSource: String by lazy { textMentionHTML(user.id) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt index 00a195bc0a..35799730da 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt @@ -1,14 +1,12 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* class UnderlineTextSource( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asMarkdownSource: String by lazy { source.underlineMarkdown() } override val asMarkdownV2Source: String by lazy { underlineMarkdownV2() } override val asHtmlSource: String by lazy { underlineHTML() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 55504c97e8..644e441646 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -92,11 +92,11 @@ internal data class RawMessage( ) { private val content: MessageContent? by lazy { val adaptedCaptionEntities = caption ?.let { - it.fullListOfSubSource(caption_entities ?.asTextParts(caption) ?: emptyList()) + (caption_entities ?: emptyList()).asTextParts(caption) } ?: emptyList() when { - text != null -> TextContent(text, text.fullListOfSubSource(entities ?.asTextParts(text) ?: emptyList())) + text != null -> TextContent(text, (entities ?: emptyList()).asTextParts(text)) audio != null -> AudioContent( audio, caption, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt index 23869d4946..0a8a14ae9b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.utils -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.link @@ -73,30 +72,30 @@ internal fun List.shiftSourcesToTheLeft(shiftCount: Int = 1): List.joinSubSourcesMarkdownV2() = joinToString("") { - it.source.asMarkdownV2Source +private fun List.joinSubSourcesMarkdownV2() = joinToString("") { + it.asMarkdownV2Source } -private fun List.joinSubSourcesHtml() = joinToString("") { - it.source.asHtmlSource +private fun List.joinSubSourcesHtml() = joinToString("") { + it.asHtmlSource } internal fun MultilevelTextSource.markdownV2Default( openControlSymbol: String, closeControlSymbol: String = openControlSymbol -) = "$openControlSymbol${textParts.joinSubSourcesMarkdownV2()}$closeControlSymbol" +) = "$openControlSymbol${textSources.joinSubSourcesMarkdownV2()}$closeControlSymbol" internal fun MultilevelTextSource.htmlDefault( openControlSymbol: String, closeControlSymbol: String = openControlSymbol -) = "<$openControlSymbol>${textParts.joinSubSourcesHtml()}" +) = "<$openControlSymbol>${textSources.joinSubSourcesHtml()}" internal fun MultilevelTextSource.linkMarkdownV2( link: String -) = "[${textParts.joinSubSourcesMarkdownV2()}](${link.escapeMarkdownV2Link()})" +) = "[${textSources.joinSubSourcesMarkdownV2()}](${link.escapeMarkdownV2Link()})" internal fun MultilevelTextSource.linkHTML( link: String -) = "${textParts.joinSubSourcesHtml()}" +) = "${textSources.joinSubSourcesHtml()}" internal fun MultilevelTextSource.emailMarkdownV2(address: String): String = linkMarkdownV2("mailto://$address") @@ -107,8 +106,8 @@ internal fun MultilevelTextSource.boldMarkdownV2(): String = markdownV2Default(m internal fun MultilevelTextSource.boldHTML(): String = htmlDefault(htmlBoldControl) -internal fun MultilevelTextSource.cashTagMarkdownV2(): String = textParts.joinSubSourcesMarkdownV2() -internal fun MultilevelTextSource.cashTagHTML(): String = textParts.joinSubSourcesHtml() +internal fun MultilevelTextSource.cashTagMarkdownV2(): String = textSources.joinSubSourcesMarkdownV2() +internal fun MultilevelTextSource.cashTagHTML(): String = textSources.joinSubSourcesHtml() internal fun MultilevelTextSource.italicMarkdownV2(): String = markdownV2Default(markdownItalicControl) @@ -126,18 +125,18 @@ internal fun MultilevelTextSource.underlineHTML(): String = htmlDefault(htmlUnde internal fun MultilevelTextSource.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link) internal fun MultilevelTextSource.textMentionHTML(userId: UserId): String = linkHTML(userId.link) -internal fun MultilevelTextSource.mentionMarkdownV2(): String = "@${textParts.joinSubSourcesMarkdownV2()}" -internal fun MultilevelTextSource.mentionHTML(): String = "@${textParts.joinSubSourcesHtml()}" +internal fun MultilevelTextSource.mentionMarkdownV2(): String = "@${textSources.joinSubSourcesMarkdownV2()}" +internal fun MultilevelTextSource.mentionHTML(): String = "@${textSources.joinSubSourcesHtml()}" -internal fun MultilevelTextSource.hashTagMarkdownV2(): String = "\\#${textParts.joinSubSourcesMarkdownV2()}" -internal fun MultilevelTextSource.hashTagHTML(): String = "#${textParts.joinSubSourcesHtml()}" +internal fun MultilevelTextSource.hashTagMarkdownV2(): String = "\\#${textSources.joinSubSourcesMarkdownV2()}" +internal fun MultilevelTextSource.hashTagHTML(): String = "#${textSources.joinSubSourcesHtml()}" -internal fun MultilevelTextSource.phoneMarkdownV2(): String = textParts.joinSubSourcesMarkdownV2() -internal fun MultilevelTextSource.phoneHTML(): String = textParts.joinSubSourcesHtml() +internal fun MultilevelTextSource.phoneMarkdownV2(): String = textSources.joinSubSourcesMarkdownV2() +internal fun MultilevelTextSource.phoneHTML(): String = textSources.joinSubSourcesHtml() -internal fun MultilevelTextSource.commandMarkdownV2(): String = "/${textParts.joinSubSourcesMarkdownV2()}" -internal fun MultilevelTextSource.commandHTML(): String = "/${textParts.joinSubSourcesHtml()}" +internal fun MultilevelTextSource.commandMarkdownV2(): String = "/${textSources.joinSubSourcesMarkdownV2()}" +internal fun MultilevelTextSource.commandHTML(): String = "/${textSources.joinSubSourcesHtml()}" diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt index f39a5cfef0..afb30a7196 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.MessageEntity +import dev.inmo.tgbotapi.CommonAbstracts.justTextSources import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.utils.* import kotlin.test.* @@ -32,43 +33,21 @@ class TextPartsCreatingTests { ) ) - val textParts = createTextPart(text, entities) + val textParts = entities.asTextParts(text) + assertTrue (textParts.first().source is RegularTextSource) + assertTrue (textParts[1].source is BoldTextSource) + assertTrue (textParts[2].source is RegularTextSource) - assertTrue ( - textParts.first().source is BoldTextSource - ) - - val boldSource = textParts.first().source as BoldTextSource - assertTrue ( - boldSource.textParts.first().source is ItalicTextSource - ) - assertTrue ( - boldSource.textParts[1].source is RegularTextSource - ) - assertTrue ( - boldSource.textParts[2].source is StrikethroughTextSource - ) - assertTrue ( - (boldSource.textParts[2].source as StrikethroughTextSource).textParts.first().source is UnderlineTextSource - ) - - - val fullTextParts = text.fullListOfSubSource(textParts) - - assertTrue( - fullTextParts.first().source is RegularTextSource - ) - assertTrue( - fullTextParts[1].source is BoldTextSource - ) - assertTrue( - fullTextParts[2].source is RegularTextSource - ) + val boldSource = textParts[1].source as BoldTextSource + assertTrue (boldSource.textSources.first() is ItalicTextSource) + assertTrue (boldSource.textSources[1] is RegularTextSource) + assertTrue (boldSource.textSources[2] is StrikethroughTextSource) + assertTrue ((boldSource.textSources[2] as StrikethroughTextSource).textSources.first() is UnderlineTextSource) assertEquals( formattedV2Text, - createMarkdownV2Text(fullTextParts.map { it.source }).first() + textParts.justTextSources().toMarkdownV2Texts().first() ) } @@ -99,43 +78,21 @@ class TextPartsCreatingTests { ) ) - val textParts = createTextPart(text, entities) + val textParts = entities.asTextParts(text) + assertTrue (textParts.first().source is RegularTextSource) + assertTrue (textParts[1].source is BoldTextSource) + assertTrue (textParts[2].source is RegularTextSource) - assertTrue ( - textParts.first().source is BoldTextSource - ) - - val boldSource = textParts.first().source as BoldTextSource - assertTrue ( - boldSource.textParts.first().source is ItalicTextSource - ) - assertTrue ( - boldSource.textParts[1].source is RegularTextSource - ) - assertTrue ( - boldSource.textParts[2].source is StrikethroughTextSource - ) - assertTrue ( - (boldSource.textParts[2].source as StrikethroughTextSource).textParts.first().source is UnderlineTextSource - ) - - - val fullTextParts = text.fullListOfSubSource(textParts) - - assertTrue( - fullTextParts.first().source is RegularTextSource - ) - assertTrue( - fullTextParts[1].source is BoldTextSource - ) - assertTrue( - fullTextParts[2].source is RegularTextSource - ) + val boldSource = textParts[1].source as BoldTextSource + assertTrue (boldSource.textSources.first() is ItalicTextSource) + assertTrue (boldSource.textSources[1] is RegularTextSource) + assertTrue (boldSource.textSources[2] is StrikethroughTextSource) + assertTrue ((boldSource.textSources[2] as StrikethroughTextSource).textSources.first() is UnderlineTextSource) assertEquals( formattedHtmlText, - createHtmlText(fullTextParts.map { it.source }).first() + textParts.justTextSources().toHtmlTexts().first() ) } } From 54cfea9adfb3d6ad4f261539552a3255e0e66c64 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 6 Nov 2020 14:42:30 +0600 Subject: [PATCH 36/42] fill changelog --- CHANGELOG.md | 5 +++++ .../kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf0baa7cd7..63731b1d96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,11 @@ * `List#separateForMessage` * `List#separateForCaption` * `List#separateForText` + * Rewritten work with text sources and text parts: + * Now any `Message` type with entities will have full list of entities. That means that parts without any + formatter entities will use `RegularTextSource` + * `MultilevelTextSource#textParts` has been deprecated. Now each `MultilevelTextSource` have its own + `textSources` list * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt index 9113ee5c18..bf20cd6b82 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt @@ -29,7 +29,7 @@ data class TextPart( fun List.justTextSources() = map { it.source } fun List.makeString() = joinToString("") { it.source } -fun MultilevelTextSource.textParts(offset: Int): List = textSources.toTextParts(offset) +internal fun MultilevelTextSource.textParts(offset: Int): List = textSources.toTextParts(offset) fun List.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List> { if (isEmpty()) { return emptyList() From 3620350cc0d6a3b8f6a6418cbcfccb3cceb79833 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 6 Nov 2020 18:52:59 +0600 Subject: [PATCH 37/42] add simple text dsl for textsources --- .../tgbotapi/CommonAbstracts/Captioned.kt | 2 +- .../tgbotapi/CommonAbstracts/Explained.kt | 2 +- .../tgbotapi/CommonAbstracts/TextSource.kt | 17 +++++ .../inmo/tgbotapi/CommonAbstracts/Texted.kt | 2 +- .../types/MessageEntity/RawMessageEntity.kt | 8 +- .../textsources/BoldTextSource.kt | 11 ++- .../textsources/BotCommandTextSource.kt | 21 +++-- .../textsources/CashTagTextSource.kt | 12 ++- .../textsources/CodeTextSource.kt | 9 ++- .../textsources/EMailTextSource.kt | 12 ++- .../textsources/HashTagTextSource.kt | 28 +++++-- .../textsources/ItalicTextSource.kt | 13 +++- .../textsources/MentionTextSource.kt | 24 +++++- .../textsources/PhoneNumberTextSource.kt | 13 +++- .../textsources/PreTextSource.kt | 11 ++- .../textsources/RegularTextSource.kt | 10 ++- .../textsources/StrikethroughTextSource.kt | 14 +++- .../textsources/TextLinkTextSource.kt | 10 ++- .../textsources/TextMentionTextSource.kt | 12 ++- .../textsources/URLTextSource.kt | 10 ++- .../textsources/UnderlineTextSource.kt | 14 +++- .../types/message/content/TextContent.kt | 4 +- .../utils/CaptionAndTextSourcesToText.kt | 22 +++--- .../utils/MultilevelTextSourceFormatting.kt | 25 ++++-- .../types/MessageEntity/EntitiesTestText.kt | 56 ++++++++++++++ .../MessageEntity}/StringFormattingTests.kt | 22 +++++- .../MessageEntity/TextPartsCreatingTests.kt | 76 +------------------ .../tgbotapi/extensions/api/BotExtensions.kt | 25 +++++- .../formatting/ResendingTextFormatting.kt | 26 +++---- 29 files changed, 363 insertions(+), 148 deletions(-) create mode 100644 tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/EntitiesTestText.kt rename tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/{utils => types/MessageEntity}/StringFormattingTests.kt (55%) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt index e9145102ab..5d55cc4854 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt @@ -23,4 +23,4 @@ interface CaptionedInput : Captioned { * Convert its [CaptionedInput.captionEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource] * with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] */ -fun CaptionedInput.fullEntitiesList(): FullTextSourcesList = caption ?.fullListOfSubSource(captionEntities) ?.map { it.source } ?: emptyList() +fun CaptionedInput.fullEntitiesList(): TextSourcesList = caption ?.fullListOfSubSource(captionEntities) ?.map { it.source } ?: emptyList() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt index dd1e659658..40770b027c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt @@ -29,4 +29,4 @@ interface ExplainedInput : Explained { * Convert its [ExplainedInput.explanationEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource] * with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] */ -fun ExplainedInput.fullEntitiesList(): FullTextSourcesList = explanation ?.fullListOfSubSource(explanationEntities) ?.map { it.source } ?: emptyList() +fun ExplainedInput.fullEntitiesList(): TextSourcesList = explanation ?.fullListOfSubSource(explanationEntities) ?.map { it.source } ?: emptyList() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt index bf20cd6b82..aac31893f5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt @@ -1,10 +1,16 @@ package dev.inmo.tgbotapi.CommonAbstracts +import dev.inmo.tgbotapi.types.MessageEntity.textsources.regular import dev.inmo.tgbotapi.types.MessageEntity.toTextParts import dev.inmo.tgbotapi.types.captionLength import dev.inmo.tgbotapi.types.textLength +const val DirectInvocationOfTextSourceConstructor = "It is strongly not recommended to use constructors directly instead of factory methods" + +typealias TextSourcesList = List +@Deprecated("All lists of TextSource in public API now are full. So, this typealias is redundant") typealias FullTextSourcesList = List +@Deprecated("All lists of TextPart in public API now are full. So, this typealias is redundant") typealias FullTextPartsList = List interface TextSource { @@ -12,8 +18,19 @@ interface TextSource { val asMarkdownV2Source: String val asHtmlSource: String val source: String + + val asText: String + get() = source } +@Suppress("NOTHING_TO_INLINE") +inline operator fun TextSource.plus(other: TextSource) = listOf(this, other) +@Suppress("NOTHING_TO_INLINE") +inline operator fun TextSource.plus(other: List) = listOf(this) + other +@Suppress("NOTHING_TO_INLINE") +inline operator fun TextSource.plus(text: String) = listOf(this, regular(text)) +@Suppress("NOTHING_TO_INLINE") +inline operator fun List.plus(text: String) = this + regular(text) interface MultilevelTextSource : TextSource { @Deprecated("Will be removed in near major release") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt index b28b796591..9b5ade197b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt @@ -29,4 +29,4 @@ interface TextedInput : Texted { * Convert its [TextedInput.textEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource] * with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] */ -fun TextedInput.fullEntitiesList(): FullTextSourcesList = text ?.fullListOfSubSource(textEntities) ?.map { it.source } ?: emptyList() +fun TextedInput.fullEntitiesList(): TextSourcesList = text ?.fullListOfSubSource(textEntities) ?.map { it.source } ?: emptyList() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt index ce48f51baa..e41728b732 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt @@ -28,7 +28,7 @@ internal fun RawMessageEntity.asTextParts( "mention" -> MentionTextSource(sourceSubstring, shiftedSubSources) "hashtag" -> HashTagTextSource(sourceSubstring, shiftedSubSources) "cashtag" -> CashTagTextSource(sourceSubstring, shiftedSubSources) - "bot_command" -> BotCommandTextSource(sourceSubstring, shiftedSubSources) + "bot_command" -> BotCommandTextSource(sourceSubstring) "url" -> URLTextSource(sourceSubstring) "email" -> EMailTextSource(sourceSubstring, shiftedSubSources) "phone_number" -> PhoneNumberTextSource(sourceSubstring, shiftedSubSources) @@ -130,6 +130,12 @@ internal fun List.toTextParts(preOffset: Int = 0): List { } } +fun String.removeLeading(word: String) = if (startsWith(word)){ + substring(word.length) +} else { + this +} + internal fun List.toRawMessageEntities(): List = toTextParts().asRawMessageEntities() internal fun RawMessageEntities.asTextParts(sourceString: String): List = sourceString.fullListOfSubSource( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt index 882f2df3ea..41345fe1e0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt @@ -4,7 +4,10 @@ import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.MessageEntity.toTextParts import dev.inmo.tgbotapi.utils.* -class BoldTextSource( +/** + * @see bold + */ +data class BoldTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val textSources: List ) : MultilevelTextSource { @@ -13,7 +16,9 @@ class BoldTextSource( override val asHtmlSource: String by lazy { boldHTML() } } -@Suppress("NOTHING_TO_INLINE") -inline fun bold(text: String) = BoldTextSource(text, emptyList()) @Suppress("NOTHING_TO_INLINE") inline fun bold(parts: List) = BoldTextSource(parts.makeString(), parts) +@Suppress("NOTHING_TO_INLINE") +inline fun bold(vararg parts: TextSource) = bold(parts.toList()) +@Suppress("NOTHING_TO_INLINE") +inline fun bold(text: String) = bold(regular(text)) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt index 44a8be5e94..ed79857629 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt @@ -1,19 +1,28 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.types.MessageEntity.removeLeading import dev.inmo.tgbotapi.utils.* private val commandRegex = Regex("[/!][^@\\s]*") -class BotCommandTextSource( - override val source: String, - override val textSources: List -) : MultilevelTextSource { +/** + * @see botCommand + */ +data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( + override val source: String +) : TextSource { val command: String by lazy { commandRegex.find(source) ?.value ?.substring(1) ?: source.substring(1)// skip first symbol like "/" or "!" } override val asMarkdownSource: String by lazy { source.commandMarkdown() } - override val asMarkdownV2Source: String by lazy { commandMarkdownV2() } - override val asHtmlSource: String by lazy { commandHTML() } + override val asMarkdownV2Source: String by lazy { source.commandMarkdownV2() } + override val asHtmlSource: String by lazy { source.commandHTML() } } + +/** + * @param command Without leading "/" + */ +@Suppress("NOTHING_TO_INLINE") +inline fun botCommand(command: String) = BotCommandTextSource("/$command") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt index b421977893..504a5ebe2f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt @@ -3,7 +3,10 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* -class CashTagTextSource( +/** + * @see cashTag + */ +data class CashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val textSources: List ) : MultilevelTextSource { @@ -11,3 +14,10 @@ class CashTagTextSource( override val asMarkdownV2Source: String by lazy { cashTagMarkdownV2() } override val asHtmlSource: String by lazy { cashTagHTML() } } + +@Suppress("NOTHING_TO_INLINE") +inline fun cashTag(parts: List) = CashTagTextSource(parts.makeString(), parts) +@Suppress("NOTHING_TO_INLINE") +inline fun cashTag(vararg parts: TextSource) = cashTag(parts.toList()) +@Suppress("NOTHING_TO_INLINE") +inline fun cashTag(tag: String) = cashTag(regular(tag)) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt index c47cbbdb91..d4102a622e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt @@ -1,12 +1,19 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources +import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.utils.* -class CodeTextSource( +/** + * @see code + */ +data class CodeTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String ) : TextSource { override val asMarkdownSource: String by lazy { source.codeMarkdown() } override val asMarkdownV2Source: String by lazy { source.codeMarkdownV2() } override val asHtmlSource: String by lazy { source.codeHTML() } } + +@Suppress("NOTHING_TO_INLINE") +inline fun code(code: String) = CodeTextSource(code) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt index b4355986bf..9fceafd296 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt @@ -3,7 +3,10 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* -class EMailTextSource( +/** + * @see email + */ +data class EMailTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val textSources: List ) : MultilevelTextSource { @@ -11,3 +14,10 @@ class EMailTextSource( override val asMarkdownV2Source: String by lazy { emailMarkdownV2(source) } override val asHtmlSource: String by lazy { emailHTML(source) } } + +@Suppress("NOTHING_TO_INLINE") +inline fun email(parts: List) = EMailTextSource(parts.makeString(), parts) +@Suppress("NOTHING_TO_INLINE") +inline fun email(vararg parts: TextSource) = email(parts.toList()) +@Suppress("NOTHING_TO_INLINE") +inline fun email(emailAddress: String) = email(regular(emailAddress)) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt index 4ff9ddd98a..f7f2787c07 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt @@ -3,18 +3,30 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* -private val String.withoutSharp - get() = if (startsWith("#")){ - substring(1) - } else { - this - } - -class HashTagTextSource( +/** + * @see hashtag + */ +data class HashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val textSources: List ) : MultilevelTextSource { override val asMarkdownSource: String by lazy { source.hashTagMarkdown() } override val asMarkdownV2Source: String by lazy { hashTagMarkdownV2() } override val asHtmlSource: String by lazy { hashTagHTML() } + + init { + if (!source.startsWith("#")) { + error("HashTag source must starts with #, but actual value is \"$source\"") + } + } } + +@Suppress("NOTHING_TO_INLINE", "EXPERIMENTAL_API_USAGE") +inline fun hashtag(parts: List) = (regular("#") + parts).let { HashTagTextSource(it.makeString(), it) } +@Suppress("NOTHING_TO_INLINE") +inline fun hashtag(vararg parts: TextSource) = hashtag(parts.toList()) +/** + * Without sharp (#) + */ +@Suppress("NOTHING_TO_INLINE") +inline fun hashtag(hashtag: String) = hashtag(regular(hashtag)) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt index d142936213..8821e1a05b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt @@ -3,7 +3,10 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* -class ItalicTextSource( +/** + * @see italic + */ +data class ItalicTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val textSources: List ) : MultilevelTextSource { @@ -11,3 +14,11 @@ class ItalicTextSource( override val asMarkdownV2Source: String by lazy { italicMarkdownV2() } override val asHtmlSource: String by lazy { italicHTML() } } + +@Suppress("NOTHING_TO_INLINE") +inline fun italic(parts: List) = ItalicTextSource(parts.makeString(), parts) +@Suppress("NOTHING_TO_INLINE") +inline fun italic(vararg parts: TextSource) = italic(parts.toList()) +@Suppress("NOTHING_TO_INLINE") +inline fun italic(text: String) = italic(regular(text)) + diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt index f3251eea49..0c6a168053 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.types.MessageEntity.removeLeading import dev.inmo.tgbotapi.utils.* private val String.withoutCommercialAt @@ -10,11 +11,32 @@ private val String.withoutCommercialAt this } -class MentionTextSource( +/** + * @see mention + */ +data class MentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val textSources: List ) : MultilevelTextSource { override val asMarkdownSource: String by lazy { source.mentionMarkdown() } override val asMarkdownV2Source: String by lazy { mentionMarkdownV2() } override val asHtmlSource: String by lazy { mentionHTML() } + + init { + if (!source.startsWith("@")) { + error("Mention source must starts with @, but actual value is \"$source\"") + } + } } + +@Suppress("NOTHING_TO_INLINE") +inline fun mention(parts: List) = (regular("@") + parts).let { MentionTextSource(it.makeString(), it) } +@Suppress("NOTHING_TO_INLINE") +inline fun mention(vararg parts: TextSource) = mention(parts.toList()) + +/** + * Without leading "@" + */ +@Suppress("NOTHING_TO_INLINE") +inline fun mention(whoToMention: String) = mention(regular(whoToMention)) + diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt index c3c697ee73..dada89e413 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt @@ -3,7 +3,10 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* -class PhoneNumberTextSource( +/** + * @see phone + */ +data class PhoneNumberTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val textSources: List ) : MultilevelTextSource { @@ -11,3 +14,11 @@ class PhoneNumberTextSource( override val asMarkdownV2Source: String by lazy { phoneMarkdownV2() } override val asHtmlSource: String by lazy { phoneHTML() } } + +@Suppress("NOTHING_TO_INLINE") +inline fun phone(parts: List) = PhoneNumberTextSource(parts.makeString(), parts) +@Suppress("NOTHING_TO_INLINE") +inline fun phone(vararg parts: TextSource) = phone(parts.toList()) +@Suppress("NOTHING_TO_INLINE") +inline fun phone(number: String) = phone(regular(number)) + diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt index efebe3d252..62e4371746 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt @@ -1,9 +1,12 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* -class PreTextSource( +/** + * @see pre + */ +data class PreTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, val language: String? = null ) : TextSource { @@ -11,3 +14,7 @@ class PreTextSource( override val asMarkdownV2Source: String by lazy { source.preMarkdownV2(language) } override val asHtmlSource: String by lazy { source.preHTML(language) } } + +@Suppress("NOTHING_TO_INLINE") +inline fun pre(code: String, language: String? = null) = PreTextSource(code, language) + diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt index 4439bcaf4d..87807b935d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt @@ -1,12 +1,18 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* -class RegularTextSource( +/** + * @see regular + */ +data class RegularTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String ) : TextSource { override val asMarkdownSource: String by lazy { source.regularMarkdown() } override val asMarkdownV2Source: String by lazy { source.regularMarkdownV2() } override val asHtmlSource: String by lazy { source.regularHtml() } } + +@Suppress("NOTHING_TO_INLINE") +inline fun regular(text: String) = RegularTextSource(text) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt index 0d34b23f2a..34a5cb9775 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt @@ -3,11 +3,21 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* -class StrikethroughTextSource( +/** + * @see strikethrough + */ +data class StrikethroughTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val textSources: List ) : MultilevelTextSource { override val asHtmlSource: String by lazy { strikethroughHTML() } override val asMarkdownV2Source: String by lazy { strikethroughMarkdownV2() } override val asMarkdownSource: String by lazy { source.strikethroughMarkdown() } -} \ No newline at end of file +} + +@Suppress("NOTHING_TO_INLINE") +inline fun strikethrough(parts: List) = StrikethroughTextSource(parts.makeString(), parts) +@Suppress("NOTHING_TO_INLINE") +inline fun strikethrough(vararg parts: TextSource) = strikethrough(parts.toList()) +@Suppress("NOTHING_TO_INLINE") +inline fun strikethrough(text: String) = strikethrough(regular(text)) \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt index 82bc46c3b3..0a8a3c512b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt @@ -1,9 +1,12 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* -class TextLinkTextSource( +/** + * @see link + */ +data class TextLinkTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, val url: String ) : TextSource { @@ -11,3 +14,6 @@ class TextLinkTextSource( override val asMarkdownV2Source: String by lazy { source.linkMarkdownV2(url) } override val asHtmlSource: String by lazy { source.linkHTML(url) } } + +@Suppress("NOTHING_TO_INLINE") +inline fun link(text: String, url: String) = TextLinkTextSource(text, url) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt index f71cb532dc..086e232510 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt @@ -4,7 +4,10 @@ import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.utils.* -class TextMentionTextSource( +/** + * @see mention + */ +data class TextMentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, val user: User, override val textSources: List @@ -13,3 +16,10 @@ class TextMentionTextSource( override val asMarkdownV2Source: String by lazy { textMentionMarkdownV2(user.id) } override val asHtmlSource: String by lazy { textMentionHTML(user.id) } } + +@Suppress("NOTHING_TO_INLINE") +inline fun mention(parts: List, user: User) = TextMentionTextSource(parts.makeString(), user, parts) +@Suppress("NOTHING_TO_INLINE") +inline fun mention(user: User, vararg parts: TextSource) = mention(parts.toList(), user) +@Suppress("NOTHING_TO_INLINE") +inline fun mention(text: String, user: User) = mention(user, regular(text)) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt index b5763b8538..806d54cde9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt @@ -1,12 +1,18 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* -class URLTextSource( +/** + * @see link + */ +data class URLTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String ) : TextSource { override val asMarkdownSource: String by lazy { source.linkMarkdown(source) } override val asMarkdownV2Source: String by lazy { source.linkMarkdownV2(source) } override val asHtmlSource: String by lazy { source.linkHTML(source) } } + +@Suppress("NOTHING_TO_INLINE") +inline fun link(url: String) = URLTextSource(url) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt index 35799730da..ef6250b253 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt @@ -3,11 +3,21 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* -class UnderlineTextSource( +/** + * @see underline + */ +data class UnderlineTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val textSources: List ) : MultilevelTextSource { override val asMarkdownSource: String by lazy { source.underlineMarkdown() } override val asMarkdownV2Source: String by lazy { underlineMarkdownV2() } override val asHtmlSource: String by lazy { underlineHTML() } -} \ No newline at end of file +} + +@Suppress("NOTHING_TO_INLINE") +inline fun underline(parts: List) = UnderlineTextSource(parts.makeString(), parts) +@Suppress("NOTHING_TO_INLINE") +inline fun underline(vararg parts: TextSource) = underline(parts.toList()) +@Suppress("NOTHING_TO_INLINE") +inline fun underline(text: String) = underline(regular(text)) \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt index 33cc9c3319..4fbe499201 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt @@ -1,6 +1,6 @@ package dev.inmo.tgbotapi.types.message.content -import dev.inmo.tgbotapi.CommonAbstracts.FullTextSourcesList +import dev.inmo.tgbotapi.CommonAbstracts.TextSourcesList import dev.inmo.tgbotapi.CommonAbstracts.TextPart import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.SendTextMessage @@ -81,4 +81,4 @@ data class TextContent( * Convert its [TextContent.entities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource] * with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] */ -fun TextContent.fullEntitiesList(): FullTextSourcesList = text.fullListOfSubSource(entities).map { it.source } +fun TextContent.fullEntitiesList(): TextSourcesList = text.fullListOfSubSource(entities).map { it.source } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CaptionAndTextSourcesToText.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CaptionAndTextSourcesToText.kt index 715c9d41d0..be317d0bf3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CaptionAndTextSourcesToText.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CaptionAndTextSourcesToText.kt @@ -7,7 +7,7 @@ import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.types.message.content.fullEntitiesList internal fun createFormattedText( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last, mode: ParseMode = MarkdownParseMode ): List { @@ -48,17 +48,17 @@ internal fun createFormattedText( internal fun createMarkdownText( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last ): List = createFormattedText(entities, partLength, MarkdownParseMode) -internal fun FullTextSourcesList.toMarkdownTexts(): List = createMarkdownText( +internal fun TextSourcesList.toMarkdownTexts(): List = createMarkdownText( this, textLength.last ) internal fun TextContent.toMarkdownTexts(): List = fullEntitiesList().toMarkdownTexts() -internal fun FullTextSourcesList.toMarkdownExplanations(): List = createMarkdownText( +internal fun TextSourcesList.toMarkdownExplanations(): List = createMarkdownText( this, explanationLimit.last ) @@ -66,23 +66,23 @@ internal fun ExplainedInput.toMarkdownExplanations(): List = fullEntitie internal fun createMarkdownV2Text( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last ): List = createFormattedText(entities, partLength, MarkdownV2ParseMode) -internal fun FullTextSourcesList.toMarkdownV2Captions(): List = createMarkdownV2Text( +internal fun TextSourcesList.toMarkdownV2Captions(): List = createMarkdownV2Text( this, captionLength.last ) internal fun CaptionedInput.toMarkdownV2Captions(): List = fullEntitiesList().toMarkdownV2Captions() -internal fun FullTextSourcesList.toMarkdownV2Texts(): List = createMarkdownV2Text( +internal fun TextSourcesList.toMarkdownV2Texts(): List = createMarkdownV2Text( this, textLength.last ) internal fun TextContent.toMarkdownV2Texts(): List = fullEntitiesList().toMarkdownV2Texts() -internal fun FullTextSourcesList.toMarkdownV2Explanations(): List = createMarkdownV2Text( +internal fun TextSourcesList.toMarkdownV2Explanations(): List = createMarkdownV2Text( this, explanationLimit.last ) @@ -90,17 +90,17 @@ internal fun ExplainedInput.toMarkdownV2Explanations(): List = fullEntit internal fun createHtmlText( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last ): List = createFormattedText(entities, partLength, HTMLParseMode) -internal fun FullTextSourcesList.toHtmlCaptions(): List = createHtmlText( +internal fun TextSourcesList.toHtmlCaptions(): List = createHtmlText( this, captionLength.last ) internal fun CaptionedInput.toHtmlCaptions(): List = fullEntitiesList().toHtmlCaptions() -internal fun FullTextSourcesList.toHtmlTexts(): List = createHtmlText( +internal fun TextSourcesList.toHtmlTexts(): List = createHtmlText( this, textLength.last ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt index 0a8a14ae9b..0c6ed5bf1b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt @@ -98,6 +98,16 @@ internal fun MultilevelTextSource.linkHTML( ) = "${textSources.joinSubSourcesHtml()}" +internal fun MultilevelTextSource.optionalPrefix( + mustStartsWith: String, + controlWord: String = mustStartsWith +) = if (source.startsWith(mustStartsWith)) { + "" +} else { + controlWord +} + + internal fun MultilevelTextSource.emailMarkdownV2(address: String): String = linkMarkdownV2("mailto://$address") internal fun MultilevelTextSource.emailHTML(address: String): String = linkHTML("mailto://$address}") @@ -125,18 +135,21 @@ internal fun MultilevelTextSource.underlineHTML(): String = htmlDefault(htmlUnde internal fun MultilevelTextSource.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link) internal fun MultilevelTextSource.textMentionHTML(userId: UserId): String = linkHTML(userId.link) -internal fun MultilevelTextSource.mentionMarkdownV2(): String = "@${textSources.joinSubSourcesMarkdownV2()}" -internal fun MultilevelTextSource.mentionHTML(): String = "@${textSources.joinSubSourcesHtml()}" +internal fun MultilevelTextSource.mentionMarkdownV2(): String = optionalPrefix("@") + textSources.joinSubSourcesMarkdownV2() +internal fun MultilevelTextSource.mentionHTML(): String = optionalPrefix("@") + textSources.joinSubSourcesHtml() -internal fun MultilevelTextSource.hashTagMarkdownV2(): String = "\\#${textSources.joinSubSourcesMarkdownV2()}" -internal fun MultilevelTextSource.hashTagHTML(): String = "#${textSources.joinSubSourcesHtml()}" +internal fun MultilevelTextSource.hashTagMarkdownV2(): String = when { + source.startsWith("\\#") || source.startsWith("#") -> "" + else -> "\\#" +} + textSources.joinSubSourcesMarkdownV2() +internal fun MultilevelTextSource.hashTagHTML(): String = optionalPrefix("#") + textSources.joinSubSourcesHtml() internal fun MultilevelTextSource.phoneMarkdownV2(): String = textSources.joinSubSourcesMarkdownV2() internal fun MultilevelTextSource.phoneHTML(): String = textSources.joinSubSourcesHtml() -internal fun MultilevelTextSource.commandMarkdownV2(): String = "/${textSources.joinSubSourcesMarkdownV2()}" -internal fun MultilevelTextSource.commandHTML(): String = "/${textSources.joinSubSourcesHtml()}" +internal fun MultilevelTextSource.commandMarkdownV2(): String = optionalPrefix("/") + textSources.joinSubSourcesMarkdownV2() +internal fun MultilevelTextSource.commandHTML(): String = optionalPrefix("/") + textSources.joinSubSourcesHtml() diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/EntitiesTestText.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/EntitiesTestText.kt new file mode 100644 index 0000000000..e754be23b6 --- /dev/null +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/EntitiesTestText.kt @@ -0,0 +1,56 @@ +package dev.inmo.tgbotapi.types.MessageEntity + +import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.types.MessageEntity.textsources.* +import kotlin.test.assertTrue + +const val testText = "It is simple hello world with #tag and @mention" +const val formattedV2Text = "It *_is_ ~__simple__~* hello world with \\#tag and @mention" +const val formattedHtmlText = "It is simple hello world with #tag and @mention" +internal val testTextEntities = listOf( + RawMessageEntity( + "bold", + 3, + 9 + ), + RawMessageEntity( + "italic", + 3, + 2 + ), + RawMessageEntity( + "strikethrough", + 6, + 6 + ), + RawMessageEntity( + "underline", + 6, + 6 + ), + RawMessageEntity( + "hashtag", + 30, + 4 + ), + RawMessageEntity( + "mention", + 39, + 6 + ) +) + +fun List.testTextParts() { + assertTrue (first().source is RegularTextSource) + assertTrue (get(1).source is BoldTextSource) + assertTrue (get(2).source is RegularTextSource) + assertTrue (get(3).source is HashTagTextSource) + assertTrue (get(4).source is RegularTextSource) + assertTrue (get(5).source is MentionTextSource) + + val boldSource = get(1).source as BoldTextSource + assertTrue (boldSource.textSources.first() is ItalicTextSource) + assertTrue (boldSource.textSources[1] is RegularTextSource) + assertTrue (boldSource.textSources[2] is StrikethroughTextSource) + assertTrue ((boldSource.textSources[2] as StrikethroughTextSource).textSources.first() is UnderlineTextSource) +} diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/utils/StringFormattingTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/StringFormattingTests.kt similarity index 55% rename from tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/utils/StringFormattingTests.kt rename to tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/StringFormattingTests.kt index 7db4187b1c..b5c16de001 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/utils/StringFormattingTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/StringFormattingTests.kt @@ -1,5 +1,9 @@ -package dev.inmo.tgbotapi.utils +package dev.inmo.tgbotapi.types.MessageEntity +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.types.MessageEntity.textsources.* +import dev.inmo.tgbotapi.CommonAbstracts.plus +import dev.inmo.tgbotapi.utils.* import kotlin.test.Test import kotlin.test.assertEquals @@ -33,4 +37,20 @@ class StringFormattingTests { originalHelloWorld.preMarkdown() ) } + + @Test + fun testThatCreatingOfStringWithSimpleDSLWorksCorrectly() { + val sources: List = regular("It ") + + bold(italic("is") + + " " + + strikethrough(underline("simple"))) + + " hello world with " + + hashtag("tag") + + " and " + + mention("mention") + sources.toTextParts().testTextParts() + + assertEquals(formattedV2Text, sources.toMarkdownV2Texts().first()) + assertEquals(formattedHtmlText, sources.toHtmlTexts().first()) + } } diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt index afb30a7196..d1721cc2fb 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt @@ -8,42 +8,8 @@ import kotlin.test.* class TextPartsCreatingTests { @Test fun testThatTextWithMultilevelPartsCorrectlyCreating() { - val text = "It is simple hello world" - val formattedV2Text = "It *_is_ ~__simple__~* hello world" - val entities = listOf( - RawMessageEntity( - "bold", - 3, - 9 - ), - RawMessageEntity( - "italic", - 3, - 2 - ), - RawMessageEntity( - "strikethrough", - 6, - 6 - ), - RawMessageEntity( - "underline", - 6, - 6 - ) - ) - - val textParts = entities.asTextParts(text) - - assertTrue (textParts.first().source is RegularTextSource) - assertTrue (textParts[1].source is BoldTextSource) - assertTrue (textParts[2].source is RegularTextSource) - - val boldSource = textParts[1].source as BoldTextSource - assertTrue (boldSource.textSources.first() is ItalicTextSource) - assertTrue (boldSource.textSources[1] is RegularTextSource) - assertTrue (boldSource.textSources[2] is StrikethroughTextSource) - assertTrue ((boldSource.textSources[2] as StrikethroughTextSource).textSources.first() is UnderlineTextSource) + val textParts = testTextEntities.asTextParts(testText) + textParts.testTextParts() assertEquals( formattedV2Text, @@ -53,42 +19,8 @@ class TextPartsCreatingTests { @Test fun testThatTextWithMultilevelPartsCorrectlyCreatingInHtml() { - val text = "It is simple hello world" - val formattedHtmlText = "It is simple hello world" - val entities = listOf( - RawMessageEntity( - "bold", - 3, - 9 - ), - RawMessageEntity( - "italic", - 3, - 2 - ), - RawMessageEntity( - "strikethrough", - 6, - 6 - ), - RawMessageEntity( - "underline", - 6, - 6 - ) - ) - - val textParts = entities.asTextParts(text) - - assertTrue (textParts.first().source is RegularTextSource) - assertTrue (textParts[1].source is BoldTextSource) - assertTrue (textParts[2].source is RegularTextSource) - - val boldSource = textParts[1].source as BoldTextSource - assertTrue (boldSource.textSources.first() is ItalicTextSource) - assertTrue (boldSource.textSources[1] is RegularTextSource) - assertTrue (boldSource.textSources[2] is StrikethroughTextSource) - assertTrue ((boldSource.textSources[2] as StrikethroughTextSource).textSources.first() is UnderlineTextSource) + val textParts = testTextEntities.asTextParts(testText) + textParts.testTextParts() assertEquals( formattedHtmlText, diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt index f3f02d62a2..c931181091 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt @@ -8,12 +8,22 @@ import io.ktor.client.HttpClient import io.ktor.client.HttpClientConfig import io.ktor.client.engine.* +/** + * Allows to create bot using bot [urlsKeeper] + */ +fun telegramBot( + urlsKeeper: TelegramAPIUrlsKeeper +): TelegramBot = KtorRequestsExecutor( + urlsKeeper, + HttpClient() +) + /** * Allows to create bot using bot [urlsKeeper] and already prepared [client] */ fun telegramBot( urlsKeeper: TelegramAPIUrlsKeeper, - client: HttpClient = HttpClient() + client: HttpClient ): TelegramBot = KtorRequestsExecutor( urlsKeeper, client @@ -60,6 +70,15 @@ inline fun telegramBot( HttpClient(clientConfig) ) +/** + * Allows to create bot using bot [token], [apiUrl] (for custom api servers) and already prepared [client] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + token: String, + apiUrl: String = telegramBotAPIDefaultUrl +): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl)) + /** * Allows to create bot using bot [token], [apiUrl] (for custom api servers) and already prepared [client] */ @@ -67,7 +86,7 @@ inline fun telegramBot( inline fun telegramBot( token: String, apiUrl: String = telegramBotAPIDefaultUrl, - client: HttpClient = HttpClient() + client: HttpClient ): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), client) @Suppress("NOTHING_TO_INLINE") @@ -106,7 +125,7 @@ inline fun telegramBot( inline fun telegramBot( token: String, apiUrl: String = telegramBotAPIDefaultUrl, - noinline clientConfig: HttpClientConfig<*>.() -> Unit = {} + noinline clientConfig: HttpClientConfig<*>.() -> Unit ) = telegramBot( TelegramAPIUrlsKeeper(token, apiUrl), clientConfig diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/ResendingTextFormatting.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/ResendingTextFormatting.kt index 68fbaf58fb..a459574b13 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/ResendingTextFormatting.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/ResendingTextFormatting.kt @@ -7,7 +7,7 @@ import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.types.message.content.fullEntitiesList fun createFormattedText( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last, mode: ParseMode = MarkdownParseMode ): List { @@ -48,23 +48,23 @@ fun createFormattedText( fun createMarkdownText( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last ): List = createFormattedText(entities, partLength, MarkdownParseMode) -fun FullTextSourcesList.toMarkdownCaptions(): List = createMarkdownText( +fun TextSourcesList.toMarkdownCaptions(): List = createMarkdownText( this, captionLength.last ) fun CaptionedInput.toMarkdownCaptions(): List = fullEntitiesList().toMarkdownCaptions() -fun FullTextSourcesList.toMarkdownTexts(): List = createMarkdownText( +fun TextSourcesList.toMarkdownTexts(): List = createMarkdownText( this, textLength.last ) fun TextContent.toMarkdownTexts(): List = fullEntitiesList().toMarkdownTexts() -fun FullTextSourcesList.toMarkdownExplanations(): List = createMarkdownText( +fun TextSourcesList.toMarkdownExplanations(): List = createMarkdownText( this, explanationLimit.last ) @@ -72,23 +72,23 @@ fun ExplainedInput.toMarkdownExplanations(): List = fullEntitiesList().t fun createMarkdownV2Text( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last ): List = createFormattedText(entities, partLength, MarkdownV2ParseMode) -fun FullTextSourcesList.toMarkdownV2Captions(): List = createMarkdownV2Text( +fun TextSourcesList.toMarkdownV2Captions(): List = createMarkdownV2Text( this, captionLength.last ) fun CaptionedInput.toMarkdownV2Captions(): List = fullEntitiesList().toMarkdownV2Captions() -fun FullTextSourcesList.toMarkdownV2Texts(): List = createMarkdownV2Text( +fun TextSourcesList.toMarkdownV2Texts(): List = createMarkdownV2Text( this, textLength.last ) fun TextContent.toMarkdownV2Texts(): List = fullEntitiesList().toMarkdownV2Texts() -fun FullTextSourcesList.toMarkdownV2Explanations(): List = createMarkdownV2Text( +fun TextSourcesList.toMarkdownV2Explanations(): List = createMarkdownV2Text( this, explanationLimit.last ) @@ -96,23 +96,23 @@ fun ExplainedInput.toMarkdownV2Explanations(): List = fullEntitiesList() fun createHtmlText( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last ): List = createFormattedText(entities, partLength, HTMLParseMode) -fun FullTextSourcesList.toHtmlCaptions(): List = createHtmlText( +fun TextSourcesList.toHtmlCaptions(): List = createHtmlText( this, captionLength.last ) fun CaptionedInput.toHtmlCaptions(): List = fullEntitiesList().toHtmlCaptions() -fun FullTextSourcesList.toHtmlTexts(): List = createHtmlText( +fun TextSourcesList.toHtmlTexts(): List = createHtmlText( this, textLength.last ) fun TextContent.toHtmlTexts(): List = fullEntitiesList().toHtmlTexts() -fun FullTextSourcesList.toHtmlExplanations(): List = createHtmlText( +fun TextSourcesList.toHtmlExplanations(): List = createHtmlText( this, explanationLimit.last ) From d73fa4076f764c0ffd1f5c2710cf09270efe0d90 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 6 Nov 2020 19:13:59 +0600 Subject: [PATCH 38/42] add several extension properties to texted/captioned/explained interfaces --- CHANGELOG.md | 1 + .../kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt | 8 ++++++++ .../dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt | 5 +---- .../kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt | 8 ++++++++ .../kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt | 8 ++++++++ 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63731b1d96..91a84a9ea7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ formatter entities will use `RegularTextSource` * `MultilevelTextSource#textParts` has been deprecated. Now each `MultilevelTextSource` have its own `textSources` list + * New dsl for creating of `TextSource` lists * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt index 5d55cc4854..81cbcdca86 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt @@ -19,8 +19,16 @@ interface CaptionedInput : Captioned { val captionEntities: List } +/** + * @see CaptionedInput.captionEntities + * @see justTextSources + */ +val CaptionedInput.textSources + get() = captionEntities.justTextSources() + /** * Convert its [CaptionedInput.captionEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource] * with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] */ +@Deprecated("Currently list of entities already full. This method is redundant") fun CaptionedInput.fullEntitiesList(): TextSourcesList = caption ?.fullListOfSubSource(captionEntities) ?.map { it.source } ?: emptyList() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt index f3361259d1..6a2ac806a7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt @@ -1,9 +1,6 @@ package dev.inmo.tgbotapi.CommonAbstracts -import dev.inmo.tgbotapi.types.FoursquareId -import dev.inmo.tgbotapi.types.FoursquareType -import dev.inmo.tgbotapi.types.GooglePlaceId -import dev.inmo.tgbotapi.types.GooglePlaceType +import dev.inmo.tgbotapi.types.* interface CommonVenueData : Titled { override val title: String diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt index 40770b027c..54fcb6b158 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt @@ -25,8 +25,16 @@ interface ExplainedInput : Explained { val explanationEntities: List } +/** + * @see ExplainedInput.explanationEntities + * @see justTextSources + */ +val ExplainedInput.textSources + get() = explanationEntities.justTextSources() + /** * Convert its [ExplainedInput.explanationEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource] * with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] */ +@Deprecated("Currently list of entities already full. This method is redundant") fun ExplainedInput.fullEntitiesList(): TextSourcesList = explanation ?.fullListOfSubSource(explanationEntities) ?.map { it.source } ?: emptyList() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt index 9b5ade197b..059575534f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt @@ -25,8 +25,16 @@ interface TextedInput : Texted { val textEntities: List } +/** + * @see TextedInput.textEntities + * @see justTextSources + */ +val TextedInput.textSources + get() = textEntities.justTextSources() + /** * Convert its [TextedInput.textEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource] * with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] */ +@Deprecated("Currently list of entities already full. This method is redundant") fun TextedInput.fullEntitiesList(): TextSourcesList = text ?.fullListOfSubSource(textEntities) ?.map { it.source } ?: emptyList() From 311512b5dbfb95ccbbe905c8490c97b35b08fac4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 7 Nov 2020 01:34:22 +0600 Subject: [PATCH 39/42] fix chat interfaces serializers --- .../dev/inmo/tgbotapi/types/chat/abstracts/ChannelChat.kt | 4 ++++ .../dev/inmo/tgbotapi/types/chat/abstracts/GroupChat.kt | 4 ++++ .../dev/inmo/tgbotapi/types/chat/abstracts/PrivateChat.kt | 4 ++++ .../dev/inmo/tgbotapi/types/chat/abstracts/PublicChat.kt | 4 ++++ .../dev/inmo/tgbotapi/types/chat/abstracts/SuperPublicChat.kt | 4 ++++ .../dev/inmo/tgbotapi/types/chat/abstracts/SupergroupChat.kt | 4 ++++ .../dev/inmo/tgbotapi/types/chat/abstracts/UsernameChat.kt | 3 +++ .../types/chat/abstracts/extended/ExtendedChannelChat.kt | 3 +++ .../types/chat/abstracts/extended/ExtendedGroupChat.kt | 3 +++ .../types/chat/abstracts/extended/ExtendedPrivateChat.kt | 3 +++ .../types/chat/abstracts/extended/ExtendedSupergroupChat.kt | 3 +++ 11 files changed, 39 insertions(+) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/ChannelChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/ChannelChat.kt index 2a6043809f..3e42f887d1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/ChannelChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/ChannelChat.kt @@ -1,3 +1,7 @@ package dev.inmo.tgbotapi.types.chat.abstracts +import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable + +@Serializable(PreviewChatSerializer::class) interface ChannelChat : SuperPublicChat diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/GroupChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/GroupChat.kt index 849d6b9e3a..591a565624 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/GroupChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/GroupChat.kt @@ -1,3 +1,7 @@ package dev.inmo.tgbotapi.types.chat.abstracts +import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable + +@Serializable(PreviewChatSerializer::class) interface GroupChat : PublicChat diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PrivateChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PrivateChat.kt index 2459398282..65a254544b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PrivateChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PrivateChat.kt @@ -1,5 +1,9 @@ package dev.inmo.tgbotapi.types.chat.abstracts +import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable + +@Serializable(PreviewChatSerializer::class) interface PrivateChat : Chat, UsernameChat { val firstName: String val lastName: String diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PublicChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PublicChat.kt index 98c70cec84..f78e434f44 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PublicChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PublicChat.kt @@ -1,5 +1,9 @@ package dev.inmo.tgbotapi.types.chat.abstracts +import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable + +@Serializable(PreviewChatSerializer::class) interface PublicChat : Chat { val title: String } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SuperPublicChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SuperPublicChat.kt index 0403f89fa6..ce290dbe2f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SuperPublicChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SuperPublicChat.kt @@ -1,3 +1,7 @@ package dev.inmo.tgbotapi.types.chat.abstracts +import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable + +@Serializable(PreviewChatSerializer::class) interface SuperPublicChat : PublicChat, UsernameChat diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SupergroupChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SupergroupChat.kt index f49d4d144f..d4ad4d90d2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SupergroupChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SupergroupChat.kt @@ -1,3 +1,7 @@ package dev.inmo.tgbotapi.types.chat.abstracts +import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable + +@Serializable(PreviewChatSerializer::class) interface SupergroupChat : GroupChat, SuperPublicChat diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/UsernameChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/UsernameChat.kt index 99ced04a6a..eb2149799f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/UsernameChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/UsernameChat.kt @@ -1,7 +1,10 @@ package dev.inmo.tgbotapi.types.chat.abstracts import dev.inmo.tgbotapi.types.Username +import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable +@Serializable(PreviewChatSerializer::class) interface UsernameChat : Chat { val username: Username? } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChannelChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChannelChat.kt index cbda4c68db..e21d2e314b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChannelChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChannelChat.kt @@ -1,8 +1,11 @@ package dev.inmo.tgbotapi.types.chat.abstracts.extended import dev.inmo.tgbotapi.types.ChatId +import dev.inmo.tgbotapi.types.chat.ExtendedChatSerializer import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat +import kotlinx.serialization.Serializable +@Serializable(ExtendedChatSerializer::class) interface ExtendedChannelChat : ChannelChat, ExtendedPublicChat { val linkedGroupChatId: ChatId? } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedGroupChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedGroupChat.kt index df9c9e157b..a24939a299 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedGroupChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedGroupChat.kt @@ -1,8 +1,11 @@ package dev.inmo.tgbotapi.types.chat.abstracts.extended import dev.inmo.tgbotapi.types.chat.ChatPermissions +import dev.inmo.tgbotapi.types.chat.ExtendedChatSerializer import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat +import kotlinx.serialization.Serializable +@Serializable(ExtendedChatSerializer::class) interface ExtendedGroupChat : GroupChat, ExtendedPublicChat { val permissions: ChatPermissions } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedPrivateChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedPrivateChat.kt index 297c7f3986..55a03723a5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedPrivateChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedPrivateChat.kt @@ -1,7 +1,10 @@ package dev.inmo.tgbotapi.types.chat.abstracts.extended +import dev.inmo.tgbotapi.types.chat.ExtendedChatSerializer import dev.inmo.tgbotapi.types.chat.abstracts.PrivateChat +import kotlinx.serialization.Serializable +@Serializable(ExtendedChatSerializer::class) interface ExtendedPrivateChat : PrivateChat, ExtendedChat { val bio: String } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedSupergroupChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedSupergroupChat.kt index 75ef3df3f6..fc50b3bd37 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedSupergroupChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedSupergroupChat.kt @@ -1,8 +1,11 @@ package dev.inmo.tgbotapi.types.chat.abstracts.extended import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.chat.ExtendedChatSerializer import dev.inmo.tgbotapi.types.chat.abstracts.SupergroupChat +import kotlinx.serialization.Serializable +@Serializable(ExtendedChatSerializer::class) interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat { val slowModeDelay: Long? val stickerSetName: StickerSetName? From 1cf7ae7438f79ea0999e59f896c6e5a63bcdc2b3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 7 Nov 2020 13:42:10 +0600 Subject: [PATCH 40/42] add micro_utils and deprecate old coroutine methods --- CHANGELOG.md | 2 ++ gradle.properties | 2 ++ tgbotapi.core/build.gradle | 2 ++ .../dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt | 2 +- .../dev/inmo/tgbotapi/CommonAbstracts/Explained.kt | 2 +- .../dev/inmo/tgbotapi/CommonAbstracts/Texted.kt | 2 +- .../inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt | 3 ++- .../Ktor/base/DownloadFileRequestCallFactory.kt | 4 ++-- .../types/MessageEntity/RawMessageEntity.kt | 4 ++-- .../MessageEntity/textsources/BoldTextSource.kt | 4 +++- .../textsources/BotCommandTextSource.kt | 4 +++- .../MessageEntity/textsources/CashTagTextSource.kt | 3 +++ .../MessageEntity/textsources/CodeTextSource.kt | 3 +++ .../MessageEntity/textsources/EMailTextSource.kt | 3 +++ .../MessageEntity/textsources/HashTagTextSource.kt | 3 +++ .../MessageEntity/textsources/ItalicTextSource.kt | 3 +++ .../MessageEntity/textsources/MentionTextSource.kt | 4 +++- .../textsources/PhoneNumberTextSource.kt | 3 +++ .../MessageEntity/textsources/PreTextSource.kt | 3 +++ .../MessageEntity/textsources/RegularTextSource.kt | 3 +++ .../textsources/StrikethroughTextSource.kt | 3 +++ .../textsources/TextLinkTextSource.kt | 3 +++ .../textsources/TextMentionTextSource.kt | 3 +++ .../MessageEntity/textsources/URLTextSource.kt | 3 +++ .../textsources/UnderlineTextSource.kt | 3 +++ .../dev/inmo/tgbotapi/types/message/RawMessage.kt | 1 - .../tgbotapi/types/message/content/TextContent.kt | 4 +++- .../message/content/media/AnimationContent.kt | 4 ++-- .../types/message/content/media/AudioContent.kt | 2 +- .../types/message/content/media/DocumentContent.kt | 2 +- .../types/message/content/media/PhotoContent.kt | 2 +- .../types/message/content/media/VideoContent.kt | 2 +- .../types/message/content/media/VoiceContent.kt | 4 ++-- .../kotlin/dev/inmo/tgbotapi/utils/HandleSafely.kt | 14 ++++++-------- .../BaseMessageUpdateToMediaGroupUpdate.kt | 2 +- .../{ => internal}/CaptionAndTextSourcesToText.kt | 2 +- .../MultilevelTextSourceFormatting.kt | 2 +- .../utils/{ => internal}/StringFormatting.kt | 2 +- .../types/MessageEntity/StringFormattingTests.kt | 2 +- .../types/MessageEntity/TextPartsCreatingTests.kt | 4 ++-- .../tgbotapi/extensions/utils/SafelyShortcut.kt | 6 ++++-- .../extensions/utils/shortcuts/RequestsExecutor.kt | 6 +++--- .../utils/updates/retrieving/LongPolling.kt | 6 ++++-- .../extensions/utils/updates/retrieving/Webhook.kt | 6 +++--- 44 files changed, 101 insertions(+), 46 deletions(-) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/{ => internal}/BaseMessageUpdateToMediaGroupUpdate.kt (98%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/{ => internal}/CaptionAndTextSourcesToText.kt (98%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/{ => internal}/MultilevelTextSourceFormatting.kt (99%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/{ => internal}/StringFormatting.kt (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91a84a9ea7..3a5c441700 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * `Common`: * `Version`: * `Coroutine`: `1.4.0` -> `1.4.1` + * **NEW** `MicroUtils`: `0.2.7` * `Core`: * Support of `logOut` method (`LogOut` object as a `Request`) * Support of `close` method (`Close` object as a `Request`) @@ -77,6 +78,7 @@ * `MultilevelTextSource#textParts` has been deprecated. Now each `MultilevelTextSource` have its own `textSources` list * New dsl for creating of `TextSource` lists + * Built-in `handleSafely` and `ExceptionHandler` is deprecated * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/gradle.properties b/gradle.properties index e73cbad343..42d720c08a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,6 +12,8 @@ klock_version=1.12.1 uuid_version=0.2.2 ktor_version=1.4.1 +micro_utils_version=0.2.7 + javax_activation_version=1.1.1 library_group=dev.inmo diff --git a/tgbotapi.core/build.gradle b/tgbotapi.core/build.gradle index eaf93b61f8..e0248e76d1 100644 --- a/tgbotapi.core/build.gradle +++ b/tgbotapi.core/build.gradle @@ -47,6 +47,8 @@ kotlin { api "com.soywiz.korlibs.klock:klock:$klock_version" api "com.benasher44:uuid:$uuid_version" + api "dev.inmo:micro_utils.coroutines:$micro_utils_version" + api "io.ktor:ktor-client-core:$ktor_version" } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt index 81cbcdca86..139ae89e82 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.CommonAbstracts import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.utils.fullListOfSubSource +import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource interface Captioned { val caption: String? diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt index 54fcb6b158..fb837163fd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.CommonAbstracts import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.utils.fullListOfSubSource +import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource interface Explained { val explanation: String? diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt index 059575534f..4ff32e73de 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.CommonAbstracts import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.utils.fullListOfSubSource +import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource interface Texted { val text: String? diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt index 780c39992a..949c55caf0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.bot.Ktor +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.bot.BaseRequestsExecutor import dev.inmo.tgbotapi.bot.Ktor.base.* import dev.inmo.tgbotapi.bot.exceptions.newRequestException @@ -36,7 +37,7 @@ class KtorRequestsExecutor( } override suspend fun execute(request: Request): T { - return handleSafely( + return safely( { e -> throw if (e is ClientRequestException) { val content = e.response ?.readText() ?: throw e diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt index 05d3874332..cbccc36e5c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt @@ -1,10 +1,10 @@ package dev.inmo.tgbotapi.bot.Ktor.base +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory import dev.inmo.tgbotapi.requests.DownloadFile import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper -import dev.inmo.tgbotapi.utils.handleSafely import io.ktor.client.HttpClient import io.ktor.client.request.get import kotlinx.serialization.json.Json @@ -18,7 +18,7 @@ object DownloadFileRequestCallFactory : KtorCallFactory { ): T? = (request as? DownloadFile) ?.let { val fullUrl = "${urlsKeeper.fileBaseUrl}/${it.filePath}" - return handleSafely { + return safely { @Suppress("UNCHECKED_CAST") client.get(fullUrl) as T // always ByteArray } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt index e41728b732..d8bff5f11d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt @@ -3,8 +3,8 @@ package dev.inmo.tgbotapi.types.MessageEntity import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.types.User -import dev.inmo.tgbotapi.utils.fullListOfSubSource -import dev.inmo.tgbotapi.utils.shiftSourcesToTheLeft +import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource +import dev.inmo.tgbotapi.utils.internal.shiftSourcesToTheLeft import kotlinx.serialization.Serializable @Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt index 41345fe1e0..64c1d3dee4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* -import dev.inmo.tgbotapi.types.MessageEntity.toTextParts import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.boldMarkdown +import dev.inmo.tgbotapi.utils.internal.boldMarkdownV2 /** * @see bold diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt index ed79857629..8ca260ddf2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* -import dev.inmo.tgbotapi.types.MessageEntity.removeLeading import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.commandMarkdown +import dev.inmo.tgbotapi.utils.internal.commandMarkdownV2 private val commandRegex = Regex("[/!][^@\\s]*") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt index 504a5ebe2f..221fd5712e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.cashTagMarkdown +import dev.inmo.tgbotapi.utils.internal.cashTagMarkdownV2 /** * @see cashTag diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt index d4102a622e..86d4aae7cd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt @@ -3,6 +3,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.codeMarkdown +import dev.inmo.tgbotapi.utils.internal.codeMarkdownV2 /** * @see code diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt index 9fceafd296..77704d1e69 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.emailMarkdown +import dev.inmo.tgbotapi.utils.internal.emailMarkdownV2 /** * @see email diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt index f7f2787c07..37ecbe8861 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.hashTagMarkdown +import dev.inmo.tgbotapi.utils.internal.hashTagMarkdownV2 /** * @see hashtag diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt index 8821e1a05b..887238f2bb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.italicMarkdown +import dev.inmo.tgbotapi.utils.internal.italicMarkdownV2 /** * @see italic diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt index 0c6a168053..ef17ac5632 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* -import dev.inmo.tgbotapi.types.MessageEntity.removeLeading import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.mentionMarkdown +import dev.inmo.tgbotapi.utils.internal.mentionMarkdownV2 private val String.withoutCommercialAt get() = if (startsWith("@")) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt index dada89e413..321fb3f6f5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.phoneMarkdown +import dev.inmo.tgbotapi.utils.internal.phoneMarkdownV2 /** * @see phone diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt index 62e4371746..8ec55f8deb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.preMarkdown +import dev.inmo.tgbotapi.utils.internal.preMarkdownV2 /** * @see pre diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt index 87807b935d..d70f3d1129 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.regularMarkdown +import dev.inmo.tgbotapi.utils.internal.regularMarkdownV2 /** * @see regular diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt index 34a5cb9775..b273b012c0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.strikethroughMarkdown +import dev.inmo.tgbotapi.utils.internal.strikethroughMarkdownV2 /** * @see strikethrough diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt index 0a8a3c512b..c0e3098dba 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.linkMarkdown +import dev.inmo.tgbotapi.utils.internal.linkMarkdownV2 /** * @see link diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt index 086e232510..4ef48dbee6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt @@ -3,6 +3,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.textMentionMarkdown +import dev.inmo.tgbotapi.utils.internal.textMentionMarkdownV2 /** * @see mention diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt index 806d54cde9..4a5fb0825b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.linkMarkdown +import dev.inmo.tgbotapi.utils.internal.linkMarkdownV2 /** * @see link diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt index ef6250b253..3523f12496 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.underlineMarkdown +import dev.inmo.tgbotapi.utils.internal.underlineMarkdownV2 /** * @see underline diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 644e441646..cfccea7958 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -22,7 +22,6 @@ import dev.inmo.tgbotapi.types.payments.Invoice import dev.inmo.tgbotapi.types.payments.SuccessfulPayment import dev.inmo.tgbotapi.types.polls.Poll import dev.inmo.tgbotapi.types.venue.Venue -import dev.inmo.tgbotapi.utils.fullListOfSubSource import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlin.reflect.KClass diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt index 4fbe499201..08a2d23a34 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt @@ -10,7 +10,9 @@ import dev.inmo.tgbotapi.types.ParseMode.* import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent -import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource +import dev.inmo.tgbotapi.utils.internal.toMarkdownTexts data class TextContent( val text: String, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt index c7b1f6c662..f0cf652083 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt @@ -14,8 +14,8 @@ import dev.inmo.tgbotapi.types.files.AnimationFile import dev.inmo.tgbotapi.types.files.DocumentFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent -import dev.inmo.tgbotapi.utils.toHtmlCaptions -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions +import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Captions data class AnimationContent( override val media: AnimationFile, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt index 3e93231ffc..b326522b96 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt @@ -12,7 +12,7 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.AudioFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.AudioMediaGroupContent -import dev.inmo.tgbotapi.utils.toHtmlCaptions +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class AudioContent( override val media: AudioFile, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt index 21975585e6..8ff70ac761 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt @@ -15,7 +15,7 @@ import dev.inmo.tgbotapi.types.files.asDocumentFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.DocumentMediaGroupContent import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent -import dev.inmo.tgbotapi.utils.toHtmlCaptions +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class DocumentContent( override val media: DocumentFile, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt index 958477102a..9a7ceabb4c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt @@ -13,7 +13,7 @@ import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaCollectionContent import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent -import dev.inmo.tgbotapi.utils.toHtmlCaptions +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class PhotoContent( override val mediaCollection: Photo, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt index 9931dee306..aa5b4185bb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt @@ -12,7 +12,7 @@ import dev.inmo.tgbotapi.types.files.VideoFile import dev.inmo.tgbotapi.types.files.toInputMediaVideo import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent -import dev.inmo.tgbotapi.utils.toHtmlCaptions +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class VideoContent( override val media: VideoFile, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt index 1d2b2dd4ce..6a9894444f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt @@ -13,8 +13,8 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.VoiceFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent -import dev.inmo.tgbotapi.utils.toHtmlCaptions -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions +import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Captions data class VoiceContent( override val media: VoiceFile, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/HandleSafely.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/HandleSafely.kt index 148d08835d..6f93f28984 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/HandleSafely.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/HandleSafely.kt @@ -1,23 +1,21 @@ package dev.inmo.tgbotapi.utils +import dev.inmo.micro_utils.coroutines.ExceptionHandler +import dev.inmo.micro_utils.coroutines.safely import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.supervisorScope -typealias ExceptionHandler = suspend (Throwable) -> T +@Deprecated("In future will be used typealias from micro_utils", ReplaceWith("ExceptionHandler", "dev.inmo.micro_utils.coroutines.ExceptionHandler")) +typealias ExceptionHandler = ExceptionHandler /** * It will run [block] inside of [supervisorScope] to avoid problems with catching of exceptions * * @param [onException] Will be called when happen exception inside of [block]. By default will throw exception - this * exception will be available for catching */ +@Deprecated("In future will be used typealias from micro_utils", ReplaceWith("safely", "dev.inmo.micro_utils.coroutines.safely")) suspend inline fun handleSafely( noinline onException: ExceptionHandler = { throw it }, noinline block: suspend CoroutineScope.() -> T -): T { - return try { - supervisorScope(block) - } catch (e: Throwable) { - onException(e) - } -} +): T = safely(onException, block) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/BaseMessageUpdateToMediaGroupUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/BaseMessageUpdateToMediaGroupUpdate.kt similarity index 98% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/BaseMessageUpdateToMediaGroupUpdate.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/BaseMessageUpdateToMediaGroupUpdate.kt index 07efbe4b31..5e4cc86d4f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/BaseMessageUpdateToMediaGroupUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/BaseMessageUpdateToMediaGroupUpdate.kt @@ -1,4 +1,4 @@ -package dev.inmo.tgbotapi.utils +package dev.inmo.tgbotapi.utils.internal import dev.inmo.tgbotapi.types.MediaGroupIdentifier import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CaptionAndTextSourcesToText.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt similarity index 98% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CaptionAndTextSourcesToText.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt index be317d0bf3..a1c9d049af 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CaptionAndTextSourcesToText.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt @@ -1,4 +1,4 @@ -package dev.inmo.tgbotapi.utils +package dev.inmo.tgbotapi.utils.internal import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt similarity index 99% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt index 0c6ed5bf1b..69e44e5d6c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt @@ -1,4 +1,4 @@ -package dev.inmo.tgbotapi.utils +package dev.inmo.tgbotapi.utils.internal import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StringFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt similarity index 99% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StringFormatting.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt index abe06bf13a..2c3b8e8076 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StringFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt @@ -1,4 +1,4 @@ -package dev.inmo.tgbotapi.utils +package dev.inmo.tgbotapi.utils.internal import dev.inmo.tgbotapi.types.ParseMode.* import dev.inmo.tgbotapi.types.UserId diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/StringFormattingTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/StringFormattingTests.kt index b5c16de001..34a7e66975 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/StringFormattingTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/StringFormattingTests.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.types.MessageEntity import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.CommonAbstracts.plus -import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* import kotlin.test.Test import kotlin.test.assertEquals diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt index d1721cc2fb..a4150e0d3d 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt @@ -1,8 +1,8 @@ package dev.inmo.tgbotapi.types.MessageEntity import dev.inmo.tgbotapi.CommonAbstracts.justTextSources -import dev.inmo.tgbotapi.types.MessageEntity.textsources.* -import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.toHtmlTexts +import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Texts import kotlin.test.* class TextPartsCreatingTests { diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SafelyShortcut.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SafelyShortcut.kt index ad8ab08006..6add07d0b8 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SafelyShortcut.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SafelyShortcut.kt @@ -1,16 +1,18 @@ package dev.inmo.tgbotapi.extensions.utils +import dev.inmo.micro_utils.coroutines.ExceptionHandler import dev.inmo.tgbotapi.utils.* import kotlinx.coroutines.CoroutineScope /** - * Shortcut for [handleSafely]. It was created for more comfortable way of handling different things + * Shortcut for [dev.inmo.micro_utils.coroutines.safely]. It was created for more comfortable way of handling different things */ @PreviewFeature +@Deprecated("In future will be used typealias from micro_utils", ReplaceWith("safely", "dev.inmo.micro_utils.coroutines.safely")) suspend inline fun safely( noinline onException: ExceptionHandler = { throw it }, noinline block: suspend CoroutineScope.() -> T -): T = handleSafely( +): T = dev.inmo.micro_utils.coroutines.safely( onException, block ) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/RequestsExecutor.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/RequestsExecutor.kt index aa4d9b225c..f3ba0f62e7 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/RequestsExecutor.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/RequestsExecutor.kt @@ -1,15 +1,15 @@ package dev.inmo.tgbotapi.extensions.utils.shortcuts +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.bot.RequestsExecutor import dev.inmo.tgbotapi.requests.abstracts.Request -import dev.inmo.tgbotapi.utils.handleSafely import kotlinx.coroutines.* fun RequestsExecutor.executeAsync( request: Request, scope: CoroutineScope ): Deferred = scope.async { - handleSafely { + safely { execute(request) } } @@ -29,7 +29,7 @@ suspend fun RequestsExecutor.executeUnsafe( var leftRetries = retries val exceptions = onAllFailed ?.let { mutableListOf() } do { - return handleSafely( + return safely ( { leftRetries-- delay(retriesDelay) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt index 03a16b401b..f6802145d1 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt @@ -1,5 +1,7 @@ package dev.inmo.tgbotapi.extensions.utils.updates.retrieving +import dev.inmo.micro_utils.coroutines.ExceptionHandler +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.bot.RequestsExecutor import dev.inmo.tgbotapi.bot.exceptions.RequestException import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates @@ -23,7 +25,7 @@ fun RequestsExecutor.startGettingOfUpdatesByLongPolling( var lastUpdateIdentifier: UpdateIdentifier? = null while (isActive) { - handleSafely( + safely( { e -> exceptionsHandler ?.invoke(e) if (e is RequestException) { @@ -52,7 +54,7 @@ fun RequestsExecutor.startGettingOfUpdatesByLongPolling( } } - handleSafely { + safely { for (update in updates) { updatesReceiver(update) diff --git a/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt b/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt index 68594fca19..92c50173d4 100644 --- a/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt +++ b/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt @@ -1,5 +1,7 @@ package dev.inmo.tgbotapi.extensions.utils.updates.retrieving +import dev.inmo.micro_utils.coroutines.ExceptionHandler +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.bot.RequestsExecutor import dev.inmo.tgbotapi.extensions.utils.nonstrictJsonFormat import dev.inmo.tgbotapi.extensions.utils.updates.flowsUpdatesFilter @@ -11,8 +13,6 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.types.update.abstracts.UpdateDeserializationStrategy import dev.inmo.tgbotapi.updateshandlers.* import dev.inmo.tgbotapi.updateshandlers.webhook.WebhookPrivateKeyConfig -import dev.inmo.tgbotapi.utils.ExceptionHandler -import dev.inmo.tgbotapi.utils.handleSafely import io.ktor.application.call import io.ktor.request.receiveText import io.ktor.response.respond @@ -41,7 +41,7 @@ fun Route.includeWebhookHandlingInRoute( ) { val transformer = scope.updateHandlerWithMediaGroupsAdaptation(block) post { - handleSafely( + safely( exceptionsHandler ?: {} ) { val asJson = From 1e6b0381eefad2cd82a15a9fb62f1ed6ebbb8f93 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 7 Nov 2020 14:44:05 +0600 Subject: [PATCH 41/42] StorageFile factories --- CHANGELOG.md | 1 + .../kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt | 15 +++++++++++++++ .../requests/abstracts/InputFileFromJavaFile.kt | 2 ++ .../kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt | 1 + 4 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a5c441700..f7e9277351 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ `textSources` list * New dsl for creating of `TextSource` lists * Built-in `handleSafely` and `ExceptionHandler` is deprecated + * New common factories for `StorageFile` * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt index 5ee622b20f..a5beeeb0ca 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.utils import com.benasher44.uuid.uuid4 +import io.ktor.utils.io.core.ByteReadPacket import io.ktor.utils.io.core.Input import kotlinx.serialization.Serializable @@ -18,3 +19,17 @@ data class StorageFile( ) { fun asInput() = inputSource() } + +@Suppress("NOTHING_TO_INLINE") +inline fun StorageFile( + fileName: String, + bytes: ByteArray, + mimeType: MimeType +) = StorageFile( + StorageFileInfo(mimeType.raw, fileName) +) { + ByteReadPacket(bytes) +} + +@Suppress("NOTHING_TO_INLINE") +inline fun ByteArray.asStorageFile(fileName: String, mimeType: MimeType) = StorageFile(fileName, this, mimeType) diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/InputFileFromJavaFile.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/InputFileFromJavaFile.kt index 34350831f3..7492cc3d98 100644 --- a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/InputFileFromJavaFile.kt +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/InputFileFromJavaFile.kt @@ -1,7 +1,9 @@ package dev.inmo.tgbotapi.requests.abstracts +import dev.inmo.tgbotapi.utils.MimeType import dev.inmo.tgbotapi.utils.StorageFile import java.io.File +import java.io.InputStream fun File.toInputFile() = if (exists()) { MultipartFile( diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt index 8d7ebe5c53..4aab4c57b6 100644 --- a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.utils import io.ktor.utils.io.streams.asInput import java.io.File +import java.io.InputStream import java.nio.file.Files fun StorageFile( From e8ded44562e863bfdc016a85079a6649d868dc65 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 7 Nov 2020 22:28:20 +0600 Subject: [PATCH 42/42] rename StorageFile in jvm of common --- .../inmo/tgbotapi/utils/{StorageFile.kt => StorageFileFactory.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/{StorageFile.kt => StorageFileFactory.kt} (100%) diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/StorageFileFactory.kt similarity index 100% rename from tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt rename to tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/StorageFileFactory.kt