diff --git a/CHANGELOG.md b/CHANGELOG.md index bcff6bdc64..8e4212b450 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,8 @@ * All extensions like `CaptionedInput#toHtmlCaptions` * All helper extensions for `List` * All `RequestsExecutor#executeAsync` and `RequestsExecutor#executeUnsafe` +* `TelegramBotAPI-extensions-api`: + * A lot of `RequesstExecutor#getChat` extensions was added for more explicit types showing * `TelegramBotAPI-extensions-utils`: * `safely` function was introduced. It is in `PreviewFeature` state currently * `makeLinkToMessage` extensions has been added diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/chat/get/GetChat.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/chat/get/GetChat.kt index e7912097da..528bedb4b3 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/chat/get/GetChat.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/chat/get/GetChat.kt @@ -2,8 +2,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.chat.get import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get.GetChat -import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended.* +import com.github.insanusmokrassar.TelegramBotAPI.utils.PreviewFeature suspend fun RequestsExecutor.getChat( chatId: ChatIdentifier @@ -12,3 +16,117 @@ suspend fun RequestsExecutor.getChat( suspend fun RequestsExecutor.getChat( chat: Chat ) = getChat(chat.id) + +/** + * Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a + * [ExtendedPublicChat] with unsafe operator "as" + * + * @throws ClassCastException + */ +@PreviewFeature +suspend fun RequestsExecutor.getChat( + chat: PublicChat +) = getChat(chat.id) as ExtendedPublicChat + + +/** + * Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a + * [ExtendedChannelChat] with unsafe operator "as" + * + * @throws ClassCastException + */ +@PreviewFeature +suspend fun RequestsExecutor.getChat( + chat: ChannelChat +) = getChat(chat.id) as ExtendedChannelChat + +/** + * Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a + * [ExtendedChannelChatImpl] with unsafe operator "as" + * + * @throws ClassCastException + */ +@PreviewFeature +suspend fun RequestsExecutor.getChat( + chat: ChannelChatImpl +) = getChat(chat.id) as ExtendedChannelChatImpl + + +/** + * Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a + * [ExtendedGroupChat] with unsafe operator "as" + * + * @throws ClassCastException + */ +@PreviewFeature +suspend fun RequestsExecutor.getChat( + chat: GroupChat +) = getChat(chat.id) as ExtendedGroupChat + +/** + * Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a + * [ExtendedGroupChatImpl] with unsafe operator "as" + * + * @throws ClassCastException + */ +@PreviewFeature +suspend fun RequestsExecutor.getChat( + chat: GroupChatImpl +) = getChat(chat.id) as ExtendedGroupChatImpl + + +/** + * Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a + * [ExtendedSupergroupChat] with unsafe operator "as" + * + * @throws ClassCastException + */ +@PreviewFeature +suspend fun RequestsExecutor.getChat( + chat: SupergroupChat +) = getChat(chat.id) as ExtendedSupergroupChat + +/** + * Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a + * [ExtendedSupergroupChatImpl] with unsafe operator "as" + * + * @throws ClassCastException + */ +@PreviewFeature +suspend fun RequestsExecutor.getChat( + chat: SupergroupChatImpl +) = getChat(chat.id) as ExtendedSupergroupChatImpl + + +/** + * Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a + * [ExtendedPrivateChat] with unsafe operator "as" + * + * @throws ClassCastException + */ +@PreviewFeature +suspend fun RequestsExecutor.getChat( + chat: PrivateChat +) = getChat(chat.id) as ExtendedPrivateChat + +/** + * Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a + * [ExtendedPrivateChatImpl] with unsafe operator "as" + * + * @throws ClassCastException + */ +@PreviewFeature +suspend fun RequestsExecutor.getChat( + chat: PrivateChatImpl +) = getChat(chat.id) as ExtendedPrivateChatImpl + +/** + * Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a + * [ExtendedUser] with unsafe operator "as" + * + * @throws ClassCastException + */ +@PreviewFeature +suspend fun RequestsExecutor.getChat( + chat: CommonUser +) = getChat(chat.id) as ExtendedUser