From b5f4219635073eac5b7e4babaf47907f02c3e89b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 7 Jan 2024 15:52:49 +0600 Subject: [PATCH] fixes in inaccessible message support --- .../tgbotapi/extensions/api/DeleteMessage.kt | 9 +- .../tgbotapi/extensions/api/DeleteMessages.kt | 8 +- .../tgbotapi/extensions/api/ForwardMessage.kt | 6 +- .../extensions/api/ForwardMessages.kt | 6 +- .../extensions/api/LiveLocationProvider.kt | 21 +- .../inmo/tgbotapi/extensions/api/StopPoll.kt | 6 +- .../api/chat/modify/PinChatMessage.kt | 4 +- .../api/chat/modify/UnpinChatMessage.kt | 4 +- .../tgbotapi/extensions/api/edit/Edits.kt | 4 +- .../edit/caption/EditChatMessageCaption.kt | 4 +- .../EditChatMessageReplyMarkup.kt | 4 +- .../api/edit/text/EditChatMessageText.kt | 8 +- .../extensions/api/send/CopyMessage.kt | 10 +- .../extensions/api/send/CopyMessages.kt | 4 +- .../tgbotapi/extensions/api/send/Replies.kt | 143 +++++++------- .../api/send/RepliesWithChatsAndMessages.kt | 4 +- .../api/send/SetMessageReactions.kt | 10 +- .../filters/MessageFilterByChat.kt | 10 +- .../MessageFilterExcludingMediaGroups.kt | 4 +- .../filters/MessageFilterForums.kt | 2 +- .../MessageMarkerFactories.kt | 8 +- .../dev/inmo/tgbotapi/requests/GetUpdates.kt | 3 +- .../tgbotapi/types/chat/ExtendedAbstracts.kt | 2 +- .../types/giveaway/GiveawayPrivateResults.kt | 6 +- .../message/ChannelContentMessageImpl.kt | 3 +- .../types/message/ChatEvents/PinnedMessage.kt | 1 + .../tgbotapi/types/message/GroupMessages.kt | 14 +- .../tgbotapi/types/message/PassportMessage.kt | 5 +- .../message/PrivateContentMessageImpl.kt | 4 +- .../inmo/tgbotapi/types/message/RawMessage.kt | 2 +- .../message/abstracts/ChatEventMessage.kt | 2 +- .../types/message/abstracts/CommonMessage.kt | 2 +- .../types/message/abstracts/ContentMessage.kt | 2 +- .../message/abstracts/FromUserMessage.kt | 2 +- .../types/message/abstracts/Message.kt | 9 +- .../abstracts/PossiblyEditedMessage.kt | 2 +- .../abstracts/PossiblyForwardedMessage.kt | 2 +- .../abstracts/PossiblyPaymentMessage.kt | 2 +- .../message/abstracts/PossiblyReplyMessage.kt | 2 +- .../message/abstracts/PossiblyTopicMessage.kt | 2 +- .../types/message/abstracts/SignedMessage.kt | 2 +- .../types/message/content/Abstracts.kt | 2 +- .../message/content/MediaGroupContent.kt | 1 - .../types/message/content/StoryContent.kt | 2 - .../callback/AbstractMessageCallbackQuery.kt | 9 + .../InaccessibleMessageCallbackQuery.kt | 7 + .../InaccessibleMessageDataCallbackQuery.kt | 16 ++ ...ssibleMessageGameShortNameCallbackQuery.kt | 16 ++ .../queries/callback/MessageCallbackQuery.kt | 4 +- .../queries/callback/RawCallbackQuery.kt | 24 ++- .../types/update/ChannelPostUpdate.kt | 6 +- .../tgbotapi/types/update/MessageUpdate.kt | 6 +- .../inmo/tgbotapi/types/update/RawUpdate.kt | 4 +- .../update/abstracts/BaseMessageUpdate.kt | 4 +- .../update/abstracts/BaseSentMessageUpdate.kt | 4 +- .../utils/extensions/OptionalThreadId.kt | 4 +- .../tgbotapi/extensions/utils/ClassCasts.kt | 186 +++++++++--------- .../extensions/utils/ClassCastsNew.kt | 70 +++++++ .../extensions/utils/extensions/Same.kt | 40 ++-- .../utils/extensions/UpdateChatRetriever.kt | 3 +- .../utils/extensions/raw/Message.kt | 111 +++++------ .../utils/formatting/LinksFormatting.kt | 6 +- .../utils/updates/MessageFilters.kt | 10 +- 63 files changed, 493 insertions(+), 390 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/AbstractMessageCallbackQuery.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/InaccessibleMessageCallbackQuery.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/InaccessibleMessageDataCallbackQuery.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/InaccessibleMessageGameShortNameCallbackQuery.kt diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DeleteMessage.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DeleteMessage.kt index 90c7f00b35..ab2c648790 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DeleteMessage.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DeleteMessage.kt @@ -6,9 +6,8 @@ import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.content.MediaGroupCollectionContent -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent suspend fun TelegramBot.deleteMessage( chatId: ChatIdentifier, @@ -23,7 +22,7 @@ suspend fun TelegramBot.deleteMessage( ) = deleteMessage(chat.id, messageId) suspend fun TelegramBot.deleteMessage( - message: Message + message: AccessibleMessage ): Boolean { val mediaGroupContent = ((message as? ContentMessage<*>) ?.content as? MediaGroupCollectionContent<*>) if (mediaGroupContent == null) { @@ -46,9 +45,9 @@ suspend fun TelegramBot.delete( ) = deleteMessage(chat, messageId) suspend fun TelegramBot.delete( - message: Message + message: AccessibleMessage ) = deleteMessage(message) -suspend fun Message.delete( +suspend fun AccessibleMessage.delete( requestsExecutor: TelegramBot ) = requestsExecutor.deleteMessage(this) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DeleteMessages.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DeleteMessages.kt index 406af2bae1..c44d86a107 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DeleteMessages.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DeleteMessages.kt @@ -1,11 +1,9 @@ package dev.inmo.tgbotapi.extensions.api import dev.inmo.tgbotapi.bot.TelegramBot -import dev.inmo.tgbotapi.requests.DeleteMessage import dev.inmo.tgbotapi.requests.DeleteMessages -import dev.inmo.tgbotapi.requests.ForwardMessages import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage suspend fun TelegramBot.deleteMessages( chatId: ChatIdentifier, @@ -37,7 +35,7 @@ suspend fun TelegramBot.deleteMessages( ) suspend fun TelegramBot.deleteMessages( - messages: List + messages: List ) = messages.groupBy { it.chat }.map { (chat, messages) -> deleteMessages( chatId = chat.id, @@ -63,5 +61,5 @@ suspend fun TelegramBot.delete( ) = deleteMessages(chatId = chatId, messageIds = (listOf(firstMessageId, secondMessageId) + messageIds.toList())) suspend fun TelegramBot.delete( - messages: List + messages: List ) = deleteMessages(messages) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/ForwardMessage.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/ForwardMessage.kt index 4893eb13c8..8bdde19ab8 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/ForwardMessage.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/ForwardMessage.kt @@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.MessageThreadId import dev.inmo.tgbotapi.types.chat.Chat -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.threadId suspend fun TelegramBot.forwardMessage( @@ -49,7 +49,7 @@ suspend fun TelegramBot.forwardMessage( suspend fun TelegramBot.forwardMessage( toChatId: ChatIdentifier, - message: Message, + message: AccessibleMessage, threadId: MessageThreadId? = toChatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false @@ -57,7 +57,7 @@ suspend fun TelegramBot.forwardMessage( suspend fun TelegramBot.forwardMessage( toChat: Chat, - message: Message, + message: AccessibleMessage, threadId: MessageThreadId? = toChat.id.threadId, disableNotification: Boolean = false, protectContent: Boolean = false diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/ForwardMessages.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/ForwardMessages.kt index 894b2ca1da..edbb1bd4c0 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/ForwardMessages.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/ForwardMessages.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.extensions.api import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.ForwardMessages import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage suspend fun TelegramBot.forwardMessages( toChatId: ChatIdentifier, @@ -66,7 +66,7 @@ suspend fun TelegramBot.forwardMessages( suspend fun TelegramBot.forwardMessages( toChatId: ChatIdentifier, - messages: List, + messages: List, threadId: MessageThreadId? = toChatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -141,7 +141,7 @@ suspend fun TelegramBot.forward( suspend fun TelegramBot.forward( toChatId: ChatIdentifier, - messages: List, + messages: List, threadId: MessageThreadId? = toChatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt index 7d2d93b6d0..de3551c5a2 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt @@ -2,39 +2,24 @@ package dev.inmo.tgbotapi.extensions.api import korlibs.time.DateTime import korlibs.time.TimeSpan -import dev.inmo.micro_utils.coroutines.LinkedSupervisorJob -import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions -import dev.inmo.tgbotapi.abstracts.types.WithReplyMarkup import dev.inmo.tgbotapi.bot.TelegramBot -import dev.inmo.tgbotapi.extensions.api.edit.edit import dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation import dev.inmo.tgbotapi.extensions.api.edit.location.live.stopLiveLocation -import dev.inmo.tgbotapi.extensions.api.send.send -import dev.inmo.tgbotapi.extensions.api.send.sendLiveLocation import dev.inmo.tgbotapi.requests.send.SendLiveLocation import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.location.LiveLocation -import dev.inmo.tgbotapi.types.location.Location import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.content.LocationContent import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull import io.ktor.utils.io.core.Closeable import korlibs.time.millisecondsLong import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.CoroutineStart -import kotlinx.coroutines.currentCoroutineContext -import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.isActive import kotlinx.coroutines.launch -import kotlin.js.JsName -import kotlin.jvm.JvmName import kotlin.math.ceil val defaultLivePeriodDelayMillis = (livePeriodLimit.last - 60L) * 1000L @@ -253,7 +238,7 @@ suspend fun TelegramBot.startLiveLocation( * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param */ suspend inline fun TelegramBot.replyWithLiveLocation( - to: Message, + to: AccessibleMessage, scope: CoroutineScope, latitude: Double, longitude: Double, @@ -288,7 +273,7 @@ suspend inline fun TelegramBot.replyWithLiveLocation( * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param */ suspend inline fun TelegramBot.replyWithLiveLocation( - to: Message, + to: AccessibleMessage, scope: CoroutineScope, location: StaticLocation, liveTimeMillis: Long = defaultLivePeriodDelayMillis, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/StopPoll.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/StopPoll.kt index 5bfd721463..3bb90f8cbe 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/StopPoll.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/StopPoll.kt @@ -5,7 +5,7 @@ import dev.inmo.tgbotapi.requests.StopPoll import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.Chat -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage /** * @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] @@ -35,7 +35,7 @@ suspend fun TelegramBot.stopPoll( */ suspend fun TelegramBot.stopPoll( chatId: IdChatIdentifier, - message: Message, + message: AccessibleMessage, replyMarkup: InlineKeyboardMarkup? = null ) = stopPoll(chatId, message.messageId, replyMarkup) @@ -45,6 +45,6 @@ suspend fun TelegramBot.stopPoll( */ suspend fun TelegramBot.stopPoll( chat: Chat, - message: Message, + message: AccessibleMessage, replyMarkup: InlineKeyboardMarkup? = null ) = stopPoll(chat.id, message.messageId, replyMarkup) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt index af33a946db..01a66130c5 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt @@ -5,7 +5,7 @@ import dev.inmo.tgbotapi.requests.chat.modify.PinChatMessage import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.chat.Chat -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage suspend fun TelegramBot.pinChatMessage( chatId: ChatIdentifier, @@ -20,6 +20,6 @@ suspend fun TelegramBot.pinChatMessage( ) = pinChatMessage(chat.id, messageId, disableNotification) suspend fun TelegramBot.pinChatMessage( - message: Message, + message: AccessibleMessage, disableNotification: Boolean = false ) = pinChatMessage(message.chat.id, message.messageId, disableNotification) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt index b902698c38..2d9c5cc53c 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt @@ -5,7 +5,7 @@ import dev.inmo.tgbotapi.requests.chat.modify.UnpinChatMessage import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.chat.Chat -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage suspend fun TelegramBot.unpinChatMessage( chatId: ChatIdentifier, @@ -18,5 +18,5 @@ suspend fun TelegramBot.unpinChatMessage( ) = unpinChatMessage(chat.id, messageId) suspend fun TelegramBot.unpinChatMessage( - message: Message + message: AccessibleMessage ) = unpinChatMessage(message.chat.id, message.messageId) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/Edits.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/Edits.kt index f7f9690a67..c08d54d625 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/Edits.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/Edits.kt @@ -14,7 +14,7 @@ import dev.inmo.tgbotapi.types.location.LiveLocation import dev.inmo.tgbotapi.types.media.TelegramMedia import dev.inmo.tgbotapi.types.message.ParseMode import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.types.message.textsources.TextSource import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList @@ -181,7 +181,7 @@ suspend fun TelegramBot.edit( * as a builder for that */ suspend fun TelegramBot.edit( - message: Message, + message: AccessibleMessage, replyMarkup: InlineKeyboardMarkup? = null ) = editMessageReplyMarkup(message, replyMarkup) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditChatMessageCaption.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditChatMessageCaption.kt index e1ded4811e..f7992ccd8b 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditChatMessageCaption.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditChatMessageCaption.kt @@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.types.message.ParseMode import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.content.MediaContent import dev.inmo.tgbotapi.utils.RiskFeature @@ -98,7 +98,7 @@ suspend fun TelegramBot.editMessageCaption( */ @RiskFeature("This method is unsafe due to absence of any guaranties about the type of message. In case if message is not media message this method will throw an exception") suspend fun TelegramBot.editMessageCaption( - message: Message, + message: AccessibleMessage, entities: List, replyMarkup: InlineKeyboardMarkup? = null ): ContentMessage where T : TextedWithTextSources, T : MediaContent { diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/reply_markup/EditChatMessageReplyMarkup.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/reply_markup/EditChatMessageReplyMarkup.kt index dedb5f38b7..86756fd27b 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/reply_markup/EditChatMessageReplyMarkup.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/reply_markup/EditChatMessageReplyMarkup.kt @@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.Chat -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage /** * @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] @@ -35,7 +35,7 @@ suspend fun TelegramBot.editMessageReplyMarkup( * as a builder for that */ suspend fun TelegramBot.editMessageReplyMarkup( - message: Message, + message: AccessibleMessage, replyMarkup: InlineKeyboardMarkup? = null ) = editMessageReplyMarkup(message.chat.id, message.messageId, replyMarkup) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditChatMessageText.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditChatMessageText.kt index 1cda2d3fd7..3d00e4074c 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditChatMessageText.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditChatMessageText.kt @@ -10,7 +10,7 @@ import dev.inmo.tgbotapi.types.message.ParseMode import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.types.message.textsources.TextSource import dev.inmo.tgbotapi.utils.* @@ -174,7 +174,7 @@ suspend fun TelegramBot.editMessageText( */ @RiskFeature("This method is unsafe due to absence of any guaranties about the type of message. In case if message is not text message this method will throw an exception") suspend fun TelegramBot.editMessageText( - message: Message, + message: AccessibleMessage, entities: TextSourcesList, linkPreviewOptions: LinkPreviewOptions? = null, replyMarkup: InlineKeyboardMarkup? = null @@ -186,7 +186,7 @@ suspend fun TelegramBot.editMessageText( */ @RiskFeature("This method is unsafe due to absence of any guaranties about the type of message. In case if message is not text message this method will throw an exception") suspend fun TelegramBot.editMessageText( - message: Message, + message: AccessibleMessage, separator: TextSource? = null, linkPreviewOptions: LinkPreviewOptions? = null, replyMarkup: InlineKeyboardMarkup? = null, @@ -199,7 +199,7 @@ suspend fun TelegramBot.editMessageText( */ @RiskFeature("This method is unsafe due to absence of any guaranties about the type of message. In case if message is not text message this method will throw an exception") suspend fun TelegramBot.editMessageText( - message: Message, + message: AccessibleMessage, separator: String, linkPreviewOptions: LinkPreviewOptions? = null, replyMarkup: InlineKeyboardMarkup? = null, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessage.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessage.kt index 40ee1f326d..fe539e90ab 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessage.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessage.kt @@ -9,7 +9,7 @@ import dev.inmo.tgbotapi.types.MessageThreadId import dev.inmo.tgbotapi.types.message.ParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.Chat -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.threadId /** @@ -186,7 +186,7 @@ suspend inline fun TelegramBot.copyMessage( */ suspend inline fun TelegramBot.copyMessage( toChatId: ChatIdentifier, - message: Message, + message: AccessibleMessage, text: String? = null, parseMode: ParseMode? = null, threadId: MessageThreadId? = toChatId.threadId, @@ -203,7 +203,7 @@ suspend inline fun TelegramBot.copyMessage( */ suspend inline fun TelegramBot.copyMessage( toChat: Chat, - message: Message, + message: AccessibleMessage, text: String? = null, parseMode: ParseMode? = null, threadId: MessageThreadId? = toChat.id.threadId, @@ -220,7 +220,7 @@ suspend inline fun TelegramBot.copyMessage( */ suspend inline fun TelegramBot.copyMessage( toChatId: ChatIdentifier, - message: Message, + message: AccessibleMessage, entities: TextSourcesList, threadId: MessageThreadId? = toChatId.threadId, disableNotification: Boolean = false, @@ -236,7 +236,7 @@ suspend inline fun TelegramBot.copyMessage( */ suspend inline fun TelegramBot.copyMessage( toChat: Chat, - message: Message, + message: AccessibleMessage, entities: TextSourcesList, threadId: MessageThreadId? = toChat.id.threadId, disableNotification: Boolean = false, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt index cfca65c3ff..3fabdeb877 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.extensions.api.send import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.send.CopyMessages import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage suspend fun TelegramBot.copyMessages( toChatId: ChatIdentifier, @@ -66,7 +66,7 @@ suspend fun TelegramBot.copyMessages( suspend fun TelegramBot.copyMessages( toChatId: ChatIdentifier, - messages: List, + messages: List, threadId: MessageThreadId? = toChatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt index 8552f54aae..09b3cd0ea3 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt @@ -22,8 +22,7 @@ import dev.inmo.tgbotapi.types.files.TelegramMediaFile import dev.inmo.tgbotapi.types.files.Sticker import dev.inmo.tgbotapi.types.games.Game import dev.inmo.tgbotapi.types.location.* -import dev.inmo.tgbotapi.types.message.abstracts.Message -import dev.inmo.tgbotapi.types.message.abstracts.PossiblyTopicMessage +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.types.message.textsources.TextSource import dev.inmo.tgbotapi.types.payments.LabeledPrice @@ -44,7 +43,7 @@ import kotlin.jvm.JvmName * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param */ suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, phoneNumber: String, firstName: String, lastName: String? = null, @@ -70,7 +69,7 @@ suspend inline fun TelegramBot.reply( * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param */ suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, contact: Contact, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -95,7 +94,7 @@ suspend inline fun TelegramBot.reply( * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param */ suspend inline fun TelegramBot.replyWithDice( - to: Message, + to: AccessibleMessage, animationType: DiceAnimationType? = null, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -108,7 +107,7 @@ suspend inline fun TelegramBot.replyWithDice( * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param */ suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, animationType: DiceAnimationType, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -124,7 +123,7 @@ suspend inline fun TelegramBot.reply( * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param */ suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, latitude: Double, longitude: Double, disableNotification: Boolean = false, @@ -148,7 +147,7 @@ suspend inline fun TelegramBot.reply( * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param */ suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, location: StaticLocation, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -173,7 +172,7 @@ suspend inline fun TelegramBot.reply( * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param */ suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, text: String, parseMode: ParseMode? = null, linkPreviewOptions: LinkPreviewOptions? = null, @@ -199,7 +198,7 @@ suspend inline fun TelegramBot.reply( * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param */ suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, entities: TextSourcesList, linkPreviewOptions: LinkPreviewOptions? = null, disableNotification: Boolean = false, @@ -223,7 +222,7 @@ suspend inline fun TelegramBot.reply( * as a builder for that */ suspend fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, separator: TextSource? = null, linkPreviewOptions: LinkPreviewOptions? = null, disableNotification: Boolean = false, @@ -238,7 +237,7 @@ suspend fun TelegramBot.reply( * as a builder for that */ suspend fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, separator: String, linkPreviewOptions: LinkPreviewOptions? = null, disableNotification: Boolean = false, @@ -256,7 +255,7 @@ suspend fun TelegramBot.reply( * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param */ suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, latitude: Double, longitude: Double, title: String, @@ -288,7 +287,7 @@ suspend inline fun TelegramBot.reply( ) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, location: StaticLocation, title: String, address: String, @@ -319,7 +318,7 @@ suspend inline fun TelegramBot.reply( ) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, venue: Venue, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -340,7 +339,7 @@ suspend inline fun TelegramBot.reply( // Game suspend inline fun TelegramBot.replyWithGame( - to: Message, + to: AccessibleMessage, gameShortName: String, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -351,7 +350,7 @@ suspend inline fun TelegramBot.replyWithGame( ) suspend inline fun TelegramBot.replyWithGame( - to: Message, + to: AccessibleMessage, game: Game, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -362,7 +361,7 @@ suspend inline fun TelegramBot.replyWithGame( ) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, game: Game, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -374,7 +373,7 @@ suspend inline fun TelegramBot.reply( // Animation suspend inline fun TelegramBot.replyWithAnimation( - to: Message, + to: AccessibleMessage, animation: InputFile, thumb: InputFile? = null, text: String? = null, @@ -406,7 +405,7 @@ suspend inline fun TelegramBot.replyWithAnimation( ) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, animation: AnimationFile, text: String? = null, parseMode: ParseMode? = null, @@ -421,7 +420,7 @@ suspend inline fun TelegramBot.reply( ) = sendAnimation(to.chat, animation, text, parseMode, spoilered, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithAnimation( - to: Message, + to: AccessibleMessage, animation: InputFile, entities: TextSourcesList, spoilered: Boolean = false, @@ -451,7 +450,7 @@ suspend inline fun TelegramBot.replyWithAnimation( ) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, animation: AnimationFile, entities: TextSourcesList, spoilered: Boolean = false, @@ -468,7 +467,7 @@ suspend inline fun TelegramBot.reply( // Audio suspend inline fun TelegramBot.replyWithAudio( - to: Message, + to: AccessibleMessage, audio: InputFile, thumb: InputFile? = null, text: String? = null, @@ -483,7 +482,7 @@ suspend inline fun TelegramBot.replyWithAudio( ) = sendAudio(to.chat, audio, thumb, text, parseMode, duration, performer, title, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, audio: AudioFile, text: String? = null, parseMode: ParseMode? = null, @@ -495,7 +494,7 @@ suspend inline fun TelegramBot.reply( ) = sendAudio(to.chat, audio, text, parseMode, title, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithAudio( - to: Message, + to: AccessibleMessage, audio: InputFile, thumb: InputFile? = null, entities: TextSourcesList, @@ -509,7 +508,7 @@ suspend inline fun TelegramBot.replyWithAudio( ) = sendAudio(to.chat, audio, thumb, entities, duration, performer, title, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, audio: AudioFile, entities: TextSourcesList, title: String? = null, @@ -523,7 +522,7 @@ suspend inline fun TelegramBot.reply( // Documents suspend inline fun TelegramBot.replyWithDocument( - to: Message, + to: AccessibleMessage, document: InputFile, thumb: InputFile? = null, text: String? = null, @@ -536,7 +535,7 @@ suspend inline fun TelegramBot.replyWithDocument( ) = sendDocument(to.chat, document, thumb, text, parseMode, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, document: DocumentFile, text: String? = null, parseMode: ParseMode? = null, @@ -548,7 +547,7 @@ suspend inline fun TelegramBot.reply( ) = sendDocument(to.chat, document, text, parseMode, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) suspend inline fun TelegramBot.replyWithDocument( - to: Message, + to: AccessibleMessage, document: InputFile, thumb: InputFile? = null, entities: TextSourcesList, @@ -560,7 +559,7 @@ suspend inline fun TelegramBot.replyWithDocument( ) = sendDocument(to.chat, document, thumb, entities, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, document: DocumentFile, entities: TextSourcesList, disableNotification: Boolean = false, @@ -575,7 +574,7 @@ suspend inline fun TelegramBot.reply( @RiskFeature(rawSendingMediaGroupsWarning) suspend inline fun TelegramBot.replyWithMediaGroup( - to: Message, + to: AccessibleMessage, media: List, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -583,7 +582,7 @@ suspend inline fun TelegramBot.replyWithMediaGroup( ) = sendMediaGroup(to.chat, media, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply) suspend inline fun TelegramBot.replyWithPlaylist( - to: Message, + to: AccessibleMessage, media: List, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -591,7 +590,7 @@ suspend inline fun TelegramBot.replyWithPlaylist( ) = sendPlaylist(to.chat, media, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply) suspend inline fun TelegramBot.replyWithDocuments( - to: Message, + to: AccessibleMessage, media: List, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -599,7 +598,7 @@ suspend inline fun TelegramBot.replyWithDocuments( ) = sendDocumentsGroup(to.chat, media, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply) suspend inline fun TelegramBot.replyWithGallery( - to: Message, + to: AccessibleMessage, media: List, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -610,7 +609,7 @@ suspend inline fun TelegramBot.replyWithGallery( // Photo suspend inline fun TelegramBot.replyWithPhoto( - to: Message, + to: AccessibleMessage, fileId: InputFile, text: String? = null, parseMode: ParseMode? = null, @@ -622,7 +621,7 @@ suspend inline fun TelegramBot.replyWithPhoto( ) = sendPhoto(to.chat, fileId, text, parseMode, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, photo: Photo, text: String? = null, parseMode: ParseMode? = null, @@ -634,7 +633,7 @@ suspend inline fun TelegramBot.reply( ) = sendPhoto(to.chat, photo, text, parseMode, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, photoSize: PhotoSize, text: String? = null, parseMode: ParseMode? = null, @@ -647,7 +646,7 @@ suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.replyWithPhoto( - to: Message, + to: AccessibleMessage, fileId: InputFile, entities: TextSourcesList, spoilered: Boolean = false, @@ -658,7 +657,7 @@ suspend inline fun TelegramBot.replyWithPhoto( ) = sendPhoto(to.chat, fileId, entities, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, photo: Photo, entities: TextSourcesList, spoilered: Boolean = false, @@ -669,7 +668,7 @@ suspend inline fun TelegramBot.reply( ) = sendPhoto(to.chat, photo, entities, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, photoSize: PhotoSize, entities: TextSourcesList, spoilered: Boolean = false, @@ -683,7 +682,7 @@ suspend inline fun TelegramBot.reply( // Sticker suspend inline fun TelegramBot.replyWithSticker( - to: Message, + to: AccessibleMessage, sticker: InputFile, emoji: String? = null, disableNotification: Boolean = false, @@ -693,7 +692,7 @@ suspend inline fun TelegramBot.replyWithSticker( ) = sendSticker(to.chat, sticker, to.threadIdOrNull, emoji, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, sticker: Sticker, emoji: String? = null, disableNotification: Boolean = false, @@ -706,7 +705,7 @@ suspend inline fun TelegramBot.reply( // Videos suspend inline fun TelegramBot.replyWithVideo( - to: Message, + to: AccessibleMessage, video: InputFile, thumb: InputFile? = null, text: String? = null, @@ -722,7 +721,7 @@ suspend inline fun TelegramBot.replyWithVideo( ) = sendVideo(to.chat, video, thumb, text, parseMode, spoilered, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, video: VideoFile, text: String? = null, parseMode: ParseMode? = null, @@ -734,7 +733,7 @@ suspend inline fun TelegramBot.reply( ) = sendVideo(to.chat, video, text, parseMode, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithVideo( - to: Message, + to: AccessibleMessage, video: InputFile, thumb: InputFile? = null, entities: TextSourcesList, @@ -749,7 +748,7 @@ suspend inline fun TelegramBot.replyWithVideo( ) = sendVideo(to.chat, video, thumb, entities, spoilered, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, video: VideoFile, entities: TextSourcesList, spoilered: Boolean = false, @@ -763,7 +762,7 @@ suspend inline fun TelegramBot.reply( // VideoNotes suspend inline fun TelegramBot.replyWithVideoNote( - to: Message, + to: AccessibleMessage, videoNote: InputFile, thumb: InputFile? = null, duration: Long? = null, @@ -775,7 +774,7 @@ suspend inline fun TelegramBot.replyWithVideoNote( ) = sendVideoNote(to.chat, videoNote, thumb, duration, size, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, videoNote: VideoNoteFile, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -787,7 +786,7 @@ suspend inline fun TelegramBot.reply( // Voice suspend inline fun TelegramBot.replyWithVoice( - to: Message, + to: AccessibleMessage, voice: InputFile, text: String? = null, parseMode: ParseMode? = null, @@ -799,7 +798,7 @@ suspend inline fun TelegramBot.replyWithVoice( ) = sendVoice(to.chat, voice, text, parseMode, duration, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, voice: VoiceFile, text: String? = null, parseMode: ParseMode? = null, @@ -811,7 +810,7 @@ suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.replyWithVoice( - to: Message, + to: AccessibleMessage, voice: InputFile, entities: TextSourcesList, duration: Long? = null, @@ -822,7 +821,7 @@ suspend inline fun TelegramBot.replyWithVoice( ) = sendVoice(to.chat, voice, entities, duration, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, voice: VoiceFile, entities: TextSourcesList, disableNotification: Boolean = false, @@ -839,7 +838,7 @@ suspend inline fun TelegramBot.reply( * as a builder for that */ suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, title: String, description: String, payload: String, @@ -867,7 +866,7 @@ suspend inline fun TelegramBot.reply( // Polls suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, question: String, options: List, isAnonymous: Boolean = true, @@ -881,7 +880,7 @@ suspend inline fun TelegramBot.reply( ) = sendRegularPoll(to.chat, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, poll: RegularPoll, isClosed: Boolean = false, question: String = poll.question, @@ -896,7 +895,7 @@ suspend inline fun TelegramBot.reply( ) = sendRegularPoll(to.chat, poll, isClosed, question, options, isAnonymous, allowMultipleAnswers, closeInfo, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, question: String, options: List, correctOptionId: Int, @@ -912,7 +911,7 @@ suspend inline fun TelegramBot.reply( ) = sendQuizPoll(to.chat, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, quizPoll: QuizPoll, isClosed: Boolean = false, question: String = quizPoll.question, @@ -929,7 +928,7 @@ suspend inline fun TelegramBot.reply( ) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, explanation, parseMode, closeInfo, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, question: String, options: List, correctOptionId: Int, @@ -944,7 +943,7 @@ suspend inline fun TelegramBot.reply( ) = sendQuizPoll(to.chat, question, options, correctOptionId, isAnonymous, isClosed, entities, closeInfo, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, quizPoll: QuizPoll, entities: TextSourcesList, isClosed: Boolean = false, @@ -961,7 +960,7 @@ suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, poll: Poll, isClosed: Boolean = false, question: String = poll.question, @@ -1006,7 +1005,7 @@ suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, fromChatId: ChatIdentifier, messageId: MessageId, text: String? = null, @@ -1030,7 +1029,7 @@ suspend inline fun TelegramBot.reply( ) suspend inline fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, fromChat: Chat, messageId: MessageId, text: String? = null, @@ -1042,8 +1041,8 @@ suspend inline fun TelegramBot.reply( ) = reply(to, fromChat.id, messageId, text, parseMode, disableNotification, protectContent, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( - to: Message, - copy: Message, + to: AccessibleMessage, + copy: AccessibleMessage, text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, @@ -1053,13 +1052,13 @@ suspend inline fun TelegramBot.reply( ) = reply(to, copy.chat.id, copy.messageId, text, parseMode, disableNotification, protectContent, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, content: MessageContent, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -): Message = execute( +): AccessibleMessage = execute( content.createResend( to.chat.id, to.threadIdOrNull, @@ -1077,7 +1076,7 @@ suspend fun TelegramBot.reply( * @see handleLiveLocation */ suspend fun TelegramBot.reply( - message: Message, + message: AccessibleMessage, locationsFlow: Flow, liveTimeMillis: Long = defaultLivePeriodDelayMillis, disableNotification: Boolean = false, @@ -1102,7 +1101,7 @@ suspend fun TelegramBot.reply( @JvmName("replyLiveLocationWithLocation") @JsName("replyLiveLocationWithLocation") suspend fun TelegramBot.reply( - message: Message, + message: AccessibleMessage, locationsFlow: Flow, liveTimeMillis: Long = defaultLivePeriodDelayMillis, disableNotification: Boolean = false, @@ -1129,7 +1128,7 @@ suspend fun TelegramBot.reply( @JvmName("replyLiveLocationWithLatLong") @JsName("replyLiveLocationWithLatLong") suspend fun TelegramBot.reply( - message: Message, + message: AccessibleMessage, locationsFlow: Flow>, liveTimeMillis: Long = defaultLivePeriodDelayMillis, disableNotification: Boolean = false, @@ -1149,7 +1148,7 @@ suspend fun TelegramBot.reply( } suspend fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, mediaFile: TelegramMediaFile, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -1233,7 +1232,7 @@ suspend fun TelegramBot.reply( } suspend fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, content: TextedMediaContent, text: String?, parseMode: ParseMode? = null, @@ -1307,7 +1306,7 @@ suspend fun TelegramBot.reply( } suspend fun TelegramBot.reply( - to: Message, + to: AccessibleMessage, content: TextedMediaContent, entities: TextSourcesList, disableNotification: Boolean = false, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/RepliesWithChatsAndMessages.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/RepliesWithChatsAndMessages.kt index a81151755e..60197a66e0 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/RepliesWithChatsAndMessages.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/RepliesWithChatsAndMessages.kt @@ -23,7 +23,7 @@ import dev.inmo.tgbotapi.types.files.TelegramMediaFile import dev.inmo.tgbotapi.types.files.Sticker import dev.inmo.tgbotapi.types.games.Game import dev.inmo.tgbotapi.types.location.* -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.types.payments.LabeledPrice import dev.inmo.tgbotapi.types.payments.abstracts.Currency @@ -1166,7 +1166,7 @@ suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply( toChatId: IdChatIdentifier, toMessageId: MessageId, - copy: Message, + copy: AccessibleMessage, text: String? = null, parseMode: ParseMode? = null, threadId: MessageThreadId? = toChatId.threadId, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SetMessageReactions.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SetMessageReactions.kt index c94fdeff1f..5abec35c55 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SetMessageReactions.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SetMessageReactions.kt @@ -1,16 +1,12 @@ package dev.inmo.tgbotapi.extensions.api.send import dev.inmo.tgbotapi.bot.TelegramBot -import dev.inmo.tgbotapi.requests.send.SendAction import dev.inmo.tgbotapi.requests.send.SetMessageReactions import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageId -import dev.inmo.tgbotapi.types.MessageThreadId -import dev.inmo.tgbotapi.types.actions.* import dev.inmo.tgbotapi.types.chat.Chat -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.reactions.Reaction -import dev.inmo.tgbotapi.types.threadId suspend fun TelegramBot.setMessageReactions( chatId: ChatIdentifier, @@ -43,13 +39,13 @@ suspend fun TelegramBot.setMessageReaction( ) = setMessageReaction(chat.id, messageId, reaction, big) suspend fun TelegramBot.setMessageReactions( - message: Message, + message: AccessibleMessage, reactions: List, big: Boolean = false ) = setMessageReactions(message.chat, message.messageId, reactions, big) suspend fun TelegramBot.setMessageReaction( - message: Message, + message: AccessibleMessage, reaction: Reaction?, big: Boolean = false ) = setMessageReaction(message.chat, message.messageId, reaction, big) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt index 85bbad10ba..fd7820f464 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt @@ -6,24 +6,24 @@ import dev.inmo.tgbotapi.extensions.utils.extensions.sourceUser import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery import dev.inmo.tgbotapi.types.chat.ChatJoinRequest import dev.inmo.tgbotapi.types.chat.member.ChatMemberUpdated -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery import dev.inmo.tgbotapi.types.payments.ShippingQuery import dev.inmo.tgbotapi.types.queries.callback.CallbackQuery import dev.inmo.tgbotapi.types.update.abstracts.Update /** - * Allow only events from the same chat as base [Message] + * Allow only events from the same chat as base [AccessibleMessage] */ -val MessageFilterByChat: BehaviourContextAndTwoTypesReceiver = { message, update -> +val MessageFilterByChat: BehaviourContextAndTwoTypesReceiver = { message, update -> update.sourceChat() ?.let { it.id == message.chat.id } != false } /** - * Allow only events from the same chat as base [List] of [Message] + * Allow only events from the same chat as base [List] of [AccessibleMessage] */ -val MessagesFilterByChat: BehaviourContextAndTwoTypesReceiver, Update> = { messages, update -> +val MessagesFilterByChat: BehaviourContextAndTwoTypesReceiver, Update> = { messages, update -> val sourceChatId = update.sourceChat() ?.id sourceChatId != null && messages.all { sourceChatId == it.chat.id } } diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterExcludingMediaGroups.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterExcludingMediaGroups.kt index f6d4fc2b76..469ab1954e 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterExcludingMediaGroups.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterExcludingMediaGroups.kt @@ -1,15 +1,13 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.filters -import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.types.message.abstracts.* import dev.inmo.tgbotapi.types.message.content.MediaGroupContent import dev.inmo.tgbotapi.types.message.content.MediaGroupMessage -import dev.inmo.tgbotapi.types.update.abstracts.Update /** * Allow only messages which are not [MediaGroupMessage] */ -val CommonMessageFilterExcludeMediaGroups = SimpleFilter { +val CommonMessageFilterExcludeMediaGroups = SimpleFilter { it !is CommonMessage<*> || it.content !is MediaGroupContent<*> } diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterForums.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterForums.kt index c108b48867..293b6ad20f 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterForums.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterForums.kt @@ -7,6 +7,6 @@ import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull /** * Allow only messages which are not in some forum */ -val MessageFilterForums = SimpleFilter { +val MessageFilterForums = SimpleFilter { it.threadIdOrNull == null } diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MessageMarkerFactories.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MessageMarkerFactories.kt index 1beb82c59d..8570f545af 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MessageMarkerFactories.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MessageMarkerFactories.kt @@ -2,12 +2,12 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories import dev.inmo.tgbotapi.types.message.abstracts.* -object ByChatMessageMarkerFactory : MarkerFactory { - override suspend fun invoke(data: Message) = data.chat +object ByChatMessageMarkerFactory : MarkerFactory { + override suspend fun invoke(data: AccessibleMessage) = data.chat } -object ByUserMessageMarkerFactory : MarkerFactory { - override suspend fun invoke(data: Message) = when (data) { +object ByUserMessageMarkerFactory : MarkerFactory { + override suspend fun invoke(data: AccessibleMessage) = when (data) { is FromUserMessage -> data.user is FromChannelGroupContentMessage<*> -> data.channel else -> data.chat // including anonymous diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdates.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdates.kt index f75ba755c3..c19f91aba2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdates.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdates.kt @@ -1,6 +1,5 @@ package dev.inmo.tgbotapi.requests -import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.types.update.abstracts.UpdateSerializerWithoutSerialization @@ -15,7 +14,7 @@ private val updatesListSerializer = ListSerializer( * Request updates from Telegram Bot API system. It is important, that the result updates WILL NOT include * [dev.inmo.tgbotapi.types.update.MediaGroupUpdates.MediaGroupUpdate] objects due to the fact, * that it is internal abstraction and in fact any [dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage] - * is just a common [dev.inmo.tgbotapi.types.message.abstracts.Message] + * is just a common [dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage] * * @see dev.inmo.tgbotapi.extensions.utils.updates.retrieving.updateHandlerWithMediaGroupsAdaptation * @see dev.inmo.tgbotapi.utils.convertWithMediaGroupUpdates 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 1b044a5b59..b3887e7579 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 @@ -2,10 +2,10 @@ package dev.inmo.tgbotapi.types.chat import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.colors.ColorId +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer import dev.inmo.tgbotapi.types.reactions.Reaction -import korlibs.time.DateTime import kotlinx.serialization.Serializable @Serializable(ExtendedChatSerializer.Companion::class) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/giveaway/GiveawayPrivateResults.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/giveaway/GiveawayPrivateResults.kt index 63e3fb7f4b..8fbbf42bc2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/giveaway/GiveawayPrivateResults.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/giveaway/GiveawayPrivateResults.kt @@ -1,9 +1,7 @@ package dev.inmo.tgbotapi.types.giveaway import dev.inmo.tgbotapi.types.chat.PreviewChat -import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChannelEvent -import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChatEvent -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import kotlinx.serialization.Serializable import kotlinx.serialization.Transient @@ -12,5 +10,5 @@ data class GiveawayPrivateResults( override val chat: PreviewChat, override val unclaimedCount: Int, @Transient // TODO::Add message serializer - val message: Message? = null + val message: AccessibleMessage? = null ) : GiveawayResults 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 e3e5f0dcb4..eaab4dc3ad 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 @@ -3,7 +3,6 @@ package dev.inmo.tgbotapi.types.message import korlibs.time.DateTime import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup -import dev.inmo.tgbotapi.types.chat.ChannelChat import dev.inmo.tgbotapi.types.chat.CommonBot import dev.inmo.tgbotapi.types.chat.PreviewChannelChat import dev.inmo.tgbotapi.types.message.abstracts.* @@ -17,7 +16,7 @@ data class ChannelContentMessageImpl( override val editDate: DateTime?, override val hasProtectedContent: Boolean, override val forwardInfo: ForwardInfo?, - override val replyTo: Message?, + override val replyTo: AccessibleMessage?, override val replyMarkup: InlineKeyboardMarkup?, override val senderBot: CommonBot?, override val authorSignature: AuthorSignature?, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/PinnedMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/PinnedMessage.kt index 7f62ac4b23..11306bc6d1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/PinnedMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/PinnedMessage.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.message.ChatEvents import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.Message data class PinnedMessage( 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 73bd4a4174..78d90720e1 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 @@ -17,7 +17,7 @@ data class ConnectedFromChannelGroupContentMessageImpl( override val forwardInfo: ForwardInfo?, override val editDate: DateTime?, override val hasProtectedContent: Boolean, - override val replyTo: Message?, + override val replyTo: AccessibleMessage?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, @@ -33,7 +33,7 @@ data class UnconnectedFromChannelGroupContentMessageImpl( override val forwardInfo: ForwardInfo?, override val editDate: DateTime?, override val hasProtectedContent: Boolean, - override val replyTo: Message?, + override val replyTo: AccessibleMessage?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, @@ -48,7 +48,7 @@ data class AnonymousGroupContentMessageImpl( override val forwardInfo: ForwardInfo?, override val editDate: DateTime?, override val hasProtectedContent: Boolean, - override val replyTo: Message?, + override val replyTo: AccessibleMessage?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, @@ -64,7 +64,7 @@ data class CommonGroupContentMessageImpl( override val forwardInfo: ForwardInfo?, override val editDate: DateTime?, override val hasProtectedContent: Boolean, - override val replyTo: Message?, + override val replyTo: AccessibleMessage?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, @@ -80,7 +80,7 @@ data class FromChannelForumContentMessageImpl( override val forwardInfo: ForwardInfo?, override val editDate: DateTime?, override val hasProtectedContent: Boolean, - override val replyTo: Message?, + override val replyTo: AccessibleMessage?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, @@ -96,7 +96,7 @@ data class AnonymousForumContentMessageImpl( override val forwardInfo: ForwardInfo?, override val editDate: DateTime?, override val hasProtectedContent: Boolean, - override val replyTo: Message?, + override val replyTo: AccessibleMessage?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, @@ -113,7 +113,7 @@ data class CommonForumContentMessageImpl( override val forwardInfo: ForwardInfo?, override val editDate: DateTime?, override val hasProtectedContent: Boolean, - override val replyTo: Message?, + override val replyTo: AccessibleMessage?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PassportMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PassportMessage.kt index fd2945c430..2cc79c38d8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PassportMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PassportMessage.kt @@ -3,10 +3,9 @@ package dev.inmo.tgbotapi.types.message import korlibs.time.DateTime import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.chat.User -import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.chat.PreviewChat import dev.inmo.tgbotapi.types.message.abstracts.FromUserMessage -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.passport.PassportData data class PassportMessage( @@ -15,4 +14,4 @@ data class PassportMessage( override val from: User, override val date: DateTime, val passportData: PassportData -) : Message, FromUserMessage +) : AccessibleMessage, FromUserMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt index a9b4ae9c96..74f5ea3797 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt @@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.* import dev.inmo.tgbotapi.types.chat.CommonBot import dev.inmo.tgbotapi.types.chat.User -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage import dev.inmo.tgbotapi.types.message.content.MessageContent @@ -19,7 +19,7 @@ data class PrivateContentMessageImpl( override val editDate: DateTime?, override val hasProtectedContent: Boolean, override val forwardInfo: ForwardInfo?, - override val replyTo: Message?, + override val replyTo: AccessibleMessage?, override val replyMarkup: InlineKeyboardMarkup?, override val senderBot: CommonBot?, override val mediaGroupId: MediaGroupIdentifier?, 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 59b2fb6061..325aed76af 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 @@ -286,7 +286,7 @@ internal data class RawMessage( } } - val asMessage: Message by lazy { + val asMessage: AccessibleMessage by lazy { if (date.date == 0L) { return@lazy InaccessibleMessage( chat, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChatEventMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChatEventMessage.kt index c409d53a0e..9b4999bf0d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChatEventMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChatEventMessage.kt @@ -2,6 +2,6 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChatEvent -interface ChatEventMessage : Message { +interface ChatEventMessage : AccessibleMessage { val chatEvent: T } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/CommonMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/CommonMessage.kt index a5bc9b83aa..31acc87740 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/CommonMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/CommonMessage.kt @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.types.message.content.MessageContent -sealed interface CommonMessage : Message, +sealed interface CommonMessage : AccessibleMessage, PossiblyForwardedMessage, PossiblyEditedMessage, PossiblyReplyMessage, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ContentMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ContentMessage.kt index cfed7358dc..b39d110079 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ContentMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ContentMessage.kt @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.types.message.content.MessageContent -interface ContentMessage: Message { +interface ContentMessage: AccessibleMessage { val hasProtectedContent: Boolean val content: T 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 234b125ccf..4c568b1c50 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 @@ -2,4 +2,4 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.abstracts.FromUser -interface FromUserMessage : FromUser, Message +interface FromUserMessage : FromUser, AccessibleMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/Message.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/Message.kt index 6d01402657..7290ebb58e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/Message.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/Message.kt @@ -1,12 +1,9 @@ package dev.inmo.tgbotapi.types.message.abstracts -import dev.inmo.tgbotapi.abstracts.WithMessageId import korlibs.time.DateTime -import dev.inmo.tgbotapi.abstracts.WithPreviewChat import dev.inmo.tgbotapi.abstracts.WithPreviewChatAndMessageId import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded import dev.inmo.tgbotapi.types.MessageId -import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.chat.PreviewChat import dev.inmo.tgbotapi.types.message.RawMessage import kotlinx.serialization.* @@ -19,11 +16,13 @@ interface Message : WithPreviewChatAndMessageId { val date: DateTime } +interface AccessibleMessage : Message + @Serializable data class InaccessibleMessage( override val chat: PreviewChat, override val messageId: MessageId, -) : Message { +) : AccessibleMessage { override val date: DateTime get() = DateTime.invoke(0L) } @@ -33,7 +32,7 @@ data class UnknownMessageType( override val chat: PreviewChat, override val date: DateTime, val insideException: Exception -) : Message +) : AccessibleMessage internal class TelegramBotAPIMessageDeserializationStrategyClass : DeserializationStrategy { @OptIn(InternalSerializationApi::class) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyEditedMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyEditedMessage.kt index ac61856938..17353e32ce 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyEditedMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyEditedMessage.kt @@ -2,6 +2,6 @@ package dev.inmo.tgbotapi.types.message.abstracts import korlibs.time.DateTime -interface PossiblyEditedMessage : Message { +interface PossiblyEditedMessage : AccessibleMessage { val editDate: DateTime? } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyForwardedMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyForwardedMessage.kt index be8258d616..41b8938f74 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyForwardedMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyForwardedMessage.kt @@ -2,6 +2,6 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.types.message.ForwardInfo -interface PossiblyForwardedMessage : Message { +interface PossiblyForwardedMessage : AccessibleMessage { val forwardInfo: ForwardInfo? } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyPaymentMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyPaymentMessage.kt index 4989f3b7f1..cb8a07bb0d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyPaymentMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyPaymentMessage.kt @@ -2,6 +2,6 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.types.message.payments.abstracts.PaymentInfo -interface PossiblyPaymentMessage : Message { +interface PossiblyPaymentMessage : AccessibleMessage { val paymentInfo: PaymentInfo? } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyReplyMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyReplyMessage.kt index ef6905c0b1..d796c09520 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyReplyMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyReplyMessage.kt @@ -1,5 +1,5 @@ package dev.inmo.tgbotapi.types.message.abstracts interface PossiblyReplyMessage { - val replyTo: Message? + val replyTo: AccessibleMessage? } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyTopicMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyTopicMessage.kt index 8027809031..ba19d01b83 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyTopicMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyTopicMessage.kt @@ -2,6 +2,6 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.types.MessageThreadId -interface PossiblyTopicMessage : Message { +interface PossiblyTopicMessage : AccessibleMessage { val threadId: MessageThreadId? } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/SignedMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/SignedMessage.kt index 18aabe8616..04d4a85dd3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/SignedMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/SignedMessage.kt @@ -2,6 +2,6 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.types.AuthorSignature -interface SignedMessage : Message { +interface SignedMessage : AccessibleMessage { val authorSignature: AuthorSignature? } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Abstracts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Abstracts.kt index dd346d6403..32e0299a2e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Abstracts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Abstracts.kt @@ -165,5 +165,5 @@ sealed interface ResendableContent { replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null - ): Request + ): Request } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/MediaGroupContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/MediaGroupContent.kt index 1b0c05cb53..b582f493cd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/MediaGroupContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/MediaGroupContent.kt @@ -10,7 +10,6 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.TelegramMediaFile import dev.inmo.tgbotapi.types.media.TelegramMedia import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.textsources.TextSource import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/StoryContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/StoryContent.kt index 920e6a8699..187a155a10 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/StoryContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/StoryContent.kt @@ -7,8 +7,6 @@ import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.MessageThreadId import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.Chat -import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.abstracts.PossiblyForwardedMessage import dev.inmo.tgbotapi.types.stories.Story import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/AbstractMessageCallbackQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/AbstractMessageCallbackQuery.kt new file mode 100644 index 0000000000..2c71db3314 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/AbstractMessageCallbackQuery.kt @@ -0,0 +1,9 @@ +package dev.inmo.tgbotapi.types.queries.callback + +import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.content.MessageContent + +sealed interface AbstractMessageCallbackQuery : CallbackQuery { + val message: Message +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/InaccessibleMessageCallbackQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/InaccessibleMessageCallbackQuery.kt new file mode 100644 index 0000000000..12b965df5a --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/InaccessibleMessageCallbackQuery.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.queries.callback + +import dev.inmo.tgbotapi.types.message.abstracts.InaccessibleMessage + +sealed interface InaccessibleMessageCallbackQuery : AbstractMessageCallbackQuery { + override val message: InaccessibleMessage +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/InaccessibleMessageDataCallbackQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/InaccessibleMessageDataCallbackQuery.kt new file mode 100644 index 0000000000..0ac9245eae --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/InaccessibleMessageDataCallbackQuery.kt @@ -0,0 +1,16 @@ +package dev.inmo.tgbotapi.types.queries.callback + +import dev.inmo.tgbotapi.types.CallbackQueryIdentifier +import dev.inmo.tgbotapi.types.chat.CommonUser +import dev.inmo.tgbotapi.types.chat.User +import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.InaccessibleMessage +import dev.inmo.tgbotapi.types.message.content.MessageContent + +data class InaccessibleMessageDataCallbackQuery( + override val id: CallbackQueryIdentifier, + override val from: CommonUser, + override val chatInstance: String, + override val message: InaccessibleMessage, + override val data: String +) : DataCallbackQuery, InaccessibleMessageCallbackQuery diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/InaccessibleMessageGameShortNameCallbackQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/InaccessibleMessageGameShortNameCallbackQuery.kt new file mode 100644 index 0000000000..bfdd364e56 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/InaccessibleMessageGameShortNameCallbackQuery.kt @@ -0,0 +1,16 @@ +package dev.inmo.tgbotapi.types.queries.callback + +import dev.inmo.tgbotapi.types.CallbackQueryIdentifier +import dev.inmo.tgbotapi.types.chat.CommonUser +import dev.inmo.tgbotapi.types.chat.User +import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.InaccessibleMessage +import dev.inmo.tgbotapi.types.message.content.MessageContent + +data class InaccessibleMessageGameShortNameCallbackQuery( + override val id: CallbackQueryIdentifier, + override val from: CommonUser, + override val chatInstance: String, + override val message: InaccessibleMessage, + override val gameShortName: String +) : GameShortNameCallbackQuery, InaccessibleMessageCallbackQuery diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/MessageCallbackQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/MessageCallbackQuery.kt index c1e15e4f28..22658fc513 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/MessageCallbackQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/MessageCallbackQuery.kt @@ -3,6 +3,6 @@ package dev.inmo.tgbotapi.types.queries.callback import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.MessageContent -sealed interface MessageCallbackQuery : CallbackQuery { - val message: ContentMessage +sealed interface MessageCallbackQuery : AbstractMessageCallbackQuery { + override val message: ContentMessage } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/RawCallbackQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/RawCallbackQuery.kt index 804a0a54a8..4e42298fda 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/RawCallbackQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/queries/callback/RawCallbackQuery.kt @@ -16,7 +16,7 @@ internal data class RawCallbackQuery( @SerialName(fromField) val from: CommonUser, @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) - val message: ContentMessage? = null, + val message: Message? = null, @SerialName(inlineMessageIdField) val inlineMessageId: InlineMessageIdentifier? = null, @SerialName("chat_instance") @@ -28,8 +28,26 @@ internal data class RawCallbackQuery( private var inited: CallbackQuery? = null fun asCallbackQuery(raw: String): CallbackQuery { return inited ?: when { - message != null && data != null -> MessageDataCallbackQuery(id, from, chatInstance, message, data) - message != null && gameShortName != null -> MessageGameShortNameCallbackQuery(id, from, chatInstance, message, gameShortName) + message != null && data != null -> when { + message is ContentMessage<*> -> MessageDataCallbackQuery(id, from, chatInstance, message, data) + message is InaccessibleMessage -> InaccessibleMessageDataCallbackQuery(id, from, chatInstance, message, data) + else -> UnknownCallbackQueryType( + id, + from, + chatInstance, + raw + ) + } + message != null && gameShortName != null -> when { + message is ContentMessage<*> -> MessageGameShortNameCallbackQuery(id, from, chatInstance, message, gameShortName) + message is InaccessibleMessage -> InaccessibleMessageGameShortNameCallbackQuery(id, from, chatInstance, message, gameShortName) + else -> UnknownCallbackQueryType( + id, + from, + chatInstance, + raw + ) + } inlineMessageId != null && data != null -> InlineMessageIdDataCallbackQuery(id, from, chatInstance, inlineMessageId, data) inlineMessageId != null && gameShortName != null -> InlineMessageIdGameShortNameCallbackQuery(id, from, chatInstance, inlineMessageId, gameShortName) else -> UnknownCallbackQueryType( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChannelPostUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChannelPostUpdate.kt index b5cbaa55b8..eeb5ad2cb7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChannelPostUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChannelPostUpdate.kt @@ -1,12 +1,12 @@ package dev.inmo.tgbotapi.types.update import dev.inmo.tgbotapi.types.UpdateIdentifier -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate data class ChannelPostUpdate( override val updateId: UpdateIdentifier, - override val data: Message + override val data: AccessibleMessage ) : BaseSentMessageUpdate { - override fun copy(newData: Message): BaseSentMessageUpdate = copy(updateId, newData) + override fun copy(newData: AccessibleMessage): BaseSentMessageUpdate = copy(updateId, newData) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MessageUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MessageUpdate.kt index 9585386627..babf6dfc31 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MessageUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MessageUpdate.kt @@ -1,12 +1,12 @@ package dev.inmo.tgbotapi.types.update import dev.inmo.tgbotapi.types.UpdateIdentifier -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate data class MessageUpdate( override val updateId: UpdateIdentifier, - override val data: Message + override val data: AccessibleMessage ) : BaseSentMessageUpdate { - override fun copy(newData: Message) = copy(updateId, newData) + override fun copy(newData: AccessibleMessage) = copy(updateId, newData) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/RawUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/RawUpdate.kt index 8b1e3fe515..7eec35e1ee 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/RawUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/RawUpdate.kt @@ -28,11 +28,11 @@ internal data class RawUpdate constructor( @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) private val edited_message: CommonMessage<*>? = null, @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) - private val message: Message? = null, + private val message: AccessibleMessage? = null, @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) private val edited_channel_post: CommonMessage<*>? = null, @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) - private val channel_post: Message? = null, + private val channel_post: AccessibleMessage? = null, private val inline_query: RawInlineQuery? = null, private val chosen_inline_result: RawChosenInlineResult? = null, private val callback_query: RawCallbackQuery? = null, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseMessageUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseMessageUpdate.kt index 5db71be2ea..8601a56f6a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseMessageUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseMessageUpdate.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.types.update.abstracts -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage interface BaseMessageUpdate : Update { - override val data: Message + override val data: AccessibleMessage } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseSentMessageUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseSentMessageUpdate.kt index 65efc5e9eb..7816e42a59 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseSentMessageUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseSentMessageUpdate.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.types.update.abstracts -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage interface BaseSentMessageUpdate : BaseMessageUpdate { - fun copy(newData: Message): BaseSentMessageUpdate + fun copy(newData: AccessibleMessage): BaseSentMessageUpdate } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/OptionalThreadId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/OptionalThreadId.kt index 2369d24ba4..bab83ae2e4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/OptionalThreadId.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/OptionalThreadId.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.utils.extensions -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.PossiblyTopicMessage -val Message.threadIdOrNull +val AccessibleMessage.threadIdOrNull get() = (this as? PossiblyTopicMessage) ?.threadId diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index ccb25f7023..f78dbe92bf 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -978,346 +978,346 @@ inline fun SecureValue.requireSecureValueWithTranslations(): SecureValueWithTran this as SecureValueWithTranslations @PreviewFeature -inline fun Message.whenAnonymousGroupContentMessageImpl(block: (AnonymousGroupContentMessageImpl) -> T) = +inline fun AccessibleMessage.whenAnonymousGroupContentMessageImpl(block: (AnonymousGroupContentMessageImpl) -> T) = asAnonymousGroupContentMessageImpl()?.let(block) @PreviewFeature -inline fun Message.asAnonymousGroupContentMessageImpl(): AnonymousGroupContentMessageImpl? = +inline fun AccessibleMessage.asAnonymousGroupContentMessageImpl(): AnonymousGroupContentMessageImpl? = this as? AnonymousGroupContentMessageImpl @PreviewFeature -inline fun Message.requireAnonymousGroupContentMessageImpl(): AnonymousGroupContentMessageImpl = +inline fun AccessibleMessage.requireAnonymousGroupContentMessageImpl(): AnonymousGroupContentMessageImpl = this as AnonymousGroupContentMessageImpl @PreviewFeature -inline fun Message.whenChannelContentMessageImpl(block: (UnconnectedFromChannelGroupContentMessageImpl) -> T) = +inline fun AccessibleMessage.whenChannelContentMessageImpl(block: (UnconnectedFromChannelGroupContentMessageImpl) -> T) = asChannelContentMessageImpl()?.let(block) @PreviewFeature -inline fun Message.asChannelContentMessageImpl(): UnconnectedFromChannelGroupContentMessageImpl? = +inline fun AccessibleMessage.asChannelContentMessageImpl(): UnconnectedFromChannelGroupContentMessageImpl? = this as? UnconnectedFromChannelGroupContentMessageImpl @PreviewFeature -inline fun Message.requireChannelContentMessageImpl(): UnconnectedFromChannelGroupContentMessageImpl = +inline fun AccessibleMessage.requireChannelContentMessageImpl(): UnconnectedFromChannelGroupContentMessageImpl = this as UnconnectedFromChannelGroupContentMessageImpl @PreviewFeature -inline fun Message.whenPassportMessage(block: (PassportMessage) -> T) = asPassportMessage()?.let(block) +inline fun AccessibleMessage.whenPassportMessage(block: (PassportMessage) -> T) = asPassportMessage()?.let(block) @PreviewFeature -inline fun Message.asPassportMessage(): PassportMessage? = this as? PassportMessage +inline fun AccessibleMessage.asPassportMessage(): PassportMessage? = this as? PassportMessage @PreviewFeature -inline fun Message.requirePassportMessage(): PassportMessage = this as PassportMessage +inline fun AccessibleMessage.requirePassportMessage(): PassportMessage = this as PassportMessage @PreviewFeature -inline fun Message.whenPrivateContentMessageImpl(block: (PrivateContentMessageImpl) -> T) = +inline fun AccessibleMessage.whenPrivateContentMessageImpl(block: (PrivateContentMessageImpl) -> T) = asPrivateContentMessageImpl()?.let(block) @PreviewFeature -inline fun Message.asPrivateContentMessageImpl(): PrivateContentMessageImpl? = +inline fun AccessibleMessage.asPrivateContentMessageImpl(): PrivateContentMessageImpl? = this as? PrivateContentMessageImpl @PreviewFeature -inline fun Message.requirePrivateContentMessageImpl(): PrivateContentMessageImpl = +inline fun AccessibleMessage.requirePrivateContentMessageImpl(): PrivateContentMessageImpl = this as PrivateContentMessageImpl @PreviewFeature -inline fun Message.whenChannelEventMessage(block: (ChannelEventMessage) -> T) = +inline fun AccessibleMessage.whenChannelEventMessage(block: (ChannelEventMessage) -> T) = asChannelEventMessage()?.let(block) @PreviewFeature -inline fun Message.asChannelEventMessage(): ChannelEventMessage? = +inline fun AccessibleMessage.asChannelEventMessage(): ChannelEventMessage? = this as? ChannelEventMessage @PreviewFeature -inline fun Message.requireChannelEventMessage(): ChannelEventMessage = +inline fun AccessibleMessage.requireChannelEventMessage(): ChannelEventMessage = this as ChannelEventMessage @PreviewFeature -inline fun Message.whenCommonGroupEventMessage(block: (CommonGroupEventMessage) -> T) = +inline fun AccessibleMessage.whenCommonGroupEventMessage(block: (CommonGroupEventMessage) -> T) = asCommonGroupEventMessage()?.let(block) @PreviewFeature -inline fun Message.asCommonGroupEventMessage(): CommonGroupEventMessage? = +inline fun AccessibleMessage.asCommonGroupEventMessage(): CommonGroupEventMessage? = this as? CommonGroupEventMessage @PreviewFeature -inline fun Message.requireCommonGroupEventMessage(): CommonGroupEventMessage = +inline fun AccessibleMessage.requireCommonGroupEventMessage(): CommonGroupEventMessage = this as CommonGroupEventMessage @PreviewFeature -inline fun Message.whenCommonSupergroupEventMessage(block: (CommonSupergroupEventMessage) -> T) = +inline fun AccessibleMessage.whenCommonSupergroupEventMessage(block: (CommonSupergroupEventMessage) -> T) = asCommonSupergroupEventMessage()?.let(block) @PreviewFeature -inline fun Message.asCommonSupergroupEventMessage(): CommonSupergroupEventMessage? = +inline fun AccessibleMessage.asCommonSupergroupEventMessage(): CommonSupergroupEventMessage? = this as? CommonSupergroupEventMessage @PreviewFeature -inline fun Message.requireCommonSupergroupEventMessage(): CommonSupergroupEventMessage = +inline fun AccessibleMessage.requireCommonSupergroupEventMessage(): CommonSupergroupEventMessage = this as CommonSupergroupEventMessage @PreviewFeature -inline fun Message.whenAnonymousGroupContentMessage(block: (AnonymousGroupContentMessage) -> T) = +inline fun AccessibleMessage.whenAnonymousGroupContentMessage(block: (AnonymousGroupContentMessage) -> T) = asAnonymousGroupContentMessage()?.let(block) @PreviewFeature -inline fun Message.asAnonymousGroupContentMessage(): AnonymousGroupContentMessage? = +inline fun AccessibleMessage.asAnonymousGroupContentMessage(): AnonymousGroupContentMessage? = this as? AnonymousGroupContentMessage @PreviewFeature -inline fun Message.requireAnonymousGroupContentMessage(): AnonymousGroupContentMessage = +inline fun AccessibleMessage.requireAnonymousGroupContentMessage(): AnonymousGroupContentMessage = this as AnonymousGroupContentMessage @PreviewFeature -inline fun Message.whenChannelContentMessage(block: (ChannelContentMessage) -> T) = +inline fun AccessibleMessage.whenChannelContentMessage(block: (ChannelContentMessage) -> T) = asChannelContentMessage()?.let(block) @PreviewFeature -inline fun Message.asChannelContentMessage(): ChannelContentMessage? = +inline fun AccessibleMessage.asChannelContentMessage(): ChannelContentMessage? = this as? ChannelContentMessage @PreviewFeature -inline fun Message.requireChannelContentMessage(): ChannelContentMessage = +inline fun AccessibleMessage.requireChannelContentMessage(): ChannelContentMessage = this as ChannelContentMessage @PreviewFeature -inline fun Message.whenConnectedFromChannelGroupContentMessage(block: (ConnectedFromChannelGroupContentMessage) -> T) = +inline fun AccessibleMessage.whenConnectedFromChannelGroupContentMessage(block: (ConnectedFromChannelGroupContentMessage) -> T) = asConnectedFromChannelGroupContentMessage()?.let(block) @PreviewFeature -inline fun Message.asConnectedFromChannelGroupContentMessage(): ConnectedFromChannelGroupContentMessage? = +inline fun AccessibleMessage.asConnectedFromChannelGroupContentMessage(): ConnectedFromChannelGroupContentMessage? = this as? ConnectedFromChannelGroupContentMessage @PreviewFeature -inline fun Message.requireConnectedFromChannelGroupContentMessage(): ConnectedFromChannelGroupContentMessage = +inline fun AccessibleMessage.requireConnectedFromChannelGroupContentMessage(): ConnectedFromChannelGroupContentMessage = this as ConnectedFromChannelGroupContentMessage @PreviewFeature -inline fun Message.whenUnconnectedFromChannelGroupContentMessage(block: (UnconnectedFromChannelGroupContentMessage) -> T) = +inline fun AccessibleMessage.whenUnconnectedFromChannelGroupContentMessage(block: (UnconnectedFromChannelGroupContentMessage) -> T) = asUnconnectedFromChannelGroupContentMessage()?.let(block) @PreviewFeature -inline fun Message.asUnconnectedFromChannelGroupContentMessage(): UnconnectedFromChannelGroupContentMessage? = +inline fun AccessibleMessage.asUnconnectedFromChannelGroupContentMessage(): UnconnectedFromChannelGroupContentMessage? = this as? UnconnectedFromChannelGroupContentMessage @PreviewFeature -inline fun Message.requireUnconnectedFromChannelGroupContentMessage(): UnconnectedFromChannelGroupContentMessage = +inline fun AccessibleMessage.requireUnconnectedFromChannelGroupContentMessage(): UnconnectedFromChannelGroupContentMessage = this as UnconnectedFromChannelGroupContentMessage @PreviewFeature -inline fun Message.whenChatEventMessage(block: (ChatEventMessage) -> T) = +inline fun AccessibleMessage.whenChatEventMessage(block: (ChatEventMessage) -> T) = asChatEventMessage()?.let(block) @PreviewFeature -inline fun Message.asChatEventMessage(): ChatEventMessage? = this as? ChatEventMessage +inline fun AccessibleMessage.asChatEventMessage(): ChatEventMessage? = this as? ChatEventMessage @PreviewFeature -inline fun Message.requireChatEventMessage(): ChatEventMessage = this as ChatEventMessage +inline fun AccessibleMessage.requireChatEventMessage(): ChatEventMessage = this as ChatEventMessage @PreviewFeature -inline fun Message.whenCommonGroupContentMessage(block: (CommonGroupContentMessage) -> T) = +inline fun AccessibleMessage.whenCommonGroupContentMessage(block: (CommonGroupContentMessage) -> T) = asCommonGroupContentMessage()?.let(block) @PreviewFeature -inline fun Message.asCommonGroupContentMessage(): CommonGroupContentMessage? = +inline fun AccessibleMessage.asCommonGroupContentMessage(): CommonGroupContentMessage? = this as? CommonGroupContentMessage @PreviewFeature -inline fun Message.requireCommonGroupContentMessage(): CommonGroupContentMessage = +inline fun AccessibleMessage.requireCommonGroupContentMessage(): CommonGroupContentMessage = this as CommonGroupContentMessage @PreviewFeature -inline fun Message.whenCommonMessage(block: (CommonMessage) -> T) = asCommonMessage()?.let(block) +inline fun AccessibleMessage.whenCommonMessage(block: (CommonMessage) -> T) = asCommonMessage()?.let(block) @PreviewFeature -inline fun Message.asCommonMessage(): CommonMessage? = this as? CommonMessage +inline fun AccessibleMessage.asCommonMessage(): CommonMessage? = this as? CommonMessage @PreviewFeature -inline fun Message.requireCommonMessage(): CommonMessage = this as CommonMessage +inline fun AccessibleMessage.requireCommonMessage(): CommonMessage = this as CommonMessage @PreviewFeature -inline fun Message.whenContentMessage(block: (ContentMessage) -> T) = asContentMessage()?.let(block) +inline fun AccessibleMessage.whenContentMessage(block: (ContentMessage) -> T) = asContentMessage()?.let(block) @PreviewFeature -inline fun Message.asContentMessage(): ContentMessage? = this as? ContentMessage +inline fun AccessibleMessage.asContentMessage(): ContentMessage? = this as? ContentMessage @PreviewFeature -inline fun Message.requireContentMessage(): ContentMessage = this as ContentMessage +inline fun AccessibleMessage.requireContentMessage(): ContentMessage = this as ContentMessage @PreviewFeature -inline fun Message.whenFromChannelGroupContentMessage(block: (FromChannelGroupContentMessage) -> T) = +inline fun AccessibleMessage.whenFromChannelGroupContentMessage(block: (FromChannelGroupContentMessage) -> T) = asFromChannelGroupContentMessage()?.let(block) @PreviewFeature -inline fun Message.asFromChannelGroupContentMessage(): FromChannelGroupContentMessage? = +inline fun AccessibleMessage.asFromChannelGroupContentMessage(): FromChannelGroupContentMessage? = this as? FromChannelGroupContentMessage @PreviewFeature -inline fun Message.requireFromChannelGroupContentMessage(): FromChannelGroupContentMessage = +inline fun AccessibleMessage.requireFromChannelGroupContentMessage(): FromChannelGroupContentMessage = this as FromChannelGroupContentMessage @PreviewFeature -inline fun Message.whenGroupEventMessage(block: (GroupEventMessage) -> T) = +inline fun AccessibleMessage.whenGroupEventMessage(block: (GroupEventMessage) -> T) = asGroupEventMessage()?.let(block) @PreviewFeature -inline fun Message.asGroupEventMessage(): GroupEventMessage? = this as? GroupEventMessage +inline fun AccessibleMessage.asGroupEventMessage(): GroupEventMessage? = this as? GroupEventMessage @PreviewFeature -inline fun Message.requireGroupEventMessage(): GroupEventMessage = this as GroupEventMessage +inline fun AccessibleMessage.requireGroupEventMessage(): GroupEventMessage = this as GroupEventMessage @PreviewFeature -inline fun Message.whenPrivateEventMessage(block: (PrivateEventMessage) -> T) = +inline fun AccessibleMessage.whenPrivateEventMessage(block: (PrivateEventMessage) -> T) = asPrivateEventMessage()?.let(block) @PreviewFeature -inline fun Message.asPrivateEventMessage(): PrivateEventMessage? = +inline fun AccessibleMessage.asPrivateEventMessage(): PrivateEventMessage? = this as? PrivateEventMessage @PreviewFeature -inline fun Message.requirePrivateEventMessage(): PrivateEventMessage = +inline fun AccessibleMessage.requirePrivateEventMessage(): PrivateEventMessage = this as PrivateEventMessage @PreviewFeature -inline fun Message.whenGroupContentMessage(block: (GroupContentMessage) -> T) = +inline fun AccessibleMessage.whenGroupContentMessage(block: (GroupContentMessage) -> T) = asGroupContentMessage()?.let(block) @PreviewFeature -inline fun Message.asGroupContentMessage(): GroupContentMessage? = +inline fun AccessibleMessage.asGroupContentMessage(): GroupContentMessage? = this as? GroupContentMessage @PreviewFeature -inline fun Message.requireGroupContentMessage(): GroupContentMessage = +inline fun AccessibleMessage.requireGroupContentMessage(): GroupContentMessage = this as GroupContentMessage @PreviewFeature -inline fun Message.whenMediaGroupMessage(block: (MediaGroupMessage) -> T) = +inline fun AccessibleMessage.whenMediaGroupMessage(block: (MediaGroupMessage) -> T) = asMediaGroupMessage()?.let(block) @PreviewFeature -inline fun Message.asMediaGroupMessage(): MediaGroupMessage? = +inline fun AccessibleMessage.asMediaGroupMessage(): MediaGroupMessage? = this as? MediaGroupMessage @PreviewFeature -inline fun Message.requireMediaGroupMessage(): MediaGroupMessage = +inline fun AccessibleMessage.requireMediaGroupMessage(): MediaGroupMessage = this as MediaGroupMessage @PreviewFeature -inline fun Message.whenPossiblyEditedMessage(block: (PossiblyEditedMessage) -> T) = +inline fun AccessibleMessage.whenPossiblyEditedMessage(block: (PossiblyEditedMessage) -> T) = asPossiblyEditedMessage()?.let(block) @PreviewFeature -inline fun Message.asPossiblyEditedMessage(): PossiblyEditedMessage? = this as? PossiblyEditedMessage +inline fun AccessibleMessage.asPossiblyEditedMessage(): PossiblyEditedMessage? = this as? PossiblyEditedMessage @PreviewFeature -inline fun Message.requirePossiblyEditedMessage(): PossiblyEditedMessage = this as PossiblyEditedMessage +inline fun AccessibleMessage.requirePossiblyEditedMessage(): PossiblyEditedMessage = this as PossiblyEditedMessage @PreviewFeature -inline fun Message.whenPossiblyReplyMessage(block: (PossiblyReplyMessage) -> T) = +inline fun AccessibleMessage.whenPossiblyReplyMessage(block: (PossiblyReplyMessage) -> T) = asPossiblyReplyMessage()?.let(block) @PreviewFeature -inline fun Message.asPossiblyReplyMessage(): PossiblyReplyMessage? = this as? PossiblyReplyMessage +inline fun AccessibleMessage.asPossiblyReplyMessage(): PossiblyReplyMessage? = this as? PossiblyReplyMessage @PreviewFeature -inline fun Message.requirePossiblyReplyMessage(): PossiblyReplyMessage = this as PossiblyReplyMessage +inline fun AccessibleMessage.requirePossiblyReplyMessage(): PossiblyReplyMessage = this as PossiblyReplyMessage @PreviewFeature -inline fun Message.whenPossiblyForwardedMessage(block: (PossiblyForwardedMessage) -> T) = +inline fun AccessibleMessage.whenPossiblyForwardedMessage(block: (PossiblyForwardedMessage) -> T) = asPossiblyForwardedMessage()?.let(block) @PreviewFeature -inline fun Message.asPossiblyForwardedMessage(): PossiblyForwardedMessage? = this as? PossiblyForwardedMessage +inline fun AccessibleMessage.asPossiblyForwardedMessage(): PossiblyForwardedMessage? = this as? PossiblyForwardedMessage @PreviewFeature -inline fun Message.requirePossiblyForwardedMessage(): PossiblyForwardedMessage = this as PossiblyForwardedMessage +inline fun AccessibleMessage.requirePossiblyForwardedMessage(): PossiblyForwardedMessage = this as PossiblyForwardedMessage @PreviewFeature -inline fun Message.whenPossiblyPaymentMessage(block: (PossiblyPaymentMessage) -> T) = +inline fun AccessibleMessage.whenPossiblyPaymentMessage(block: (PossiblyPaymentMessage) -> T) = asPossiblyPaymentMessage()?.let(block) @PreviewFeature -inline fun Message.asPossiblyPaymentMessage(): PossiblyPaymentMessage? = this as? PossiblyPaymentMessage +inline fun AccessibleMessage.asPossiblyPaymentMessage(): PossiblyPaymentMessage? = this as? PossiblyPaymentMessage @PreviewFeature -inline fun Message.requirePossiblyPaymentMessage(): PossiblyPaymentMessage = this as PossiblyPaymentMessage +inline fun AccessibleMessage.requirePossiblyPaymentMessage(): PossiblyPaymentMessage = this as PossiblyPaymentMessage @PreviewFeature -inline fun Message.whenPrivateContentMessage(block: (PrivateContentMessage) -> T) = +inline fun AccessibleMessage.whenPrivateContentMessage(block: (PrivateContentMessage) -> T) = asPrivateContentMessage()?.let(block) @PreviewFeature -inline fun Message.asPrivateContentMessage(): PrivateContentMessage? = +inline fun AccessibleMessage.asPrivateContentMessage(): PrivateContentMessage? = this as? PrivateContentMessage @PreviewFeature -inline fun Message.requirePrivateContentMessage(): PrivateContentMessage = +inline fun AccessibleMessage.requirePrivateContentMessage(): PrivateContentMessage = this as PrivateContentMessage @PreviewFeature -inline fun Message.whenPublicContentMessage(block: (PublicContentMessage) -> T) = +inline fun AccessibleMessage.whenPublicContentMessage(block: (PublicContentMessage) -> T) = asPublicContentMessage()?.let(block) @PreviewFeature -inline fun Message.asPublicContentMessage(): PublicContentMessage? = +inline fun AccessibleMessage.asPublicContentMessage(): PublicContentMessage? = this as? PublicContentMessage @PreviewFeature -inline fun Message.requirePublicContentMessage(): PublicContentMessage = +inline fun AccessibleMessage.requirePublicContentMessage(): PublicContentMessage = this as PublicContentMessage @PreviewFeature -inline fun Message.whenSignedMessage(block: (SignedMessage) -> T) = asSignedMessage()?.let(block) +inline fun AccessibleMessage.whenSignedMessage(block: (SignedMessage) -> T) = asSignedMessage()?.let(block) @PreviewFeature -inline fun Message.asSignedMessage(): SignedMessage? = this as? SignedMessage +inline fun AccessibleMessage.asSignedMessage(): SignedMessage? = this as? SignedMessage @PreviewFeature -inline fun Message.requireSignedMessage(): SignedMessage = this as SignedMessage +inline fun AccessibleMessage.requireSignedMessage(): SignedMessage = this as SignedMessage @PreviewFeature -inline fun Message.whenSupergroupEventMessage(block: (SupergroupEventMessage) -> T) = +inline fun AccessibleMessage.whenSupergroupEventMessage(block: (SupergroupEventMessage) -> T) = asSupergroupEventMessage()?.let(block) @PreviewFeature -inline fun Message.asSupergroupEventMessage(): SupergroupEventMessage? = +inline fun AccessibleMessage.asSupergroupEventMessage(): SupergroupEventMessage? = this as? SupergroupEventMessage @PreviewFeature -inline fun Message.requireSupergroupEventMessage(): SupergroupEventMessage = +inline fun AccessibleMessage.requireSupergroupEventMessage(): SupergroupEventMessage = this as SupergroupEventMessage @PreviewFeature -inline fun Message.whenUnknownMessageType(block: (UnknownMessageType) -> T) = asUnknownMessageType()?.let(block) +inline fun AccessibleMessage.whenUnknownMessageType(block: (UnknownMessageType) -> T) = asUnknownMessageType()?.let(block) @PreviewFeature -inline fun Message.asUnknownMessageType(): UnknownMessageType? = this as? UnknownMessageType +inline fun AccessibleMessage.asUnknownMessageType(): UnknownMessageType? = this as? UnknownMessageType @PreviewFeature -inline fun Message.requireUnknownMessageType(): UnknownMessageType = this as UnknownMessageType +inline fun AccessibleMessage.requireUnknownMessageType(): UnknownMessageType = this as UnknownMessageType @PreviewFeature -inline fun Message.whenPossiblySentViaBotCommonMessage(block: (PossiblySentViaBotCommonMessage) -> T) = +inline fun AccessibleMessage.whenPossiblySentViaBotCommonMessage(block: (PossiblySentViaBotCommonMessage) -> T) = asPossiblySentViaBotCommonMessage()?.let(block) @PreviewFeature -inline fun Message.asPossiblySentViaBotCommonMessage(): PossiblySentViaBotCommonMessage? = +inline fun AccessibleMessage.asPossiblySentViaBotCommonMessage(): PossiblySentViaBotCommonMessage? = this as? PossiblySentViaBotCommonMessage @PreviewFeature -inline fun Message.requirePossiblySentViaBotCommonMessage(): PossiblySentViaBotCommonMessage = +inline fun AccessibleMessage.requirePossiblySentViaBotCommonMessage(): PossiblySentViaBotCommonMessage = this as PossiblySentViaBotCommonMessage @PreviewFeature -inline fun Message.whenFromUserMessage(block: (FromUserMessage) -> T) = asFromUserMessage()?.let(block) +inline fun AccessibleMessage.whenFromUserMessage(block: (FromUserMessage) -> T) = asFromUserMessage()?.let(block) @PreviewFeature -inline fun Message.asFromUserMessage(): FromUserMessage? = this as? FromUserMessage +inline fun AccessibleMessage.asFromUserMessage(): FromUserMessage? = this as? FromUserMessage @PreviewFeature -inline fun Message.requireFromUserMessage(): FromUserMessage = this as FromUserMessage +inline fun AccessibleMessage.requireFromUserMessage(): FromUserMessage = this as FromUserMessage @PreviewFeature inline fun BotAction.whenFindLocationAction(block: (FindLocationAction) -> T) = asFindLocationAction()?.let(block) 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 67d1718676..fd267c4c88 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 @@ -260,6 +260,7 @@ import dev.inmo.tgbotapi.types.message.CommonSupergroupEventMessage import dev.inmo.tgbotapi.types.message.ForwardInfo import dev.inmo.tgbotapi.types.message.PassportMessage import dev.inmo.tgbotapi.types.message.PrivateEventMessage +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.AnonymousForumContentMessage import dev.inmo.tgbotapi.types.message.abstracts.AnonymousGroupContentMessage import dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage @@ -275,6 +276,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.FromChannelGroupContentMessage import dev.inmo.tgbotapi.types.message.abstracts.FromUserMessage 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.PossiblyEditedMessage import dev.inmo.tgbotapi.types.message.abstracts.PossiblyForwardedMessage @@ -414,9 +416,13 @@ import dev.inmo.tgbotapi.types.polls.QuizPoll import dev.inmo.tgbotapi.types.polls.RegularPoll import dev.inmo.tgbotapi.types.polls.ScheduledCloseInfo import dev.inmo.tgbotapi.types.polls.UnknownPollType +import dev.inmo.tgbotapi.types.queries.callback.AbstractMessageCallbackQuery import dev.inmo.tgbotapi.types.queries.callback.CallbackQuery import dev.inmo.tgbotapi.types.queries.callback.DataCallbackQuery import dev.inmo.tgbotapi.types.queries.callback.GameShortNameCallbackQuery +import dev.inmo.tgbotapi.types.queries.callback.InaccessibleMessageCallbackQuery +import dev.inmo.tgbotapi.types.queries.callback.InaccessibleMessageDataCallbackQuery +import dev.inmo.tgbotapi.types.queries.callback.InaccessibleMessageGameShortNameCallbackQuery import dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdCallbackQuery import dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdDataCallbackQuery import dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdGameShortNameCallbackQuery @@ -841,6 +847,16 @@ public inline fun WithUser.pollAnswerOrThrow(): PollAnswer = this as public inline fun WithUser.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 WithUser.abstractMessageCallbackQueryOrThrow(): AbstractMessageCallbackQuery = + this as dev.inmo.tgbotapi.types.queries.callback.AbstractMessageCallbackQuery + +public inline fun + WithUser.ifAbstractMessageCallbackQuery(block: (AbstractMessageCallbackQuery) -> T): T? = + abstractMessageCallbackQueryOrNull() ?.let(block) + public inline fun WithUser.callbackQueryOrNull(): CallbackQuery? = this as? dev.inmo.tgbotapi.types.queries.callback.CallbackQuery @@ -878,6 +894,42 @@ public inline fun WithUser.ifGameShortNameCallbackQuery(block: (GameShortNameCallbackQuery) -> T): T? = gameShortNameCallbackQueryOrNull() ?.let(block) +public inline fun WithUser.inaccessibleMessageCallbackQueryOrNull(): + InaccessibleMessageCallbackQuery? = this as? + dev.inmo.tgbotapi.types.queries.callback.InaccessibleMessageCallbackQuery + +public inline fun WithUser.inaccessibleMessageCallbackQueryOrThrow(): + InaccessibleMessageCallbackQuery = this as + dev.inmo.tgbotapi.types.queries.callback.InaccessibleMessageCallbackQuery + +public inline fun + WithUser.ifInaccessibleMessageCallbackQuery(block: (InaccessibleMessageCallbackQuery) -> T): T? + = inaccessibleMessageCallbackQueryOrNull() ?.let(block) + +public inline fun WithUser.inaccessibleMessageDataCallbackQueryOrNull(): + InaccessibleMessageDataCallbackQuery? = this as? + dev.inmo.tgbotapi.types.queries.callback.InaccessibleMessageDataCallbackQuery + +public inline fun WithUser.inaccessibleMessageDataCallbackQueryOrThrow(): + InaccessibleMessageDataCallbackQuery = this as + dev.inmo.tgbotapi.types.queries.callback.InaccessibleMessageDataCallbackQuery + +public inline fun + WithUser.ifInaccessibleMessageDataCallbackQuery(block: (InaccessibleMessageDataCallbackQuery) -> T): + T? = inaccessibleMessageDataCallbackQueryOrNull() ?.let(block) + +public inline fun WithUser.inaccessibleMessageGameShortNameCallbackQueryOrNull(): + InaccessibleMessageGameShortNameCallbackQuery? = this as? + dev.inmo.tgbotapi.types.queries.callback.InaccessibleMessageGameShortNameCallbackQuery + +public inline fun WithUser.inaccessibleMessageGameShortNameCallbackQueryOrThrow(): + InaccessibleMessageGameShortNameCallbackQuery = this as + dev.inmo.tgbotapi.types.queries.callback.InaccessibleMessageGameShortNameCallbackQuery + +public inline fun + WithUser.ifInaccessibleMessageGameShortNameCallbackQuery(block: (InaccessibleMessageGameShortNameCallbackQuery) -> T): + T? = inaccessibleMessageGameShortNameCallbackQueryOrNull() ?.let(block) + public inline fun WithUser.inlineMessageIdCallbackQueryOrNull(): InlineMessageIdCallbackQuery? = this as? dev.inmo.tgbotapi.types.queries.callback.InlineMessageIdCallbackQuery @@ -3396,6 +3448,24 @@ public inline fun Message.ifCommonForumContentMessage(block: (CommonForumContentMessage) -> T): T? = commonForumContentMessageOrNull() ?.let(block) +public inline fun Message.accessibleMessageOrNull(): AccessibleMessage? = this as? + dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage + +public inline fun Message.accessibleMessageOrThrow(): AccessibleMessage = this as + dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage + +public inline fun Message.ifAccessibleMessage(block: (AccessibleMessage) -> T): T? = + accessibleMessageOrNull() ?.let(block) + +public inline fun Message.inaccessibleMessageOrNull(): InaccessibleMessage? = this as? + dev.inmo.tgbotapi.types.message.abstracts.InaccessibleMessage + +public inline fun Message.inaccessibleMessageOrThrow(): InaccessibleMessage = this as + dev.inmo.tgbotapi.types.message.abstracts.InaccessibleMessage + +public inline fun Message.ifInaccessibleMessage(block: (InaccessibleMessage) -> T): T? = + inaccessibleMessageOrNull() ?.let(block) + public inline fun Message.unknownMessageTypeOrNull(): UnknownMessageType? = this as? dev.inmo.tgbotapi.types.message.abstracts.UnknownMessageType diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/Same.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/Same.kt index 360d71c6f4..a8d3eb25ea 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/Same.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/Same.kt @@ -8,7 +8,7 @@ import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.MessageThreadId import dev.inmo.tgbotapi.types.Username import dev.inmo.tgbotapi.types.chat.Chat -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.threadId import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull @@ -32,43 +32,43 @@ inline fun WithPreviewChat.sameChat(chat: Chat) = * @return true in case if [this] message is placed in the same chat that [other] */ @Suppress("NOTHING_TO_INLINE") -inline fun WithPreviewChat.sameChat(other: Message) = sameChat(other.chat) +inline fun WithPreviewChat.sameChat(other: AccessibleMessage) = sameChat(other.chat) /** - * @return true in case if [this] message is from the same chat (with id == [chatId]) and [this] [Message.messageId] + * @return true in case if [this] message is from the same chat (with id == [chatId]) and [this] [AccessibleMessage.messageId] * equal [messageId] identifier */ @Suppress("NOTHING_TO_INLINE") -inline fun Message.sameMessage( +inline fun AccessibleMessage.sameMessage( chatId: ChatIdentifier, messageId: MessageId ) = sameChat(chatId) && this.messageId == messageId /** - * @return true in case if [this] message is from the same [chat] and [this] [Message.messageId] equal [messageId] + * @return true in case if [this] message is from the same [chat] and [this] [AccessibleMessage.messageId] equal [messageId] * identifier */ @Suppress("NOTHING_TO_INLINE") -inline fun Message.sameMessage( +inline fun AccessibleMessage.sameMessage( chat: Chat, messageId: MessageId ) = sameChat(chat) && this.messageId == messageId /** * @return true in case if [this] message is the same as [other]. The same here means that these messages from one chat - * and have equal [Message.messageId] identifier + * and have equal [AccessibleMessage.messageId] identifier */ @Suppress("NOTHING_TO_INLINE") -inline fun Message.sameMessage(other: Message) = sameMessage(other.chat, other.messageId) +inline fun AccessibleMessage.sameMessage(other: AccessibleMessage) = sameMessage(other.chat, other.messageId) /** * Thread is the same thing that topic * * @return true in case if [this] message is in the chat [chatId] and topic [threadId]. The same here means that these - * messages from one chat and have equal [Message.threadIdOrNull] identifier + * messages from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier */ @Suppress("NOTHING_TO_INLINE") -inline fun Message.sameTopic( +inline fun AccessibleMessage.sameTopic( chatId: ChatIdentifier, threadId: MessageThreadId? = chatId.threadId ) = sameChat(chatId) && threadIdOrNull == threadId @@ -77,10 +77,10 @@ inline fun Message.sameTopic( * Thread is the same thing that topic * * @return true in case if [this] message is in the chat [chatId] and topic [threadId]. The same here means that these - * messages from one chat and have equal [Message.threadIdOrNull] identifier + * messages from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier */ @Suppress("NOTHING_TO_INLINE") -inline fun Message.sameThread( +inline fun AccessibleMessage.sameThread( chatId: ChatIdentifier, threadId: MessageThreadId? = chatId.threadId ) = sameTopic(chatId, threadId) @@ -89,10 +89,10 @@ inline fun Message.sameThread( * Thread is the same thing that topic * * @return true in case if [this] message is from the [chat] and topic [threadId]. The same here means that these - * messages from one chat and have equal [Message.threadIdOrNull] identifier + * messages from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier */ @Suppress("NOTHING_TO_INLINE") -inline fun Message.sameTopic( +inline fun AccessibleMessage.sameTopic( chat: Chat, threadId: MessageThreadId? = chat.id.threadId ) = sameTopic(chat.id, threadId) @@ -101,10 +101,10 @@ inline fun Message.sameTopic( * Thread is the same thing that topic * * @return true in case if [this] message is from the [chat] and topic [threadId]. The same here means that these - * messages from one chat and have equal [Message.threadIdOrNull] identifier + * messages from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier */ @Suppress("NOTHING_TO_INLINE") -inline fun Message.sameThread( +inline fun AccessibleMessage.sameThread( chat: Chat, threadId: MessageThreadId? = chat.id.threadId ) = sameThread(chat.id, threadId) @@ -113,16 +113,16 @@ inline fun Message.sameThread( * Thread is the same thing that topic * * @return true in case if [this] message is from the same chat and topic as [other]. The same here means that these - * messages from one chat and have equal [Message.threadIdOrNull] identifier + * messages from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier */ @Suppress("NOTHING_TO_INLINE") -inline fun Message.sameTopic(other: Message) = sameTopic(other.chat, other.threadIdOrNull) +inline fun AccessibleMessage.sameTopic(other: AccessibleMessage) = sameTopic(other.chat, other.threadIdOrNull) /** * Thread is the same thing that topic * * @return true in case if [this] message is in the same topic as the [other]. The same here means that these messages - * from one chat and have equal [Message.threadIdOrNull] identifier + * from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier */ @Suppress("NOTHING_TO_INLINE") -inline fun Message.sameThread(other: Message) = sameTopic(other) +inline fun AccessibleMessage.sameThread(other: AccessibleMessage) = sameTopic(other) diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt index b7831999b9..dae6a94efb 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt @@ -18,9 +18,8 @@ import dev.inmo.tgbotapi.utils.PreviewFeature fun CallbackQuery.sourceChat() = when (this) { is InlineMessageIdDataCallbackQuery -> null - is MessageDataCallbackQuery -> message.chat + is AbstractMessageCallbackQuery -> message.chat is InlineMessageIdGameShortNameCallbackQuery -> null - is MessageGameShortNameCallbackQuery -> message.chat is UnknownCallbackQueryType -> null } 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 ca069ef5c4..9b65ae7a90 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt @@ -11,6 +11,7 @@ import dev.inmo.tgbotapi.types.location.Location import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.voice.* import dev.inmo.tgbotapi.types.message.abstracts.ConnectedFromChannelGroupContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList @@ -22,58 +23,58 @@ import dev.inmo.tgbotapi.types.venue.Venue import dev.inmo.tgbotapi.utils.RiskFeature @RiskFeature(RawFieldsUsageWarning) -inline val Message.from: User? +inline val AccessibleMessage.from: User? get() = asFromUser() ?.from @RiskFeature(RawFieldsUsageWarning) -inline val Message.sender_chat: PublicChat? +inline val AccessibleMessage.sender_chat: PublicChat? get() = asFromChannelGroupContentMessage() ?.senderChat @RiskFeature(RawFieldsUsageWarning) -inline val Message.forward_from: User? +inline val AccessibleMessage.forward_from: User? get() = asPossiblyForwardedMessage() ?.forwardInfo ?.asUserForwardInfo() ?.from @RiskFeature(RawFieldsUsageWarning) -inline val Message.forward_from_chat: Chat? +inline val AccessibleMessage.forward_from_chat: Chat? get() = asPossiblyForwardedMessage() ?.forwardInfo ?.asForwardFromPublicChatInfo() ?.chat @RiskFeature(RawFieldsUsageWarning) -inline val Message.forward_from_message_id: MessageId? +inline val AccessibleMessage.forward_from_message_id: MessageId? get() = asPossiblyForwardedMessage() ?.forwardInfo ?.fromChannelOrNull() ?.messageId @RiskFeature(RawFieldsUsageWarning) -inline val Message.forward_signature: ForwardSignature? +inline val AccessibleMessage.forward_signature: ForwardSignature? get() = asPossiblyForwardedMessage() ?.forwardInfo ?.fromChannelOrNull() ?.signature @RiskFeature(RawFieldsUsageWarning) -inline val Message.forward_sender_name: ForwardSenderName? +inline val AccessibleMessage.forward_sender_name: ForwardSenderName? get() = asPossiblyForwardedMessage() ?.forwardInfo ?.asAnonymousForwardInfo() ?.senderName @RiskFeature(RawFieldsUsageWarning) -inline val Message.forward_date: TelegramDate? +inline val AccessibleMessage.forward_date: TelegramDate? get() = asPossiblyForwardedMessage() ?.forwardInfo ?.dateOfOriginal @RiskFeature(RawFieldsUsageWarning) -inline val Message.is_automatic_forward: Boolean? +inline val AccessibleMessage.is_automatic_forward: Boolean? get() = this is ConnectedFromChannelGroupContentMessage<*> @RiskFeature(RawFieldsUsageWarning) -inline val Message.reply_to_message: Message? +inline val AccessibleMessage.reply_to_message: AccessibleMessage? get() = asPossiblyReplyMessage() ?.replyTo @RiskFeature(RawFieldsUsageWarning) -inline val Message.via_bot: CommonBot? +inline val AccessibleMessage.via_bot: CommonBot? get() = asPossiblySentViaBotCommonMessage() ?.senderBot @RiskFeature(RawFieldsUsageWarning) -inline val Message.edit_date: TelegramDate? +inline val AccessibleMessage.edit_date: TelegramDate? get() = asPossiblyEditedMessage() ?.editDate ?.toTelegramDate() @RiskFeature(RawFieldsUsageWarning) -inline val Message.has_protected_content: Boolean? +inline val AccessibleMessage.has_protected_content: Boolean? get() = asContentMessage() ?.hasProtectedContent @RiskFeature(RawFieldsUsageWarning) -inline val Message.media_group_id: MediaGroupIdentifier? +inline val AccessibleMessage.media_group_id: MediaGroupIdentifier? get() = asMediaGroupMessage() ?.mediaGroupId @RiskFeature(RawFieldsUsageWarning) -inline val Message.author_signature: AuthorSignature? +inline val AccessibleMessage.author_signature: AuthorSignature? get() = asSignedMessage() ?.authorSignature @RiskFeature(RawFieldsUsageWarning) -inline val Message.text: String? +inline val AccessibleMessage.text: String? get() = asContentMessage() ?.content ?.asTextContent() ?.text @RiskFeature(RawFieldsUsageWarning) -inline val Message.entities: TextSourcesList? +inline val AccessibleMessage.entities: TextSourcesList? get() = asContentMessage() ?.content ?.asTextContent() ?.textSources @RiskFeature(RawFieldsUsageWarning) -inline val Message.caption: String? +inline val AccessibleMessage.caption: String? get() = whenContentMessage { if (it.content !is TextContent) { it.content.asTextedInput() ?.text @@ -82,7 +83,7 @@ inline val Message.caption: String? } } @RiskFeature(RawFieldsUsageWarning) -inline val Message.caption_entities: TextSourcesList? +inline val AccessibleMessage.caption_entities: TextSourcesList? get() = whenContentMessage { if (it.content !is TextContent) { it.content.asTextedInput() ?.textSources @@ -91,117 +92,117 @@ inline val Message.caption_entities: TextSourcesList? } } @RiskFeature(RawFieldsUsageWarning) -inline val Message.audio: AudioFile? +inline val AccessibleMessage.audio: AudioFile? get() = asContentMessage() ?.content ?.asAudioContent() ?.media @RiskFeature(RawFieldsUsageWarning) -inline val Message.document: DocumentFile? +inline val AccessibleMessage.document: DocumentFile? get() = asContentMessage() ?.content ?.asDocumentContent() ?.media @RiskFeature(RawFieldsUsageWarning) -inline val Message.animation: AnimationFile? +inline val AccessibleMessage.animation: AnimationFile? get() = asContentMessage() ?.content ?.asAnimationContent() ?.media @RiskFeature(RawFieldsUsageWarning) -inline val Message.game: Game? +inline val AccessibleMessage.game: Game? get() = asContentMessage() ?.content ?.asGameContent() ?.game @RiskFeature(RawFieldsUsageWarning) -inline val Message.photo: Photo? +inline val AccessibleMessage.photo: Photo? get() = asContentMessage() ?.content ?.asPhotoContent() ?.mediaCollection @RiskFeature(RawFieldsUsageWarning) -inline val Message.sticker: Sticker? +inline val AccessibleMessage.sticker: Sticker? get() = asContentMessage() ?.content ?.asStickerContent() ?.media @RiskFeature(RawFieldsUsageWarning) -inline val Message.video: VideoFile? +inline val AccessibleMessage.video: VideoFile? get() = asContentMessage() ?.content ?.asVideoContent() ?.media @RiskFeature(RawFieldsUsageWarning) -inline val Message.voice: VoiceFile? +inline val AccessibleMessage.voice: VoiceFile? get() = asContentMessage() ?.content ?.asVoiceContent() ?.media @RiskFeature(RawFieldsUsageWarning) -inline val Message.video_note: VideoNoteFile? +inline val AccessibleMessage.video_note: VideoNoteFile? get() = asContentMessage() ?.content ?.asVideoNoteContent() ?.media @RiskFeature(RawFieldsUsageWarning) -inline val Message.contact: Contact? +inline val AccessibleMessage.contact: Contact? get() = asContentMessage() ?.content ?.asContactContent() ?.contact @RiskFeature(RawFieldsUsageWarning) -inline val Message.location: Location? +inline val AccessibleMessage.location: Location? get() = asContentMessage() ?.content ?.asLocationContent() ?.location @RiskFeature(RawFieldsUsageWarning) -inline val Message.venue: Venue? +inline val AccessibleMessage.venue: Venue? get() = asContentMessage() ?.content ?.asVenueContent() ?.venue @RiskFeature(RawFieldsUsageWarning) -inline val Message.poll: Poll? +inline val AccessibleMessage.poll: Poll? get() = asContentMessage() ?.content ?.asPollContent() ?.poll @RiskFeature(RawFieldsUsageWarning) -inline val Message.invoice: Invoice? +inline val AccessibleMessage.invoice: Invoice? get() = asContentMessage() ?.content ?.asInvoiceContent() ?.invoice @RiskFeature(RawFieldsUsageWarning) -inline val Message.dice: Dice? +inline val AccessibleMessage.dice: Dice? get() = asContentMessage() ?.content ?.asDiceContent() ?.dice @RiskFeature(RawFieldsUsageWarning) -inline val Message.new_chat_members: List? +inline val AccessibleMessage.new_chat_members: List? get() = asChatEventMessage() ?.chatEvent ?.asNewChatMembers() ?.members @RiskFeature(RawFieldsUsageWarning) -inline val Message.left_chat_member: User? +inline val AccessibleMessage.left_chat_member: User? get() = asChatEventMessage() ?.chatEvent ?.asLeftChatMember() ?.user @RiskFeature(RawFieldsUsageWarning) -inline val Message.new_chat_title: String? +inline val AccessibleMessage.new_chat_title: String? get() = asChatEventMessage() ?.chatEvent ?.asNewChatTitle() ?.title @RiskFeature(RawFieldsUsageWarning) -inline val Message.new_chat_photo: Photo? +inline val AccessibleMessage.new_chat_photo: Photo? get() = asChatEventMessage() ?.chatEvent ?.asNewChatPhoto() ?.photo @RiskFeature(RawFieldsUsageWarning) -inline val Message.delete_chat_photo: Boolean +inline val AccessibleMessage.delete_chat_photo: Boolean get() = asChatEventMessage() ?.chatEvent is DeleteChatPhoto @RiskFeature(RawFieldsUsageWarning) -inline val Message.group_chat_created: Boolean +inline val AccessibleMessage.group_chat_created: Boolean get() = asChatEventMessage() ?.chatEvent is GroupChatCreated @RiskFeature(RawFieldsUsageWarning) -inline val Message.supergroup_chat_created: Boolean +inline val AccessibleMessage.supergroup_chat_created: Boolean get() = asChatEventMessage() ?.chatEvent is SupergroupChatCreated @RiskFeature(RawFieldsUsageWarning) -inline val Message.channel_chat_created: Boolean +inline val AccessibleMessage.channel_chat_created: Boolean get() = asChatEventMessage() ?.chatEvent is ChannelChatCreated @RiskFeature(RawFieldsUsageWarning) -inline val Message.migrate_to_chat_id: IdChatIdentifier? +inline val AccessibleMessage.migrate_to_chat_id: IdChatIdentifier? get() = asChatEventMessage() ?.chatEvent ?.asGroupChatCreated() ?.migratedTo @RiskFeature(RawFieldsUsageWarning) -inline val Message.migrate_from_chat_id: IdChatIdentifier? +inline val AccessibleMessage.migrate_from_chat_id: IdChatIdentifier? get() = asChatEventMessage() ?.chatEvent ?.let { it ?.asSupergroupChatCreated() ?.migratedFrom ?: it ?.asMigratedToSupergroup() ?.migratedFrom } @RiskFeature(RawFieldsUsageWarning) -inline val Message.pinned_message: Message? +inline val AccessibleMessage.pinned_message: Message? get() = asChatEventMessage() ?.chatEvent ?.asPinnedMessage() ?.message @RiskFeature(RawFieldsUsageWarning) -inline val Message.successful_payment: SuccessfulPayment? +inline val AccessibleMessage.successful_payment: SuccessfulPayment? get() = asChatEventMessage() ?.chatEvent ?.asSuccessfulPaymentEvent() ?.payment @RiskFeature(RawFieldsUsageWarning) -inline val Message.video_chat_scheduled: VideoChatScheduled? +inline val AccessibleMessage.video_chat_scheduled: VideoChatScheduled? get() = asChatEventMessage() ?.chatEvent ?.asVideoChatScheduled() @RiskFeature(RawFieldsUsageWarning) -inline val Message.video_chat_started: VideoChatStarted? +inline val AccessibleMessage.video_chat_started: VideoChatStarted? get() = asChatEventMessage() ?.chatEvent ?.asVideoChatStarted() @RiskFeature(RawFieldsUsageWarning) -inline val Message.video_chat_ended: VideoChatEnded? +inline val AccessibleMessage.video_chat_ended: VideoChatEnded? get() = asChatEventMessage() ?.chatEvent ?.asVideoChatEnded() @RiskFeature(RawFieldsUsageWarning) -inline val Message.video_chat_participants_invited: VideoChatParticipantsInvited? +inline val AccessibleMessage.video_chat_participants_invited: VideoChatParticipantsInvited? get() = asChatEventMessage() ?.chatEvent ?.asVideoChatParticipantsInvited() @RiskFeature(RawFieldsUsageWarning) -inline val Message.message_auto_delete_timer_changed: MessageAutoDeleteTimerChanged? +inline val AccessibleMessage.message_auto_delete_timer_changed: MessageAutoDeleteTimerChanged? get() = asChatEventMessage() ?.chatEvent ?.asMessageAutoDeleteTimerChanged() @RiskFeature(RawFieldsUsageWarning) -inline val Message.connected_website: String? +inline val AccessibleMessage.connected_website: String? get() = asChatEventMessage() ?.chatEvent ?.asUserLoggedIn() ?.domain @RiskFeature(RawFieldsUsageWarning) -inline val Message.proximity_alert_triggered: ProximityAlertTriggered? +inline val AccessibleMessage.proximity_alert_triggered: ProximityAlertTriggered? get() = asChatEventMessage() ?.chatEvent ?.asProximityAlertTriggered() @RiskFeature(RawFieldsUsageWarning) -inline val Message.passport_data: PassportData? +inline val AccessibleMessage.passport_data: PassportData? get() = asPassportMessage() ?.passportData @RiskFeature(RawFieldsUsageWarning) -inline val Message.reply_markup: InlineKeyboardMarkup? +inline val AccessibleMessage.reply_markup: InlineKeyboardMarkup? get() = asCommonMessage() ?.replyMarkup diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt index 98bd0ccc5d..af8342df7a 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.extensions.utils.formatting import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.chat.* -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.textsources.link import io.ktor.http.encodeURLQueryComponent @@ -69,7 +69,7 @@ fun makeLinkToMessage( ): String = makeLinkToMessage(chatId.chatId, messageId, chatId.threadId) /** - * Link which can be used as by any user to get access to [Message]. Returns null in case when there are no + * Link which can be used as by any user to get access to [AccessibleMessage]. Returns null in case when there are no * known way to build link (for [PrivateChat]s, for example) */ fun makeLinkToMessage( @@ -88,7 +88,7 @@ fun makeLinkToMessage( /** * @see makeLinkToMessage */ -val Message.messageLink: String? +val AccessibleMessage.messageLink: String? get() = makeLinkToMessage( chat, messageId diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/MessageFilters.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/MessageFilters.kt index 03963a88f4..9461999457 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/MessageFilters.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/MessageFilters.kt @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.extensions.utils.updates import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage -import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull @@ -58,10 +58,10 @@ fun CommonMessage<*>.hasNoCommands(): Boolean = !this.hasCommands() * } * ``` * - * @return true if this [Message] is from forum ([threadIdOrNull] is not null). False otherwise. + * @return true if this [AccessibleMessage] is from forum ([threadIdOrNull] is not null). False otherwise. * @see notForumMessage */ -fun Message.forumMessage(): Boolean = threadIdOrNull != null +fun AccessibleMessage.forumMessage(): Boolean = threadIdOrNull != null /** * A predicate to test that message has not been sent in the forum. @@ -76,7 +76,7 @@ fun Message.forumMessage(): Boolean = threadIdOrNull != null * } * ``` * - * @return true if this [Message] is not from forum ([threadIdOrNull] is not null). False otherwise. + * @return true if this [AccessibleMessage] is not from forum ([threadIdOrNull] is not null). False otherwise. * @see forumMessage */ -fun Message.notForumMessage(): Boolean = !forumMessage() +fun AccessibleMessage.notForumMessage(): Boolean = !forumMessage()