diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAnimation.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAnimation.kt index 0de73f8fdc..e094a177b4 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAnimation.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAnimation.kt @@ -11,6 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Conten import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.AnimationContent import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull +import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError import kotlinx.serialization.* fun SendAnimation( @@ -93,7 +94,7 @@ data class SendAnimationData internal constructor( init { text ?.let { if (it.length !in captionLength) { - throw IllegalArgumentException("Caption must be in $captionLength range") + throwRangeError("Caption length", captionLength, it.length) } } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAudio.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAudio.kt index 5facb438f5..b222130865 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAudio.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendAudio.kt @@ -12,6 +12,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Conten import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.AudioContent import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull +import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError import kotlinx.serialization.* fun SendAudio( @@ -95,7 +96,7 @@ data class SendAudioData internal constructor( init { text ?.let { if (it.length !in captionLength) { - throw IllegalArgumentException("Caption must be in $captionLength range") + throwRangeError("Caption length", captionLength, it.length) } } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendDocument.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendDocument.kt index 44ff036ec2..e7cce4798f 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendDocument.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendDocument.kt @@ -11,6 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Conten import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.DocumentContent import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull +import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError import kotlinx.serialization.* fun SendDocument( @@ -79,7 +80,7 @@ data class SendDocumentData internal constructor( init { text ?.let { if (it.length !in captionLength) { - throw IllegalArgumentException("Caption must be in $captionLength range") + throwRangeError("Caption length", captionLength, it.length) } } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt index 4f7054bb29..c28dab19ea 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendMediaGroup.kt @@ -8,12 +8,15 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializerClass +import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls import kotlinx.serialization.* import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.json.jsonArray -val membersCountInMediaGroup: IntRange = 2 .. 10 +@Deprecated("Replaced and renamed", ReplaceWith("mediaCountInMediaGroup", "com.github.insanusmokrassar.TelegramBotAPI.types.mediaCountInMediaGroup")) +val membersCountInMediaGroup + get() = mediaCountInMediaGroup fun SendMediaGroup( chatId: ChatIdentifier, @@ -21,8 +24,8 @@ fun SendMediaGroup( disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null ): Request> { - if (media.size !in membersCountInMediaGroup) { - throw IllegalArgumentException("Count of members for media group must be in $membersCountInMediaGroup range") + if (media.size !in mediaCountInMediaGroup) { + throwRangeError("Count of members in media group", mediaCountInMediaGroup, media.size) } val files: List = media.flatMap { diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendPhoto.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendPhoto.kt index b9b005d8b4..27e6be47fe 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendPhoto.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendPhoto.kt @@ -10,6 +10,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.PhotoContent +import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError import kotlinx.serialization.* fun SendPhoto( @@ -65,7 +66,7 @@ data class SendPhotoData internal constructor( init { text ?.let { if (it.length !in captionLength) { - throw IllegalArgumentException("Caption must be in $captionLength range") + throwRangeError("Caption length", captionLength, it.length) } } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideo.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideo.kt index 97781a1f7a..6bd81fe76c 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideo.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideo.kt @@ -11,6 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Conten import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.VideoContent import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull +import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError import kotlinx.serialization.* fun SendVideo( @@ -97,7 +98,7 @@ data class SendVideoData internal constructor( init { text ?.let { if (it.length !in captionLength) { - throw IllegalArgumentException("Caption must be in $captionLength range") + throwRangeError("Caption length", captionLength, it.length) } } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideoNote.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideoNote.kt index e4e3d11bfd..93cb292b29 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideoNote.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVideoNote.kt @@ -11,6 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Conten import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.VideoNoteContent import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull +import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError import kotlinx.serialization.* fun SendVideoNote( @@ -92,7 +93,7 @@ data class SendVideoNoteData internal constructor( init { text ?.let { if (it.length !in captionLength) { - throw IllegalArgumentException("Caption must be in $captionLength range") + throwRangeError("Caption length", captionLength, it.length) } } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVoice.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVoice.kt index a341372e5c..24272364fd 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVoice.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/media/SendVoice.kt @@ -11,6 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Conten import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.VoiceContent import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull +import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError import kotlinx.serialization.* fun SendVoice( @@ -84,7 +85,7 @@ data class SendVoiceData internal constructor( init { text ?.let { if (it.length !in captionLength) { - throw IllegalArgumentException("Caption must be in $captionLength range") + throwRangeError("Caption length", captionLength, it.length) } } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index 7ec3a22149..52920da548 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -55,6 +55,8 @@ val botCommandLimit = botCommandLengthLimit val botCommandDescriptionLimit = 3 .. 256 val botCommandsLimit = 0 .. 100 +val mediaCountInMediaGroup: IntRange = 2 .. 10 + val explanationLimit = 0 .. 200 @Deprecated("Will be removed in near updates", ReplaceWith("explanationLimit")) val quizPollExplanationLimit = explanationLimit