From b0c6b80d8bb87fae96bd43a3647e2d999ca59f3b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 21 Jun 2022 18:30:31 +0600 Subject: [PATCH] small improvements --- .../dev/inmo/tgbotapi/types/chat/Extended.kt | 4 ++-- .../tgbotapi/types/chat/ExtendedAbstracts.kt | 5 ++--- .../tgbotapi/extensions/utils/ClassCasts.kt | 18 ++++++++++++++++++ .../extensions/utils/extensions/raw/Sticker.kt | 2 ++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt index 957623cebd..fed027677d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt @@ -97,9 +97,9 @@ data class ExtendedSupergroupChatImpl( @SerialName(locationField) override val location: ChatLocation? = null, @SerialName(joinToSendMessagesField) - override val requireToJoinForMessaging: Boolean = false, + override val requiresJoinForMessaging: Boolean = false, @SerialName(joinByRequestField) - override val requireAdminApproveOnJoin: Boolean = false + override val requireAdminApproveToJoin: Boolean = false ) : ExtendedSupergroupChat @Serializable 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 6cb3e3979a..26cf8115ae 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 @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.chat import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.chat.ExtendedChat import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer import kotlinx.serialization.Serializable @@ -43,12 +42,12 @@ sealed interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat { /** * This field represents field "join_to_send_messages" from API */ - val requireToJoinForMessaging: Boolean + val requiresJoinForMessaging: Boolean /** * This field represents field "join_by_request" from API */ - val requireAdminApproveOnJoin: Boolean + val requireAdminApproveToJoin: Boolean } @Serializable(ExtendedChatSerializer::class) 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 9751afd056..0ea185d5b1 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 @@ -235,6 +235,24 @@ inline fun Chat.asExtendedSupergroupChat(): ExtendedSupergroupChat? = this as? E @PreviewFeature inline fun Chat.requireExtendedSupergroupChat(): ExtendedSupergroupChat = this as ExtendedSupergroupChat +@PreviewFeature +inline fun Chat.whenPremiumChat(block: (PremiumChat) -> T) = asPremiumChat() ?.let(block) + +@PreviewFeature +inline fun Chat.asPremiumChat(): PremiumChat? = this as? PremiumChat + +@PreviewFeature +inline fun Chat.requirePremiumChat(): PremiumChat = this as PremiumChat + +@PreviewFeature +inline fun Chat.whenAbleToAddInAttachmentMenuChat(block: (AbleToAddInAttachmentMenuChat) -> T) = asAbleToAddInAttachmentMenuChat() ?.let(block) + +@PreviewFeature +inline fun Chat.asAbleToAddInAttachmentMenuChat(): AbleToAddInAttachmentMenuChat? = this as? AbleToAddInAttachmentMenuChat + +@PreviewFeature +inline fun Chat.requireAbleToAddInAttachmentMenuChat(): AbleToAddInAttachmentMenuChat = this as AbleToAddInAttachmentMenuChat + @PreviewFeature inline fun CallbackQuery.whenDataCallbackQuery(block: (DataCallbackQuery) -> T) = asDataCallbackQuery() ?.let(block) diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Sticker.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Sticker.kt index 4a399695be..fadb73ea4d 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Sticker.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Sticker.kt @@ -19,3 +19,5 @@ inline val Sticker.mask_position: MaskPosition? get() = maskPosition inline val Sticker.file_size: Long? get() = fileSize +inline val Sticker.premium_animation: File? + get() = premiumAnimationFile