diff --git a/CHANGELOG.md b/CHANGELOG.md index 20e22e133d..db55b8a298 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,30 @@ # TelegramBotAPI changelog +## 0.34.0 + +**UPDATE UP TO Telegram Bot API 5.2** +_**ALL OLD DEPRECATIONS WERE REMOVED**_ + +* `Core`: + * Type `ChatType` has been added + * New `ExtendedChat` for unknown messages `UnknownExtendedChat` has been added + * `SendInvoice#startParameter` becomes optional and replaced in `SendInvoice` constructor + * New interface `CommonSendInvoiceData` has been added + * Fields `CommonSendInvoiceData#maxTipAmount` and `CommonSendInvoiceData#suggestedTipAmounts` have been added + * New type `InputInvoiceMessageContent` has been added + * New interface `TextedWithTextSources` on top of `Texted` interface + * Interface `TextedInput` now extends `TextedWithTextSources` with overriding of `textSources` field as not + nullable + * `textSources` become main field in `TextedInput` + * **MIGRATION** Remove all `import dev.inmo.tgbotapi.CommonAbstracts.textSources` in your project + * `textEntities` become are calculable property in `TextedInput` + * Interface `Captioned` and `CaptionedInput` now is deprecated + * Most of captions usages were replaced with texts + * Interface `Explained` and `ExplainedInput` now is deprecated + * Most of captions usages were replaced with texts + * Interface `VoiceChatEvent` now is `CommonEvent` + * Mechanism of `RawMessageEntity` converting were fully rewritten + ## 0.33.4 * `Common`: diff --git a/gradle.properties b/gradle.properties index a74e4d5857..5e93b2b6b2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ micro_utils_version=0.4.35 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.33.4 +library_version=0.34.0 github_release_plugin_version=2.2.12 diff --git a/tgbotapi.core/README.md b/tgbotapi.core/README.md index 4728898a5b..edb5912051 100644 --- a/tgbotapi.core/README.md +++ b/tgbotapi.core/README.md @@ -1,6 +1,5 @@ # TelegramBotAPI Core -[![Download](https://api.bintray.com/packages/insanusmokrassar/TelegramBotAPI/tgbotapi.core/images/download.svg) ](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.core/_latestVersion) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core) ## What is it? @@ -10,7 +9,7 @@ moments are describing by official [Telegram Bot API](https://core.telegram.org/ ## Compatibility -This version compatible with [9th of March 2021 update of TelegramBotAPI (version 5.1)](https://core.telegram.org/bots/api-changelog#march-9-2021). +This version compatible with [26th of April 2021 update of TelegramBotAPI (version 5.2)](https://core.telegram.org/bots/api-changelog#april-26-2021). ## How to implement library? 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 0b5ed05d2c..5993bb0d9d 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,26 +1,20 @@ package dev.inmo.tgbotapi.CommonAbstracts -import dev.inmo.tgbotapi.types.ParseMode.ParseMode +const val CaptionDeprecation = "Captioned interface and others will be removed soon and not recommended to use" -interface Captioned { +@Deprecated(CaptionDeprecation) +interface Captioned : Texted { + @Deprecated(CaptionDeprecation) val caption: String? + get() = text } -@Deprecated("This interface is not used in library and will be removed soon") -interface CaptionedOutput : Captioned { - val parseMode: ParseMode? -} - -interface CaptionedInput : Captioned { +@Deprecated(CaptionDeprecation) +interface CaptionedInput : Captioned, TextedInput { /** * Full list of entities. This list WILL contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] */ + @Deprecated(CaptionDeprecation) val captionEntities: List + get() = textEntities } - -/** - * @see CaptionedInput.captionEntities - * @see justTextSources - */ -val CaptionedInput.textSources - get() = captionEntities.justTextSources() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonSendInvoiceData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonSendInvoiceData.kt new file mode 100644 index 0000000000..4c7e225ff7 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonSendInvoiceData.kt @@ -0,0 +1,36 @@ +package dev.inmo.tgbotapi.CommonAbstracts + +import dev.inmo.tgbotapi.types.payments.abstracts.Currencied +import dev.inmo.tgbotapi.types.payments.abstracts.Priced + +interface CommonSendInvoiceData : Titled, Currencied, Priced { + val description: String + val payload: String + val providerToken: String + val maxTipAmount: Int? + val suggestedTipAmounts: List? + val providerData: String? + val requireName: Boolean + val requirePhoneNumber: Boolean + val requireEmail: Boolean + val requireShippingAddress: Boolean + val shouldSendPhoneNumberToProvider: Boolean + val shouldSendEmailToProvider: Boolean + val priceDependOnShipAddress: Boolean + + val photoUrl: String? + val photoSize: Long? + val photoWidth: Int? + val photoHeight: Int? + + + + fun setPhoto( + photoUrl: String, + photoSize: Long? = null, + photoWidth: Int? = null, + photoHeight: Int? = null + ) + + fun unsetPhoto() +} \ No newline at end of file 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 05e7cd1c63..c5ccd4b90b 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,31 +1,26 @@ package dev.inmo.tgbotapi.CommonAbstracts -import dev.inmo.tgbotapi.types.ParseMode.ParseMode - -interface Explained { +@Deprecated("Will be removed soon") +interface Explained : Texted { val explanation: String? + get() = text } -interface ParsableExplainedOutput : Explained { - val parseMode: ParseMode? -} +@Deprecated("Will be removed soon") +interface ParsableExplainedOutput : Explained, TextedOutput -interface EntitiesExplainedOutput : Explained { - val entities: List? -} +@Deprecated("Will be removed soon") +interface EntitiesExplainedOutput : Explained, EntitiesOutput +@Deprecated("Will be removed soon") interface ExplainedOutput : ParsableExplainedOutput, EntitiesExplainedOutput +@Deprecated("Will be removed soon") interface ExplainedInput : Explained { + val textSources: TextSourcesList /** * Full list of entities. This list WILL contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] */ val explanationEntities: List + get() = textSources.toTextParts() } - -/** - * @see ExplainedInput.explanationEntities - * @see justTextSources - */ -val ExplainedInput.textSources - get() = explanationEntities.justTextSources() 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 05590f49b4..6a51ef9cca 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 @@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.CommonAbstracts import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourceSerializer 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 import kotlinx.serialization.Serializable @@ -44,14 +43,27 @@ interface MultilevelTextSource : TextSource { } } +@Deprecated("This class will be removed soon. Use TextSources instead") data class TextPart( val range: IntRange, val source: TextSource ) +@Deprecated("This method is no longer required to work with TextSources") fun List.justTextSources() = map { it.source } +internal fun List.toTextParts(preOffset: Int = 0): List { + var i = preOffset + return map { + TextPart( + i until (i + it.source.length), + it + ).also { + i = it.range.last + 1 + } + } +} + fun List.makeString() = joinToString("") { it.source } -internal fun MultilevelTextSource.textParts(offset: Int): List = subsources.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/CommonAbstracts/Texted.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt index 0b556444e5..0274b688cf 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 @@ -5,31 +5,31 @@ import dev.inmo.tgbotapi.types.ParseMode.ParseMode interface Texted { val text: String? } +interface TextedWithTextSources : Texted { + /** + * Full list of [TextSource] built from source[TextedInput.textEntities] + */ + val textSources: List? +} interface ParsableOutput : Texted { val parseMode: ParseMode? } -interface EntitiesOutput : Texted { +interface EntitiesOutput : TextedWithTextSources { val entities: List? + get() = textSources } interface TextedOutput : ParsableOutput, EntitiesOutput -interface TextedInput : Texted { +interface TextedInput : TextedWithTextSources { + override val textSources: List /** * Here must be full list of entities. This list must contains [TextPart]s with * [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] in case if source text contains parts of * regular text */ val textEntities: List + get() = textSources.toTextParts() } - -/** - * Full list of [TextSource] built from source[TextedInput.textEntities] - * - * @see TextedInput.textEntities - * @see justTextSources - */ -val TextedInput.textSources - get() = textEntities.justTextSources() 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 617970f108..5e08caeda3 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,6 +1,7 @@ package dev.inmo.tgbotapi.requests.edit.caption -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.requests.edit.media.MediaContentMessageResultDeserializer import dev.inmo.tgbotapi.types.* @@ -58,8 +59,8 @@ data class EditChatMessageCaption internal constructor( @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditChatMessage, EditTextChatMessage, EditReplyMessage { - override val entities: List? by lazy { - rawEntities ?.asTextParts(text) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text) } override fun method(): String = editMessageCaptionMethod 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 20145b3939..cf5a2c7d20 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,6 +1,7 @@ package dev.inmo.tgbotapi.requests.edit.caption -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* @@ -47,8 +48,8 @@ data class EditInlineMessageCaption internal constructor( @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditInlineMessage, EditTextChatMessage, EditReplyMessage { - override val entities: List? by lazy { - rawEntities ?.asTextParts(text) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text) } override fun method(): String = editMessageCaptionMethod 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 a0f37f90b3..a65d6de1a0 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,6 +1,7 @@ package dev.inmo.tgbotapi.requests.edit.text -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.requests.send.TextContentMessageResultDeserializer import dev.inmo.tgbotapi.types.* @@ -64,8 +65,8 @@ data class EditChatMessageText internal constructor( @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditChatMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage { - override val entities: List? by lazy { - rawEntities ?.asTextParts(text) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text) } override fun method(): String = editMessageTextMethod 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 61c89f500d..df537101fb 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,6 +1,7 @@ package dev.inmo.tgbotapi.requests.edit.text -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* @@ -53,8 +54,8 @@ data class EditInlineMessageText internal constructor( @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditInlineMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage { - override val entities: List? by lazy { - rawEntities ?.asTextParts(text) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text) } override fun method(): String = editMessageTextMethod 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 4ddbf8e68f..877193c498 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 @@ -62,8 +62,8 @@ data class CopyMessage internal constructor( TextedOutput { override val chatId: ChatIdentifier get() = fromChatId - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } override fun method(): String = "copyMessage" 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 c36219778c..e6b72d7a00 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,6 +1,7 @@ package dev.inmo.tgbotapi.requests.send -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.types.DisableWebPagePreview import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.types.* @@ -83,8 +84,8 @@ data class SendTextMessage internal constructor( TextableSendMessageRequest>, DisableWebPagePreview { - override val entities: List? by lazy { - rawEntities ?.asTextParts(text) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text) } init { 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 4e58cc23a4..a464986417 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,6 +1,7 @@ package dev.inmo.tgbotapi.requests.send.media -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* @@ -20,7 +21,7 @@ fun SendAnimation( chatId: ChatIdentifier, animation: InputFile, thumb: InputFile? = null, - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null, duration: Long? = null, width: Int? = null, @@ -39,7 +40,7 @@ fun SendAnimation( chatId, animationAsFileId, thumbAsFileId, - caption, + text, parseMode, null, duration, @@ -144,8 +145,8 @@ data class SendAnimationData internal constructor( DuratedSendMessageRequest>, SizedSendMessageRequest> { - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } init { 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 82e15305a9..e18d8562fe 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 @@ -20,7 +20,7 @@ fun SendAudio( chatId: ChatIdentifier, audio: InputFile, thumb: InputFile? = null, - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null, duration: Long? = null, performer: String? = null, @@ -39,7 +39,7 @@ fun SendAudio( chatId, audioAsFileId, thumbAsFileId, - caption, + text, parseMode, null, duration, @@ -145,8 +145,8 @@ data class SendAudioData internal constructor( DuratedSendMessageRequest>, Performerable { - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } init { 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 6a515be8a4..9bee0c53df 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,6 +1,7 @@ package dev.inmo.tgbotapi.requests.send.media -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* @@ -29,7 +30,7 @@ fun SendDocument( chatId: ChatIdentifier, document: InputFile, thumb: InputFile? = null, - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -46,7 +47,7 @@ fun SendDocument( chatId, documentAsFileId, thumbAsFileId, - caption, + text, parseMode, null, disableNotification, @@ -157,8 +158,8 @@ data class SendDocumentData internal constructor( TextableSendMessageRequest>, ThumbedSendMessageRequest> { - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } init { 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 c492456f31..b0840dfc95 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,6 +1,7 @@ package dev.inmo.tgbotapi.requests.send.media -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* @@ -18,7 +19,7 @@ import kotlinx.serialization.* fun SendPhoto( chatId: ChatIdentifier, photo: InputFile, - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -28,7 +29,7 @@ fun SendPhoto( val data = SendPhotoData( chatId, (photo as? FileId) ?.fileId, - caption, + text, parseMode, null, disableNotification, @@ -100,8 +101,8 @@ data class SendPhotoData internal constructor( ReplyingMarkupSendMessageRequest>, TextableSendMessageRequest> { - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } init { 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 52e7ae8ba3..8d4dcfcc71 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,6 +1,7 @@ package dev.inmo.tgbotapi.requests.send.media -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* @@ -20,7 +21,7 @@ fun SendVideo( chatId: ChatIdentifier, video: InputFile, thumb: InputFile? = null, - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null, duration: Long? = null, width: Int? = null, @@ -40,7 +41,7 @@ fun SendVideo( chatId, videoAsFileId, thumbAsFileId, - caption, + text, parseMode, null, duration, @@ -150,8 +151,8 @@ data class SendVideoData internal constructor( DuratedSendMessageRequest>, SizedSendMessageRequest> { - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } init { 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 69e6d0f756..0e8c0b28ab 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,6 +1,7 @@ package dev.inmo.tgbotapi.requests.send.media -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* @@ -19,7 +20,7 @@ import kotlinx.serialization.* fun SendVoice( chatId: ChatIdentifier, voice: InputFile, - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null, duration: Long? = null, disableNotification: Boolean = false, @@ -33,7 +34,7 @@ fun SendVoice( val data = SendVoiceData( chatId, voiceAsFileId, - caption, + text, parseMode, null, duration, @@ -120,8 +121,8 @@ data class SendVoiceData internal constructor( TextableSendMessageRequest>, DuratedSendMessageRequest> { - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } init { 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 af6bc6e0da..387382016b 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 @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.requests.send.payments +import dev.inmo.tgbotapi.CommonAbstracts.CommonSendInvoiceData import dev.inmo.tgbotapi.CommonAbstracts.types.* import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest import dev.inmo.tgbotapi.types.* @@ -9,7 +10,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializ import dev.inmo.tgbotapi.types.message.payments.InvoiceContent import dev.inmo.tgbotapi.types.payments.LabeledPrice import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer -import dev.inmo.tgbotapi.types.payments.abstracts.* +import dev.inmo.tgbotapi.types.payments.abstracts.Currency import kotlinx.serialization.* private val invoiceMessageSerializer: DeserializationStrategy> @@ -23,36 +24,40 @@ data class SendInvoice( @SerialName(chatIdField) override val chatId: ChatId, @SerialName(titleField) - val title: String, + override val title: String, @SerialName(descriptionField) - val description: String, + override val description: String, @SerialName(payloadField) - val payload: String, + override val payload: String, @SerialName(providerTokenField) - val providerToken: String, - @SerialName(startParameterField) - val startParameter: StartParameter, + override val providerToken: String, @SerialName(currencyField) override val currency: Currency, @Serializable(LabeledPricesSerializer::class) @SerialName(pricesField) override val prices: List, + @SerialName(maxTipAmountField) + override val maxTipAmount: Int? = null, + @SerialName(suggestedTipAmountsField) + override val suggestedTipAmounts: List? = null, + @SerialName(startParameterField) + val startParameter: StartParameter? = null, @SerialName(providerDataField) - val providerData: String? = null, + override val providerData: String? = null, @SerialName(requireNameField) - val requireName: Boolean = false, + override val requireName: Boolean = false, @SerialName(requirePhoneNumberField) - val requirePhoneNumber: Boolean = false, + override val requirePhoneNumber: Boolean = false, @SerialName(requireEmailField) - val requireEmail: Boolean = false, + override val requireEmail: Boolean = false, @SerialName(requireShippingAddressField) - val requireShippingAddress: Boolean = false, + override val requireShippingAddress: Boolean = false, @SerialName(shouldSendPhoneNumberToProviderField) - val shouldSendPhoneNumberToProvider: Boolean = false, + override val shouldSendPhoneNumberToProvider: Boolean = false, @SerialName(shouldSendEmailToProviderField) - val shouldSendEmailToProvider: Boolean = false, + override val shouldSendEmailToProvider: Boolean = false, @SerialName(priceDependOnShipAddressField) - val priceDependOnShipAddress: Boolean = false, + override val priceDependOnShipAddress: Boolean = false, @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) @@ -61,8 +66,7 @@ data class SendInvoice( override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null -) : Currencied, - Priced, +) : CommonSendInvoiceData, ChatRequest, DisableNotification, ReplyMessageId, @@ -75,24 +79,35 @@ data class SendInvoice( get() = serializer() @SerialName(photoUrlField) - var photoUrl: String? = null + override var photoUrl: String? = null private set @SerialName(photoSizeField) - var photoSize: Long? = null + override var photoSize: Long? = null private set @SerialName(photoWidthField) - var photoWidth: Int? = null + override var photoWidth: Int? = null private set @SerialName(photoHeightField) - var photoHeight: Int? = null + override var photoHeight: Int? = null private set - fun setPhoto( + init { + suggestedTipAmounts ?.let { _ -> + require(suggestedTipAmounts.size in suggestedTipAmountsLimit) + maxTipAmount ?.let { _ -> + require( + suggestedTipAmounts.none { it > maxTipAmount } + ) + } + } + } + + override fun setPhoto( photoUrl: String, - photoSize: Long? = null, - photoWidth: Int? = null, - photoHeight: Int? = null + photoSize: Long?, + photoWidth: Int?, + photoHeight: Int? ) { this.photoUrl = photoUrl this.photoSize = photoSize @@ -100,7 +115,7 @@ data class SendInvoice( this.photoHeight = photoHeight } - fun unsetPhoto() { + override fun unsetPhoto() { photoUrl = null photoSize = null photoWidth = null 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 2af52017ef..844482379a 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 @@ -338,7 +338,7 @@ data class SendQuizPoll internal constructor( @SerialName(isClosedField) override val isClosed: Boolean = false, @SerialName(explanationField) - override val explanation: String? = null, + override val text: String? = null, @SerialName(explanationParseModeField) override val parseMode: ParseMode? = null, @SerialName(explanationEntitiesField) @@ -355,12 +355,12 @@ data class SendQuizPoll internal constructor( override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null -) : SendPoll(), ExplainedOutput { +) : SendPoll(), ExplainedOutput, TextedOutput { override val type: String = quizPollType override val requestSerializer: SerializationStrategy<*> get() = serializer() - override val entities: List? by lazy { - rawEntities ?.asTextParts(explanation ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } init { @@ -371,9 +371,9 @@ data class SendQuizPoll internal constructor( throw IllegalArgumentException("Correct option id must be in range of $correctOptionIdRange, but actual " + "value is $correctOptionId") } - if (explanation != null && explanation.length !in explanationLimit) { + if (text != null && text.length !in explanationLimit) { error("Quiz poll explanation size must be in range $explanationLimit," + - "but actual explanation contains ${explanation.length} symbols") + "but actual explanation contains ${text.length} symbols") } } } 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 c1c935fb26..8c89fdf0d5 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 @@ -80,6 +80,8 @@ val openPeriodPollSecondsLimit = 5 .. 600 val membersLimit = 1 .. 99999 +val suggestedTipAmountsLimit = 1 .. 4 + const val botActionActualityTime: Seconds = 5 // Made as lazy for correct work in K/JS @@ -315,6 +317,10 @@ const val xShiftField = "x_shift" const val yShiftField = "y_shift" const val scaleField = "scale" +const val maxTipAmountField = "max_tip_amount" +const val suggestedTipAmountsField = "suggested_tip_amounts" +const val chatTypeField = "chat_type" + const val explanationEntitiesField = "explanation_entities" const val explanationParseModeField = "explanation_parse_mode" const val openPeriodField = "open_period" @@ -349,6 +355,7 @@ const val providerPaymentChargeIdField = "provider_payment_charge_id" const val providerTokenField = "provider_token" const val providerDataField = "provider_data" const val usersField = "users" +const val startDateField = "start_date" const val requireNameField = "need_name" const val requirePhoneNumberField = "need_phone_number" 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 30f23487c8..c636fcc9f0 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,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.InlineQueryResultAudioCached @@ -48,7 +49,7 @@ data class InlineQueryResultAudioCachedImpl internal constructor( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultAudioCached { override val type: String = inlineQueryResultAudioType - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } } 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 f4221fae20..0139a0ec13 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,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString 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 @@ -59,7 +60,7 @@ data class InlineQueryResultAudioImpl internal constructor( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultAudio { override val type: String = inlineQueryResultAudioType - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } } 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 2b7bd33291..de9670b328 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,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.InlineQueryResultDocumentCached @@ -56,7 +57,7 @@ data class InlineQueryResultDocumentCachedImpl internal constructor( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultDocumentCached { override val type: String = inlineQueryResultDocumentType - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } } 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 bca7294ef3..ca5c132122 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,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString 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 @@ -73,7 +74,7 @@ data class InlineQueryResultDocumentImpl internal constructor( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultDocument { override val type: String = inlineQueryResultDocumentType - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } } 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 a65dd530ac..b177ef247d 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,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.InlineQueryResultGifCached @@ -52,7 +53,7 @@ data class InlineQueryResultGifCachedImpl internal constructor( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultGifCached { override val type: String = inlineQueryResultGifType - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } } 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 d282045d62..a09cf7c042 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,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString 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 @@ -72,8 +73,8 @@ data class InlineQueryResultGifImpl internal constructor( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultGif { override val type: String = inlineQueryResultGifType - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } init { 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 d7726fa700..ba4722d6fb 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,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.InlineQueryResultMpeg4GifCached @@ -52,7 +53,7 @@ data class InlineQueryResultMpeg4GifCachedImpl internal constructor( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultMpeg4GifCached { override val type: String = inlineQueryResultMpeg4GifType - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } } 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 9b07306447..318a4299ce 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,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString 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 @@ -72,8 +73,8 @@ data class InlineQueryResultMpeg4GifImpl internal constructor( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultMpeg4Gif { override val type: String = inlineQueryResultMpeg4GifType - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } init { 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 942fb9039a..8946df450c 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,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.InlineQueryResultPhotoCached @@ -56,7 +57,7 @@ data class InlineQueryResultPhotoCachedImpl internal constructor( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultPhotoCached { override val type: String = inlineQueryResultPhotoType - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } } \ 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 332a2ce09c..e72a13ed81 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,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString 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 @@ -67,7 +68,7 @@ data class InlineQueryResultPhotoImpl internal constructor( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultPhoto { override val type: String = inlineQueryResultPhotoType - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } } 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 8fe16705c5..5211514940 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,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.InlineQueryResultVideoCached @@ -56,7 +57,7 @@ data class InlineQueryResultVideoCachedImpl internal constructor( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultVideoCached { override val type: String = inlineQueryResultVideoType - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } } 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 e055c7f468..85c68034b8 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,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString 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 @@ -77,7 +78,7 @@ data class InlineQueryResultVideoImpl internal constructor( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultVideo { override val type: String = inlineQueryResultVideoType - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } } 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 e5e236120d..1acbf64656 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,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.InlineQueryResultVoiceCached @@ -52,7 +53,7 @@ data class InlineQueryResultVoiceCachedImpl internal constructor( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultVoiceCached { override val type: String = inlineQueryResultVoiceType - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } } 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 02c4189ed8..dd6781faff 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,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString 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 @@ -65,7 +66,7 @@ data class InlineQueryResultVoiceImpl internal constructor( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultVoice { override val type: String = inlineQueryResultVoiceType - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputInvoiceMessageContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputInvoiceMessageContent.kt new file mode 100644 index 0000000000..c02c3f7a03 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputInvoiceMessageContent.kt @@ -0,0 +1,80 @@ +package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent + +import dev.inmo.tgbotapi.CommonAbstracts.CommonSendInvoiceData +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.payments.LabeledPrice +import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer +import dev.inmo.tgbotapi.types.payments.abstracts.Currency +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +class InputInvoiceMessageContent( + @SerialName(titleField) + override val title: String, + @SerialName(descriptionField) + override val description: String, + @SerialName(payloadField) + override val payload: String, + @SerialName(providerTokenField) + override val providerToken: String, + @SerialName(currencyField) + override val currency: Currency, + @Serializable(LabeledPricesSerializer::class) + @SerialName(pricesField) + override val prices: List, + @SerialName(maxTipAmountField) + override val maxTipAmount: Int? = null, + @SerialName(suggestedTipAmountsField) + override val suggestedTipAmounts: List? = null, + @SerialName(providerDataField) + override val providerData: String? = null, + @SerialName(requireNameField) + override val requireName: Boolean = false, + @SerialName(requirePhoneNumberField) + override val requirePhoneNumber: Boolean = false, + @SerialName(requireEmailField) + override val requireEmail: Boolean = false, + @SerialName(requireShippingAddressField) + override val requireShippingAddress: Boolean = false, + @SerialName(shouldSendPhoneNumberToProviderField) + override val shouldSendPhoneNumberToProvider: Boolean = false, + @SerialName(shouldSendEmailToProviderField) + override val shouldSendEmailToProvider: Boolean = false, + @SerialName(priceDependOnShipAddressField) + override val priceDependOnShipAddress: Boolean = false +) : InputMessageContent, CommonSendInvoiceData { + @SerialName(photoUrlField) + override var photoUrl: String? = null + private set + @SerialName(photoSizeField) + override var photoSize: Long? = null + private set + + @SerialName(photoWidthField) + override var photoWidth: Int? = null + private set + @SerialName(photoHeightField) + override var photoHeight: Int? = null + private set + + override fun setPhoto( + photoUrl: String, + photoSize: Long?, + photoWidth: Int?, + photoHeight: Int? + ) { + this.photoUrl = photoUrl + this.photoSize = photoSize + this.photoWidth = photoWidth + this.photoHeight = photoHeight + } + + override fun unsetPhoto() { + photoUrl = null + photoSize = null + photoWidth = null + photoHeight = null + } +} 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 5871b5a144..17b88fb49c 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 @@ -38,7 +38,7 @@ data class InputTextMessageContent internal constructor( @SerialName(disableWebPagePreviewField) override val disableWebPagePreview: Boolean? = null ) : TextedOutput, DisableWebPagePreview, InputMessageContent { - override val entities: List? by lazy { - rawEntities ?.asTextParts(text) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text) } } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContentSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContentSerializer.kt index 58e4c76a13..39052ffbc4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContentSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContentSerializer.kt @@ -17,6 +17,7 @@ internal object InputMessageContentSerializer : KSerializer is InputLocationMessageContent -> InputLocationMessageContent.serializer().serialize(encoder, value) is InputTextMessageContent -> InputTextMessageContent.serializer().serialize(encoder, value) is InputVenueMessageContent -> InputVenueMessageContent.serializer().serialize(encoder, value) + is InputInvoiceMessageContent -> InputInvoiceMessageContent.serializer().serialize(encoder, value) else -> throw IllegalArgumentException("Unknown for serializing InputContactMessageContent") } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/abstracts/InlineQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/abstracts/InlineQuery.kt index c785cf5801..d942a452d7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/abstracts/InlineQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/abstracts/InlineQuery.kt @@ -2,10 +2,12 @@ package dev.inmo.tgbotapi.types.InlineQueries.abstracts import dev.inmo.tgbotapi.types.InlineQueryIdentifier import dev.inmo.tgbotapi.types.User +import dev.inmo.tgbotapi.types.chat.ChatType interface InlineQuery { val id: InlineQueryIdentifier val from: User val query: String val offset: String + val chatType: ChatType? } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/BaseInlineQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/BaseInlineQuery.kt index ba1e09280a..c127b2f1c1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/BaseInlineQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/BaseInlineQuery.kt @@ -3,10 +3,12 @@ package dev.inmo.tgbotapi.types.InlineQueries.query 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.chat.ChatType data class BaseInlineQuery( override val id: InlineQueryIdentifier, override val from: User, override val query: String, - override val offset: String + override val offset: String, + override val chatType: ChatType? ) : InlineQuery 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 fe94c7e34d..78200717bc 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 @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.query 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.chat.ChatType import dev.inmo.tgbotapi.types.location.Location data class LocationInlineQuery( @@ -10,5 +11,6 @@ data class LocationInlineQuery( override val from: User, override val query: String, override val offset: String, + override val chatType: ChatType?, 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 eaf43fca71..13808bbd40 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,8 @@ package dev.inmo.tgbotapi.types.InlineQueries.query import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.chat.ChatType +import dev.inmo.tgbotapi.types.chat.ChatTypeSerializer import dev.inmo.tgbotapi.types.location.Location import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -15,12 +17,15 @@ internal data class RawInlineQuery( val query: String, @SerialName(offsetField) val offset: String, + @SerialName(chatTypeField) + @Serializable(ChatTypeSerializer::class) + val chatType: ChatType? = null, @SerialName(locationField) val location: Location? = null ) { val asInlineQuery by lazy { location ?.let { - LocationInlineQuery(id, from, query, offset, location) - } ?: BaseInlineQuery(id, from, query, offset) + LocationInlineQuery(id, from, query, offset, chatType, location) + } ?: BaseInlineQuery(id, from, query, offset, chatType) } } 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 77eaec8b68..bb65c3c173 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 @@ -44,8 +44,8 @@ data class InputMediaAnimation internal constructor( override val thumb: InputFile? = null ) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, TextedOutput { override val type: String = "animation" - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } @SerialName(mediaField) 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 5dc1aba16f..5b2ed4a6cb 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 @@ -50,8 +50,8 @@ data class InputMediaAudio internal constructor( override val thumb: InputFile? = null ) : 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 val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) @@ -62,12 +62,12 @@ data class InputMediaAudio internal constructor( } fun AudioFile.toInputMediaAudio( - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null, title: String? = this.title ): InputMediaAudio = InputMediaAudio( fileId, - caption, + text, parseMode, duration, performer, 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 94e5af6b31..c695ed1363 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 @@ -13,11 +13,11 @@ internal const val documentInputMediaType = "document" fun InputMediaDocument( file: InputFile, - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null, thumb: InputFile? = null, disableContentTypeDetection: Boolean? = null -) = InputMediaDocument(file, caption, parseMode, null, thumb, disableContentTypeDetection) +) = InputMediaDocument(file, text, parseMode, null, thumb, disableContentTypeDetection) fun InputMediaDocument( file: InputFile, @@ -50,8 +50,8 @@ data class InputMediaDocument internal constructor( val disableContentTypeDetection: Boolean? = null ) : InputMedia, DocumentMediaGroupMemberInputMedia, ThumbedInputMedia { override val type: String = documentInputMediaType - override val entities: List? by lazy { - rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + override val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) @@ -62,11 +62,11 @@ data class InputMediaDocument internal constructor( } fun DocumentFile.toInputMediaDocument( - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null ) = InputMediaDocument( fileId, - caption, + text, parseMode, thumb ?.fileId ) 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 05ba4fb671..3bf3ff4ba7 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 @@ -34,8 +34,8 @@ data class InputMediaPhoto internal constructor( 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 val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) @@ -46,11 +46,11 @@ data class InputMediaPhoto internal constructor( } fun PhotoSize.toInputMediaPhoto( - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null ): InputMediaPhoto = InputMediaPhoto( fileId, - caption, + text, parseMode ) 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 f7907dd023..f5512043c1 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,6 +1,7 @@ package dev.inmo.tgbotapi.types.InputMedia -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend import dev.inmo.tgbotapi.types.* @@ -45,8 +46,8 @@ data class InputMediaVideo internal constructor ( 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 val textSources: List? by lazy { + rawEntities ?.asTextSources(text ?: return@lazy null) } override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) 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 d8bff5f11d..4234bdd191 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,10 +1,9 @@ package dev.inmo.tgbotapi.types.MessageEntity -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.types.User -import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource -import dev.inmo.tgbotapi.utils.internal.shiftSourcesToTheLeft import kotlinx.serialization.Serializable @Serializable @@ -15,70 +14,115 @@ internal data class RawMessageEntity( val url: String? = null, val user: User? = null, val language: String? = null -) - -internal fun RawMessageEntity.asTextParts( - source: String, - subParts: List -): List { - val sourceSubstring: String = source.substring(offset, offset + length) - val range = offset until (offset + length) - val shiftedSubSources = sourceSubstring.fullListOfSubSource(subParts.shiftSourcesToTheLeft(offset)).justTextSources() - return when (type) { - "mention" -> MentionTextSource(sourceSubstring, shiftedSubSources) - "hashtag" -> HashTagTextSource(sourceSubstring, shiftedSubSources) - "cashtag" -> CashTagTextSource(sourceSubstring, shiftedSubSources) - "bot_command" -> BotCommandTextSource(sourceSubstring) - "url" -> URLTextSource(sourceSubstring) - "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"), shiftedSubSources) - "underline" -> UnderlineTextSource(sourceSubstring, shiftedSubSources) - "strikethrough" -> StrikethroughTextSource(sourceSubstring, shiftedSubSources) - else -> RegularTextSource(sourceSubstring) - }.let { - val part = TextPart(range, it) - if (it !is MultilevelTextSource && subParts.isNotEmpty()) { - (subParts + part).sortedBy { currentPart -> currentPart.range.first } - } else { - listOf(part) - } +) { + internal val range by lazy { + offset until (offset + length) } } -internal fun createTextPart(originalFullString: String, entities: RawMessageEntities): List { - val mutableEntities = entities.toMutableList() - mutableEntities.sortBy { it.offset } - val resultList = mutableListOf() +internal fun RawMessageEntity.asTextSource( + source: String, + subParts: List +): TextSource { + val sourceSubstring: String = source.substring(range) + val subPartsWithRegulars by lazy { + subParts.fillWithRegulars(sourceSubstring) + } + return when (type) { + "mention" -> MentionTextSource(sourceSubstring, subPartsWithRegulars) + "hashtag" -> HashTagTextSource(sourceSubstring, subPartsWithRegulars) + "cashtag" -> CashTagTextSource(sourceSubstring, subPartsWithRegulars) + "bot_command" -> BotCommandTextSource(sourceSubstring) + "url" -> URLTextSource(sourceSubstring) + "email" -> EMailTextSource(sourceSubstring, subPartsWithRegulars) + "phone_number" -> PhoneNumberTextSource(sourceSubstring, subPartsWithRegulars) + "bold" -> BoldTextSource(sourceSubstring, subPartsWithRegulars) + "italic" -> ItalicTextSource(sourceSubstring, subPartsWithRegulars) + "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"), subPartsWithRegulars) + "underline" -> UnderlineTextSource(sourceSubstring, subPartsWithRegulars) + "strikethrough" -> StrikethroughTextSource(sourceSubstring, subPartsWithRegulars) + else -> RegularTextSource(sourceSubstring) + } +} + +private inline operator fun > ClosedRange.contains(other: ClosedRange): Boolean { + return start <= other.start && endInclusive >= other.endInclusive +} + +internal fun List.fillWithRegulars(source: String): List { + var index = 0 + val result = mutableListOf() + for (i in 0 until size) { + val textSource = get(i) + val thisSourceInStart = source.startsWith(textSource.source, index) + if (!thisSourceInStart) { + val regularEndIndex = source.indexOf(textSource.source) + result.add(regular(source.substring(index, regularEndIndex))) + index = regularEndIndex + } + result.add(textSource) + index += textSource.source.length + } + + if (index != source.length) { + result.add(regular(source.substring(index, source.length))) + } + + return result +} + +private fun createTextSources(originalFullString: String, entities: RawMessageEntities): List { + val mutableEntities = entities.toMutableList().apply { sortBy { it.offset } } + val resultList = mutableListOf() while (mutableEntities.isNotEmpty()) { - val currentFirst = mutableEntities.removeAt(0) - val subEntities = if (mutableEntities.isNotEmpty()) { - val lastIndex = currentFirst.offset + currentFirst.length - val subEntities = mutableListOf() - while (mutableEntities.isNotEmpty()) { - val currentPossibleSubEntity = mutableEntities.first() - if (currentPossibleSubEntity.offset < lastIndex) { - subEntities.add(currentPossibleSubEntity) - mutableEntities.removeAt(0) - } else { - break + var parent = mutableEntities.removeFirst() + val subentities = mutableListOf() + val toAddCutted = mutableListOf() + while (mutableEntities.isNotEmpty()) { + val potentialParent = mutableEntities.first() + when { + potentialParent.range.first > parent.range.last -> break + potentialParent.range in parent.range -> { + subentities.add(potentialParent) + } + potentialParent.offset == parent.offset && potentialParent.length > parent.length -> { + subentities.add(parent) + parent = potentialParent + } + else -> { // need to cut + toAddCutted.add(potentialParent) } } - subEntities - } else { - emptyList() + mutableEntities.remove(potentialParent) } - - resultList.addAll( - currentFirst.asTextParts( + val subtextSources = if (subentities.isNotEmpty()) { + mutableEntities.removeAll(subentities) + if (toAddCutted.isNotEmpty()) { + val borderIndex = parent.range.last + 1 + mutableEntities.addAll( + 0, + toAddCutted.map { + val firstLength = borderIndex - it.offset + subentities.add(it.copy(length = firstLength)) + it.copy( + offset = borderIndex, + length = it.length - firstLength + ) + } + ) + } + createTextSources(originalFullString, subentities) + } else { + emptyList() + } + resultList.add( + parent.asTextSource( originalFullString, - createTextPart(originalFullString, subEntities) + subtextSources ) ) } @@ -86,46 +130,41 @@ internal fun createTextPart(originalFullString: String, entities: RawMessageEnti return resultList } -internal fun TextPart.asRawMessageEntities(): List { +internal fun TextSource.toRawMessageEntities(offset: Int = 0): List { val source = source - val length = range.last - range.first + 1 - + val length = source.length 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) + when (this) { + is MentionTextSource -> RawMessageEntity("mention", offset, length) + is HashTagTextSource -> RawMessageEntity("hashtag", offset, length) + is CashTagTextSource -> RawMessageEntity("cashtag", offset, length) + is BotCommandTextSource -> RawMessageEntity("bot_command", offset, length) + is URLTextSource -> RawMessageEntity("url", offset, length) + is EMailTextSource -> RawMessageEntity("email", offset, length) + is PhoneNumberTextSource -> RawMessageEntity("phone_number", offset, length) + is BoldTextSource -> RawMessageEntity("bold", offset, length) + is ItalicTextSource -> RawMessageEntity("italic", offset, length) + is CodeTextSource -> RawMessageEntity("code", offset, length) + is PreTextSource -> RawMessageEntity("pre", offset, length, language = language) + is TextLinkTextSource -> RawMessageEntity("text_link", offset, length, url) + is TextMentionTextSource -> RawMessageEntity("text_mention", offset, length, user = user) + is UnderlineTextSource -> RawMessageEntity("underline", offset, length) + is StrikethroughTextSource -> RawMessageEntity("strikethrough", offset, length) else -> null } - ) + if (source is MultilevelTextSource) { - source.textParts(range.first).asRawMessageEntities() + ) + if (this is MultilevelTextSource) { + subsources.toRawMessageEntities(offset) } else { emptyList() } } -internal fun List.asRawMessageEntities(): List = flatMap { it.asRawMessageEntities() } -internal fun List.toTextParts(preOffset: Int = 0): List { +internal fun List.toRawMessageEntities(preOffset: Int = 0): List { var i = preOffset - return map { - TextPart( - i until (i + it.source.length), - it - ).also { - i = it.range.last + 1 + return flatMap { textSource -> + textSource.toRawMessageEntities(i).also { + i += it.maxByOrNull { it.length } ?.length ?: textSource.source.length } } } @@ -136,10 +175,8 @@ fun String.removeLeading(word: String) = if (startsWith(word)){ this } -internal fun List.toRawMessageEntities(): List = toTextParts().asRawMessageEntities() +internal fun List.toRawMessageEntities(): List = toRawMessageEntities(0) -internal fun RawMessageEntities.asTextParts(sourceString: String): List = sourceString.fullListOfSubSource( - createTextPart(sourceString, this) -) +internal fun RawMessageEntities.asTextSources(sourceString: String): List = createTextSources(sourceString, this).fillWithRegulars(sourceString) 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 b577bc040f..1129a56e55 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 @@ -3,7 +3,6 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* -import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable /** diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSourceSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSourceSerializer.kt index a9f76a93ad..4af8f92fcd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSourceSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSourceSerializer.kt @@ -2,14 +2,13 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.micro_utils.serialization.typed_serializer.TypedSerializer import dev.inmo.tgbotapi.CommonAbstracts.TextSource -import dev.inmo.tgbotapi.CommonAbstracts.justTextSources -import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntities -import dev.inmo.tgbotapi.utils.RiskFeature -import kotlinx.serialization.* -import kotlinx.serialization.builtins.serializer -import kotlinx.serialization.descriptors.* -import kotlinx.serialization.encoding.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity +import dev.inmo.tgbotapi.types.MessageEntity.asTextSources +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializer +import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder private val baseSerializers: Map> = mapOf( "regular" to RegularTextSource.serializer(), diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/actions/BotAction.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/actions/BotAction.kt index 6732f68fad..ea15453612 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/actions/BotAction.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/actions/BotAction.kt @@ -26,6 +26,8 @@ internal object BotActionSerializer: KSerializer { UploadVideoAction.actionName -> UploadVideoAction RecordAudioAction.actionName -> RecordAudioAction UploadAudioAction.actionName -> UploadAudioAction + RecordVoiceAction.actionName -> RecordVoiceAction + UploadVoiceAction.actionName -> UploadVoiceAction UploadDocumentAction.actionName -> UploadDocumentAction FindLocationAction.actionName -> FindLocationAction RecordVideoNoteAction.actionName -> RecordVideoNoteAction @@ -83,24 +85,70 @@ inline fun BotAction.asUploadVideo() = this as? UploadVideoAction * Will notify user that bot is recording some audio */ @Serializable(BotActionSerializer::class) +@Deprecated( + "Deprecated according to https://core.telegram.org/bots/api-changelog#april-26-2021", + ReplaceWith("RecordVoiceAction", "dev.inmo.tgbotapi.types.actions.RecordVoiceAction") +) object RecordAudioAction : BotAction() { override val actionName: String = "record_audio" } +@Deprecated( + "Deprecated according to https://core.telegram.org/bots/api-changelog#april-26-2021", + ReplaceWith("recordVoice", "dev.inmo.tgbotapi.types.actions.recordVoice") +) inline val recordAudio get() = RecordAudioAction +@Deprecated( + "Deprecated according to https://core.telegram.org/bots/api-changelog#april-26-2021", + ReplaceWith("asRecordVoice", "dev.inmo.tgbotapi.types.actions.asRecordVoice") +) inline fun BotAction.asRecordAudio() = this as? RecordAudioAction /** * Will notify user that bot is uploading some audio */ @Serializable(BotActionSerializer::class) +@Deprecated( + "Deprecated according to https://core.telegram.org/bots/api-changelog#april-26-2021", + ReplaceWith("UploadVoiceAction", "dev.inmo.tgbotapi.types.actions.UploadVoiceAction") +) object UploadAudioAction : BotAction() { override val actionName: String = "upload_audio" } +@Deprecated( + "Deprecated according to https://core.telegram.org/bots/api-changelog#april-26-2021", + ReplaceWith("uploadVoice", "dev.inmo.tgbotapi.types.actions.uploadVoice") +) inline val uploadAudio get() = UploadAudioAction +@Deprecated( + "Deprecated according to https://core.telegram.org/bots/api-changelog#april-26-2021", + ReplaceWith("asUploadVoice", "dev.inmo.tgbotapi.types.actions.asUploadVoice") +) inline fun BotAction.asUploadAudio() = this as? UploadAudioAction +/** + * Will notify user that bot is recording some audio + */ +@Serializable(BotActionSerializer::class) +object RecordVoiceAction : BotAction() { + override val actionName: String = "record_voice" +} +inline val recordVoice + get() = RecordVoiceAction +inline fun BotAction.asRecordVoice() = this as? RecordVoiceAction + +/** + * Will notify user that bot is uploading some audio + */ +@Serializable(BotActionSerializer::class) +object UploadVoiceAction : BotAction() { + override val actionName: String = "upload_voice" +} +inline val uploadVoice + get() = UploadVoiceAction +inline fun BotAction.asUploadVoice() = this as? UploadVoiceAction + /** * Will notify user that bot is uploading some document */ diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardMarkup.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardMarkup.kt index cc3e707e47..cd17bb80df 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardMarkup.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardMarkup.kt @@ -21,7 +21,7 @@ data class InlineKeyboardMarkup( // first button is not PayInlineKeyboardButton val firstIsPaymentButton = keyboard.first().firstOrNull() is PayInlineKeyboardButton if (!firstIsPaymentButton) { - error("In case if PayInlineKeyboardButton included in keyboard - it must ") + error("In case if PayInlineKeyboardButton included in keyboard - it must be the first one") } } } 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 23a27339a0..56a0c78fb1 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 @@ -4,10 +4,10 @@ import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.chat.abstracts.UnknownChatType import dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedChat +import dev.inmo.tgbotapi.types.chat.abstracts.extended.UnknownExtendedChat import dev.inmo.tgbotapi.types.chat.extended.* import dev.inmo.tgbotapi.utils.nonstrictJsonFormat -import kotlinx.serialization.InternalSerializationApi -import kotlinx.serialization.KSerializer +import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder @@ -17,6 +17,40 @@ import kotlinx.serialization.json.* private val formatter get() = nonstrictJsonFormat +@Serializable(ChatTypeSerializer::class) +sealed class ChatType { + abstract val stringified: String + @Serializable(ChatTypeSerializer::class) + object PrivateChatType : ChatType() { override val stringified = "private" } + @Serializable(ChatTypeSerializer::class) + object GroupChatType : ChatType() { override val stringified = "group" } + @Serializable(ChatTypeSerializer::class) + object SupergroupChatType : ChatType() { override val stringified = "supergroup" } + @Serializable(ChatTypeSerializer::class) + object ChannelChatType : ChatType() { override val stringified = "channel" } + @Serializable(ChatTypeSerializer::class) + class UnknownChatType(override val stringified: String) : ChatType() +} +val String.asChatType + get() = when (this) { + ChatType.PrivateChatType.stringified -> ChatType.PrivateChatType + ChatType.GroupChatType.stringified -> ChatType.GroupChatType + ChatType.SupergroupChatType.stringified -> ChatType.SupergroupChatType + ChatType.ChannelChatType.stringified -> ChatType.ChannelChatType + else -> ChatType.UnknownChatType(this) + } +@Serializer(ChatType::class) +object ChatTypeSerializer : KSerializer { + override val descriptor: SerialDescriptor = String.serializer().descriptor + override fun deserialize(decoder: Decoder): ChatType { + return decoder.decodeString().asChatType + } + + override fun serialize(encoder: Encoder, value: ChatType) { + encoder.encodeString(value.stringified) + } +} + internal object PreviewChatSerializer : KSerializer { @InternalSerializationApi override val descriptor: SerialDescriptor = buildSerialDescriptor("PreviewChatSerializer", PolymorphicKind.OPEN) @@ -24,14 +58,14 @@ internal object PreviewChatSerializer : KSerializer { override fun deserialize(decoder: Decoder): Chat { val decodedJson = JsonObject.serializer().deserialize(decoder) - val type = decodedJson[typeField] ?.jsonPrimitive ?.content ?: error("Field $typeField must be presented, but absent in $decodedJson") + val type = decodedJson[typeField] ?.jsonPrimitive ?.content ?.asChatType ?: error("Field $typeField must be presented, but absent in $decodedJson") return when (type) { - "private" -> formatter.decodeFromJsonElement(PrivateChatImpl.serializer(), decodedJson) - "group" -> formatter.decodeFromJsonElement(GroupChatImpl.serializer(), decodedJson) - "supergroup" -> formatter.decodeFromJsonElement(SupergroupChatImpl.serializer(), decodedJson) - "channel" -> formatter.decodeFromJsonElement(ChannelChatImpl.serializer(), decodedJson) - else -> UnknownChatType( + ChatType.PrivateChatType -> formatter.decodeFromJsonElement(PrivateChatImpl.serializer(), decodedJson) + ChatType.GroupChatType -> formatter.decodeFromJsonElement(GroupChatImpl.serializer(), decodedJson) + ChatType.SupergroupChatType -> formatter.decodeFromJsonElement(SupergroupChatImpl.serializer(), decodedJson) + ChatType.ChannelChatType -> formatter.decodeFromJsonElement(ChannelChatImpl.serializer(), decodedJson) + is ChatType.UnknownChatType -> UnknownChatType( formatter.decodeFromJsonElement(Long.serializer(), decodedJson[chatIdField] ?: JsonPrimitive(-1)).toChatId(), decodedJson.toString() ) @@ -56,14 +90,18 @@ internal object ExtendedChatSerializer : KSerializer { override fun deserialize(decoder: Decoder): ExtendedChat { val decodedJson = JsonObject.serializer().deserialize(decoder) - val type = decodedJson[typeField] ?.jsonPrimitive ?.content ?: error("Field $typeField must be presented, but absent in $decodedJson") + val type = decodedJson[typeField] ?.jsonPrimitive ?.content ?.asChatType ?: error("Field $typeField must be presented, but absent in $decodedJson") return when (type) { - "private" -> formatter.decodeFromJsonElement(ExtendedPrivateChatImpl.serializer(), decodedJson) - "group" -> formatter.decodeFromJsonElement(ExtendedGroupChatImpl.serializer(), decodedJson) - "supergroup" -> formatter.decodeFromJsonElement(ExtendedSupergroupChatImpl.serializer(), decodedJson) - "channel" -> formatter.decodeFromJsonElement(ExtendedChannelChatImpl.serializer(), decodedJson) - else -> throw IllegalArgumentException("Unknown type of chat") +// else -> throw IllegalArgumentException("Unknown type of chat") + ChatType.PrivateChatType -> formatter.decodeFromJsonElement(ExtendedPrivateChatImpl.serializer(), decodedJson) + ChatType.GroupChatType -> formatter.decodeFromJsonElement(ExtendedGroupChatImpl.serializer(), decodedJson) + ChatType.SupergroupChatType -> formatter.decodeFromJsonElement(ExtendedSupergroupChatImpl.serializer(), decodedJson) + ChatType.ChannelChatType -> formatter.decodeFromJsonElement(ExtendedChannelChatImpl.serializer(), decodedJson) + is ChatType.UnknownChatType -> UnknownExtendedChat( + formatter.decodeFromJsonElement(Long.serializer(), decodedJson[chatIdField] ?: JsonPrimitive(-1)).toChatId(), + decodedJson.toString() + ) } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChat.kt index 9a888d273c..dea56901e6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChat.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.chat.abstracts.extended +import dev.inmo.tgbotapi.types.ChatId import dev.inmo.tgbotapi.types.ChatPhoto import dev.inmo.tgbotapi.types.chat.ExtendedChatSerializer import dev.inmo.tgbotapi.types.chat.abstracts.Chat @@ -8,4 +9,11 @@ import kotlinx.serialization.Serializable @Serializable(ExtendedChatSerializer::class) interface ExtendedChat : Chat { val chatPhoto: ChatPhoto? -} \ No newline at end of file +} + +data class UnknownExtendedChat( + override val id: ChatId, + val raw: String +) : ExtendedChat { + override val chatPhoto: ChatPhoto? = null +} 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 45b4525896..c3f761259b 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 @@ -34,11 +34,11 @@ data class VideoFile( @Suppress("NOTHING_TO_INLINE") inline fun VideoFile.toInputMediaVideo( - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null ) = InputMediaVideo( fileId, - caption, + text, parseMode, width, height, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/Game.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/Game.kt index 34043f6ad6..63c3c00241 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/Game.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/Game.kt @@ -8,7 +8,7 @@ data class Game( override val title: String, val description: String, val photo: Photo, - override val caption: String? = null, - override val captionEntities: List = emptyList(), + override val text: String? = null, + override val textSources: TextSourcesList = emptyList(), val animation: AnimationFile? = null -) : Titled, CaptionedInput +) : Titled, CaptionedInput, TextedInput diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/RawGame.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/RawGame.kt index a48c195f78..db398702e3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/RawGame.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/RawGame.kt @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.games import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntities -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts +import dev.inmo.tgbotapi.types.MessageEntity.asTextSources import dev.inmo.tgbotapi.types.files.* import kotlinx.serialization.* @@ -16,9 +16,9 @@ internal data class RawGame( @SerialName(photoField) private val photo: Photo, @SerialName(textField) - private val caption: String? = null, + private val text: String? = null, @SerialName(textEntitiesField) - private val captionEntities: RawMessageEntities = emptyList(), + private val textEntities: RawMessageEntities = emptyList(), @SerialName(animationField) private val animation: AnimationFile? = null ) { @@ -27,8 +27,8 @@ internal data class RawGame( title, description, photo, - caption, - caption ?.let { _ -> captionEntities.asTextParts(caption) } ?: emptyList(), + text, + text ?.let { _ -> textEntities.asTextSources(text) } ?: emptyList(), animation ) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/VoiceChatEvent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/VoiceChatEvent.kt index 54bb629cde..289fc5daac 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/VoiceChatEvent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/VoiceChatEvent.kt @@ -1,3 +1,3 @@ package dev.inmo.tgbotapi.types.message.ChatEvents.abstracts -interface VoiceChatEvent : SupergroupEvent +interface VoiceChatEvent : CommonEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/voice/VoiceChatScheduled.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/voice/VoiceChatScheduled.kt new file mode 100644 index 0000000000..8db852aecc --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/voice/VoiceChatScheduled.kt @@ -0,0 +1,13 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents.voice + +import dev.inmo.tgbotapi.types.TelegramDate +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.VoiceChatEvent +import dev.inmo.tgbotapi.types.startDateField +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class VoiceChatScheduled( + @SerialName(startDateField) + val startDate: TelegramDate +) : VoiceChatEvent 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 2d3ebdc703..086b33b792 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 @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.message import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntities -import dev.inmo.tgbotapi.types.MessageEntity.asTextParts +import dev.inmo.tgbotapi.types.MessageEntity.asTextSources import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.* import dev.inmo.tgbotapi.types.dice.Dice @@ -83,6 +83,7 @@ internal data class RawMessage( private val successful_payment: SuccessfulPayment? = null, // Voice Chat Service Messages + private val voice_chat_scheduled: VoiceChatScheduled? = null, private val voice_chat_started: VoiceChatStarted? = null, private val voice_chat_ended: VoiceChatEnded? = null, private val voice_chat_participants_invited: VoiceChatParticipantsInvited? = null, @@ -101,11 +102,11 @@ internal data class RawMessage( ) { private val content: MessageContent? by lazy { val adaptedCaptionEntities = caption ?.let { - (caption_entities ?: emptyList()).asTextParts(caption) + (caption_entities ?: emptyList()).asTextSources(caption) } ?: emptyList() when { - text != null -> TextContent(text, (entities ?: emptyList()).asTextParts(text)) + text != null -> TextContent(text, (entities ?: emptyList()).asTextSources(text)) audio != null -> AudioContent( audio, caption, @@ -182,6 +183,7 @@ internal data class RawMessage( new_chat_title != null -> NewChatTitle(new_chat_title) new_chat_photo != null -> NewChatPhoto(new_chat_photo.toList()) voice_chat_started != null -> voice_chat_started + voice_chat_scheduled != null -> voice_chat_scheduled message_auto_delete_timer_changed != null -> message_auto_delete_timer_changed voice_chat_ended != null -> voice_chat_ended voice_chat_participants_invited != null -> voice_chat_participants_invited 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 abc204e63e..67f08598ae 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,19 +1,18 @@ package dev.inmo.tgbotapi.types.message.content -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSourcesList +import dev.inmo.tgbotapi.CommonAbstracts.TextedInput import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.SendTextMessage import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier -import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.types.ParseMode.defaultParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent data class TextContent( override val text: String, - override val textEntities: List = emptyList() + override val textSources: TextSourcesList = emptyList(), ) : MessageContent, TextedInput { override fun createResend( chatId: ChatIdentifier, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/MediaGroupContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/MediaGroupContent.kt index 7cf2eb6b16..354fb20903 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/MediaGroupContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/MediaGroupContent.kt @@ -1,9 +1,10 @@ package dev.inmo.tgbotapi.types.message.content.abstracts import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput +import dev.inmo.tgbotapi.CommonAbstracts.TextedInput import dev.inmo.tgbotapi.types.InputMedia.* -interface MediaGroupContent : MediaContent, CaptionedInput { +interface MediaGroupContent : MediaContent, CaptionedInput, TextedInput { fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia } 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 edbcb2312b..e1863bf213 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 @@ -15,9 +15,9 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent data class AnimationContent( override val media: AnimationFile, val includedDocument: DocumentFile?, - override val caption: String?, - override val captionEntities: List -) : MediaContent, CaptionedInput { + override val text: String?, + override val textSources: TextSourcesList = emptyList() +) : MediaContent, CaptionedInput, TextedInput { override fun createResend( chatId: ChatIdentifier, disableNotification: Boolean, 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 2d4f9a7148..cb850e9598 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 @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.CommonAbstracts.TextPart -import dev.inmo.tgbotapi.CommonAbstracts.textSources +import dev.inmo.tgbotapi.CommonAbstracts.TextSourcesList import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendAudio import dev.inmo.tgbotapi.types.ChatIdentifier @@ -15,8 +14,8 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.AudioMediaGroupContent data class AudioContent( override val media: AudioFile, - override val caption: String? = null, - override val captionEntities: List = emptyList() + override val text: String? = null, + override val textSources: TextSourcesList = emptyList() ) : AudioMediaGroupContent { override fun createResend( chatId: ChatIdentifier, 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 747cc77fdb..aa8f4dba37 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 @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.TextSourcesList +import dev.inmo.tgbotapi.CommonAbstracts.TextedInput import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendDocument import dev.inmo.tgbotapi.types.ChatIdentifier @@ -16,8 +17,8 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent data class DocumentContent( override val media: DocumentFile, - override val caption: String? = null, - override val captionEntities: List = emptyList() + override val text: String? = null, + override val textSources: TextSourcesList = emptyList() ) : DocumentMediaGroupContent { override fun createResend( chatId: ChatIdentifier, @@ -43,10 +44,10 @@ data class DocumentContent( @Suppress("NOTHING_TO_INLINE") inline fun MediaContent.asDocumentContent() = when (this) { - is CaptionedInput -> DocumentContent( + is TextedInput -> DocumentContent( media.asDocumentFile(), - caption, - captionEntities + text, + textSources ) else -> DocumentContent( media.asDocumentFile() 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 27fc6102fa..11eea15039 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 @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.CommonAbstracts.TextPart -import dev.inmo.tgbotapi.CommonAbstracts.textSources +import dev.inmo.tgbotapi.CommonAbstracts.TextSourcesList import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendPhoto import dev.inmo.tgbotapi.types.ChatIdentifier @@ -16,8 +15,8 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent data class PhotoContent( override val mediaCollection: Photo, - override val caption: String? = null, - override val captionEntities: List = emptyList() + override val text: String? = null, + override val textSources: TextSourcesList = emptyList() ) : MediaCollectionContent, VisualMediaGroupContent { override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content") 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 5b1ec9197b..e32b9ab412 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 @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.CommonAbstracts.TextPart -import dev.inmo.tgbotapi.CommonAbstracts.textSources +import dev.inmo.tgbotapi.CommonAbstracts.TextSourcesList import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendVideo import dev.inmo.tgbotapi.types.ChatIdentifier @@ -15,8 +14,8 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent data class VideoContent( override val media: VideoFile, - override val caption: String? = null, - override val captionEntities: List = emptyList() + override val text: String? = null, + override val textSources: TextSourcesList = emptyList() ) : VisualMediaGroupContent { override fun createResend( chatId: ChatIdentifier, 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 421f2b6a75..95e6340edf 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,9 +13,9 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent data class VoiceContent( override val media: VoiceFile, - override val caption: String? = null, - override val captionEntities: List = emptyList() -) : MediaContent, CaptionedInput { + override val text: String? = null, + override val textSources: TextSourcesList = emptyList() +) : MediaContent, CaptionedInput, TextedInput { override fun createResend( chatId: ChatIdentifier, disableNotification: Boolean, 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 8ca845fcd0..60dff15177 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 @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.types.polls 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.CommonAbstracts.TextSource import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.utils.nonstrictJsonFormat @@ -135,8 +135,8 @@ data class QuizPoll( * Nullable due to documentation (https://core.telegram.org/bots/api#poll) */ val correctOptionId: Int? = null, - override val explanation: String? = null, - override val explanationEntities: List = emptyList(), + override val text: String? = null, + override val textSources: List = emptyList(), override val isClosed: Boolean = false, override val isAnonymous: Boolean = false, override val scheduledCloseInfo: ScheduledCloseInfo? = null @@ -159,7 +159,7 @@ internal object PollSerializer : KSerializer { rawPoll.votesCount, rawPoll.correctOptionId, rawPoll.explanation, - rawPoll.explanation?.let { rawPoll.explanationEntities.asTextParts(it) } ?: emptyList(), + rawPoll.explanation?.let { rawPoll.explanationEntities.asTextSources(it) } ?: emptyList(), rawPoll.isClosed, rawPoll.isAnonymous, rawPoll.scheduledCloseInfo @@ -210,8 +210,8 @@ internal object PollSerializer : KSerializer { value.isAnonymous, regularPollType, correctOptionId = value.correctOptionId, - explanation = value.explanation, - explanationEntities = value.explanationEntities.asRawMessageEntities(), + explanation = value.text, + explanationEntities = value.textSources.toRawMessageEntities(), openPeriod = (closeInfo as? ApproximateScheduledCloseInfo) ?.openDuration ?.seconds ?.toLong(), closeDate = (closeInfo as? ExactScheduledCloseInfo) ?.closeDateTime ?.unixMillisLong ?.div(1000L) ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt index bac1e06c41..8ded23db22 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt @@ -1,77 +1,12 @@ package dev.inmo.tgbotapi.utils.internal -import dev.inmo.tgbotapi.CommonAbstracts.* -import dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource +import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.link import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Link import dev.inmo.tgbotapi.utils.extensions.toHtml -internal fun String.fullListOfSubSource(sourceList: List): List { - val sortedSourceList = sourceList.sortedBy { it.range.first }.toMutableList() - - var previousLastIndex = 0 - - val newSubSources = mutableListOf() - - while (sortedSourceList.isNotEmpty()) { - val topSource = sortedSourceList.removeAt(0) - if (topSource.range.first - previousLastIndex > 0) { - val range = previousLastIndex until topSource.range.first - newSubSources.add( - TextPart( - range, - RegularTextSource( - substring(range) - ) - ) - ) - } - newSubSources.add(topSource) - previousLastIndex = topSource.range.last + 1 - } - - if (length > previousLastIndex) { - val range = previousLastIndex until length - newSubSources.add( - TextPart( - range, - RegularTextSource( - substring(range) - ) - ) - ) - } - - return newSubSources -} - -internal fun List.shiftSourcesToTheLeft(shiftCount: Int = 1): List { - return mapNotNull { - val first = (it.range.first - shiftCount).let { firstCalculated -> - if (firstCalculated < 0) { - 0 - } else { - firstCalculated - } - } - val last = (it.range.last - shiftCount).let { lastCalculated -> - if (lastCalculated < 0) { - 0 - } else { - lastCalculated - } - } - it.copy(range = first .. last).let { newSubSource -> - if (newSubSource.range.isEmpty()) { - null - } else { - newSubSource - } - } - } -} - private fun List.joinSubSourcesMarkdownV2() = joinToString("") { it.markdownV2 } diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/BotActionTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/BotActionTests.kt index a0f688c821..8dd4d8f159 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/BotActionTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/BotActionTests.kt @@ -22,6 +22,8 @@ class BotActionTests { UploadVideoAction -> example.botAction.actionName RecordAudioAction -> example.botAction.actionName UploadAudioAction -> example.botAction.actionName + RecordVoiceAction -> example.botAction.actionName + UploadVoiceAction -> example.botAction.actionName UploadDocumentAction -> example.botAction.actionName FindLocationAction -> example.botAction.actionName RecordVideoNoteAction -> example.botAction.actionName @@ -51,6 +53,8 @@ class BotActionTests { UploadVideoAction.example(), RecordAudioAction.example(), UploadAudioAction.example(), + RecordVoiceAction.example(), + UploadVoiceAction.example(), UploadDocumentAction.example(), FindLocationAction.example(), RecordVideoNoteAction.example(), 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 index b75814dcf1..08092c0350 100644 --- 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 @@ -1,6 +1,6 @@ package dev.inmo.tgbotapi.types.MessageEntity -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import kotlin.test.assertTrue @@ -36,19 +36,19 @@ internal val testTextEntities = listOf( RawMessageEntity( "mention", 39, - 6 + 8 ) ) -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) +fun List.testTextSources() { + assertTrue (first() is RegularTextSource) + assertTrue (get(1) is BoldTextSource) + assertTrue (get(2) is RegularTextSource) + assertTrue (get(3) is HashTagTextSource) + assertTrue (get(4) is RegularTextSource) + assertTrue (get(5) is MentionTextSource) - val boldSource = get(1).source as BoldTextSource + val boldSource = get(1) as BoldTextSource assertTrue (boldSource.subsources.first() is ItalicTextSource) assertTrue (boldSource.subsources[1] is RegularTextSource) assertTrue (boldSource.subsources[2] is StrikethroughTextSource) 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 1ba73f4c7f..f7b15a854a 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 @@ -48,7 +48,7 @@ class StringFormattingTests { hashtag("tag") + " and " + mention("mention") - sources.toTextParts().testTextParts() + sources.testTextSources() 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 14e0a82f2e..a4e3900028 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,6 +1,5 @@ package dev.inmo.tgbotapi.types.MessageEntity -import dev.inmo.tgbotapi.CommonAbstracts.justTextSources import dev.inmo.tgbotapi.extensions.utils.formatting.toHtmlTexts import dev.inmo.tgbotapi.extensions.utils.formatting.toMarkdownV2Texts import kotlin.test.Test @@ -9,23 +8,23 @@ import kotlin.test.assertEquals class TextPartsCreatingTests { @Test fun testThatTextWithMultilevelPartsCorrectlyCreating() { - val textParts = testTextEntities.asTextParts(testText) - textParts.testTextParts() + val textSources = testTextEntities.asTextSources(testText) + textSources.testTextSources() assertEquals( formattedV2Text, - textParts.justTextSources().toMarkdownV2Texts().first() + textSources.toMarkdownV2Texts().first() ) } @Test fun testThatTextWithMultilevelPartsCorrectlyCreatingInHtml() { - val textParts = testTextEntities.asTextParts(testText) - textParts.testTextParts() + val textSources = testTextEntities.asTextSources(testText) + textSources.testTextSources() assertEquals( formattedHtmlText, - textParts.justTextSources().toHtmlTexts().first() + textSources.toHtmlTexts().first() ) } } diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TextSourcesTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TextSourcesTests.kt index 1dd7e893ef..3f1b2a4b16 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TextSourcesTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TextSourcesTests.kt @@ -4,10 +4,7 @@ import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.TestsJsonFormat import dev.inmo.tgbotapi.extensions.utils.formatting.* -import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourceSerializer -import kotlinx.serialization.PolymorphicSerializer import kotlinx.serialization.builtins.ListSerializer -import kotlinx.serialization.encodeToString import kotlin.test.Test import kotlin.test.assertEquals 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 1becc8e0d3..9d28dc4288 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,7 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.edit.caption -import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput -import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.edit.caption.EditChatMessageCaption import dev.inmo.tgbotapi.types.ChatIdentifier @@ -35,7 +34,7 @@ suspend fun TelegramBot.editMessageCaption( text: String, parseMode: ParseMode? = null, replyMarkup: InlineKeyboardMarkup? = null -): ContentMessage where T : CaptionedInput, T : MediaContent { +): ContentMessage where T : TextedWithTextSources, T : MediaContent { return editMessageCaption(message.chat.id, message.messageId, text, parseMode, replyMarkup) } @@ -59,6 +58,6 @@ suspend fun TelegramBot.editMessageCaption( message: ContentMessage, entities: List, replyMarkup: InlineKeyboardMarkup? = null -): ContentMessage where T : CaptionedInput, T : MediaContent { +): ContentMessage where T : TextedWithTextSources, 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/passport/SetPassportDataErrors.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/passport/SetPassportDataErrors.kt index 5e19524a04..478f7fc993 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/passport/SetPassportDataErrors.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/passport/SetPassportDataErrors.kt @@ -2,7 +2,8 @@ package dev.inmo.tgbotapi.extensions.api.passport import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.SetPassportDataErrors -import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.User +import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.message.PassportMessage import dev.inmo.tgbotapi.types.passport.PassportData import dev.inmo.tgbotapi.types.passport.PassportElementError diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt index 05ab7eb80f..71e11aef1c 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt @@ -35,14 +35,30 @@ suspend fun TelegramBot.sendActionUploadVideo( chatId: ChatIdentifier ) = sendBotAction(chatId, UploadVideoAction) +@Deprecated( + "Deprecated according to https://core.telegram.org/bots/api-changelog#april-26-2021", + ReplaceWith("sendActionRecordVoice", "dev.inmo.tgbotapi.extensions.api.send.sendActionRecordVoice") +) suspend fun TelegramBot.sendActionRecordAudio( chatId: ChatIdentifier ) = sendBotAction(chatId, RecordAudioAction) +@Deprecated( + "Deprecated according to https://core.telegram.org/bots/api-changelog#april-26-2021", + ReplaceWith("sendActionUploadVoice", "dev.inmo.tgbotapi.extensions.api.send.sendActionUploadVoice") +) suspend fun TelegramBot.sendActionUploadAudio( chatId: ChatIdentifier ) = sendBotAction(chatId, UploadAudioAction) +suspend fun TelegramBot.sendActionRecordVoice( + chatId: ChatIdentifier +) = sendBotAction(chatId, RecordVoiceAction) + +suspend fun TelegramBot.sendActionUploadVoice( + chatId: ChatIdentifier +) = sendBotAction(chatId, UploadVoiceAction) + suspend fun TelegramBot.sendActionUploadDocument( chatId: ChatIdentifier ) = sendBotAction(chatId, UploadDocumentAction) @@ -76,14 +92,30 @@ suspend fun TelegramBot.sendActionUploadVideo( chat: Chat ) = sendBotAction(chat, UploadVideoAction) +@Deprecated( + "Deprecated according to https://core.telegram.org/bots/api-changelog#april-26-2021", + ReplaceWith("sendActionRecordVoice", "dev.inmo.tgbotapi.extensions.api.send.sendActionRecordVoice") +) suspend fun TelegramBot.sendActionRecordAudio( chat: Chat ) = sendBotAction(chat, RecordAudioAction) +@Deprecated( + "Deprecated according to https://core.telegram.org/bots/api-changelog#april-26-2021", + ReplaceWith("sendActionUploadVoice", "dev.inmo.tgbotapi.extensions.api.send.sendActionUploadVoice") +) suspend fun TelegramBot.sendActionUploadAudio( chat: Chat ) = sendBotAction(chat, UploadAudioAction) +suspend fun TelegramBot.sendActionRecordVoice( + chat: Chat +) = sendBotAction(chat, RecordVoiceAction) + +suspend fun TelegramBot.sendActionUploadVoice( + chat: Chat +) = sendBotAction(chat, UploadVoiceAction) + suspend fun TelegramBot.sendActionUploadDocument( chat: Chat ) = sendBotAction(chat, UploadDocumentAction) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt index 13e964debe..0e9f1fb94e 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt @@ -56,8 +56,18 @@ suspend fun TelegramBot.withTypingAction(chatId: ChatId, block: TelegramBotA suspend fun TelegramBot.withUploadPhotoAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, UploadPhotoAction, block) suspend fun TelegramBot.withRecordVideoAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, RecordVideoAction, block) suspend fun TelegramBot.withUploadVideoAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, UploadVideoAction, block) +@Deprecated( + "Deprecated according to https://core.telegram.org/bots/api-changelog#april-26-2021", + ReplaceWith("withRecordVoiceAction", "dev.inmo.tgbotapi.extensions.api.send.withRecordVoiceAction") +) suspend fun TelegramBot.withRecordAudioAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, RecordAudioAction, block) +@Deprecated( + "Deprecated according to https://core.telegram.org/bots/api-changelog#april-26-2021", + ReplaceWith("withUploadVoiceAction", "dev.inmo.tgbotapi.extensions.api.send.withUploadVoiceAction") +) suspend fun TelegramBot.withUploadAudioAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, UploadAudioAction, block) +suspend fun TelegramBot.withRecordVoiceAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, RecordVoiceAction, block) +suspend fun TelegramBot.withUploadVoiceAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, UploadVoiceAction, block) suspend fun TelegramBot.withUploadDocumentAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, UploadDocumentAction, block) suspend fun TelegramBot.withFindLocationAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, FindLocationAction, block) suspend fun TelegramBot.withRecordVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, RecordVideoNoteAction, block) @@ -68,8 +78,18 @@ suspend fun TelegramBot.withTypingAction(chat: Chat, block: TelegramBotActio suspend fun TelegramBot.withUploadPhotoAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, UploadPhotoAction, block) suspend fun TelegramBot.withRecordVideoAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, RecordVideoAction, block) suspend fun TelegramBot.withUploadVideoAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, UploadVideoAction, block) +@Deprecated( + "Deprecated according to https://core.telegram.org/bots/api-changelog#april-26-2021", + ReplaceWith("withRecordVoiceAction", "dev.inmo.tgbotapi.extensions.api.send.withRecordVoiceAction") +) suspend fun TelegramBot.withRecordAudioAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, RecordAudioAction, block) +@Deprecated( + "Deprecated according to https://core.telegram.org/bots/api-changelog#april-26-2021", + ReplaceWith("withUploadVoiceAction", "dev.inmo.tgbotapi.extensions.api.send.withUploadVoiceAction") +) suspend fun TelegramBot.withUploadAudioAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, UploadAudioAction, block) +suspend fun TelegramBot.withRecordVoiceAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, RecordVoiceAction, block) +suspend fun TelegramBot.withUploadVoiceAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, UploadVoiceAction, block) suspend fun TelegramBot.withUploadDocumentAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, UploadDocumentAction, block) suspend fun TelegramBot.withFindLocationAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, FindLocationAction, block) suspend fun TelegramBot.withRecordVideoNoteAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, RecordVideoNoteAction, block) 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 d4ee9ed59d..c641033456 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 @@ -16,7 +16,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.Message suspend fun TelegramBot.sendPhoto( chatId: ChatIdentifier, fileId: InputFile, - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, @@ -26,7 +26,7 @@ suspend fun TelegramBot.sendPhoto( SendPhoto( chatId, fileId, - caption, + text, parseMode, disableNotification, replyToMessageId, @@ -38,65 +38,65 @@ suspend fun TelegramBot.sendPhoto( suspend fun TelegramBot.sendPhoto( chat: Chat, fileId: InputFile, - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat.id, fileId, caption, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chat.id, fileId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendPhoto( chatId: ChatIdentifier, photo: Photo, - caption: String? = null, + text: String? = null, 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, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendPhoto( chat: Chat, photo: Photo, - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat.id, photo, caption, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chat.id, photo, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithPhoto( to: Message, fileId: InputFile, - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, fileId, caption, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(to.chat, fileId, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithPhoto( to: Message, photo: Photo, - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, photo, caption, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(to.chat, photo, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, photo: Photo, - caption: String? = null, + text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithPhoto(to, photo, caption, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) +) = replyWithPhoto(to, photo, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.sendPhoto( 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 3af85856f1..1fdce04371 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 @@ -14,9 +14,11 @@ suspend fun TelegramBot.sendInvoice( description: String, payload: String, providerToken: String, - startParameter: StartParameter, currency: Currency, prices: List, + maxTipAmount: Int? = null, + suggestedTipAmounts: List? = null, + startParameter: StartParameter? = null, providerData: String? = null, requireName: Boolean = false, requirePhoneNumber: Boolean = false, @@ -30,7 +32,7 @@ suspend fun TelegramBot.sendInvoice( 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, allowSendingWithoutReply, replyMarkup) + SendInvoice(chatId, title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts ?.sorted(), startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) suspend fun TelegramBot.sendInvoice( @@ -39,9 +41,11 @@ suspend fun TelegramBot.sendInvoice( description: String, payload: String, providerToken: String, - startParameter: StartParameter, currency: Currency, prices: List, + maxTipAmount: Int? = null, + suggestedTipAmounts: List? = null, + startParameter: StartParameter? = null, providerData: String? = null, requireName: Boolean = false, requirePhoneNumber: Boolean = false, @@ -54,7 +58,7 @@ suspend fun TelegramBot.sendInvoice( 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, allowSendingWithoutReply, replyMarkup) +) = sendInvoice(user.id, title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts, startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithInvoice( to: Message, @@ -62,9 +66,11 @@ suspend inline fun TelegramBot.replyWithInvoice( description: String, payload: String, providerToken: String, - startParameter: StartParameter, currency: Currency, prices: List, + maxTipAmount: Int? = null, + suggestedTipAmounts: List? = null, + startParameter: StartParameter? = null, providerData: String? = null, requireName: Boolean = false, requirePhoneNumber: Boolean = false, @@ -76,4 +82,4 @@ suspend inline fun TelegramBot.replyWithInvoice( 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, allowSendingWithoutReply, replyMarkup) +) = sendInvoice(to.chat.id, title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts, startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/Variants.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/Variants.kt index 63ed115bef..457ec155f5 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/Variants.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/Variants.kt @@ -2,7 +2,8 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder import dev.inmo.micro_utils.coroutines.DeferredAction import dev.inmo.micro_utils.coroutines.invokeFirstOf -import kotlinx.coroutines.* +import kotlinx.coroutines.Deferred +import kotlinx.coroutines.async suspend fun BehaviourContext.parallel( action: BehaviourContextReceiver diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt index ccdbd3051b..6157825208 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt @@ -1,10 +1,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext -import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate import dev.inmo.tgbotapi.requests.abstracts.Request -import dev.inmo.tgbotapi.types.CallbackQuery.CallbackQuery -import dev.inmo.tgbotapi.types.CallbackQuery.DataCallbackQuery import dev.inmo.tgbotapi.types.ChatMemberUpdated import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate import dev.inmo.tgbotapi.types.update.MyChatMemberUpdatedUpdate diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt index 66676f7c6e..2150b7649b 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt @@ -3,7 +3,6 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow -import dev.inmo.tgbotapi.extensions.utils.asChatMemberUpdatedUpdate import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.ChatMemberUpdated import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt index 0946a99140..4ab3479166 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt @@ -1,8 +1,8 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.tgbotapi.CommonAbstracts.textSources -import dev.inmo.tgbotapi.extensions.behaviour_builder.* -import dev.inmo.tgbotapi.extensions.utils.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver +import dev.inmo.tgbotapi.extensions.utils.asBotCommandTextSource import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage import dev.inmo.tgbotapi.types.message.content.TextContent import kotlinx.coroutines.Job diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index 21fc99db2e..9811b1ab8b 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -1,8 +1,8 @@ @file:Suppress("NOTHING_TO_INLINE", "unused", "UNCHECKED_CAST") package dev.inmo.tgbotapi.extensions.utils -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.requests.send.payments.SendInvoice import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.CallbackQuery.* import dev.inmo.tgbotapi.types.ChatMember.* @@ -525,6 +525,10 @@ inline fun BotAction.asRecordAudioAction(): RecordAudioAction? = this as? Record @PreviewFeature inline fun BotAction.requireRecordAudioAction(): RecordAudioAction = this as RecordAudioAction @PreviewFeature +inline fun BotAction.asRecordVoiceAction(): RecordVoiceAction? = this as? RecordVoiceAction +@PreviewFeature +inline fun BotAction.requireRecordVoiceAction(): RecordVoiceAction = this as RecordVoiceAction +@PreviewFeature inline fun BotAction.asRecordVideoAction(): RecordVideoAction? = this as? RecordVideoAction @PreviewFeature inline fun BotAction.requireRecordVideoAction(): RecordVideoAction = this as RecordVideoAction @@ -541,6 +545,10 @@ inline fun BotAction.asUploadAudioAction(): UploadAudioAction? = this as? Upload @PreviewFeature inline fun BotAction.requireUploadAudioAction(): UploadAudioAction = this as UploadAudioAction @PreviewFeature +inline fun BotAction.asUploadVoiceAction(): UploadVoiceAction? = this as? UploadVoiceAction +@PreviewFeature +inline fun BotAction.requireUploadVoiceAction(): UploadVoiceAction = this as UploadVoiceAction +@PreviewFeature inline fun BotAction.asUploadDocumentAction(): UploadDocumentAction? = this as? UploadDocumentAction @PreviewFeature inline fun BotAction.requireUploadDocumentAction(): UploadDocumentAction = this as UploadDocumentAction @@ -581,6 +589,10 @@ inline fun InputMessageContent.asInputVenueMessageContent(): InputVenueMessageCo @PreviewFeature inline fun InputMessageContent.requireInputVenueMessageContent(): InputVenueMessageContent = this as InputVenueMessageContent @PreviewFeature +inline fun InputMessageContent.asInputInvoiceMessageContent(): InputInvoiceMessageContent? = this as? InputInvoiceMessageContent +@PreviewFeature +inline fun InputMessageContent.requireInputInvoiceMessageContent(): InputInvoiceMessageContent = this as InputInvoiceMessageContent +@PreviewFeature inline fun InlineQueryResult.asInlineQueryResultArticle(): InlineQueryResultArticle? = this as? InlineQueryResultArticle @PreviewFeature inline fun InlineQueryResult.requireInlineQueryResultArticle(): InlineQueryResultArticle = this as InlineQueryResultArticle @@ -1296,3 +1308,11 @@ inline fun ChatEvent.requireVoiceChatParticipantsInvited(): VoiceChatParticipant inline fun ChatEvent.asVoiceChatStarted(): VoiceChatStarted? = this as? VoiceChatStarted @PreviewFeature inline fun ChatEvent.requireVoiceChatStarted(): VoiceChatStarted = this as VoiceChatStarted +@PreviewFeature +inline fun CommonSendInvoiceData.asSendInvoice(): SendInvoice? = this as? SendInvoice +@PreviewFeature +inline fun CommonSendInvoiceData.requireVoiceChatParticipantsInvited(): SendInvoice = this as SendInvoice +@PreviewFeature +inline fun CommonSendInvoiceData.asInputInvoiceMessageContent(): InputInvoiceMessageContent? = this as? InputInvoiceMessageContent +@PreviewFeature +inline fun CommonSendInvoiceData.requireInputInvoiceMessageContent(): InputInvoiceMessageContent = this as InputInvoiceMessageContent diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentMessageConversations.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentMessageConversations.kt index 37841333c7..1866a5137e 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentMessageConversations.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentMessageConversations.kt @@ -7,7 +7,6 @@ import dev.inmo.tgbotapi.types.message.content.media.* import dev.inmo.tgbotapi.types.message.payments.InvoiceContent import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.mapNotNull -import kotlin.reflect.KClass private inline fun Flow>.withContentType() = mapNotNull { it.withContent() diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt index 61eed8ef21..8fa69aadad 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt @@ -4,7 +4,6 @@ import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.BotCommandTextSource import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.TextContent -import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent val defaultArgsSeparator = Regex(" ") @@ -19,10 +18,13 @@ fun List.parseCommandsWithParams( var currentArgs = "" fun includeCurrent() = currentBotCommandSource ?.let { currentArgs = currentArgs.trim() - if (currentArgs.isNotEmpty()) { - result[it.command] = currentArgs.split(argsSeparator).toTypedArray() - currentArgs = "" + result[it.command] = if (currentArgs.isNotEmpty()) { + currentArgs.split(argsSeparator).toTypedArray() + } else { + emptyArray() } + currentArgs = "" + currentBotCommandSource = null } for (textSource in this) { if (textSource is BotCommandTextSource) { @@ -39,23 +41,9 @@ fun List.parseCommandsWithParams( /** * Parse commands and their args. Logic will find command, get all subsequent data as args until new command */ -fun TextedInput.parseCommandsWithParams( +fun TextedWithTextSources.parseCommandsWithParams( argsSeparator: Regex = defaultArgsSeparator -) = textSources.parseCommandsWithParams(argsSeparator) - -/** - * Parse commands and their args. Logic will find command, get all subsequent data as args until new command - */ -fun TextedOutput.parseCommandsWithParams( - argsSeparator: Regex = defaultArgsSeparator -) = entities ?.parseCommandsWithParams(argsSeparator) ?: emptyMap() - -/** - * Parse commands and their args. Logic will find command, get all subsequent data as args until new command - */ -fun CaptionedInput.parseCommandsWithParams( - argsSeparator: Regex = defaultArgsSeparator -) = textSources.parseCommandsWithParams(argsSeparator) +) = textSources ?.parseCommandsWithParams(argsSeparator) ?: emptyMap() /** * Parse commands and their args. Logic will find command, get all subsequent data as args until new command diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/CommandsShortcuts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/CommandsShortcuts.kt index 6df7887dea..749ae68aef 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/CommandsShortcuts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/CommandsShortcuts.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.extensions.utils.shortcuts import dev.inmo.tgbotapi.CommonAbstracts.TextSource -import dev.inmo.tgbotapi.CommonAbstracts.textSources import dev.inmo.tgbotapi.extensions.utils.onlyTextContentMessages import dev.inmo.tgbotapi.extensions.utils.updates.asContentMessagesFlow import dev.inmo.tgbotapi.types.MessageEntity.textsources.BotCommandTextSource 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 2c70dd1c2b..507349899d 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,9 +1,8 @@ package dev.inmo.tgbotapi.types.files import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper +import java.io.* import java.io.File -import java.io.FileOutputStream -import java.io.InputStream import java.net.URL fun PathedFile.asStream(