diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/FromUser.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/FromUser.kt index aae284a45e..6bdb6dcde8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/FromUser.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/FromUser.kt @@ -6,11 +6,23 @@ import dev.inmo.tgbotapi.types.chat.User * Inheritors of this interface have some [User] as a source of data. For example, any [dev.inmo.tgbotapi.types.queries.callback.CallbackQuery] * have [User] as the source of that query */ -interface FromUser : WithUser { +interface OptionallyFromUser : OptionallyWithUser { /** * The source [User] of this type */ - val from: User + val from: User? + override val user: User? + get() = from +} +/** + * Inheritors of this interface have some [User] as a source of data. For example, any [dev.inmo.tgbotapi.types.queries.callback.CallbackQuery] + * have [User] as the source of that query + */ +interface FromUser : OptionallyFromUser, WithUser { + /** + * The source [User] of this type + */ + override val from: User override val user: User get() = from } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/WithUser.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/WithUser.kt index fb107ead22..ab84ded0f1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/WithUser.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/WithUser.kt @@ -9,6 +9,14 @@ import dev.inmo.tgbotapi.types.chat.User * @see FromUser */ @ClassCastsIncluded(excludeRegex = ".*Impl") -interface WithUser { - val user: User +interface OptionallyWithUser { + val user: User? +} +/** + * All inheritors of this type have [User] in their data as one of the main data + * + * @see FromUser + */ +interface WithUser : OptionallyWithUser { + override val user: User } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/RawChatId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/RawChatId.kt index e8ccc5a40b..d6e8cabba4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/RawChatId.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/RawChatId.kt @@ -10,6 +10,7 @@ value class RawChatId( ) { companion object { val DefaultUserId = RawChatId(136817688L) // I do not know why, it is Telegram crutch + val FakeUserId = RawChatId(777000L) // Brought with Telegram Bot API 7.9 as backward compatibility value for from field } override fun toString(): String { 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 1a9fd81ac6..50bea7370e 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 @@ -5,11 +5,13 @@ import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.CommonBot import dev.inmo.tgbotapi.types.chat.PreviewChannelChat +import dev.inmo.tgbotapi.types.chat.User import dev.inmo.tgbotapi.types.message.abstracts.* import dev.inmo.tgbotapi.types.message.content.MessageContent data class ChannelContentMessageImpl( override val messageId: MessageId, + override val from: User?, override val chat: PreviewChannelChat, override val content: T, override val date: DateTime, @@ -25,6 +27,7 @@ data class ChannelContentMessageImpl( ) : ChannelContentMessage { constructor( messageId: MessageId, + from: User?, chat: PreviewChannelChat, content: T, date: DateTime, @@ -38,6 +41,6 @@ data class ChannelContentMessageImpl( mediaGroupId: MediaGroupId?, fromOffline: Boolean, ) : this( - messageId, chat, content, date, editDate, hasProtectedContent, forwardInfo.messageOrigin(), replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, senderBot, authorSignature, mediaGroupId, fromOffline + messageId, from, chat, content, date, editDate, hasProtectedContent, forwardInfo.messageOrigin(), replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, senderBot, authorSignature, mediaGroupId, fromOffline ) } 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 2c42e9e2f0..ae73502f94 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 @@ -37,6 +37,7 @@ import dev.inmo.tgbotapi.types.request.ChatShared import dev.inmo.tgbotapi.types.request.UsersShared import dev.inmo.tgbotapi.types.stories.Story import dev.inmo.tgbotapi.types.venue.Venue +import dev.inmo.tgbotapi.utils.isFakeTelegramUser import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlin.reflect.KClass @@ -160,6 +161,7 @@ internal data class RawMessage( private val giveaway_created: GiveawayCreated? = null, private val giveaway_completed: GiveawayPrivateResults? = null, ) { + private val checkedFrom = from ?.takeIf { !it.isFakeTelegramUser() } private val content: MessageContent? by lazy { val adaptedCaptionEntities = caption ?.let { (caption_entities ?: emptyList()).asTextSources(caption) @@ -298,14 +300,14 @@ internal data class RawMessage( when (chat) { is PreviewSupergroupChat -> CommonSupergroupEventMessage( messageId, - from ?: error("Supergroup events are expected to contain 'from' field"), + checkedFrom ?: from ?: error("Supergroup events are expected to contain 'from' field"), chat, chatEvent as? SupergroupEvent ?: throwWrongChatEvent(SupergroupEvent::class, chatEvent), date.asDate ) is PreviewGroupChat -> CommonGroupEventMessage( messageId, - from ?: error("Supergroup events are expected to contain 'from' field"), + checkedFrom ?: from ?: error("Supergroup events are expected to contain 'from' field"), chat, chatEvent as? GroupEvent ?: throwWrongChatEvent(GroupChat::class, chatEvent), date.asDate @@ -337,6 +339,7 @@ internal data class RawMessage( is PreviewPublicChat -> when (chat) { is PreviewChannelChat -> ChannelContentMessageImpl( messageId = messageId, + from = checkedFrom ?: from, chat = chat, content = content, date = date.asDate, @@ -396,7 +399,7 @@ internal data class RawMessage( chat = actualForumChat, messageId = messageId, threadId = messageThreadId, - from = from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"), + from = checkedFrom ?: from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"), date = date.asDate, forwardOrigin = forward_origin, editDate = edit_date ?.asDate, @@ -465,7 +468,7 @@ internal data class RawMessage( null -> CommonGroupContentMessageImpl( chat = chat, messageId = messageId, - from = from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"), + from = checkedFrom ?: from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"), date = date.asDate, forwardOrigin = forward_origin, editDate = edit_date ?.asDate, @@ -534,7 +537,7 @@ internal data class RawMessage( null -> CommonGroupContentMessageImpl( chat = chat, messageId = messageId, - from = from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"), + from = checkedFrom ?: from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"), date = date.asDate, forwardOrigin = forward_origin, editDate = edit_date ?.asDate, @@ -552,7 +555,7 @@ internal data class RawMessage( is PreviewPrivateChat -> if (business_connection_id == null) { PrivateContentMessageImpl( messageId = messageId, - from = from ?: error("Was detected common message, but owner (sender) of the message was not found"), + from = checkedFrom ?: from ?: error("Was detected common message, but owner (sender) of the message was not found"), chat = chat, content = content, date = date.asDate, @@ -569,7 +572,7 @@ internal data class RawMessage( } else { BusinessContentMessageImpl( messageId = messageId, - from = from ?: error("Was detected common message, but owner (sender) of the message was not found"), + from = checkedFrom ?: from ?: error("Was detected common message, but owner (sender) of the message was not found"), chat = BusinessChatImpl( chat.id.toBusinessChatId(business_connection_id), chat @@ -594,7 +597,7 @@ internal data class RawMessage( PassportMessage( messageId, chat, - from ?: error("For passport must be provided user, but got null"), + checkedFrom ?: from ?: error("For passport must be provided user, but got null"), date.asDate, passport_data ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelContentMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelContentMessage.kt index 1cb54a4762..435466e558 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelContentMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelContentMessage.kt @@ -4,7 +4,7 @@ import dev.inmo.tgbotapi.types.chat.ChannelChat import dev.inmo.tgbotapi.types.chat.PreviewChannelChat import dev.inmo.tgbotapi.types.message.content.MessageContent -interface ChannelContentMessage : PossiblySentViaBotCommonMessage, SignedMessage, WithSenderChatMessage { +interface ChannelContentMessage : PossiblySentViaBotCommonMessage, SignedMessage, WithSenderChatMessage, OptionallyFromUserMessage { override val chat: PreviewChannelChat override val senderChat: PreviewChannelChat get() = chat diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/FromUserMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/FromUserMessage.kt index 4c568b1c50..f5db3a0433 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/FromUserMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/FromUserMessage.kt @@ -1,5 +1,8 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.abstracts.FromUser +import dev.inmo.tgbotapi.abstracts.OptionallyFromUser -interface FromUserMessage : FromUser, AccessibleMessage +interface OptionallyFromUserMessage : OptionallyFromUser, AccessibleMessage + +interface FromUserMessage : OptionallyFromUserMessage, FromUser diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramFakeUser.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramFakeUser.kt new file mode 100644 index 0000000000..9f3306ea06 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramFakeUser.kt @@ -0,0 +1,14 @@ +package dev.inmo.tgbotapi.utils + +import dev.inmo.tgbotapi.types.RawChatId +import dev.inmo.tgbotapi.types.UserId +import dev.inmo.tgbotapi.types.chat.CommonUser +import dev.inmo.tgbotapi.types.chat.User + +val TelegramFakeUser = CommonUser( + id = UserId(RawChatId.FakeUserId), + firstName = "Telegram" +) + +fun User.isFakeTelegramUser() = id == TelegramFakeUser.id && firstName == TelegramFakeUser.firstName + diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt index 3770eeb27c..b131db0432 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt @@ -17,6 +17,7 @@ fun List>.asMedia return when (sourceMessage) { is ChannelContentMessage -> ChannelContentMessageImpl( messageId = sourceMessage.messageId, + from = sourceMessage.from, chat = sourceMessage.chat, content = content, date = sourceMessage.date, 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 e1059824f9..3386b01d4a 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 @@ -11,6 +11,8 @@ package dev.inmo.tgbotapi.extensions.utils import dev.inmo.tgbotapi.abstracts.CommonSendInvoiceData import dev.inmo.tgbotapi.abstracts.FromUser +import dev.inmo.tgbotapi.abstracts.OptionallyFromUser +import dev.inmo.tgbotapi.abstracts.OptionallyWithUser import dev.inmo.tgbotapi.abstracts.WithUser import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton import dev.inmo.tgbotapi.requests.send.payments.CreateInvoiceLink @@ -296,6 +298,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.GroupContentMessage import dev.inmo.tgbotapi.types.message.abstracts.GroupEventMessage import dev.inmo.tgbotapi.types.message.abstracts.InaccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.OptionallyFromUserMessage import dev.inmo.tgbotapi.types.message.abstracts.PossiblyEditedMessage import dev.inmo.tgbotapi.types.message.abstracts.PossiblyForwardedMessage import dev.inmo.tgbotapi.types.message.abstracts.PossiblyMediaGroupMessage @@ -525,519 +528,573 @@ public inline fun CommonSendInvoiceData.ifInputInvoiceMessageContent(block: (InputInvoiceMessageContent) -> T): T? = inputInvoiceMessageContentOrNull() ?.let(block) -public inline fun WithUser.fromUserOrNull(): FromUser? = this as? +public inline fun OptionallyWithUser.optionallyFromUserOrNull(): OptionallyFromUser? = this as? + dev.inmo.tgbotapi.abstracts.OptionallyFromUser + +public inline fun OptionallyWithUser.optionallyFromUserOrThrow(): OptionallyFromUser = this as + dev.inmo.tgbotapi.abstracts.OptionallyFromUser + +public inline fun OptionallyWithUser.ifOptionallyFromUser(block: (OptionallyFromUser) -> T): T? + = optionallyFromUserOrNull() ?.let(block) + +public inline fun OptionallyWithUser.fromUserOrNull(): FromUser? = this as? dev.inmo.tgbotapi.abstracts.FromUser -public inline fun WithUser.fromUserOrThrow(): FromUser = this as +public inline fun OptionallyWithUser.fromUserOrThrow(): FromUser = this as dev.inmo.tgbotapi.abstracts.FromUser -public inline fun WithUser.ifFromUser(block: (FromUser) -> T): T? = fromUserOrNull() +public inline fun OptionallyWithUser.ifFromUser(block: (FromUser) -> T): T? = fromUserOrNull() ?.let(block) -public inline fun WithUser.chatInviteLinkOrNull(): ChatInviteLink? = this as? +public inline fun OptionallyWithUser.withUserOrNull(): WithUser? = this as? + dev.inmo.tgbotapi.abstracts.WithUser + +public inline fun OptionallyWithUser.withUserOrThrow(): WithUser = this as + dev.inmo.tgbotapi.abstracts.WithUser + +public inline fun OptionallyWithUser.ifWithUser(block: (WithUser) -> T): T? = withUserOrNull() + ?.let(block) + +public inline fun OptionallyWithUser.chatInviteLinkOrNull(): ChatInviteLink? = this as? dev.inmo.tgbotapi.types.ChatInviteLink -public inline fun WithUser.chatInviteLinkOrThrow(): ChatInviteLink = this as +public inline fun OptionallyWithUser.chatInviteLinkOrThrow(): ChatInviteLink = this as dev.inmo.tgbotapi.types.ChatInviteLink -public inline fun WithUser.ifChatInviteLink(block: (ChatInviteLink) -> T): T? = +public inline fun OptionallyWithUser.ifChatInviteLink(block: (ChatInviteLink) -> T): T? = chatInviteLinkOrNull() ?.let(block) -public inline fun WithUser.secondaryChatInviteLinkOrNull(): SecondaryChatInviteLink? = this as? - dev.inmo.tgbotapi.types.SecondaryChatInviteLink +public inline fun OptionallyWithUser.secondaryChatInviteLinkOrNull(): SecondaryChatInviteLink? = + this as? dev.inmo.tgbotapi.types.SecondaryChatInviteLink -public inline fun WithUser.secondaryChatInviteLinkOrThrow(): SecondaryChatInviteLink = this as - dev.inmo.tgbotapi.types.SecondaryChatInviteLink - -public inline fun WithUser.ifSecondaryChatInviteLink(block: (SecondaryChatInviteLink) -> T): T? - = secondaryChatInviteLinkOrNull() ?.let(block) - -public inline fun WithUser.primaryInviteLinkOrNull(): PrimaryInviteLink? = this as? - dev.inmo.tgbotapi.types.PrimaryInviteLink - -public inline fun WithUser.primaryInviteLinkOrThrow(): PrimaryInviteLink = this as - dev.inmo.tgbotapi.types.PrimaryInviteLink - -public inline fun WithUser.ifPrimaryInviteLink(block: (PrimaryInviteLink) -> T): T? = - primaryInviteLinkOrNull() ?.let(block) - -public inline fun WithUser.chatInviteLinkWithJoinRequestOrNull(): ChatInviteLinkWithJoinRequest? = - this as? dev.inmo.tgbotapi.types.ChatInviteLinkWithJoinRequest - -public inline fun WithUser.chatInviteLinkWithJoinRequestOrThrow(): ChatInviteLinkWithJoinRequest = - this as dev.inmo.tgbotapi.types.ChatInviteLinkWithJoinRequest +public inline fun OptionallyWithUser.secondaryChatInviteLinkOrThrow(): SecondaryChatInviteLink = + this as dev.inmo.tgbotapi.types.SecondaryChatInviteLink public inline fun - WithUser.ifChatInviteLinkWithJoinRequest(block: (ChatInviteLinkWithJoinRequest) -> T): T? = - chatInviteLinkWithJoinRequestOrNull() ?.let(block) + OptionallyWithUser.ifSecondaryChatInviteLink(block: (SecondaryChatInviteLink) -> T): T? = + secondaryChatInviteLinkOrNull() ?.let(block) -public inline fun WithUser.chatInviteLinkWithLimitedMembersOrNull(): +public inline fun OptionallyWithUser.primaryInviteLinkOrNull(): PrimaryInviteLink? = this as? + dev.inmo.tgbotapi.types.PrimaryInviteLink + +public inline fun OptionallyWithUser.primaryInviteLinkOrThrow(): PrimaryInviteLink = this as + dev.inmo.tgbotapi.types.PrimaryInviteLink + +public inline fun OptionallyWithUser.ifPrimaryInviteLink(block: (PrimaryInviteLink) -> T): T? = + primaryInviteLinkOrNull() ?.let(block) + +public inline fun OptionallyWithUser.chatInviteLinkWithJoinRequestOrNull(): + ChatInviteLinkWithJoinRequest? = this as? dev.inmo.tgbotapi.types.ChatInviteLinkWithJoinRequest + +public inline fun OptionallyWithUser.chatInviteLinkWithJoinRequestOrThrow(): + ChatInviteLinkWithJoinRequest = this as dev.inmo.tgbotapi.types.ChatInviteLinkWithJoinRequest + +public inline fun + OptionallyWithUser.ifChatInviteLinkWithJoinRequest(block: (ChatInviteLinkWithJoinRequest) -> T): + T? = chatInviteLinkWithJoinRequestOrNull() ?.let(block) + +public inline fun OptionallyWithUser.chatInviteLinkWithLimitedMembersOrNull(): ChatInviteLinkWithLimitedMembers? = this as? dev.inmo.tgbotapi.types.ChatInviteLinkWithLimitedMembers -public inline fun WithUser.chatInviteLinkWithLimitedMembersOrThrow(): +public inline fun OptionallyWithUser.chatInviteLinkWithLimitedMembersOrThrow(): ChatInviteLinkWithLimitedMembers = this as dev.inmo.tgbotapi.types.ChatInviteLinkWithLimitedMembers public inline fun - WithUser.ifChatInviteLinkWithLimitedMembers(block: (ChatInviteLinkWithLimitedMembers) -> T): T? - = chatInviteLinkWithLimitedMembersOrNull() ?.let(block) + OptionallyWithUser.ifChatInviteLinkWithLimitedMembers(block: (ChatInviteLinkWithLimitedMembers) -> T): + T? = chatInviteLinkWithLimitedMembersOrNull() ?.let(block) -public inline fun WithUser.chatInviteLinkUnlimitedOrNull(): ChatInviteLinkUnlimited? = this as? - dev.inmo.tgbotapi.types.ChatInviteLinkUnlimited +public inline fun OptionallyWithUser.chatInviteLinkUnlimitedOrNull(): ChatInviteLinkUnlimited? = + this as? dev.inmo.tgbotapi.types.ChatInviteLinkUnlimited -public inline fun WithUser.chatInviteLinkUnlimitedOrThrow(): ChatInviteLinkUnlimited = this as - dev.inmo.tgbotapi.types.ChatInviteLinkUnlimited +public inline fun OptionallyWithUser.chatInviteLinkUnlimitedOrThrow(): ChatInviteLinkUnlimited = + this as dev.inmo.tgbotapi.types.ChatInviteLinkUnlimited -public inline fun WithUser.ifChatInviteLinkUnlimited(block: (ChatInviteLinkUnlimited) -> T): T? - = chatInviteLinkUnlimitedOrNull() ?.let(block) +public inline fun + OptionallyWithUser.ifChatInviteLinkUnlimited(block: (ChatInviteLinkUnlimited) -> T): T? = + chatInviteLinkUnlimitedOrNull() ?.let(block) -public inline fun WithUser.baseChosenInlineResultOrNull(): BaseChosenInlineResult? = this as? - dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.BaseChosenInlineResult +public inline fun OptionallyWithUser.baseChosenInlineResultOrNull(): BaseChosenInlineResult? = this + as? dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.BaseChosenInlineResult -public inline fun WithUser.baseChosenInlineResultOrThrow(): BaseChosenInlineResult = this as - dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.BaseChosenInlineResult +public inline fun OptionallyWithUser.baseChosenInlineResultOrThrow(): BaseChosenInlineResult = this + as dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.BaseChosenInlineResult -public inline fun WithUser.ifBaseChosenInlineResult(block: (BaseChosenInlineResult) -> T): T? = +public inline fun + OptionallyWithUser.ifBaseChosenInlineResult(block: (BaseChosenInlineResult) -> T): T? = baseChosenInlineResultOrNull() ?.let(block) -public inline fun WithUser.chosenInlineResultOrNull(): ChosenInlineResult? = this as? +public inline fun OptionallyWithUser.chosenInlineResultOrNull(): ChosenInlineResult? = this as? dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.ChosenInlineResult -public inline fun WithUser.chosenInlineResultOrThrow(): ChosenInlineResult = this as +public inline fun OptionallyWithUser.chosenInlineResultOrThrow(): ChosenInlineResult = this as dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.ChosenInlineResult -public inline fun WithUser.ifChosenInlineResult(block: (ChosenInlineResult) -> T): T? = - chosenInlineResultOrNull() ?.let(block) +public inline fun OptionallyWithUser.ifChosenInlineResult(block: (ChosenInlineResult) -> T): T? + = chosenInlineResultOrNull() ?.let(block) -public inline fun WithUser.locationChosenInlineResultOrNull(): LocationChosenInlineResult? = this - as? dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.LocationChosenInlineResult +public inline fun OptionallyWithUser.locationChosenInlineResultOrNull(): LocationChosenInlineResult? + = this as? dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.LocationChosenInlineResult -public inline fun WithUser.locationChosenInlineResultOrThrow(): LocationChosenInlineResult = this as - dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.LocationChosenInlineResult +public inline fun OptionallyWithUser.locationChosenInlineResultOrThrow(): LocationChosenInlineResult + = this as dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.LocationChosenInlineResult public inline fun - WithUser.ifLocationChosenInlineResult(block: (LocationChosenInlineResult) -> T): T? = + OptionallyWithUser.ifLocationChosenInlineResult(block: (LocationChosenInlineResult) -> T): T? = locationChosenInlineResultOrNull() ?.let(block) -public inline fun WithUser.baseInlineQueryOrNull(): BaseInlineQuery? = this as? +public inline fun OptionallyWithUser.baseInlineQueryOrNull(): BaseInlineQuery? = this as? dev.inmo.tgbotapi.types.InlineQueries.query.BaseInlineQuery -public inline fun WithUser.baseInlineQueryOrThrow(): BaseInlineQuery = this as +public inline fun OptionallyWithUser.baseInlineQueryOrThrow(): BaseInlineQuery = this as dev.inmo.tgbotapi.types.InlineQueries.query.BaseInlineQuery -public inline fun WithUser.ifBaseInlineQuery(block: (BaseInlineQuery) -> T): T? = +public inline fun OptionallyWithUser.ifBaseInlineQuery(block: (BaseInlineQuery) -> T): T? = baseInlineQueryOrNull() ?.let(block) -public inline fun WithUser.inlineQueryOrNull(): InlineQuery? = this as? +public inline fun OptionallyWithUser.inlineQueryOrNull(): InlineQuery? = this as? dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery -public inline fun WithUser.inlineQueryOrThrow(): InlineQuery = this as +public inline fun OptionallyWithUser.inlineQueryOrThrow(): InlineQuery = this as dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery -public inline fun WithUser.ifInlineQuery(block: (InlineQuery) -> T): T? = inlineQueryOrNull() - ?.let(block) +public inline fun OptionallyWithUser.ifInlineQuery(block: (InlineQuery) -> T): T? = + inlineQueryOrNull() ?.let(block) -public inline fun WithUser.locationInlineQueryOrNull(): LocationInlineQuery? = this as? +public inline fun OptionallyWithUser.locationInlineQueryOrNull(): LocationInlineQuery? = this as? dev.inmo.tgbotapi.types.InlineQueries.query.LocationInlineQuery -public inline fun WithUser.locationInlineQueryOrThrow(): LocationInlineQuery = this as +public inline fun OptionallyWithUser.locationInlineQueryOrThrow(): LocationInlineQuery = this as dev.inmo.tgbotapi.types.InlineQueries.query.LocationInlineQuery -public inline fun WithUser.ifLocationInlineQuery(block: (LocationInlineQuery) -> T): T? = - locationInlineQueryOrNull() ?.let(block) +public inline fun OptionallyWithUser.ifLocationInlineQuery(block: (LocationInlineQuery) -> T): + T? = locationInlineQueryOrNull() ?.let(block) -public inline fun WithUser.chatJoinRequestOrNull(): ChatJoinRequest? = this as? +public inline fun OptionallyWithUser.chatJoinRequestOrNull(): ChatJoinRequest? = this as? dev.inmo.tgbotapi.types.chat.ChatJoinRequest -public inline fun WithUser.chatJoinRequestOrThrow(): ChatJoinRequest = this as +public inline fun OptionallyWithUser.chatJoinRequestOrThrow(): ChatJoinRequest = this as dev.inmo.tgbotapi.types.chat.ChatJoinRequest -public inline fun WithUser.ifChatJoinRequest(block: (ChatJoinRequest) -> T): T? = +public inline fun OptionallyWithUser.ifChatJoinRequest(block: (ChatJoinRequest) -> T): T? = chatJoinRequestOrNull() ?.let(block) -public inline fun WithUser.administratorChatMemberOrNull(): AdministratorChatMember? = this as? - dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember +public inline fun OptionallyWithUser.administratorChatMemberOrNull(): AdministratorChatMember? = + this as? dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember -public inline fun WithUser.administratorChatMemberOrThrow(): AdministratorChatMember = this as - dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember +public inline fun OptionallyWithUser.administratorChatMemberOrThrow(): AdministratorChatMember = + this as dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember -public inline fun WithUser.ifAdministratorChatMember(block: (AdministratorChatMember) -> T): T? - = administratorChatMemberOrNull() ?.let(block) +public inline fun + OptionallyWithUser.ifAdministratorChatMember(block: (AdministratorChatMember) -> T): T? = + administratorChatMemberOrNull() ?.let(block) -public inline fun WithUser.bannedChatMemberOrNull(): BannedChatMember? = this as? +public inline fun OptionallyWithUser.bannedChatMemberOrNull(): BannedChatMember? = this as? dev.inmo.tgbotapi.types.chat.member.BannedChatMember -public inline fun WithUser.bannedChatMemberOrThrow(): BannedChatMember = this as +public inline fun OptionallyWithUser.bannedChatMemberOrThrow(): BannedChatMember = this as dev.inmo.tgbotapi.types.chat.member.BannedChatMember -public inline fun WithUser.ifBannedChatMember(block: (BannedChatMember) -> T): T? = +public inline fun OptionallyWithUser.ifBannedChatMember(block: (BannedChatMember) -> T): T? = bannedChatMemberOrNull() ?.let(block) -public inline fun WithUser.chatMemberOrNull(): ChatMember? = this as? +public inline fun OptionallyWithUser.chatMemberOrNull(): ChatMember? = this as? dev.inmo.tgbotapi.types.chat.member.ChatMember -public inline fun WithUser.chatMemberOrThrow(): ChatMember = this as +public inline fun OptionallyWithUser.chatMemberOrThrow(): ChatMember = this as dev.inmo.tgbotapi.types.chat.member.ChatMember -public inline fun WithUser.ifChatMember(block: (ChatMember) -> T): T? = chatMemberOrNull() - ?.let(block) +public inline fun OptionallyWithUser.ifChatMember(block: (ChatMember) -> T): T? = + chatMemberOrNull() ?.let(block) -public inline fun WithUser.chatMemberUpdatedOrNull(): ChatMemberUpdated? = this as? +public inline fun OptionallyWithUser.chatMemberUpdatedOrNull(): ChatMemberUpdated? = this as? dev.inmo.tgbotapi.types.chat.member.ChatMemberUpdated -public inline fun WithUser.chatMemberUpdatedOrThrow(): ChatMemberUpdated = this as +public inline fun OptionallyWithUser.chatMemberUpdatedOrThrow(): ChatMemberUpdated = this as dev.inmo.tgbotapi.types.chat.member.ChatMemberUpdated -public inline fun WithUser.ifChatMemberUpdated(block: (ChatMemberUpdated) -> T): T? = +public inline fun OptionallyWithUser.ifChatMemberUpdated(block: (ChatMemberUpdated) -> T): T? = chatMemberUpdatedOrNull() ?.let(block) -public inline fun WithUser.kickedChatMemberOrNull(): KickedChatMember? = this as? +public inline fun OptionallyWithUser.kickedChatMemberOrNull(): KickedChatMember? = this as? dev.inmo.tgbotapi.types.chat.member.KickedChatMember -public inline fun WithUser.kickedChatMemberOrThrow(): KickedChatMember = this as +public inline fun OptionallyWithUser.kickedChatMemberOrThrow(): KickedChatMember = this as dev.inmo.tgbotapi.types.chat.member.KickedChatMember -public inline fun WithUser.ifKickedChatMember(block: (KickedChatMember) -> T): T? = +public inline fun OptionallyWithUser.ifKickedChatMember(block: (KickedChatMember) -> T): T? = kickedChatMemberOrNull() ?.let(block) -public inline fun WithUser.leftChatMemberOrNull(): LeftChatMember? = this as? +public inline fun OptionallyWithUser.leftChatMemberOrNull(): LeftChatMember? = this as? dev.inmo.tgbotapi.types.chat.member.LeftChatMember -public inline fun WithUser.leftChatMemberOrThrow(): LeftChatMember = this as +public inline fun OptionallyWithUser.leftChatMemberOrThrow(): LeftChatMember = this as dev.inmo.tgbotapi.types.chat.member.LeftChatMember -public inline fun WithUser.ifLeftChatMember(block: (LeftChatMember) -> T): T? = +public inline fun OptionallyWithUser.ifLeftChatMember(block: (LeftChatMember) -> T): T? = leftChatMemberOrNull() ?.let(block) -public inline fun WithUser.memberChatMemberOrNull(): MemberChatMember? = this as? +public inline fun OptionallyWithUser.memberChatMemberOrNull(): MemberChatMember? = this as? dev.inmo.tgbotapi.types.chat.member.MemberChatMember -public inline fun WithUser.memberChatMemberOrThrow(): MemberChatMember = this as +public inline fun OptionallyWithUser.memberChatMemberOrThrow(): MemberChatMember = this as dev.inmo.tgbotapi.types.chat.member.MemberChatMember -public inline fun WithUser.ifMemberChatMember(block: (MemberChatMember) -> T): T? = +public inline fun OptionallyWithUser.ifMemberChatMember(block: (MemberChatMember) -> T): T? = memberChatMemberOrNull() ?.let(block) -public inline fun WithUser.ownerChatMemberOrNull(): OwnerChatMember? = this as? +public inline fun OptionallyWithUser.ownerChatMemberOrNull(): OwnerChatMember? = this as? dev.inmo.tgbotapi.types.chat.member.OwnerChatMember -public inline fun WithUser.ownerChatMemberOrThrow(): OwnerChatMember = this as +public inline fun OptionallyWithUser.ownerChatMemberOrThrow(): OwnerChatMember = this as dev.inmo.tgbotapi.types.chat.member.OwnerChatMember -public inline fun WithUser.ifOwnerChatMember(block: (OwnerChatMember) -> T): T? = +public inline fun OptionallyWithUser.ifOwnerChatMember(block: (OwnerChatMember) -> T): T? = ownerChatMemberOrNull() ?.let(block) -public inline fun WithUser.restrictedChatMemberOrNull(): RestrictedChatMember? = this as? +public inline fun OptionallyWithUser.restrictedChatMemberOrNull(): RestrictedChatMember? = this as? dev.inmo.tgbotapi.types.chat.member.RestrictedChatMember -public inline fun WithUser.restrictedChatMemberOrThrow(): RestrictedChatMember = this as +public inline fun OptionallyWithUser.restrictedChatMemberOrThrow(): RestrictedChatMember = this as dev.inmo.tgbotapi.types.chat.member.RestrictedChatMember -public inline fun WithUser.ifRestrictedChatMember(block: (RestrictedChatMember) -> T): T? = - restrictedChatMemberOrNull() ?.let(block) +public inline fun OptionallyWithUser.ifRestrictedChatMember(block: (RestrictedChatMember) -> T): + T? = restrictedChatMemberOrNull() ?.let(block) -public inline fun WithUser.specialRightsChatMemberOrNull(): SpecialRightsChatMember? = this as? - dev.inmo.tgbotapi.types.chat.member.SpecialRightsChatMember +public inline fun OptionallyWithUser.specialRightsChatMemberOrNull(): SpecialRightsChatMember? = + this as? dev.inmo.tgbotapi.types.chat.member.SpecialRightsChatMember -public inline fun WithUser.specialRightsChatMemberOrThrow(): SpecialRightsChatMember = this as - dev.inmo.tgbotapi.types.chat.member.SpecialRightsChatMember +public inline fun OptionallyWithUser.specialRightsChatMemberOrThrow(): SpecialRightsChatMember = + this as dev.inmo.tgbotapi.types.chat.member.SpecialRightsChatMember -public inline fun WithUser.ifSpecialRightsChatMember(block: (SpecialRightsChatMember) -> T): T? - = specialRightsChatMemberOrNull() ?.let(block) +public inline fun + OptionallyWithUser.ifSpecialRightsChatMember(block: (SpecialRightsChatMember) -> T): T? = + specialRightsChatMemberOrNull() ?.let(block) -public inline fun WithUser.leftChatMemberEventOrNull(): LeftChatMemberEvent? = this as? +public inline fun OptionallyWithUser.leftChatMemberEventOrNull(): LeftChatMemberEvent? = this as? dev.inmo.tgbotapi.types.message.ChatEvents.LeftChatMemberEvent -public inline fun WithUser.leftChatMemberEventOrThrow(): LeftChatMemberEvent = this as +public inline fun OptionallyWithUser.leftChatMemberEventOrThrow(): LeftChatMemberEvent = this as dev.inmo.tgbotapi.types.message.ChatEvents.LeftChatMemberEvent -public inline fun WithUser.ifLeftChatMemberEvent(block: (LeftChatMemberEvent) -> T): T? = - leftChatMemberEventOrNull() ?.let(block) +public inline fun OptionallyWithUser.ifLeftChatMemberEvent(block: (LeftChatMemberEvent) -> T): + T? = leftChatMemberEventOrNull() ?.let(block) -public inline fun WithUser.commonGroupEventMessageOrNull(): CommonGroupEventMessage? = - this as? +public inline fun OptionallyWithUser.commonGroupEventMessageOrNull(): + CommonGroupEventMessage? = this as? dev.inmo.tgbotapi.types.message.CommonGroupEventMessage -public inline fun WithUser.commonGroupEventMessageOrThrow(): CommonGroupEventMessage = - this as +public inline fun OptionallyWithUser.commonGroupEventMessageOrThrow(): + CommonGroupEventMessage = this as dev.inmo.tgbotapi.types.message.CommonGroupEventMessage public inline fun - WithUser.ifCommonGroupEventMessage(block: (CommonGroupEventMessage) -> T): T? = - commonGroupEventMessageOrNull() ?.let(block) + OptionallyWithUser.ifCommonGroupEventMessage(block: (CommonGroupEventMessage) -> T): + T? = commonGroupEventMessageOrNull() ?.let(block) -public inline fun WithUser.commonSupergroupEventMessageOrNull(): +public inline fun OptionallyWithUser.commonSupergroupEventMessageOrNull(): CommonSupergroupEventMessage? = this as? dev.inmo.tgbotapi.types.message.CommonSupergroupEventMessage -public inline fun WithUser.commonSupergroupEventMessageOrThrow(): +public inline fun OptionallyWithUser.commonSupergroupEventMessageOrThrow(): CommonSupergroupEventMessage = this as dev.inmo.tgbotapi.types.message.CommonSupergroupEventMessage public inline fun - WithUser.ifCommonSupergroupEventMessage(block: (CommonSupergroupEventMessage) -> T): + OptionallyWithUser.ifCommonSupergroupEventMessage(block: (CommonSupergroupEventMessage) -> T): T? = commonSupergroupEventMessageOrNull() ?.let(block) -public inline fun WithUser.passportMessageOrNull(): PassportMessage? = this as? +public inline fun OptionallyWithUser.passportMessageOrNull(): PassportMessage? = this as? dev.inmo.tgbotapi.types.message.PassportMessage -public inline fun WithUser.passportMessageOrThrow(): PassportMessage = this as +public inline fun OptionallyWithUser.passportMessageOrThrow(): PassportMessage = this as dev.inmo.tgbotapi.types.message.PassportMessage -public inline fun WithUser.ifPassportMessage(block: (PassportMessage) -> T): T? = +public inline fun OptionallyWithUser.ifPassportMessage(block: (PassportMessage) -> T): T? = passportMessageOrNull() ?.let(block) -public inline fun WithUser.businessContentMessageOrNull(): BusinessContentMessage? = - this as? +public inline fun OptionallyWithUser.businessContentMessageOrNull(): + BusinessContentMessage? = this as? dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage -public inline fun WithUser.businessContentMessageOrThrow(): BusinessContentMessage = - this as +public inline fun OptionallyWithUser.businessContentMessageOrThrow(): + BusinessContentMessage = this as dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage public inline fun - WithUser.ifBusinessContentMessage(block: (BusinessContentMessage) -> T): T? = - businessContentMessageOrNull() ?.let(block) + OptionallyWithUser.ifBusinessContentMessage(block: (BusinessContentMessage) -> T): + T? = businessContentMessageOrNull() ?.let(block) -public inline fun WithUser.fromUserMessageOrNull(): FromUserMessage? = this as? +public inline fun OptionallyWithUser.channelContentMessageOrNull(): + ChannelContentMessage? = this as? + dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage + +public inline fun OptionallyWithUser.channelContentMessageOrThrow(): + ChannelContentMessage = this as + dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage + +public inline fun + OptionallyWithUser.ifChannelContentMessage(block: (ChannelContentMessage) -> T): + T? = channelContentMessageOrNull() ?.let(block) + +public inline fun OptionallyWithUser.optionallyFromUserMessageOrNull(): OptionallyFromUserMessage? = + this as? dev.inmo.tgbotapi.types.message.abstracts.OptionallyFromUserMessage + +public inline fun OptionallyWithUser.optionallyFromUserMessageOrThrow(): OptionallyFromUserMessage = + this as dev.inmo.tgbotapi.types.message.abstracts.OptionallyFromUserMessage + +public inline fun + OptionallyWithUser.ifOptionallyFromUserMessage(block: (OptionallyFromUserMessage) -> T): T? = + optionallyFromUserMessageOrNull() ?.let(block) + +public inline fun OptionallyWithUser.fromUserMessageOrNull(): FromUserMessage? = this as? dev.inmo.tgbotapi.types.message.abstracts.FromUserMessage -public inline fun WithUser.fromUserMessageOrThrow(): FromUserMessage = this as +public inline fun OptionallyWithUser.fromUserMessageOrThrow(): FromUserMessage = this as dev.inmo.tgbotapi.types.message.abstracts.FromUserMessage -public inline fun WithUser.ifFromUserMessage(block: (FromUserMessage) -> T): T? = +public inline fun OptionallyWithUser.ifFromUserMessage(block: (FromUserMessage) -> T): T? = fromUserMessageOrNull() ?.let(block) -public inline fun WithUser.groupEventMessageOrNull(): GroupEventMessage? = this as? +public inline fun OptionallyWithUser.groupEventMessageOrNull(): GroupEventMessage? = + this as? dev.inmo.tgbotapi.types.message.abstracts.GroupEventMessage -public inline fun WithUser.groupEventMessageOrThrow(): GroupEventMessage = this as +public inline fun OptionallyWithUser.groupEventMessageOrThrow(): GroupEventMessage = + this as dev.inmo.tgbotapi.types.message.abstracts.GroupEventMessage -public inline fun WithUser.ifGroupEventMessage(block: (GroupEventMessage) -> T): T? - = groupEventMessageOrNull() ?.let(block) +public inline fun + OptionallyWithUser.ifGroupEventMessage(block: (GroupEventMessage) -> T): T? = + groupEventMessageOrNull() ?.let(block) -public inline fun WithUser.commonGroupContentMessageOrNull(): +public inline fun OptionallyWithUser.commonGroupContentMessageOrNull(): CommonGroupContentMessage? = this as? dev.inmo.tgbotapi.types.message.abstracts.CommonGroupContentMessage -public inline fun WithUser.commonGroupContentMessageOrThrow(): +public inline fun OptionallyWithUser.commonGroupContentMessageOrThrow(): CommonGroupContentMessage = this as dev.inmo.tgbotapi.types.message.abstracts.CommonGroupContentMessage public inline fun - WithUser.ifCommonGroupContentMessage(block: (CommonGroupContentMessage) -> T): + OptionallyWithUser.ifCommonGroupContentMessage(block: (CommonGroupContentMessage) -> T): T? = commonGroupContentMessageOrNull() ?.let(block) -public inline fun WithUser.commonForumContentMessageOrNull(): +public inline fun OptionallyWithUser.commonForumContentMessageOrNull(): CommonForumContentMessage? = this as? dev.inmo.tgbotapi.types.message.abstracts.CommonForumContentMessage -public inline fun WithUser.commonForumContentMessageOrThrow(): +public inline fun OptionallyWithUser.commonForumContentMessageOrThrow(): CommonForumContentMessage = this as dev.inmo.tgbotapi.types.message.abstracts.CommonForumContentMessage public inline fun - WithUser.ifCommonForumContentMessage(block: (CommonForumContentMessage) -> T): + OptionallyWithUser.ifCommonForumContentMessage(block: (CommonForumContentMessage) -> T): T? = commonForumContentMessageOrNull() ?.let(block) -public inline fun WithUser.privateContentMessageOrNull(): PrivateContentMessage? = - this as? +public inline fun OptionallyWithUser.privateContentMessageOrNull(): + PrivateContentMessage? = this as? dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage -public inline fun WithUser.privateContentMessageOrThrow(): PrivateContentMessage = - this as +public inline fun OptionallyWithUser.privateContentMessageOrThrow(): + PrivateContentMessage = this as dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage public inline fun - WithUser.ifPrivateContentMessage(block: (PrivateContentMessage) -> T): T? = - privateContentMessageOrNull() ?.let(block) + OptionallyWithUser.ifPrivateContentMessage(block: (PrivateContentMessage) -> T): + T? = privateContentMessageOrNull() ?.let(block) -public inline fun WithUser.supergroupEventMessageOrNull(): SupergroupEventMessage? - = this as? +public inline fun OptionallyWithUser.supergroupEventMessageOrNull(): + SupergroupEventMessage? = this as? dev.inmo.tgbotapi.types.message.abstracts.SupergroupEventMessage -public inline fun WithUser.supergroupEventMessageOrThrow(): SupergroupEventMessage - = this as +public inline fun OptionallyWithUser.supergroupEventMessageOrThrow(): + SupergroupEventMessage = this as dev.inmo.tgbotapi.types.message.abstracts.SupergroupEventMessage public inline fun - WithUser.ifSupergroupEventMessage(block: (SupergroupEventMessage) -> T): T? = - supergroupEventMessageOrNull() ?.let(block) + OptionallyWithUser.ifSupergroupEventMessage(block: (SupergroupEventMessage) -> T): + T? = supergroupEventMessageOrNull() ?.let(block) -public inline fun WithUser.preCheckoutQueryOrNull(): PreCheckoutQuery? = this as? +public inline fun OptionallyWithUser.preCheckoutQueryOrNull(): PreCheckoutQuery? = this as? dev.inmo.tgbotapi.types.payments.PreCheckoutQuery -public inline fun WithUser.preCheckoutQueryOrThrow(): PreCheckoutQuery = this as +public inline fun OptionallyWithUser.preCheckoutQueryOrThrow(): PreCheckoutQuery = this as dev.inmo.tgbotapi.types.payments.PreCheckoutQuery -public inline fun WithUser.ifPreCheckoutQuery(block: (PreCheckoutQuery) -> T): T? = +public inline fun OptionallyWithUser.ifPreCheckoutQuery(block: (PreCheckoutQuery) -> T): T? = preCheckoutQueryOrNull() ?.let(block) -public inline fun WithUser.shippingQueryOrNull(): ShippingQuery? = this as? +public inline fun OptionallyWithUser.shippingQueryOrNull(): ShippingQuery? = this as? dev.inmo.tgbotapi.types.payments.ShippingQuery -public inline fun WithUser.shippingQueryOrThrow(): ShippingQuery = this as +public inline fun OptionallyWithUser.shippingQueryOrThrow(): ShippingQuery = this as dev.inmo.tgbotapi.types.payments.ShippingQuery -public inline fun WithUser.ifShippingQuery(block: (ShippingQuery) -> T): T? = +public inline fun OptionallyWithUser.ifShippingQuery(block: (ShippingQuery) -> T): T? = shippingQueryOrNull() ?.let(block) -public inline fun WithUser.pollAnswerOrNull(): PollAnswer? = this as? +public inline fun OptionallyWithUser.pollAnswerOrNull(): PollAnswer? = this as? dev.inmo.tgbotapi.types.polls.PollAnswer -public inline fun WithUser.pollAnswerOrThrow(): PollAnswer = this as +public inline fun OptionallyWithUser.pollAnswerOrThrow(): PollAnswer = this as dev.inmo.tgbotapi.types.polls.PollAnswer -public inline fun WithUser.ifPollAnswer(block: (PollAnswer) -> T): T? = pollAnswerOrNull() - ?.let(block) +public inline fun OptionallyWithUser.ifPollAnswer(block: (PollAnswer) -> T): T? = + pollAnswerOrNull() ?.let(block) -public inline fun WithUser.abstractMessageCallbackQueryOrNull(): AbstractMessageCallbackQuery? = - this as? dev.inmo.tgbotapi.types.queries.callback.AbstractMessageCallbackQuery +public inline fun OptionallyWithUser.abstractMessageCallbackQueryOrNull(): + AbstractMessageCallbackQuery? = this as? + dev.inmo.tgbotapi.types.queries.callback.AbstractMessageCallbackQuery -public inline fun WithUser.abstractMessageCallbackQueryOrThrow(): AbstractMessageCallbackQuery = - this as dev.inmo.tgbotapi.types.queries.callback.AbstractMessageCallbackQuery +public inline fun OptionallyWithUser.abstractMessageCallbackQueryOrThrow(): + AbstractMessageCallbackQuery = this as + dev.inmo.tgbotapi.types.queries.callback.AbstractMessageCallbackQuery public inline fun - WithUser.ifAbstractMessageCallbackQuery(block: (AbstractMessageCallbackQuery) -> T): T? = - abstractMessageCallbackQueryOrNull() ?.let(block) + OptionallyWithUser.ifAbstractMessageCallbackQuery(block: (AbstractMessageCallbackQuery) -> T): + T? = abstractMessageCallbackQueryOrNull() ?.let(block) -public inline fun WithUser.callbackQueryOrNull(): CallbackQuery? = this as? +public inline fun OptionallyWithUser.callbackQueryOrNull(): CallbackQuery? = this as? dev.inmo.tgbotapi.types.queries.callback.CallbackQuery -public inline fun WithUser.callbackQueryOrThrow(): CallbackQuery = this as +public inline fun OptionallyWithUser.callbackQueryOrThrow(): CallbackQuery = this as dev.inmo.tgbotapi.types.queries.callback.CallbackQuery -public inline fun WithUser.ifCallbackQuery(block: (CallbackQuery) -> T): T? = +public inline fun OptionallyWithUser.ifCallbackQuery(block: (CallbackQuery) -> T): T? = callbackQueryOrNull() ?.let(block) -public inline fun WithUser.unknownCallbackQueryTypeOrNull(): UnknownCallbackQueryType? = this as? - dev.inmo.tgbotapi.types.queries.callback.UnknownCallbackQueryType +public inline fun OptionallyWithUser.unknownCallbackQueryTypeOrNull(): UnknownCallbackQueryType? = + this as? dev.inmo.tgbotapi.types.queries.callback.UnknownCallbackQueryType -public inline fun WithUser.unknownCallbackQueryTypeOrThrow(): UnknownCallbackQueryType = this as - dev.inmo.tgbotapi.types.queries.callback.UnknownCallbackQueryType - -public inline fun WithUser.ifUnknownCallbackQueryType(block: (UnknownCallbackQueryType) -> T): - T? = unknownCallbackQueryTypeOrNull() ?.let(block) - -public inline fun WithUser.dataCallbackQueryOrNull(): DataCallbackQuery? = this as? - dev.inmo.tgbotapi.types.queries.callback.DataCallbackQuery - -public inline fun WithUser.dataCallbackQueryOrThrow(): DataCallbackQuery = this as - dev.inmo.tgbotapi.types.queries.callback.DataCallbackQuery - -public inline fun WithUser.ifDataCallbackQuery(block: (DataCallbackQuery) -> T): T? = - dataCallbackQueryOrNull() ?.let(block) - -public inline fun WithUser.gameShortNameCallbackQueryOrNull(): GameShortNameCallbackQuery? = this - as? dev.inmo.tgbotapi.types.queries.callback.GameShortNameCallbackQuery - -public inline fun WithUser.gameShortNameCallbackQueryOrThrow(): GameShortNameCallbackQuery = this as - dev.inmo.tgbotapi.types.queries.callback.GameShortNameCallbackQuery +public inline fun OptionallyWithUser.unknownCallbackQueryTypeOrThrow(): UnknownCallbackQueryType = + this as dev.inmo.tgbotapi.types.queries.callback.UnknownCallbackQueryType public inline fun - WithUser.ifGameShortNameCallbackQuery(block: (GameShortNameCallbackQuery) -> T): T? = + OptionallyWithUser.ifUnknownCallbackQueryType(block: (UnknownCallbackQueryType) -> T): T? = + unknownCallbackQueryTypeOrNull() ?.let(block) + +public inline fun OptionallyWithUser.dataCallbackQueryOrNull(): DataCallbackQuery? = this as? + dev.inmo.tgbotapi.types.queries.callback.DataCallbackQuery + +public inline fun OptionallyWithUser.dataCallbackQueryOrThrow(): DataCallbackQuery = this as + dev.inmo.tgbotapi.types.queries.callback.DataCallbackQuery + +public inline fun OptionallyWithUser.ifDataCallbackQuery(block: (DataCallbackQuery) -> T): T? = + dataCallbackQueryOrNull() ?.let(block) + +public inline fun OptionallyWithUser.gameShortNameCallbackQueryOrNull(): GameShortNameCallbackQuery? + = this as? dev.inmo.tgbotapi.types.queries.callback.GameShortNameCallbackQuery + +public inline fun OptionallyWithUser.gameShortNameCallbackQueryOrThrow(): GameShortNameCallbackQuery + = this as dev.inmo.tgbotapi.types.queries.callback.GameShortNameCallbackQuery + +public inline fun + OptionallyWithUser.ifGameShortNameCallbackQuery(block: (GameShortNameCallbackQuery) -> T): T? = gameShortNameCallbackQueryOrNull() ?.let(block) -public inline fun WithUser.inaccessibleMessageCallbackQueryOrNull(): +public inline fun OptionallyWithUser.inaccessibleMessageCallbackQueryOrNull(): InaccessibleMessageCallbackQuery? = this as? dev.inmo.tgbotapi.types.queries.callback.InaccessibleMessageCallbackQuery -public inline fun WithUser.inaccessibleMessageCallbackQueryOrThrow(): +public inline fun OptionallyWithUser.inaccessibleMessageCallbackQueryOrThrow(): InaccessibleMessageCallbackQuery = this as dev.inmo.tgbotapi.types.queries.callback.InaccessibleMessageCallbackQuery public inline fun - WithUser.ifInaccessibleMessageCallbackQuery(block: (InaccessibleMessageCallbackQuery) -> T): T? - = inaccessibleMessageCallbackQueryOrNull() ?.let(block) + OptionallyWithUser.ifInaccessibleMessageCallbackQuery(block: (InaccessibleMessageCallbackQuery) -> T): + T? = inaccessibleMessageCallbackQueryOrNull() ?.let(block) -public inline fun WithUser.inaccessibleMessageDataCallbackQueryOrNull(): +public inline fun OptionallyWithUser.inaccessibleMessageDataCallbackQueryOrNull(): InaccessibleMessageDataCallbackQuery? = this as? dev.inmo.tgbotapi.types.queries.callback.InaccessibleMessageDataCallbackQuery -public inline fun WithUser.inaccessibleMessageDataCallbackQueryOrThrow(): +public inline fun OptionallyWithUser.inaccessibleMessageDataCallbackQueryOrThrow(): InaccessibleMessageDataCallbackQuery = this as dev.inmo.tgbotapi.types.queries.callback.InaccessibleMessageDataCallbackQuery public inline fun - WithUser.ifInaccessibleMessageDataCallbackQuery(block: (InaccessibleMessageDataCallbackQuery) -> T): + OptionallyWithUser.ifInaccessibleMessageDataCallbackQuery(block: (InaccessibleMessageDataCallbackQuery) -> T): T? = inaccessibleMessageDataCallbackQueryOrNull() ?.let(block) -public inline fun WithUser.inaccessibleMessageGameShortNameCallbackQueryOrNull(): +public inline fun OptionallyWithUser.inaccessibleMessageGameShortNameCallbackQueryOrNull(): InaccessibleMessageGameShortNameCallbackQuery? = this as? dev.inmo.tgbotapi.types.queries.callback.InaccessibleMessageGameShortNameCallbackQuery -public inline fun WithUser.inaccessibleMessageGameShortNameCallbackQueryOrThrow(): +public inline fun OptionallyWithUser.inaccessibleMessageGameShortNameCallbackQueryOrThrow(): InaccessibleMessageGameShortNameCallbackQuery = this as dev.inmo.tgbotapi.types.queries.callback.InaccessibleMessageGameShortNameCallbackQuery public inline fun - WithUser.ifInaccessibleMessageGameShortNameCallbackQuery(block: (InaccessibleMessageGameShortNameCallbackQuery) -> T): + OptionallyWithUser.ifInaccessibleMessageGameShortNameCallbackQuery(block: (InaccessibleMessageGameShortNameCallbackQuery) -> T): T? = inaccessibleMessageGameShortNameCallbackQueryOrNull() ?.let(block) -public inline fun WithUser.inlineMessageIdCallbackQueryOrNull(): InlineMessageIdCallbackQuery? = - this as? dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdCallbackQuery +public inline fun OptionallyWithUser.inlineMessageIdCallbackQueryOrNull(): + InlineMessageIdCallbackQuery? = this as? + dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdCallbackQuery -public inline fun WithUser.inlineMessageIdCallbackQueryOrThrow(): InlineMessageIdCallbackQuery = - this as dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdCallbackQuery +public inline fun OptionallyWithUser.inlineMessageIdCallbackQueryOrThrow(): + InlineMessageIdCallbackQuery = this as + dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdCallbackQuery public inline fun - WithUser.ifInlineMessageIdCallbackQuery(block: (InlineMessageIdCallbackQuery) -> T): T? = - inlineMessageIdCallbackQueryOrNull() ?.let(block) + OptionallyWithUser.ifInlineMessageIdCallbackQuery(block: (InlineMessageIdCallbackQuery) -> T): + T? = inlineMessageIdCallbackQueryOrNull() ?.let(block) -public inline fun WithUser.inlineMessageIdDataCallbackQueryOrNull(): +public inline fun OptionallyWithUser.inlineMessageIdDataCallbackQueryOrNull(): InlineMessageIdDataCallbackQuery? = this as? dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdDataCallbackQuery -public inline fun WithUser.inlineMessageIdDataCallbackQueryOrThrow(): +public inline fun OptionallyWithUser.inlineMessageIdDataCallbackQueryOrThrow(): InlineMessageIdDataCallbackQuery = this as dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdDataCallbackQuery public inline fun - WithUser.ifInlineMessageIdDataCallbackQuery(block: (InlineMessageIdDataCallbackQuery) -> T): T? - = inlineMessageIdDataCallbackQueryOrNull() ?.let(block) + OptionallyWithUser.ifInlineMessageIdDataCallbackQuery(block: (InlineMessageIdDataCallbackQuery) -> T): + T? = inlineMessageIdDataCallbackQueryOrNull() ?.let(block) -public inline fun WithUser.inlineMessageIdGameShortNameCallbackQueryOrNull(): +public inline fun OptionallyWithUser.inlineMessageIdGameShortNameCallbackQueryOrNull(): InlineMessageIdGameShortNameCallbackQuery? = this as? dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdGameShortNameCallbackQuery -public inline fun WithUser.inlineMessageIdGameShortNameCallbackQueryOrThrow(): +public inline fun OptionallyWithUser.inlineMessageIdGameShortNameCallbackQueryOrThrow(): InlineMessageIdGameShortNameCallbackQuery = this as dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdGameShortNameCallbackQuery public inline fun - WithUser.ifInlineMessageIdGameShortNameCallbackQuery(block: (InlineMessageIdGameShortNameCallbackQuery) -> T): + OptionallyWithUser.ifInlineMessageIdGameShortNameCallbackQuery(block: (InlineMessageIdGameShortNameCallbackQuery) -> T): T? = inlineMessageIdGameShortNameCallbackQueryOrNull() ?.let(block) -public inline fun WithUser.messageCallbackQueryOrNull(): MessageCallbackQuery? = this as? +public inline fun OptionallyWithUser.messageCallbackQueryOrNull(): MessageCallbackQuery? = this as? dev.inmo.tgbotapi.types.queries.callback.MessageCallbackQuery -public inline fun WithUser.messageCallbackQueryOrThrow(): MessageCallbackQuery = this as +public inline fun OptionallyWithUser.messageCallbackQueryOrThrow(): MessageCallbackQuery = this as dev.inmo.tgbotapi.types.queries.callback.MessageCallbackQuery -public inline fun WithUser.ifMessageCallbackQuery(block: (MessageCallbackQuery) -> T): T? = - messageCallbackQueryOrNull() ?.let(block) +public inline fun OptionallyWithUser.ifMessageCallbackQuery(block: (MessageCallbackQuery) -> T): + T? = messageCallbackQueryOrNull() ?.let(block) -public inline fun WithUser.messageDataCallbackQueryOrNull(): MessageDataCallbackQuery? = this as? - dev.inmo.tgbotapi.types.queries.callback.MessageDataCallbackQuery +public inline fun OptionallyWithUser.messageDataCallbackQueryOrNull(): MessageDataCallbackQuery? = + this as? dev.inmo.tgbotapi.types.queries.callback.MessageDataCallbackQuery -public inline fun WithUser.messageDataCallbackQueryOrThrow(): MessageDataCallbackQuery = this as - dev.inmo.tgbotapi.types.queries.callback.MessageDataCallbackQuery +public inline fun OptionallyWithUser.messageDataCallbackQueryOrThrow(): MessageDataCallbackQuery = + this as dev.inmo.tgbotapi.types.queries.callback.MessageDataCallbackQuery -public inline fun WithUser.ifMessageDataCallbackQuery(block: (MessageDataCallbackQuery) -> T): - T? = messageDataCallbackQueryOrNull() ?.let(block) +public inline fun + OptionallyWithUser.ifMessageDataCallbackQuery(block: (MessageDataCallbackQuery) -> T): T? = + messageDataCallbackQueryOrNull() ?.let(block) -public inline fun WithUser.messageGameShortNameCallbackQueryOrNull(): +public inline fun OptionallyWithUser.messageGameShortNameCallbackQueryOrNull(): MessageGameShortNameCallbackQuery? = this as? dev.inmo.tgbotapi.types.queries.callback.MessageGameShortNameCallbackQuery -public inline fun WithUser.messageGameShortNameCallbackQueryOrThrow(): +public inline fun OptionallyWithUser.messageGameShortNameCallbackQueryOrThrow(): MessageGameShortNameCallbackQuery = this as dev.inmo.tgbotapi.types.queries.callback.MessageGameShortNameCallbackQuery public inline fun - WithUser.ifMessageGameShortNameCallbackQuery(block: (MessageGameShortNameCallbackQuery) -> T): + OptionallyWithUser.ifMessageGameShortNameCallbackQuery(block: (MessageGameShortNameCallbackQuery) -> T): T? = messageGameShortNameCallbackQueryOrNull() ?.let(block) public inline fun InlineQueryResultsButton.startOrNull(): InlineQueryResultsButton.Start? = this as? @@ -3701,6 +3758,15 @@ public inline fun Message.contentMessageOrThrow(): ContentMessage Message.ifContentMessage(block: (ContentMessage) -> T): T? = contentMessageOrNull() ?.let(block) +public inline fun Message.optionallyFromUserMessageOrNull(): OptionallyFromUserMessage? = this as? + dev.inmo.tgbotapi.types.message.abstracts.OptionallyFromUserMessage + +public inline fun Message.optionallyFromUserMessageOrThrow(): OptionallyFromUserMessage = this as + dev.inmo.tgbotapi.types.message.abstracts.OptionallyFromUserMessage + +public inline fun Message.ifOptionallyFromUserMessage(block: (OptionallyFromUserMessage) -> T): + T? = optionallyFromUserMessageOrNull() ?.let(block) + public inline fun Message.fromUserMessageOrNull(): FromUserMessage? = this as? dev.inmo.tgbotapi.types.message.abstracts.FromUserMessage diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNewAny.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNewAny.kt index c782f769ca..1092af4617 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNewAny.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNewAny.kt @@ -3,10 +3,21 @@ package dev.inmo.tgbotapi.extensions.utils import dev.inmo.tgbotapi.abstracts.FromUser +import dev.inmo.tgbotapi.abstracts.OptionallyFromUser +import dev.inmo.tgbotapi.abstracts.OptionallyWithUser import dev.inmo.tgbotapi.abstracts.WithUser import dev.inmo.tgbotapi.types.abstracts.WithOptionalLanguageCode import dev.inmo.tgbotapi.utils.PreviewFeature +@PreviewFeature +inline fun Any.ifOptionallyFromUser(block: (OptionallyFromUser) -> T) = optionallyFromUserOrNull()?.let(block) + +@PreviewFeature +inline fun Any.optionallyFromUserOrNull(): OptionallyFromUser? = this as? OptionallyFromUser + +@PreviewFeature +inline fun Any.optionallyFromUserOrThrow(): OptionallyFromUser = this as OptionallyFromUser + @PreviewFeature inline fun Any.ifFromUser(block: (FromUser) -> T) = fromUserOrNull()?.let(block) @@ -16,6 +27,15 @@ inline fun Any.fromUserOrNull(): FromUser? = this as? FromUser @PreviewFeature inline fun Any.fromUserOrThrow(): FromUser = this as FromUser +@PreviewFeature +inline fun Any.ifOptionallyWithUser(block: (OptionallyWithUser) -> T) = optionallyWithUserOrNull()?.let(block) + +@PreviewFeature +inline fun Any.optionallyWithUserOrNull(): OptionallyWithUser? = this as? OptionallyWithUser + +@PreviewFeature +inline fun Any.optionallyWithUserOrThrow(): OptionallyWithUser = this as OptionallyWithUser + @PreviewFeature inline fun Any.ifWithUser(block: (WithUser) -> T) = withUserOrNull()?.let(block) 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 eff8b72812..5aaf7383a5 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 @@ -23,7 +23,7 @@ import dev.inmo.tgbotapi.utils.RiskFeature @RiskFeature(RawFieldsUsageWarning) inline val Message.from: User? - get() = asFromUser() ?.from + get() = optionallyFromUserMessageOrNull() ?.from @RiskFeature(RawFieldsUsageWarning) inline val Message.sender_chat: PublicChat? get() = asFromChannelGroupContentMessage() ?.senderChat