From a01ca438378547c9dd831ab7a87663bbf335e0b8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 16 Feb 2024 21:54:13 +0600 Subject: [PATCH] add support of Story content and reply_to_story field --- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 5 +++++ .../kotlin/dev/inmo/tgbotapi/types/ReplyInfo.kt | 9 ++++++++- .../dev/inmo/tgbotapi/types/message/RawMessage.kt | 2 ++ .../kotlin/dev/inmo/tgbotapi/types/stories/Story.kt | 12 +++++++++++- .../inmo/tgbotapi/extensions/utils/ClassCastsNew.kt | 9 +++++++++ 5 files changed, 35 insertions(+), 2 deletions(-) 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 9b1ef20df7..788dd7401c 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 @@ -45,6 +45,11 @@ value class CustomEmojiId( val appLink get() = "${internalTgAppLinksBeginning}emoji?id=$this" } +@Serializable +@JvmInline +value class StoryId( + val long: Long +) typealias Seconds = Int typealias MilliSeconds = Long 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 419a3bba83..445749a753 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 @@ -9,7 +9,6 @@ import dev.inmo.tgbotapi.types.giveaway.GiveawayPublicResults import dev.inmo.tgbotapi.types.giveaway.Giveaway import dev.inmo.tgbotapi.types.location.Location import dev.inmo.tgbotapi.types.message.MessageOrigin -import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.payments.Invoice import dev.inmo.tgbotapi.types.polls.Poll @@ -34,6 +33,14 @@ sealed interface ReplyInfo { get() = message.metaInfo } + @Serializable + data class ToStory( + val story: Story + ): ReplyInfo { + override val messageMeta: Message.MetaInfo? + get() = null + } + @Serializable(External.Companion::class) sealed interface External : ReplyInfo { val origin: MessageOrigin 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 4436bd9827..86aa9e29cb 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 @@ -54,6 +54,7 @@ internal data class RawMessage( private val is_topic_message: Boolean? = null, private val is_automatic_forward: Boolean? = null, private val reply_to_message: RawMessage? = null, + private val reply_to_story: Story? = null, private val external_reply: ReplyInfo.External? = null, private val quote: TextQuote? = null, private val via_bot: CommonBot? = null, @@ -300,6 +301,7 @@ internal data class RawMessage( reply_to_message != null -> ReplyInfo.Internal( reply_to_message.asMessage ) + reply_to_story != null -> ReplyInfo.ToStory(reply_to_story) external_reply != null -> external_reply else -> null } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt index 35154fd101..e6c71e9f5c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt @@ -1,7 +1,17 @@ package dev.inmo.tgbotapi.types.stories import dev.inmo.tgbotapi.types.ReplyInfo +import dev.inmo.tgbotapi.types.StoryId +import dev.inmo.tgbotapi.types.chat.PreviewChat +import dev.inmo.tgbotapi.types.chatField +import dev.inmo.tgbotapi.types.idField +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -class Story : ReplyInfo.External.ContentVariant +class Story( + @SerialName(idField) + val id: StoryId, + @SerialName(chatField) + val chat: PreviewChat +) : ReplyInfo.External.ContentVariant 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 7ad2015604..7db7709e5b 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 @@ -1631,6 +1631,15 @@ public inline fun ReplyInfo.internalOrThrow(): ReplyInfo.Internal = this as public inline fun ReplyInfo.ifInternal(block: (ReplyInfo.Internal) -> T): T? = internalOrNull() ?.let(block) +public inline fun ReplyInfo.toStoryOrNull(): ReplyInfo.ToStory? = this as? + dev.inmo.tgbotapi.types.ReplyInfo.ToStory + +public inline fun ReplyInfo.toStoryOrThrow(): ReplyInfo.ToStory = this as + dev.inmo.tgbotapi.types.ReplyInfo.ToStory + +public inline fun ReplyInfo.ifToStory(block: (ReplyInfo.ToStory) -> T): T? = toStoryOrNull() + ?.let(block) + public inline fun BotAction.typingActionOrNull(): TypingAction? = this as? dev.inmo.tgbotapi.types.actions.TypingAction