From 8df72edd524773e54cff6bbd0a8e3163954d33c0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 7 Jan 2024 20:00:07 +0600 Subject: [PATCH] fixes of build --- .../triggers_handling/ContentTriggers.kt | 2 +- .../dev/inmo/tgbotapi/types/ReplyInfo.kt | 8 +- .../tgbotapi/types/files/AnimationFile.kt | 2 +- .../inmo/tgbotapi/types/files/AudioFile.kt | 2 +- .../inmo/tgbotapi/types/files/DocumentFile.kt | 2 +- .../types/files/MediaContentVariant.kt | 5 ++ .../inmo/tgbotapi/types/files/PhotoSize.kt | 17 ++++- .../dev/inmo/tgbotapi/types/files/Sticker.kt | 2 +- .../inmo/tgbotapi/types/files/VideoFile.kt | 2 +- .../tgbotapi/types/files/VideoNoteFile.kt | 2 +- .../inmo/tgbotapi/types/files/VoiceFile.kt | 2 +- .../message/ChannelContentMessageImpl.kt | 2 +- .../tgbotapi/types/message/ForwardInfo.kt | 1 + .../tgbotapi/types/message/GroupMessages.kt | 14 ++-- .../tgbotapi/types/message/MessageOrigin.kt | 2 +- .../message/PrivateContentMessageImpl.kt | 2 +- .../dev/inmo/tgbotapi/SimpleInputFilesTest.kt | 7 +- .../extensions/utils/ClassCastsNew.kt | 75 +++++++++++++++++++ .../utils/extensions/raw/Message.kt | 2 +- 19 files changed, 125 insertions(+), 26 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/MediaContentVariant.kt diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt index 0b3e5ec1eb..1bec1193e7 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt @@ -741,7 +741,7 @@ suspend fun BC.onScheduledGiveawayContent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BC.onScheduledGiveawayContent( +suspend fun BC.onGiveawayPublicResultsContent( initialFilter: CommonMessageFilter? = null, subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ReplyInfo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ReplyInfo.kt index 4045b5117a..d2c832927d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ReplyInfo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ReplyInfo.kt @@ -63,13 +63,13 @@ sealed interface ReplyInfo { ) : Content @Serializable - data class Media( + data class Media( override val origin: MessageOrigin, override val chat: SuperPublicChat?, override val messageMeta: Message.MetaInfo?, override val spoilered: Boolean, - override val content: T - ) : Content, SpoilerableData where T: ContentVariant, T : TelegramMediaFile + override val content: MediaContentVariant + ) : Content, SpoilerableData } @Serializable @@ -133,7 +133,7 @@ sealed interface ReplyInfo { return content ?.let { when (it) { - is TelegramMediaFile -> { + is MediaContentVariant -> { Content.Media( origin, chat, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AnimationFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AnimationFile.kt index cff7534719..466a418c79 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AnimationFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AnimationFile.kt @@ -24,4 +24,4 @@ data class AnimationFile( @SerialName(fileSizeField) override val fileSize: Long? = null ) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, CustomNamedMediaFile, SizedMediaFile, - ReplyInfo.External.ContentVariant + MediaContentVariant diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt index 5996f41bb3..4edfc7d3e6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt @@ -28,6 +28,6 @@ data class AudioFile( @SerialName(thumbnailField) override val thumbnail: PhotoSize? = null ) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, TitledMediaFile, - Performerable, ReplyInfo.External.ContentVariant + Performerable, MediaContentVariant fun AudioFile.asVoiceFile() = VoiceFile(fileId, fileUniqueId, duration, mimeType, fileSize) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/DocumentFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/DocumentFile.kt index a5a0676543..9adfe6f7b5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/DocumentFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/DocumentFile.kt @@ -20,7 +20,7 @@ data class DocumentFile( override val mimeType: MimeType? = null, @SerialName(fileNameField) override val fileName: String? = null -) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, CustomNamedMediaFile, ReplyInfo.External.ContentVariant +) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, CustomNamedMediaFile, MediaContentVariant @Suppress("NOTHING_TO_INLINE") inline fun TelegramMediaFile.asDocumentFile() = if (this is DocumentFile) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/MediaContentVariant.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/MediaContentVariant.kt new file mode 100644 index 0000000000..2eec7aae08 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/MediaContentVariant.kt @@ -0,0 +1,5 @@ +package dev.inmo.tgbotapi.types.files + +import dev.inmo.tgbotapi.types.ReplyInfo + +interface MediaContentVariant : ReplyInfo.External.ContentVariant, TelegramMediaFile \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/PhotoSize.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/PhotoSize.kt index fdac2d0e5f..62561c1a89 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/PhotoSize.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/PhotoSize.kt @@ -12,7 +12,22 @@ import kotlin.jvm.JvmInline @JvmInline value class Photo( val photos: List -) : List by photos, ReplyInfo.External.ContentVariant +) : List by photos, MediaContentVariant { + val biggest: PhotoSize + get() = biggest()!! + override val fileId: FileId + get() = biggest.fileId + override val fileUniqueId: FileUniqueId + get() = biggest.fileUniqueId + override val fileSize: Long? + get() = biggest.fileSize + + init { + require(photos.isNotEmpty()) { + "Photos collection must not be empty" + } + } +} fun Photo.biggest(): PhotoSize? = maxByOrNull { it.resolution diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt index 199bae6c9b..06f4704306 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt @@ -34,7 +34,7 @@ data class StickerSurrogate( // TODO:: Serializer @Serializable(StickerSerializer::class) -sealed interface Sticker : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile, ReplyInfo.External.ContentVariant { +sealed interface Sticker : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile, MediaContentVariant { val emoji: String? val stickerSetName: StickerSetName? val stickerFormat: StickerFormat 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 5ab993cb56..7665e712f2 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 @@ -30,7 +30,7 @@ data class VideoFile( @SerialName(fileSizeField) override val fileSize: Long? = null ) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile, - ReplyInfo.External.ContentVariant + MediaContentVariant @Suppress("NOTHING_TO_INLINE") inline fun VideoFile.toTelegramMediaVideo( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoNoteFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoNoteFile.kt index f93debfb83..a8e0623961 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoNoteFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoNoteFile.kt @@ -18,7 +18,7 @@ data class VideoNoteFile( override val thumbnail: PhotoSize? = null, @SerialName(fileSizeField) override val fileSize: Long? = null -) : TelegramMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile, ReplyInfo.External.ContentVariant { +) : TelegramMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile, MediaContentVariant { override val height: Int get() = width } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt index b26631c800..b21524b630 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt @@ -19,7 +19,7 @@ data class VoiceFile( override val mimeType: MimeType? = null, @SerialName(fileSizeField) override val fileSize: Long? = null -) : TelegramMediaFile, MimedMediaFile, PlayableMediaFile, ReplyInfo.External.ContentVariant +) : TelegramMediaFile, MimedMediaFile, PlayableMediaFile, MediaContentVariant fun VoiceFile.asAudioFile( performer: String? = null, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelContentMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelContentMessageImpl.kt index f76af91f66..26602f901b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelContentMessageImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelContentMessageImpl.kt @@ -36,6 +36,6 @@ data class ChannelContentMessageImpl( authorSignature: AuthorSignature?, mediaGroupId: MediaGroupIdentifier?, ) : this( - messageId, chat, content, date, editDate, hasProtectedContent, forwardInfo.messageOrigin(), replyTo, replyMarkup, senderBot, authorSignature, mediaGroupId + messageId, chat, content, date, editDate, hasProtectedContent, forwardInfo.messageOrigin(), replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, senderBot, authorSignature, mediaGroupId ) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ForwardInfo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ForwardInfo.kt index be74e8c3db..287cc2b757 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ForwardInfo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ForwardInfo.kt @@ -83,6 +83,7 @@ fun MessageOrigin.forwardInfo() = when(this) { date, user ) + is MessageOrigin.Unknown -> null } fun ForwardInfo.messageOrigin() = when (this) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt index 967f87d4df..c9d42f2bf6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt @@ -40,7 +40,7 @@ data class ConnectedFromChannelGroupContentMessageImpl( authorSignature: AuthorSignature?, mediaGroupId: MediaGroupIdentifier?, ) : this( - chat, channel, messageId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo, replyMarkup, content, senderBot, authorSignature, mediaGroupId + chat, channel, messageId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, authorSignature, mediaGroupId ) } @@ -74,7 +74,7 @@ data class UnconnectedFromChannelGroupContentMessageImpl( authorSignature: AuthorSignature?, mediaGroupId: MediaGroupIdentifier?, ) : this( - chat, channel, messageId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo, replyMarkup, content, senderBot, authorSignature, mediaGroupId + chat, channel, messageId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, authorSignature, mediaGroupId ) } @@ -106,7 +106,7 @@ data class AnonymousGroupContentMessageImpl( authorSignature: AuthorSignature?, mediaGroupId: MediaGroupIdentifier?, ) : this( - chat, messageId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo, replyMarkup, content, senderBot, authorSignature, mediaGroupId + chat, messageId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, authorSignature, mediaGroupId ) } @@ -138,7 +138,7 @@ data class CommonGroupContentMessageImpl( senderBot: CommonBot?, mediaGroupId: MediaGroupIdentifier?, ) : this( - chat, messageId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo, replyMarkup, content, senderBot, mediaGroupId + chat, messageId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, mediaGroupId ) } @@ -174,7 +174,7 @@ data class FromChannelForumContentMessageImpl( authorSignature: AuthorSignature?, mediaGroupId: MediaGroupIdentifier?, ) : this( - chat, channel, messageId, threadId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo, replyMarkup, content, senderBot, authorSignature, mediaGroupId + chat, channel, messageId, threadId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, authorSignature, mediaGroupId ) } @@ -208,7 +208,7 @@ data class AnonymousForumContentMessageImpl( authorSignature: AuthorSignature?, mediaGroupId: MediaGroupIdentifier?, ) : this( - chat, messageId, threadId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo, replyMarkup, content, senderBot, authorSignature, mediaGroupId + chat, messageId, threadId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, authorSignature, mediaGroupId ) } @@ -242,6 +242,6 @@ data class CommonForumContentMessageImpl( senderBot: CommonBot?, mediaGroupId: MediaGroupIdentifier?, ) : this( - chat, messageId, threadId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo, replyMarkup, content, senderBot, mediaGroupId + chat, messageId, threadId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, mediaGroupId ) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/MessageOrigin.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/MessageOrigin.kt index 1ab6d6e542..f6b886b4de 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/MessageOrigin.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/MessageOrigin.kt @@ -21,7 +21,7 @@ sealed interface MessageOrigin { @Serializable data class User( @SerialName(senderUserField) - val user: PreviewUser, + val user: dev.inmo.tgbotapi.types.chat.User, @SerialName(dateField) override val date: TelegramDate ) : MessageOrigin { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt index a2482308df..01fbf50758 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt @@ -38,6 +38,6 @@ data class PrivateContentMessageImpl( senderBot: CommonBot?, mediaGroupId: MediaGroupIdentifier?, ) : this( - messageId, from, chat, content, date, editDate, hasProtectedContent, forwardInfo.messageOrigin(), replyTo, replyMarkup, senderBot, mediaGroupId + messageId, from, chat, content, date, editDate, hasProtectedContent, forwardInfo.messageOrigin(), replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, senderBot, mediaGroupId ) } diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/SimpleInputFilesTest.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/SimpleInputFilesTest.kt index a0facdfb88..520b27f950 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/SimpleInputFilesTest.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/SimpleInputFilesTest.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi import dev.inmo.tgbotapi.requests.abstracts.toInputFile +import dev.inmo.tgbotapi.types.files.Photo import dev.inmo.tgbotapi.types.media.MediaGroupMemberTelegramMediaSerializer import dev.inmo.tgbotapi.types.files.PhotoSize import dev.inmo.tgbotapi.types.message.content.PhotoContent @@ -20,8 +21,10 @@ class SimpleInputFilesTest { @Test fun test_that_creating_of_photo_and_converting_to_input_media_working_correctly() { val photoContent = PhotoContent( - listOf( - PhotoSize("example_file_id".toInputFile(), "example_unique_file_id", 100, 100, 100) + Photo( + listOf( + PhotoSize("example_file_id".toInputFile(), "example_unique_file_id", 100, 100, 100) + ) ) ) val inputMedia = photoContent.toMediaGroupMemberTelegramMedia() diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt index 6942deb6ef..313b784543 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt @@ -75,6 +75,7 @@ import dev.inmo.tgbotapi.types.InlineQueries.query.BaseInlineQuery import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery import dev.inmo.tgbotapi.types.InlineQueries.query.LocationInlineQuery import dev.inmo.tgbotapi.types.PrimaryInviteLink +import dev.inmo.tgbotapi.types.ReplyInfo import dev.inmo.tgbotapi.types.SecondaryChatInviteLink import dev.inmo.tgbotapi.types.Username import dev.inmo.tgbotapi.types.actions.BotAction @@ -179,9 +180,11 @@ import dev.inmo.tgbotapi.types.files.MaskAnimatedSticker import dev.inmo.tgbotapi.types.files.MaskSimpleSticker import dev.inmo.tgbotapi.types.files.MaskSticker import dev.inmo.tgbotapi.types.files.MaskVideoSticker +import dev.inmo.tgbotapi.types.files.MediaContentVariant import dev.inmo.tgbotapi.types.files.MimedMediaFile import dev.inmo.tgbotapi.types.files.PassportFile import dev.inmo.tgbotapi.types.files.PathedFile +import dev.inmo.tgbotapi.types.files.Photo import dev.inmo.tgbotapi.types.files.PhotoSize import dev.inmo.tgbotapi.types.files.PlayableMediaFile import dev.inmo.tgbotapi.types.files.RegularAnimatedSticker @@ -1572,6 +1575,60 @@ public inline fun InputMessageContent.ifInputVenueMessageContent(block: (InputVenueMessageContent) -> T): T? = inputVenueMessageContentOrNull() ?.let(block) +public inline fun ReplyInfo.externalOrNull(): ReplyInfo.External? = this as? + dev.inmo.tgbotapi.types.ReplyInfo.External + +public inline fun ReplyInfo.externalOrThrow(): ReplyInfo.External = this as + dev.inmo.tgbotapi.types.ReplyInfo.External + +public inline fun ReplyInfo.ifExternal(block: (ReplyInfo.External) -> T): T? = externalOrNull() + ?.let(block) + +public inline fun ReplyInfo.contentOrNull(): ReplyInfo.External.Content? = this as? + dev.inmo.tgbotapi.types.ReplyInfo.External.Content + +public inline fun ReplyInfo.contentOrThrow(): ReplyInfo.External.Content = this as + dev.inmo.tgbotapi.types.ReplyInfo.External.Content + +public inline fun ReplyInfo.ifContent(block: (ReplyInfo.External.Content) -> T): T? = + contentOrNull() ?.let(block) + +public inline fun ReplyInfo.mediaOrNull(): ReplyInfo.External.Content.Media? = this as? + dev.inmo.tgbotapi.types.ReplyInfo.External.Content.Media + +public inline fun ReplyInfo.mediaOrThrow(): ReplyInfo.External.Content.Media = this as + dev.inmo.tgbotapi.types.ReplyInfo.External.Content.Media + +public inline fun ReplyInfo.ifMedia(block: (ReplyInfo.External.Content.Media) -> T): T? = + mediaOrNull() ?.let(block) + +public inline fun ReplyInfo.simpleOrNull(): ReplyInfo.External.Content.Simple? = this as? + dev.inmo.tgbotapi.types.ReplyInfo.External.Content.Simple + +public inline fun ReplyInfo.simpleOrThrow(): ReplyInfo.External.Content.Simple = this as + dev.inmo.tgbotapi.types.ReplyInfo.External.Content.Simple + +public inline fun ReplyInfo.ifSimple(block: (ReplyInfo.External.Content.Simple) -> T): T? = + simpleOrNull() ?.let(block) + +public inline fun ReplyInfo.textOrNull(): ReplyInfo.External.Text? = this as? + dev.inmo.tgbotapi.types.ReplyInfo.External.Text + +public inline fun ReplyInfo.textOrThrow(): ReplyInfo.External.Text = this as + dev.inmo.tgbotapi.types.ReplyInfo.External.Text + +public inline fun ReplyInfo.ifText(block: (ReplyInfo.External.Text) -> T): T? = textOrNull() + ?.let(block) + +public inline fun ReplyInfo.internalOrNull(): ReplyInfo.Internal? = this as? + dev.inmo.tgbotapi.types.ReplyInfo.Internal + +public inline fun ReplyInfo.internalOrThrow(): ReplyInfo.Internal = this as + dev.inmo.tgbotapi.types.ReplyInfo.Internal + +public inline fun ReplyInfo.ifInternal(block: (ReplyInfo.Internal) -> T): T? = internalOrNull() + ?.let(block) + public inline fun BotAction.typingActionOrNull(): TypingAction? = this as? dev.inmo.tgbotapi.types.actions.TypingAction @@ -2385,6 +2442,15 @@ public inline fun TelegramMediaFile.fileOrThrow(): File = this as dev.inmo.tgbot public inline fun TelegramMediaFile.ifFile(block: (File) -> T): T? = fileOrNull() ?.let(block) +public inline fun TelegramMediaFile.mediaContentVariantOrNull(): MediaContentVariant? = this as? + dev.inmo.tgbotapi.types.files.MediaContentVariant + +public inline fun TelegramMediaFile.mediaContentVariantOrThrow(): MediaContentVariant = this as + dev.inmo.tgbotapi.types.files.MediaContentVariant + +public inline fun TelegramMediaFile.ifMediaContentVariant(block: (MediaContentVariant) -> T): T? + = mediaContentVariantOrNull() ?.let(block) + public inline fun TelegramMediaFile.mimedMediaFileOrNull(): MimedMediaFile? = this as? dev.inmo.tgbotapi.types.files.MimedMediaFile @@ -2412,6 +2478,15 @@ public inline fun TelegramMediaFile.pathedFileOrThrow(): PathedFile = this as public inline fun TelegramMediaFile.ifPathedFile(block: (PathedFile) -> T): T? = pathedFileOrNull() ?.let(block) +public inline fun TelegramMediaFile.photoOrNull(): Photo? = this as? + dev.inmo.tgbotapi.types.files.Photo + +public inline fun TelegramMediaFile.photoOrThrow(): Photo = this as + dev.inmo.tgbotapi.types.files.Photo + +public inline fun TelegramMediaFile.ifPhoto(block: (Photo) -> T): T? = photoOrNull() + ?.let(block) + public inline fun TelegramMediaFile.photoSizeOrNull(): PhotoSize? = this as? dev.inmo.tgbotapi.types.files.PhotoSize diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt index 0874d13255..9b65ae7a90 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt @@ -51,7 +51,7 @@ inline val AccessibleMessage.is_automatic_forward: Boolean? get() = this is ConnectedFromChannelGroupContentMessage<*> @RiskFeature(RawFieldsUsageWarning) inline val AccessibleMessage.reply_to_message: AccessibleMessage? - get() = asPossiblyReplyMessage() ?.replyInfo + get() = asPossiblyReplyMessage() ?.replyTo @RiskFeature(RawFieldsUsageWarning) inline val AccessibleMessage.via_bot: CommonBot? get() = asPossiblySentViaBotCommonMessage() ?.senderBot