From 867a46d3971d8d8e9f896893d67eebc5363e3257 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 6 Nov 2022 12:51:53 +0600 Subject: [PATCH] add support of forum chats --- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 3 + .../dev/inmo/tgbotapi/types/chat/Abstracts.kt | 23 +- .../tgbotapi/types/chat/ChatSerializers.kt | 16 +- .../dev/inmo/tgbotapi/types/chat/Extended.kt | 35 +++ .../tgbotapi/types/chat/ExtendedAbstracts.kt | 3 + .../dev/inmo/tgbotapi/types/chat/Impls.kt | 10 + .../tgbotapi/types/message/GroupMessages.kt | 46 ++++ .../inmo/tgbotapi/types/message/RawMessage.kt | 111 +++++++++- .../types/message/abstracts/GroupMessages.kt | 20 +- .../extensions/utils/ClassCastsNew.kt | 208 +++++++++++++++--- 10 files changed, 432 insertions(+), 43 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 70f9e1f47b..fd37ef0ace 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 @@ -11,6 +11,7 @@ import kotlin.jvm.JvmInline typealias Identifier = Long typealias MessageId = Long +typealias MessageThreadId = Long typealias MessageIdentifier = MessageId typealias InlineQueryIdentifier = String typealias UpdateIdentifier = Long @@ -148,6 +149,7 @@ const val tgWebAppStartParamField = "tgWebAppStartParam" const val chatIdField = "chat_id" const val senderChatIdField = "sender_chat_id" const val messageIdField = "message_id" +const val messageThreadIdField = "message_thread_id" const val updateIdField = "update_id" const val fromChatIdField = "from_chat_id" const val disableWebPagePreviewField = "disable_web_page_preview" @@ -313,6 +315,7 @@ const val botCommandsField = "commands" const val scopeField = "scope" const val isMemberField = "is_member" +const val isForumField = "is_forum" const val canSendMessagesField = "can_send_messages" const val canSendMediaMessagesField = "can_send_media_messages" const val canSendOtherMessagesField = "can_send_other_messages" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Abstracts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Abstracts.kt index 2bb134d168..258604a209 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Abstracts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Abstracts.kt @@ -5,10 +5,9 @@ import dev.inmo.tgbotapi.types.* import kotlinx.serialization.Serializable @Serializable(PreviewChatSerializer::class) -sealed interface ChannelChat : SuperPublicChat - -@Serializable(PreviewChatSerializer::class) -sealed interface GroupChat : PublicChat +sealed interface UsernameChat : Chat { + val username: Username? +} @Serializable(PreviewChatSerializer::class) sealed interface PrivateChat : Chat, UsernameChat { @@ -22,16 +21,20 @@ sealed interface PublicChat : Chat { val title: String } -@Serializable(PreviewChatSerializer::class) -sealed interface SupergroupChat : GroupChat, SuperPublicChat - @Serializable(PreviewChatSerializer::class) sealed interface SuperPublicChat : PublicChat, UsernameChat @Serializable(PreviewChatSerializer::class) -sealed interface UsernameChat : Chat { - val username: Username? -} +sealed interface ChannelChat : SuperPublicChat + +@Serializable(PreviewChatSerializer::class) +sealed interface GroupChat : PublicChat + +@Serializable(PreviewChatSerializer::class) +sealed interface SupergroupChat : GroupChat, SuperPublicChat + +@Serializable(PreviewChatSerializer::class) +sealed interface ForumChat : SupergroupChat @Serializable(PreviewChatSerializer::class) sealed interface PossiblyPremiumChat : Chat { 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 3d887f8ffe..c211b909ba 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 @@ -57,11 +57,16 @@ object PreviewChatSerializer : KSerializer { val decodedJson = JsonObject.serializer().deserialize(decoder) val type = decodedJson[typeField] ?.jsonPrimitive ?.content ?.asChatType ?: error("Field $typeField must be presented, but absent in $decodedJson") + val isForum = decodedJson[isForumField] ?.jsonPrimitive ?.booleanOrNull == true return when (type) { ChatType.PrivateChatType -> formatter.decodeFromJsonElement(PrivateChatImpl.serializer(), decodedJson) ChatType.GroupChatType -> formatter.decodeFromJsonElement(GroupChatImpl.serializer(), decodedJson) - ChatType.SupergroupChatType -> formatter.decodeFromJsonElement(SupergroupChatImpl.serializer(), decodedJson) + ChatType.SupergroupChatType -> if (isForum) { + formatter.decodeFromJsonElement(ForumChatImpl.serializer(), decodedJson) + } else { + 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(), @@ -77,6 +82,7 @@ object PreviewChatSerializer : KSerializer { is PrivateChatImpl -> PrivateChatImpl.serializer().serialize(encoder, value) is GroupChatImpl -> GroupChatImpl.serializer().serialize(encoder, value) is SupergroupChatImpl -> SupergroupChatImpl.serializer().serialize(encoder, value) + is ForumChatImpl -> ForumChatImpl.serializer().serialize(encoder, value) is ChannelChatImpl -> ChannelChatImpl.serializer().serialize(encoder, value) is CommonBot -> CommonBot.serializer().serialize(encoder, value) is ExtendedBot -> ExtendedBot.serializer().serialize(encoder, value) @@ -95,12 +101,17 @@ object ExtendedChatSerializer : KSerializer { val decodedJson = JsonObject.serializer().deserialize(decoder) val type = decodedJson[typeField] ?.jsonPrimitive ?.content ?.asChatType ?: error("Field $typeField must be presented, but absent in $decodedJson") + val isForum = decodedJson[isForumField] ?.jsonPrimitive ?.booleanOrNull == true return when (type) { // 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.SupergroupChatType -> if (isForum) { + formatter.decodeFromJsonElement(ExtendedForumChatImpl.serializer(), decodedJson) + } else { + 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(), @@ -115,6 +126,7 @@ object ExtendedChatSerializer : KSerializer { is ExtendedPrivateChatImpl -> ExtendedPrivateChatImpl.serializer().serialize(encoder, value) is ExtendedGroupChatImpl -> ExtendedGroupChatImpl.serializer().serialize(encoder, value) is ExtendedSupergroupChatImpl -> ExtendedSupergroupChatImpl.serializer().serialize(encoder, value) + is ExtendedForumChatImpl -> ExtendedForumChatImpl.serializer().serialize(encoder, value) is ExtendedChannelChatImpl -> ExtendedChannelChatImpl.serializer().serialize(encoder, value) is UnknownExtendedChat -> JsonObject.serializer().serialize(encoder, value.rawJson) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt index 01ead1be28..6d1615849e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt @@ -104,6 +104,41 @@ data class ExtendedSupergroupChatImpl( override val requireAdminApproveToJoin: Boolean = false ) : ExtendedSupergroupChat +@Serializable +data class ExtendedForumChatImpl( + @SerialName(idField) + override val id: ChatId, + @SerialName(titleField) + override val title: String, + @SerialName(usernameField) + override val username: Username? = null, + @SerialName(photoField) + override val chatPhoto: ChatPhoto? = null, + @SerialName(permissionsField) + override val permissions: ChatPermissions, + @SerialName(descriptionField) + override val description: String = "", + @SerialName(inviteLinkField) + override val inviteLink: String? = null, + @SerialName(pinnedMessageField) + @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) + override val pinnedMessage: Message? = null, + @SerialName(stickerSetNameFullField) + override val stickerSetName: StickerSetName? = null, + @SerialName(slowModeDelayField) + override val slowModeDelay: Long? = null, + @SerialName(canSetStickerSetField) + override val canSetStickerSet: Boolean = false, + @SerialName(linkedChatIdField) + override val linkedChannelChatId: ChatId? = null, + @SerialName(locationField) + override val location: ChatLocation? = null, + @SerialName(joinToSendMessagesField) + override val requiresJoinForMessaging: Boolean = false, + @SerialName(joinByRequestField) + override val requireAdminApproveToJoin: Boolean = false +) : ExtendedForumChat + @Serializable data class ExtendedBot( override val id: UserId, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt index 6705d8203d..4eed327336 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt @@ -51,6 +51,9 @@ sealed interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat { val requireAdminApproveToJoin: Boolean } +@Serializable(ExtendedChatSerializer::class) +sealed interface ExtendedForumChat : ExtendedSupergroupChat + @Serializable(ExtendedChatSerializer::class) sealed interface ExtendedChat : Chat { val chatPhoto: ChatPhoto? diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Impls.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Impls.kt index ac61c30301..3af9d12774 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Impls.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Impls.kt @@ -37,6 +37,16 @@ data class SupergroupChatImpl( override val username: Username? = null ) : SupergroupChat +@Serializable +data class ForumChatImpl( + @SerialName(idField) + override val id: ChatId, + @SerialName(titleField) + override val title: String, + @SerialName(usernameField) + override val username: Username? = null +) : ForumChat + @Serializable data class ChannelChatImpl( @SerialName(idField) 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 18b98428e4..f297b81df1 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 @@ -66,3 +66,49 @@ data class CommonGroupContentMessageImpl( override val content: T, override val senderBot: CommonBot? ) : CommonGroupContentMessage + +data class FromChannelForumContentMessageImpl( + override val chat: ForumChat, + override val channel: ChannelChat, + override val messageId: MessageId, + override val threadId: MessageThreadId, + override val date: DateTime, + override val forwardInfo: ForwardInfo?, + override val editDate: DateTime?, + override val hasProtectedContent: Boolean, + override val replyTo: Message?, + override val replyMarkup: InlineKeyboardMarkup?, + override val content: T, + override val senderBot: CommonBot?, + override val authorSignature: AuthorSignature? +) : FromChannelForumContentMessage + +data class AnonymousForumContentMessageImpl( + override val chat: ForumChat, + override val messageId: MessageId, + override val threadId: MessageThreadId, + override val date: DateTime, + override val forwardInfo: ForwardInfo?, + override val editDate: DateTime?, + override val hasProtectedContent: Boolean, + override val replyTo: Message?, + override val replyMarkup: InlineKeyboardMarkup?, + override val content: T, + override val senderBot: CommonBot?, + override val authorSignature: AuthorSignature? +) : AnonymousForumContentMessage + +data class CommonForumContentMessageImpl( + override val chat: ForumChat, + override val messageId: MessageId, + override val threadId: MessageThreadId, + override val from: User, + override val date: DateTime, + override val forwardInfo: ForwardInfo?, + override val editDate: DateTime?, + override val hasProtectedContent: Boolean, + override val replyTo: Message?, + override val replyMarkup: InlineKeyboardMarkup?, + override val content: T, + override val senderBot: CommonBot? +) : CommonForumContentMessage 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 459c45ca2e..4b390034b2 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 @@ -34,6 +34,8 @@ internal data class RawMessage( val messageId: MessageId, val date: TelegramDate, private val chat: Chat, + @SerialName(messageThreadIdField) + private val messageThreadId: MessageThreadId? = null, private val from: User? = null, private val sender_chat: PublicChat? = null, private val forward_from: User? = null, @@ -307,6 +309,113 @@ internal data class RawMessage( via_bot, author_signature ) + is ForumChat -> if (messageThreadId != null) { + when (sender_chat) { + is ChannelChat -> FromChannelForumContentMessageImpl( + chat, + sender_chat, + messageId, + messageThreadId, + date.asDate, + forwarded, + edit_date ?.asDate, + has_protected_content == true, + reply_to_message ?.asMessage, + reply_markup, + content, + via_bot, + author_signature + ) + is GroupChat -> AnonymousForumContentMessageImpl( + chat, + messageId, + messageThreadId, + date.asDate, + forwarded, + edit_date ?.asDate, + has_protected_content == true, + reply_to_message ?.asMessage, + reply_markup, + content, + via_bot, + author_signature + ) + null -> CommonForumContentMessageImpl( + chat, + messageId, + messageThreadId, + from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"), + date.asDate, + forwarded, + edit_date ?.asDate, + has_protected_content == true, + reply_to_message ?.asMessage, + reply_markup, + content, + via_bot + ) + } + } else { + when (sender_chat) { + is ChannelChat -> if (is_automatic_forward == true) { + ConnectedFromChannelGroupContentMessageImpl( + chat, + sender_chat, + messageId, + date.asDate, + forwarded, + edit_date ?.asDate, + has_protected_content == true, + reply_to_message ?.asMessage, + reply_markup, + content, + via_bot, + author_signature + ) + } else { + UnconnectedFromChannelGroupContentMessageImpl( + chat, + sender_chat, + messageId, + date.asDate, + forwarded, + edit_date ?.asDate, + has_protected_content == true, + reply_to_message ?.asMessage, + reply_markup, + content, + via_bot, + author_signature + ) + } + is GroupChat -> AnonymousGroupContentMessageImpl( + chat, + messageId, + date.asDate, + forwarded, + edit_date ?.asDate, + has_protected_content == true, + reply_to_message ?.asMessage, + reply_markup, + content, + via_bot, + author_signature + ) + null -> CommonGroupContentMessageImpl( + chat, + messageId, + from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"), + date.asDate, + forwarded, + edit_date ?.asDate, + has_protected_content == true, + reply_to_message ?.asMessage, + reply_markup, + content, + via_bot + ) + } + } is GroupChat -> when (sender_chat) { is ChannelChat -> if (is_automatic_forward == true) { ConnectedFromChannelGroupContentMessageImpl( @@ -365,9 +474,7 @@ internal data class RawMessage( content, via_bot ) - else -> error("Currently in groups supported only fields \"sender_chat\" with channel, group or null, but was $sender_chat") } - else -> error("Unknown type of public chat: $chat") } is PrivateChat -> PrivateContentMessageImpl( messageId, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt index 7ec7f0bc6c..b03eb1900f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt @@ -1,15 +1,22 @@ package dev.inmo.tgbotapi.types.message.abstracts +import dev.inmo.tgbotapi.types.MessageThreadId import dev.inmo.tgbotapi.types.chat.ChannelChat +import dev.inmo.tgbotapi.types.chat.ForumChat import dev.inmo.tgbotapi.types.chat.GroupChat import dev.inmo.tgbotapi.types.message.content.MessageContent -interface GroupContentMessage : PublicContentMessage { +sealed interface GroupContentMessage : PublicContentMessage { override val chat: GroupChat } +sealed interface ForumContentMessage : GroupContentMessage { + override val chat: ForumChat + val threadId: MessageThreadId +} -interface FromChannelGroupContentMessage : GroupContentMessage, SignedMessage, WithSenderChatMessage { + +sealed interface FromChannelGroupContentMessage : GroupContentMessage, SignedMessage, WithSenderChatMessage { val channel: ChannelChat override val senderChat: ChannelChat get() = channel @@ -24,3 +31,12 @@ interface AnonymousGroupContentMessage : GroupContentMessage } interface CommonGroupContentMessage : GroupContentMessage, FromUserMessage + +interface FromChannelForumContentMessage : FromChannelGroupContentMessage, ForumContentMessage + +interface AnonymousForumContentMessage : ForumContentMessage, SignedMessage, WithSenderChatMessage { + override val senderChat: GroupChat + get() = chat +} + +interface CommonForumContentMessage : ForumContentMessage, FromUserMessage 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 54668e5609..c2091ffb91 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 @@ -124,6 +124,8 @@ import dev.inmo.tgbotapi.types.chat.ExtendedBot import dev.inmo.tgbotapi.types.chat.ExtendedChannelChat import dev.inmo.tgbotapi.types.chat.ExtendedChannelChatImpl import dev.inmo.tgbotapi.types.chat.ExtendedChat +import dev.inmo.tgbotapi.types.chat.ExtendedForumChat +import dev.inmo.tgbotapi.types.chat.ExtendedForumChatImpl import dev.inmo.tgbotapi.types.chat.ExtendedGroupChat import dev.inmo.tgbotapi.types.chat.ExtendedGroupChatImpl import dev.inmo.tgbotapi.types.chat.ExtendedPrivateChat @@ -131,6 +133,8 @@ import dev.inmo.tgbotapi.types.chat.ExtendedPrivateChatImpl import dev.inmo.tgbotapi.types.chat.ExtendedPublicChat import dev.inmo.tgbotapi.types.chat.ExtendedSupergroupChat import dev.inmo.tgbotapi.types.chat.ExtendedSupergroupChatImpl +import dev.inmo.tgbotapi.types.chat.ForumChat +import dev.inmo.tgbotapi.types.chat.ForumChatImpl import dev.inmo.tgbotapi.types.chat.GroupChat import dev.inmo.tgbotapi.types.chat.GroupChatImpl import dev.inmo.tgbotapi.types.chat.PossiblyPremiumChat @@ -212,6 +216,7 @@ import dev.inmo.tgbotapi.types.media.TelegramMediaVideo import dev.inmo.tgbotapi.types.media.ThumbedTelegramMedia import dev.inmo.tgbotapi.types.media.TitledTelegramMedia import dev.inmo.tgbotapi.types.media.VisualMediaGroupMemberTelegramMedia +import dev.inmo.tgbotapi.types.message.AnonymousForumContentMessageImpl import dev.inmo.tgbotapi.types.message.AnonymousGroupContentMessageImpl import dev.inmo.tgbotapi.types.message.ChannelContentMessageImpl import dev.inmo.tgbotapi.types.message.ChannelEventMessage @@ -242,23 +247,29 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.voice.VideoChatEnded import dev.inmo.tgbotapi.types.message.ChatEvents.voice.VideoChatParticipantsInvited import dev.inmo.tgbotapi.types.message.ChatEvents.voice.VideoChatScheduled import dev.inmo.tgbotapi.types.message.ChatEvents.voice.VideoChatStarted +import dev.inmo.tgbotapi.types.message.CommonForumContentMessageImpl import dev.inmo.tgbotapi.types.message.CommonGroupContentMessageImpl import dev.inmo.tgbotapi.types.message.CommonGroupEventMessage import dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage import dev.inmo.tgbotapi.types.message.CommonSupergroupEventMessage import dev.inmo.tgbotapi.types.message.ConnectedFromChannelGroupContentMessageImpl import dev.inmo.tgbotapi.types.message.ForwardInfo +import dev.inmo.tgbotapi.types.message.FromChannelForumContentMessageImpl import dev.inmo.tgbotapi.types.message.PassportMessage import dev.inmo.tgbotapi.types.message.PrivateContentMessageImpl import dev.inmo.tgbotapi.types.message.PrivateEventMessage import dev.inmo.tgbotapi.types.message.UnconnectedFromChannelGroupContentMessageImpl +import dev.inmo.tgbotapi.types.message.abstracts.AnonymousForumContentMessage import dev.inmo.tgbotapi.types.message.abstracts.AnonymousGroupContentMessage import dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage +import dev.inmo.tgbotapi.types.message.abstracts.CommonForumContentMessage import dev.inmo.tgbotapi.types.message.abstracts.CommonGroupContentMessage import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage import dev.inmo.tgbotapi.types.message.abstracts.ConnectedFromChannelGroupContentMessage import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.ForumContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.FromChannelForumContentMessage import dev.inmo.tgbotapi.types.message.abstracts.FromChannelGroupContentMessage import dev.inmo.tgbotapi.types.message.abstracts.FromUserMessage import dev.inmo.tgbotapi.types.message.abstracts.GroupContentMessage @@ -761,6 +772,18 @@ public inline fun WithUser.ifCommonGroupContentMessageImpl(block: (CommonGroupContentMessageImpl) -> T): T? = commonGroupContentMessageImplOrNull() ?.let(block) +public inline fun WithUser.commonForumContentMessageImplOrNull(): + CommonForumContentMessageImpl? = this as? + dev.inmo.tgbotapi.types.message.CommonForumContentMessageImpl + +public inline fun WithUser.commonForumContentMessageImplOrThrow(): + CommonForumContentMessageImpl = this as + dev.inmo.tgbotapi.types.message.CommonForumContentMessageImpl + +public inline fun + WithUser.ifCommonForumContentMessageImpl(block: (CommonForumContentMessageImpl) -> T): + T? = commonForumContentMessageImplOrNull() ?.let(block) + public inline fun WithUser.passportMessageOrNull(): PassportMessage? = this as? dev.inmo.tgbotapi.types.message.PassportMessage @@ -812,6 +835,18 @@ public inline fun WithUser.ifCommonGroupContentMessage(block: (CommonGroupContentMessage) -> T): T? = commonGroupContentMessageOrNull() ?.let(block) +public inline fun WithUser.commonForumContentMessageOrNull(): + CommonForumContentMessage? = this as? + dev.inmo.tgbotapi.types.message.abstracts.CommonForumContentMessage + +public inline fun WithUser.commonForumContentMessageOrThrow(): + CommonForumContentMessage = this as + dev.inmo.tgbotapi.types.message.abstracts.CommonForumContentMessage + +public inline fun + WithUser.ifCommonForumContentMessage(block: (CommonForumContentMessage) -> T): + T? = commonForumContentMessageOrNull() ?.let(block) + public inline fun WithUser.privateContentMessageOrNull(): PrivateContentMessage? = this as? dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage @@ -1848,23 +1883,15 @@ public inline fun KeyboardMarkup.replyKeyboardRemoveOrThrow(): ReplyKeyboardRemo public inline fun KeyboardMarkup.ifReplyKeyboardRemove(block: (ReplyKeyboardRemove) -> T): T? = replyKeyboardRemoveOrNull() ?.let(block) -public inline fun Chat.channelChatOrNull(): ChannelChat? = this as? - dev.inmo.tgbotapi.types.chat.ChannelChat +public inline fun Chat.usernameChatOrNull(): UsernameChat? = this as? + dev.inmo.tgbotapi.types.chat.UsernameChat -public inline fun Chat.channelChatOrThrow(): ChannelChat = this as - dev.inmo.tgbotapi.types.chat.ChannelChat +public inline fun Chat.usernameChatOrThrow(): UsernameChat = this as + dev.inmo.tgbotapi.types.chat.UsernameChat -public inline fun Chat.ifChannelChat(block: (ChannelChat) -> T): T? = channelChatOrNull() +public inline fun Chat.ifUsernameChat(block: (UsernameChat) -> T): T? = usernameChatOrNull() ?.let(block) -public inline fun Chat.groupChatOrNull(): GroupChat? = this as? - dev.inmo.tgbotapi.types.chat.GroupChat - -public inline fun Chat.groupChatOrThrow(): GroupChat = this as - dev.inmo.tgbotapi.types.chat.GroupChat - -public inline fun Chat.ifGroupChat(block: (GroupChat) -> T): T? = groupChatOrNull() ?.let(block) - public inline fun Chat.privateChatOrNull(): PrivateChat? = this as? dev.inmo.tgbotapi.types.chat.PrivateChat @@ -1883,15 +1910,6 @@ public inline fun Chat.publicChatOrThrow(): PublicChat = this as public inline fun Chat.ifPublicChat(block: (PublicChat) -> T): T? = publicChatOrNull() ?.let(block) -public inline fun Chat.supergroupChatOrNull(): SupergroupChat? = this as? - dev.inmo.tgbotapi.types.chat.SupergroupChat - -public inline fun Chat.supergroupChatOrThrow(): SupergroupChat = this as - dev.inmo.tgbotapi.types.chat.SupergroupChat - -public inline fun Chat.ifSupergroupChat(block: (SupergroupChat) -> T): T? = - supergroupChatOrNull() ?.let(block) - public inline fun Chat.superPublicChatOrNull(): SuperPublicChat? = this as? dev.inmo.tgbotapi.types.chat.SuperPublicChat @@ -1901,15 +1919,40 @@ public inline fun Chat.superPublicChatOrThrow(): SuperPublicChat = this as public inline fun Chat.ifSuperPublicChat(block: (SuperPublicChat) -> T): T? = superPublicChatOrNull() ?.let(block) -public inline fun Chat.usernameChatOrNull(): UsernameChat? = this as? - dev.inmo.tgbotapi.types.chat.UsernameChat +public inline fun Chat.channelChatOrNull(): ChannelChat? = this as? + dev.inmo.tgbotapi.types.chat.ChannelChat -public inline fun Chat.usernameChatOrThrow(): UsernameChat = this as - dev.inmo.tgbotapi.types.chat.UsernameChat +public inline fun Chat.channelChatOrThrow(): ChannelChat = this as + dev.inmo.tgbotapi.types.chat.ChannelChat -public inline fun Chat.ifUsernameChat(block: (UsernameChat) -> T): T? = usernameChatOrNull() +public inline fun Chat.ifChannelChat(block: (ChannelChat) -> T): T? = channelChatOrNull() ?.let(block) +public inline fun Chat.groupChatOrNull(): GroupChat? = this as? + dev.inmo.tgbotapi.types.chat.GroupChat + +public inline fun Chat.groupChatOrThrow(): GroupChat = this as + dev.inmo.tgbotapi.types.chat.GroupChat + +public inline fun Chat.ifGroupChat(block: (GroupChat) -> T): T? = groupChatOrNull() ?.let(block) + +public inline fun Chat.supergroupChatOrNull(): SupergroupChat? = this as? + dev.inmo.tgbotapi.types.chat.SupergroupChat + +public inline fun Chat.supergroupChatOrThrow(): SupergroupChat = this as + dev.inmo.tgbotapi.types.chat.SupergroupChat + +public inline fun Chat.ifSupergroupChat(block: (SupergroupChat) -> T): T? = + supergroupChatOrNull() ?.let(block) + +public inline fun Chat.forumChatOrNull(): ForumChat? = this as? + dev.inmo.tgbotapi.types.chat.ForumChat + +public inline fun Chat.forumChatOrThrow(): ForumChat = this as + dev.inmo.tgbotapi.types.chat.ForumChat + +public inline fun Chat.ifForumChat(block: (ForumChat) -> T): T? = forumChatOrNull() ?.let(block) + public inline fun Chat.possiblyPremiumChatOrNull(): PossiblyPremiumChat? = this as? dev.inmo.tgbotapi.types.chat.PossiblyPremiumChat @@ -1965,6 +2008,15 @@ public inline fun Chat.extendedSupergroupChatImplOrThrow(): ExtendedSupergroupCh public inline fun Chat.ifExtendedSupergroupChatImpl(block: (ExtendedSupergroupChatImpl) -> T): T? = extendedSupergroupChatImplOrNull() ?.let(block) +public inline fun Chat.extendedForumChatImplOrNull(): ExtendedForumChatImpl? = this as? + dev.inmo.tgbotapi.types.chat.ExtendedForumChatImpl + +public inline fun Chat.extendedForumChatImplOrThrow(): ExtendedForumChatImpl = this as + dev.inmo.tgbotapi.types.chat.ExtendedForumChatImpl + +public inline fun Chat.ifExtendedForumChatImpl(block: (ExtendedForumChatImpl) -> T): T? = + extendedForumChatImplOrNull() ?.let(block) + public inline fun Chat.extendedBotOrNull(): ExtendedBot? = this as? dev.inmo.tgbotapi.types.chat.ExtendedBot @@ -2028,6 +2080,15 @@ public inline fun Chat.extendedSupergroupChatOrThrow(): ExtendedSupergroupChat = public inline fun Chat.ifExtendedSupergroupChat(block: (ExtendedSupergroupChat) -> T): T? = extendedSupergroupChatOrNull() ?.let(block) +public inline fun Chat.extendedForumChatOrNull(): ExtendedForumChat? = this as? + dev.inmo.tgbotapi.types.chat.ExtendedForumChat + +public inline fun Chat.extendedForumChatOrThrow(): ExtendedForumChat = this as + dev.inmo.tgbotapi.types.chat.ExtendedForumChat + +public inline fun Chat.ifExtendedForumChat(block: (ExtendedForumChat) -> T): T? = + extendedForumChatOrNull() ?.let(block) + public inline fun Chat.extendedChatOrNull(): ExtendedChat? = this as? dev.inmo.tgbotapi.types.chat.ExtendedChat @@ -2064,6 +2125,15 @@ public inline fun Chat.supergroupChatImplOrThrow(): SupergroupChatImpl = this as public inline fun Chat.ifSupergroupChatImpl(block: (SupergroupChatImpl) -> T): T? = supergroupChatImplOrNull() ?.let(block) +public inline fun Chat.forumChatImplOrNull(): ForumChatImpl? = this as? + dev.inmo.tgbotapi.types.chat.ForumChatImpl + +public inline fun Chat.forumChatImplOrThrow(): ForumChatImpl = this as + dev.inmo.tgbotapi.types.chat.ForumChatImpl + +public inline fun Chat.ifForumChatImpl(block: (ForumChatImpl) -> T): T? = forumChatImplOrNull() + ?.let(block) + public inline fun Chat.channelChatImplOrNull(): ChannelChatImpl? = this as? dev.inmo.tgbotapi.types.chat.ChannelChatImpl @@ -3011,6 +3081,42 @@ public inline fun Message.ifCommonGroupContentMessageImpl(block: (CommonGroupContentMessageImpl) -> T): T? = commonGroupContentMessageImplOrNull() ?.let(block) +public inline fun Message.fromChannelForumContentMessageImplOrNull(): + FromChannelForumContentMessageImpl? = this as? + dev.inmo.tgbotapi.types.message.FromChannelForumContentMessageImpl + +public inline fun Message.fromChannelForumContentMessageImplOrThrow(): + FromChannelForumContentMessageImpl = this as + dev.inmo.tgbotapi.types.message.FromChannelForumContentMessageImpl + +public inline fun + Message.ifFromChannelForumContentMessageImpl(block: (FromChannelForumContentMessageImpl) -> T): + T? = fromChannelForumContentMessageImplOrNull() ?.let(block) + +public inline fun Message.anonymousForumContentMessageImplOrNull(): + AnonymousForumContentMessageImpl? = this as? + dev.inmo.tgbotapi.types.message.AnonymousForumContentMessageImpl + +public inline fun Message.anonymousForumContentMessageImplOrThrow(): + AnonymousForumContentMessageImpl = this as + dev.inmo.tgbotapi.types.message.AnonymousForumContentMessageImpl + +public inline fun + Message.ifAnonymousForumContentMessageImpl(block: (AnonymousForumContentMessageImpl) -> T): + T? = anonymousForumContentMessageImplOrNull() ?.let(block) + +public inline fun Message.commonForumContentMessageImplOrNull(): + CommonForumContentMessageImpl? = this as? + dev.inmo.tgbotapi.types.message.CommonForumContentMessageImpl + +public inline fun Message.commonForumContentMessageImplOrThrow(): + CommonForumContentMessageImpl = this as + dev.inmo.tgbotapi.types.message.CommonForumContentMessageImpl + +public inline fun + Message.ifCommonForumContentMessageImpl(block: (CommonForumContentMessageImpl) -> T): + T? = commonForumContentMessageImplOrNull() ?.let(block) + public inline fun Message.passportMessageOrNull(): PassportMessage? = this as? dev.inmo.tgbotapi.types.message.PassportMessage @@ -3111,6 +3217,18 @@ public inline fun Message.ifGroupContentMessage(block: (GroupContentMessage) -> T): T? = groupContentMessageOrNull() ?.let(block) +public inline fun Message.forumContentMessageOrNull(): ForumContentMessage? = this + as? + dev.inmo.tgbotapi.types.message.abstracts.ForumContentMessage + +public inline fun Message.forumContentMessageOrThrow(): ForumContentMessage = this + as + dev.inmo.tgbotapi.types.message.abstracts.ForumContentMessage + +public inline fun + Message.ifForumContentMessage(block: (ForumContentMessage) -> T): T? = + forumContentMessageOrNull() ?.let(block) + public inline fun Message.fromChannelGroupContentMessageOrNull(): FromChannelGroupContentMessage? = this as? dev.inmo.tgbotapi.types.message.abstracts.FromChannelGroupContentMessage @@ -3171,6 +3289,42 @@ public inline fun Message.ifCommonGroupContentMessage(block: (CommonGroupContentMessage) -> T): T? = commonGroupContentMessageOrNull() ?.let(block) +public inline fun Message.fromChannelForumContentMessageOrNull(): + FromChannelForumContentMessage? = this as? + dev.inmo.tgbotapi.types.message.abstracts.FromChannelForumContentMessage + +public inline fun Message.fromChannelForumContentMessageOrThrow(): + FromChannelForumContentMessage = this as + dev.inmo.tgbotapi.types.message.abstracts.FromChannelForumContentMessage + +public inline fun + Message.ifFromChannelForumContentMessage(block: (FromChannelForumContentMessage) -> T): + T? = fromChannelForumContentMessageOrNull() ?.let(block) + +public inline fun Message.anonymousForumContentMessageOrNull(): + AnonymousForumContentMessage? = this as? + dev.inmo.tgbotapi.types.message.abstracts.AnonymousForumContentMessage + +public inline fun Message.anonymousForumContentMessageOrThrow(): + AnonymousForumContentMessage = this as + dev.inmo.tgbotapi.types.message.abstracts.AnonymousForumContentMessage + +public inline fun + Message.ifAnonymousForumContentMessage(block: (AnonymousForumContentMessage) -> T): + T? = anonymousForumContentMessageOrNull() ?.let(block) + +public inline fun Message.commonForumContentMessageOrNull(): + CommonForumContentMessage? = this as? + dev.inmo.tgbotapi.types.message.abstracts.CommonForumContentMessage + +public inline fun Message.commonForumContentMessageOrThrow(): + CommonForumContentMessage = this as + dev.inmo.tgbotapi.types.message.abstracts.CommonForumContentMessage + +public inline fun + Message.ifCommonForumContentMessage(block: (CommonForumContentMessage) -> T): T? + = commonForumContentMessageOrNull() ?.let(block) + public inline fun Message.mediaGroupMessageOrNull(): MediaGroupMessage? = this as? dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage