From 10d92c2fdbc17ce1e28f9bde09814f8b5208cf52 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 29 Aug 2024 17:54:00 +0600 Subject: [PATCH] improvements and breaking changes in ChatMember hierarchy --- CHANGELOG.md | 22 +++++ .../api/tgbotapi.behaviour_builder.api | 14 ++- .../filters/ChatMemberUpdatedFilterByEvent.kt | 6 +- .../utils/extensions/ChatMember.kt | 24 ----- tgbotapi.core/api/tgbotapi.core.api | 36 +++---- .../types/chat/member/BannedChatMember.kt | 7 -- .../tgbotapi/types/chat/member/ChatMember.kt | 5 +- .../types/chat/member/KickedChatMember.kt | 2 +- .../types/chat/member/RestrictedChatMember.kt | 97 +++++++++++-------- .../chat/member/RestrictedMemberChatMember.kt | 53 ++++++++++ tgbotapi.utils/api/tgbotapi.utils.api | 11 +-- .../tgbotapi/extensions/utils/ClassCasts.kt | 12 +-- .../extensions/utils/ClassCastsNew.kt | 10 -- .../extensions/utils/extensions/ChatMember.kt | 81 ++++++++++++++++ .../utils/extensions/ChatMemberUpdated.kt | 17 +++- 15 files changed, 266 insertions(+), 131 deletions(-) delete mode 100644 tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/extensions/ChatMember.kt delete mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/BannedChatMember.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/RestrictedMemberChatMember.kt create mode 100644 tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/ChatMember.kt rename {tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder => tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions}/utils/extensions/ChatMemberUpdated.kt (77%) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2dc1db32b..10538e2ddc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,34 @@ ## 18.0.0 +**THIS UPDATE CONTAINS BREAKING CHANGES** + +--- + +**Migration (step-by-step)** + +Replace in a whole project: + +1. `RestrictedChatMember` -> `RestrictedMemberChatMember` +2. `BannedChatMember` -> `RestrictedChatMember` + +--- + +**Changes:** + * `Version`: * `Kotlin`: `2.0.10` -> `2.0.20` * `Serialization`: `1.7.1` -> `1.7.2` * `MicroUtils`: `0.22.0` -> `0.22.1` * `KSLog`: `1.3.5` -> `1.3.6` * `Ktor`: `2.3.11` -> `2.3.12` +* `Core`: + * `RestrictedChatMember` has been renamed to `RestrictedMemberChatMember` + * `BannedChatMember` has been renamed to `RestrictedChatMember` + * `KickedChatMember` now implements `RestrictedChatMember` (due to rename) +* `Utils`: + * Add a lot of extensions like `ChatMember.isMember` + * Add a lot of extensions like `ChatMemberUpdated.joinedChat` ## 17.0.0 diff --git a/tgbotapi.behaviour_builder/api/tgbotapi.behaviour_builder.api b/tgbotapi.behaviour_builder/api/tgbotapi.behaviour_builder.api index fc6038f1c3..f1b270e1d6 100644 --- a/tgbotapi.behaviour_builder/api/tgbotapi.behaviour_builder.api +++ b/tgbotapi.behaviour_builder/api/tgbotapi.behaviour_builder.api @@ -1369,18 +1369,21 @@ public final class dev/inmo/tgbotapi/extensions/behaviour_builder/utils/Subconte } public final class dev/inmo/tgbotapi/extensions/behaviour_builder/utils/extensions/ChatMemberKt { - public static final fun getHasSpecialRights (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z public static final fun isAdministrator (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z - public static final fun isAdministratorStrict (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z + public static final fun isBanned (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z + public static final fun isCommonAdministrator (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z + public static final fun isCommonMember (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z public static final fun isKicked (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z public static final fun isKickedOrRestricted (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z public static final fun isLeft (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z public static final fun isLeftOrKicked (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z public static final fun isMember (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z - public static final fun isMemberStrict (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z public static final fun isOwner (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z public static final fun isRestricted (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z - public static final fun isSubscriber (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z + public static final fun isRestrictedAndNotKicked (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z + public static final fun isRestrictedMember (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z + public static final fun isSpecialRightsMember (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z + public static final fun isSubscriberMember (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Z } public final class dev/inmo/tgbotapi/extensions/behaviour_builder/utils/extensions/ChatMemberUpdatedKt { @@ -1395,8 +1398,9 @@ public final class dev/inmo/tgbotapi/extensions/behaviour_builder/utils/extensio public static final fun getJoinedChat (Ldev/inmo/tgbotapi/types/chat/member/ChatMemberUpdated;)Z public static final fun getLeftChat (Ldev/inmo/tgbotapi/types/chat/member/ChatMemberUpdated;)Z public static final fun getSubscribed (Ldev/inmo/tgbotapi/types/chat/member/ChatMemberUpdated;)Z - public static final fun getSubscriptionChanged (Ldev/inmo/tgbotapi/types/chat/member/ChatMemberUpdated;)Z + public static final fun getSubscriptionUpdated (Ldev/inmo/tgbotapi/types/chat/member/ChatMemberUpdated;)Z public static final fun getUnsubscribed (Ldev/inmo/tgbotapi/types/chat/member/ChatMemberUpdated;)Z + public static final fun getUnsubscribedAndLeft (Ldev/inmo/tgbotapi/types/chat/member/ChatMemberUpdated;)Z } public final class dev/inmo/tgbotapi/extensions/behaviour_builder/utils/extensions/EnablePrivacyPolicyCommandKt { diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/ChatMemberUpdatedFilterByEvent.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/ChatMemberUpdatedFilterByEvent.kt index b9594dc2dc..d291a748b1 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/ChatMemberUpdatedFilterByEvent.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/ChatMemberUpdatedFilterByEvent.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.filters import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter -import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.extensions.* +import dev.inmo.tgbotapi.extensions.utils.extensions.* import dev.inmo.tgbotapi.types.chat.member.* /** @@ -26,10 +26,10 @@ val chatMemberSubscribedFilter = SimpleFilter { } /** - * Allows only member [subscriptionChanged] updates + * Allows only member [subscriptionUpdated] updates */ val chatMemberSubscriptionChangedFilter = SimpleFilter { - it.subscriptionChanged + it.subscriptionUpdated } /** diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/extensions/ChatMember.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/extensions/ChatMember.kt deleted file mode 100644 index c193aa162a..0000000000 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/extensions/ChatMember.kt +++ /dev/null @@ -1,24 +0,0 @@ -package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.extensions - -import dev.inmo.tgbotapi.types.chat.member.* - -val ChatMember.isLeft: Boolean get() = this is LeftChatMember -val ChatMember.isKicked: Boolean get() = this is KickedChatMember -val ChatMember.isLeftOrKicked: Boolean get() = isLeft || isKicked -val ChatMember.isRestricted: Boolean get() = this is RestrictedChatMember -val ChatMember.isMember: Boolean get() = this is MemberChatMember -val ChatMember.isOwner: Boolean get() = this is OwnerChatMember -val ChatMember.isSubscriber: Boolean get() = this is SubscriptionMemberChatMember -val ChatMember.isAdministrator: Boolean get() = this is AdministratorChatMember - -/** - * Checks if member is strictly [MemberChatMember], not any derivatives - */ -val ChatMember.isMemberStrict: Boolean get() = this is MemberChatMemberImpl -/** - * Checks if member is strictly [AdministratorChatMember], not any derivatives - */ -val ChatMember.isAdministratorStrict: Boolean get() = this is AdministratorChatMemberImpl - -val ChatMember.hasSpecialRights: Boolean get() = this is SpecialRightsChatMember -val ChatMember.isKickedOrRestricted: Boolean get() = this is BannedChatMember diff --git a/tgbotapi.core/api/tgbotapi.core.api b/tgbotapi.core/api/tgbotapi.core.api index a8d77e93d2..d10d8a0d42 100644 --- a/tgbotapi.core/api/tgbotapi.core.api +++ b/tgbotapi.core/api/tgbotapi.core.api @@ -15681,14 +15681,6 @@ public final class dev/inmo/tgbotapi/types/chat/member/AdministratorChatMemberSe public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V } -public abstract interface class dev/inmo/tgbotapi/types/chat/member/BannedChatMember : dev/inmo/tgbotapi/abstracts/types/UntilDate, dev/inmo/tgbotapi/types/chat/member/ChatMember { - public static final field Companion Ldev/inmo/tgbotapi/types/chat/member/BannedChatMember$Companion; -} - -public final class dev/inmo/tgbotapi/types/chat/member/BannedChatMember$Companion { - public final fun serializer ()Lkotlinx/serialization/KSerializer; -} - public abstract interface class dev/inmo/tgbotapi/types/chat/member/ChatAdministratorRights : dev/inmo/tgbotapi/types/chat/member/SpecialChatAdministratorRights { public static final field Companion Ldev/inmo/tgbotapi/types/chat/member/ChatAdministratorRights$Companion; public abstract fun getCanDeleteStories ()Z @@ -15856,7 +15848,7 @@ public final class dev/inmo/tgbotapi/types/chat/member/ChatMemberUpdated$Compani public final fun serializer ()Lkotlinx/serialization/KSerializer; } -public final class dev/inmo/tgbotapi/types/chat/member/KickedChatMember : dev/inmo/tgbotapi/types/chat/member/BannedChatMember { +public final class dev/inmo/tgbotapi/types/chat/member/KickedChatMember : dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember { public static final field Companion Ldev/inmo/tgbotapi/types/chat/member/KickedChatMember$Companion; public fun (Ldev/inmo/tgbotapi/types/chat/User;Ldev/inmo/tgbotapi/types/TelegramDate;)V public synthetic fun (Ldev/inmo/tgbotapi/types/chat/User;Ldev/inmo/tgbotapi/types/TelegramDate;ILkotlin/jvm/internal/DefaultConstructorMarker;)V @@ -16008,8 +16000,18 @@ public final class dev/inmo/tgbotapi/types/chat/member/OwnerChatMember$Companion public final fun serializer ()Lkotlinx/serialization/KSerializer; } -public final class dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember : dev/inmo/tgbotapi/types/chat/ChatPermissions, dev/inmo/tgbotapi/types/chat/member/BannedChatMember, dev/inmo/tgbotapi/types/chat/member/SpecialRightsChatMember { +public abstract interface class dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember : dev/inmo/tgbotapi/abstracts/types/UntilDate, dev/inmo/tgbotapi/types/chat/member/ChatMember { public static final field Companion Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMember$Companion; +} + +public final class dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember$Companion { + public final fun invoke (Ldev/inmo/tgbotapi/types/chat/User;Ldev/inmo/tgbotapi/types/TelegramDate;ZZZZZZZZZZZZZZZ)Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMemberImpl; + public static synthetic fun invoke$default (Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMember$Companion;Ldev/inmo/tgbotapi/types/chat/User;Ldev/inmo/tgbotapi/types/TelegramDate;ZZZZZZZZZZZZZZZILjava/lang/Object;)Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMemberImpl; + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public final class dev/inmo/tgbotapi/types/chat/member/RestrictedChatMemberImpl : dev/inmo/tgbotapi/types/chat/ChatPermissions, dev/inmo/tgbotapi/types/chat/member/MemberChatMember, dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember, dev/inmo/tgbotapi/types/chat/member/SpecialRightsChatMember { + public static final field Companion Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMemberImpl$Companion; public fun (Ldev/inmo/tgbotapi/types/chat/User;Ldev/inmo/tgbotapi/types/TelegramDate;ZZZZZZZZZZZZZZZ)V public synthetic fun (Ldev/inmo/tgbotapi/types/chat/User;Ldev/inmo/tgbotapi/types/TelegramDate;ZZZZZZZZZZZZZZZILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun component1 ()Ldev/inmo/tgbotapi/types/chat/User; @@ -16029,8 +16031,8 @@ public final class dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember : de public final fun component7 ()Z public final fun component8 ()Z public final fun component9 ()Z - public final fun copy (Ldev/inmo/tgbotapi/types/chat/User;Ldev/inmo/tgbotapi/types/TelegramDate;ZZZZZZZZZZZZZZZ)Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMember; - public static synthetic fun copy$default (Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMember;Ldev/inmo/tgbotapi/types/chat/User;Ldev/inmo/tgbotapi/types/TelegramDate;ZZZZZZZZZZZZZZZILjava/lang/Object;)Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMember; + public final fun copy (Ldev/inmo/tgbotapi/types/chat/User;Ldev/inmo/tgbotapi/types/TelegramDate;ZZZZZZZZZZZZZZZ)Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMemberImpl; + public static synthetic fun copy$default (Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMemberImpl;Ldev/inmo/tgbotapi/types/chat/User;Ldev/inmo/tgbotapi/types/TelegramDate;ZZZZZZZZZZZZZZZILjava/lang/Object;)Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMemberImpl; public fun copyCommon (Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;)Ldev/inmo/tgbotapi/types/chat/ChatPermissions; public fun copyGranular (Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;)Ldev/inmo/tgbotapi/types/chat/ChatPermissions; public fun equals (Ljava/lang/Object;)Z @@ -16062,18 +16064,18 @@ public final class dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember : de public fun toString ()Ljava/lang/String; } -public synthetic class dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember$$serializer : kotlinx/serialization/internal/GeneratedSerializer { - public static final field INSTANCE Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMember$$serializer; +public synthetic class dev/inmo/tgbotapi/types/chat/member/RestrictedChatMemberImpl$$serializer : kotlinx/serialization/internal/GeneratedSerializer { + public static final field INSTANCE Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMemberImpl$$serializer; public final fun childSerializers ()[Lkotlinx/serialization/KSerializer; - public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMember; + public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMemberImpl; public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; - public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMember;)V + public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMemberImpl;)V public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer; } -public final class dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember$Companion { +public final class dev/inmo/tgbotapi/types/chat/member/RestrictedChatMemberImpl$Companion { public final fun serializer ()Lkotlinx/serialization/KSerializer; } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/BannedChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/BannedChatMember.kt deleted file mode 100644 index b5cbb48456..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/BannedChatMember.kt +++ /dev/null @@ -1,7 +0,0 @@ -package dev.inmo.tgbotapi.types.chat.member - -import dev.inmo.tgbotapi.abstracts.types.UntilDate -import kotlinx.serialization.Serializable - -@Serializable(ChatMemberSerializer::class) -sealed interface BannedChatMember : ChatMember, UntilDate diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/ChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/ChatMember.kt index e2c67a3eba..29325c1a94 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/ChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/ChatMember.kt @@ -12,7 +12,6 @@ import kotlinx.serialization.builtins.serializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.jsonPrimitive @@ -28,7 +27,7 @@ sealed interface ChatMember : WithUser { Administrator("administrator", AdministratorChatMemberImpl.serializer()), Member("member", MemberChatMemberImpl.serializer(), { status, json -> status == "member" && json[untilDateField] ?.jsonPrimitive == null }), SubscriptionMember("member", SubscriptionMemberChatMemberImpl.serializer(), { status, json -> status == "member" && json[untilDateField] ?.jsonPrimitive != null }), - Restricted("restricted", RestrictedChatMember.serializer()), + Restricted("restricted", RestrictedMemberChatMember.serializer()), Left("left", LeftChatMemberImpl.serializer()), Kicked("kicked", KickedChatMember.serializer()) } @@ -74,7 +73,7 @@ object ChatMemberSerializer : KSerializer { is AdministratorChatMemberImpl -> AdministratorChatMemberImpl.serializer().serialize(encoder, value) is SubscriptionMemberChatMemberImpl -> SubscriptionMemberChatMemberImpl.serializer().serialize(encoder, value) is MemberChatMemberImpl -> MemberChatMemberImpl.serializer().serialize(encoder, value) - is RestrictedChatMember -> RestrictedChatMember.serializer().serialize(encoder, value) + is RestrictedMemberChatMember -> RestrictedMemberChatMember.serializer().serialize(encoder, value) is LeftChatMemberImpl -> LeftChatMemberImpl.serializer().serialize(encoder, value) is KickedChatMember -> KickedChatMember.serializer().serialize(encoder, value) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/KickedChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/KickedChatMember.kt index 2ae0b29ae0..91d0655db0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/KickedChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/KickedChatMember.kt @@ -10,7 +10,7 @@ data class KickedChatMember( override val user: User, @SerialName(untilDateField) override val untilDate: TelegramDate? = null -) : BannedChatMember { +) : RestrictedChatMember { @SerialName(statusField) @Required @EncodeDefault diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember.kt index 0167262e1a..f0002d1a96 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/RestrictedChatMember.kt @@ -1,49 +1,60 @@ package dev.inmo.tgbotapi.types.chat.member +import dev.inmo.tgbotapi.abstracts.types.UntilDate import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.chat.ChatPermissions import dev.inmo.tgbotapi.types.chat.User -import kotlinx.serialization.* +import kotlinx.serialization.Serializable -@Serializable -data class RestrictedChatMember( - @SerialName(userField) - override val user: User, - @SerialName(untilDateField) - override val untilDate: TelegramDate? = null, - @SerialName(isMemberField) - val isMember: Boolean = false, - @SerialName(canSendMessagesField) - override val canSendMessages: Boolean = false, - @SerialName(canSendAudiosField) - override val canSendAudios: Boolean = false, - @SerialName(canSendDocumentsField) - override val canSendDocuments: Boolean = false, - @SerialName(canSendPhotosField) - override val canSendPhotos: Boolean = false, - @SerialName(canSendVideosField) - override val canSendVideos: Boolean = false, - @SerialName(canSendVideoNotesField) - override val canSendVideoNotes: Boolean = false, - @SerialName(canSendVoiceNotesField) - override val canSendVoiceNotes: Boolean = false, - @SerialName(canSendPollsField) - override val canSendPolls: Boolean = false, - @SerialName(canSendOtherMessagesField) - override val canSendOtherMessages: Boolean = false, - @SerialName(canAddWebPagePreviewsField) - override val canAddWebPagePreviews: Boolean = false, - @SerialName(canChangeInfoField) - override val canChangeInfo: Boolean = false, - @SerialName(canInviteUsersField) - override val canInviteUsers: Boolean = false, - @SerialName(canPinMessagesField) - override val canPinMessages: Boolean = false, - @SerialName(canManageTopicsField) - override val canManageTopics: Boolean = false -) : BannedChatMember, SpecialRightsChatMember, ChatPermissions { - @SerialName(statusField) - @Required - @EncodeDefault - override val status: ChatMember.Status = ChatMember.Status.Restricted +@Serializable(ChatMemberSerializer::class) +sealed interface RestrictedChatMember : ChatMember, UntilDate { + companion object { + // backward compatibility fun + @Deprecated( + "Renamed", + ReplaceWith( + "RestrictedChatMemberImpl(user, untilDate, isMember, canSendMessages, canSendAudios, canSendDocuments, canSendPhotos, canSendVideos, canSendVideoNotes, canSendVoiceNotes, canSendPolls, canSendOtherMessages, canAddWebPagePreviews, canChangeInfo, canInviteUsers, canPinMessages, canManageTopics)", + "dev.inmo.tgbotapi.types.chat.members.RestrictedChatMemberImpl", + ) + ) + operator fun invoke( + user: User, + untilDate: TelegramDate? = null, + isMember: Boolean = false, + canSendMessages: Boolean = false, + canSendAudios: Boolean = false, + canSendDocuments: Boolean = false, + canSendPhotos: Boolean = false, + canSendVideos: Boolean = false, + canSendVideoNotes: Boolean = false, + canSendVoiceNotes: Boolean = false, + canSendPolls: Boolean = false, + canSendOtherMessages: Boolean = false, + canAddWebPagePreviews: Boolean = false, + canChangeInfo: Boolean = false, + canInviteUsers: Boolean = false, + canPinMessages: Boolean = false, + canManageTopics: Boolean = false + ) = RestrictedMemberChatMember( + user = user, + untilDate = untilDate, + isMember = isMember, + canSendMessages = canSendMessages, + canSendAudios = canSendAudios, + canSendDocuments = canSendDocuments, + canSendPhotos = canSendPhotos, + canSendVideos = canSendVideos, + canSendVideoNotes = canSendVideoNotes, + canSendVoiceNotes = canSendVoiceNotes, + canSendPolls = canSendPolls, + canSendOtherMessages = canSendOtherMessages, + canAddWebPagePreviews = canAddWebPagePreviews, + canChangeInfo = canChangeInfo, + canInviteUsers = canInviteUsers, + canPinMessages = canPinMessages, + canManageTopics = canManageTopics + ) + } } + +@Deprecated("Renamed", ReplaceWith("RestrictedChatMember", "dev.inmo.tgbotapi.types.chat.member.RestrictedChatMember")) +typealias BannedChatMember = RestrictedChatMember diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/RestrictedMemberChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/RestrictedMemberChatMember.kt new file mode 100644 index 0000000000..ed92eb7f8c --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/RestrictedMemberChatMember.kt @@ -0,0 +1,53 @@ +package dev.inmo.tgbotapi.types.chat.member + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.chat.ChatPermissions +import dev.inmo.tgbotapi.types.chat.User +import kotlinx.serialization.* + +/** + * Represents `ChatMemberRestricted` from telegram bots api and means that member is still member of chat but has been + * restricted in his rights + */ +@Serializable +data class RestrictedMemberChatMember( + @SerialName(userField) + override val user: User, + @SerialName(untilDateField) + override val untilDate: TelegramDate? = null, + @SerialName(isMemberField) + val isMember: Boolean = false, + @SerialName(canSendMessagesField) + override val canSendMessages: Boolean = false, + @SerialName(canSendAudiosField) + override val canSendAudios: Boolean = false, + @SerialName(canSendDocumentsField) + override val canSendDocuments: Boolean = false, + @SerialName(canSendPhotosField) + override val canSendPhotos: Boolean = false, + @SerialName(canSendVideosField) + override val canSendVideos: Boolean = false, + @SerialName(canSendVideoNotesField) + override val canSendVideoNotes: Boolean = false, + @SerialName(canSendVoiceNotesField) + override val canSendVoiceNotes: Boolean = false, + @SerialName(canSendPollsField) + override val canSendPolls: Boolean = false, + @SerialName(canSendOtherMessagesField) + override val canSendOtherMessages: Boolean = false, + @SerialName(canAddWebPagePreviewsField) + override val canAddWebPagePreviews: Boolean = false, + @SerialName(canChangeInfoField) + override val canChangeInfo: Boolean = false, + @SerialName(canInviteUsersField) + override val canInviteUsers: Boolean = false, + @SerialName(canPinMessagesField) + override val canPinMessages: Boolean = false, + @SerialName(canManageTopicsField) + override val canManageTopics: Boolean = false +) : RestrictedChatMember, SpecialRightsChatMember, MemberChatMember, ChatPermissions { + @SerialName(statusField) + @Required + @EncodeDefault + override val status: ChatMember.Status = ChatMember.Status.Restricted +} diff --git a/tgbotapi.utils/api/tgbotapi.utils.api b/tgbotapi.utils/api/tgbotapi.utils.api index 26009da75a..95d076f8fc 100644 --- a/tgbotapi.utils/api/tgbotapi.utils.api +++ b/tgbotapi.utils/api/tgbotapi.utils.api @@ -20,7 +20,7 @@ public final class dev/inmo/tgbotapi/extensions/utils/ClassCastsKt { public static final fun asAudioMediaGroupMemberTelegramMedia (Ldev/inmo/tgbotapi/types/media/TelegramFreeMedia;)Ldev/inmo/tgbotapi/types/media/AudioMediaGroupMemberTelegramMedia; public static final fun asBankStatement (Ldev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElement;)Ldev/inmo/tgbotapi/types/passport/encrypted/BankStatement; public static final fun asBankStatementSecureValue (Ldev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue;)Ldev/inmo/tgbotapi/types/passport/decrypted/BankStatementSecureValue; - public static final fun asBannedChatMember (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Ldev/inmo/tgbotapi/types/chat/member/BannedChatMember; + public static final fun asBannedChatMember (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMember; public static final fun asBaseChosenInlineResult (Ldev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/ChosenInlineResult;)Ldev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/BaseChosenInlineResult; public static final fun asBaseEditMessageUpdate (Ldev/inmo/tgbotapi/types/update/abstracts/Update;)Ldev/inmo/tgbotapi/types/update/abstracts/BaseEditMessageUpdate; public static final fun asBaseInlineQuery (Ldev/inmo/tgbotapi/types/InlineQueries/query/InlineQuery;)Ldev/inmo/tgbotapi/types/InlineQueries/query/BaseInlineQuery; @@ -256,7 +256,7 @@ public final class dev/inmo/tgbotapi/extensions/utils/ClassCastsKt { public static final fun asRentalAgreementSecureValue (Ldev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue;)Ldev/inmo/tgbotapi/types/passport/decrypted/RentalAgreementSecureValue; public static final fun asReplyKeyboardMarkup (Ldev/inmo/tgbotapi/types/buttons/KeyboardMarkup;)Ldev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup; public static final fun asReplyKeyboardRemove (Ldev/inmo/tgbotapi/types/buttons/KeyboardMarkup;)Ldev/inmo/tgbotapi/types/buttons/ReplyKeyboardRemove; - public static final fun asRestrictedChatMember (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMember; + public static final fun asRestrictedChatMember (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMemberImpl; public static final fun asSecondaryChatInviteLink (Ldev/inmo/tgbotapi/types/ChatInviteLink;)Ldev/inmo/tgbotapi/types/SecondaryChatInviteLink; public static final fun asSecureValueIdentity (Ldev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue;)Ldev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueIdentity; public static final fun asSecureValueWithData (Ldev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue;)Ldev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithData; @@ -363,7 +363,7 @@ public final class dev/inmo/tgbotapi/extensions/utils/ClassCastsKt { public static final fun requireAudioMediaGroupMemberTelegramMedia (Ldev/inmo/tgbotapi/types/media/TelegramFreeMedia;)Ldev/inmo/tgbotapi/types/media/AudioMediaGroupMemberTelegramMedia; public static final fun requireBankStatement (Ldev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElement;)Ldev/inmo/tgbotapi/types/passport/encrypted/BankStatement; public static final fun requireBankStatementSecureValue (Ldev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue;)Ldev/inmo/tgbotapi/types/passport/decrypted/BankStatementSecureValue; - public static final fun requireBannedChatMember (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Ldev/inmo/tgbotapi/types/chat/member/BannedChatMember; + public static final fun requireBannedChatMember (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMember; public static final fun requireBaseChosenInlineResult (Ldev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/ChosenInlineResult;)Ldev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/BaseChosenInlineResult; public static final fun requireBaseEditMessageUpdate (Ldev/inmo/tgbotapi/types/update/abstracts/Update;)Ldev/inmo/tgbotapi/types/update/abstracts/BaseEditMessageUpdate; public static final fun requireBaseInlineQuery (Ldev/inmo/tgbotapi/types/InlineQueries/query/InlineQuery;)Ldev/inmo/tgbotapi/types/InlineQueries/query/BaseInlineQuery; @@ -599,7 +599,7 @@ public final class dev/inmo/tgbotapi/extensions/utils/ClassCastsKt { public static final fun requireRentalAgreementSecureValue (Ldev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue;)Ldev/inmo/tgbotapi/types/passport/decrypted/RentalAgreementSecureValue; public static final fun requireReplyKeyboardMarkup (Ldev/inmo/tgbotapi/types/buttons/KeyboardMarkup;)Ldev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup; public static final fun requireReplyKeyboardRemove (Ldev/inmo/tgbotapi/types/buttons/KeyboardMarkup;)Ldev/inmo/tgbotapi/types/buttons/ReplyKeyboardRemove; - public static final fun requireRestrictedChatMember (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMember; + public static final fun requireRestrictedChatMember (Ldev/inmo/tgbotapi/types/chat/member/ChatMember;)Ldev/inmo/tgbotapi/types/chat/member/RestrictedChatMemberImpl; public static final fun requireSecondaryChatInviteLink (Ldev/inmo/tgbotapi/types/ChatInviteLink;)Ldev/inmo/tgbotapi/types/SecondaryChatInviteLink; public static final fun requireSecureValueIdentity (Ldev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue;)Ldev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueIdentity; public static final fun requireSecureValueWithData (Ldev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue;)Ldev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithData; @@ -1095,8 +1095,6 @@ public final class dev/inmo/tgbotapi/extensions/utils/ClassCastsNewKt { public static final fun bankStatementOrThrow (Ldev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElement;)Ldev/inmo/tgbotapi/types/passport/encrypted/BankStatement; public static final fun bankStatementSecureValueOrNull (Ldev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue;)Ldev/inmo/tgbotapi/types/passport/decrypted/BankStatementSecureValue; public static final fun bankStatementSecureValueOrThrow (Ldev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue;)Ldev/inmo/tgbotapi/types/passport/decrypted/BankStatementSecureValue; - public static final fun bannedChatMemberOrNull (Ldev/inmo/tgbotapi/abstracts/OptionallyWithUser;)Ldev/inmo/tgbotapi/types/chat/member/BannedChatMember; - public static final fun bannedChatMemberOrThrow (Ldev/inmo/tgbotapi/abstracts/OptionallyWithUser;)Ldev/inmo/tgbotapi/types/chat/member/BannedChatMember; public static final fun baseChosenInlineResultOrNull (Ldev/inmo/tgbotapi/abstracts/OptionallyWithUser;)Ldev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/BaseChosenInlineResult; public static final fun baseChosenInlineResultOrThrow (Ldev/inmo/tgbotapi/abstracts/OptionallyWithUser;)Ldev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/BaseChosenInlineResult; public static final fun baseEditMessageUpdateOrNull (Ldev/inmo/tgbotapi/types/update/abstracts/Update;)Ldev/inmo/tgbotapi/types/update/abstracts/BaseEditMessageUpdate; @@ -1490,7 +1488,6 @@ public final class dev/inmo/tgbotapi/extensions/utils/ClassCastsNewKt { public static final fun ifAudioMediaGroupPartContent (Ldev/inmo/tgbotapi/types/message/content/ResendableContent;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun ifBankStatement (Ldev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElement;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun ifBankStatementSecureValue (Ldev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun ifBannedChatMember (Ldev/inmo/tgbotapi/abstracts/OptionallyWithUser;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun ifBaseChosenInlineResult (Ldev/inmo/tgbotapi/abstracts/OptionallyWithUser;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun ifBaseEditMessageUpdate (Ldev/inmo/tgbotapi/types/update/abstracts/Update;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun ifBaseInlineQuery (Ldev/inmo/tgbotapi/abstracts/OptionallyWithUser;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; 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 90eb2ffc5f..6984efc27e 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 @@ -1961,14 +1961,14 @@ inline fun ChatMember.asMemberChatMember(): MemberChatMember? = this as? MemberC inline fun ChatMember.requireMemberChatMember(): MemberChatMember = this as MemberChatMember @PreviewFeature -inline fun ChatMember.whenRestrictedChatMember(block: (RestrictedChatMember) -> T) = +inline fun ChatMember.whenRestrictedChatMember(block: (RestrictedMemberChatMember) -> T) = asRestrictedChatMember()?.let(block) @PreviewFeature -inline fun ChatMember.asRestrictedChatMember(): RestrictedChatMember? = this as? RestrictedChatMember +inline fun ChatMember.asRestrictedChatMember(): RestrictedMemberChatMember? = this as? RestrictedMemberChatMember @PreviewFeature -inline fun ChatMember.requireRestrictedChatMember(): RestrictedChatMember = this as RestrictedChatMember +inline fun ChatMember.requireRestrictedChatMember(): RestrictedMemberChatMember = this as RestrictedMemberChatMember @PreviewFeature inline fun ChatMember.whenAdministratorChatMember(block: (AdministratorChatMember) -> T) = @@ -1981,13 +1981,13 @@ inline fun ChatMember.asAdministratorChatMember(): AdministratorChatMember? = th inline fun ChatMember.requireAdministratorChatMember(): AdministratorChatMember = this as AdministratorChatMember @PreviewFeature -inline fun ChatMember.whenBannedChatMember(block: (BannedChatMember) -> T) = asBannedChatMember()?.let(block) +inline fun ChatMember.whenBannedChatMember(block: (RestrictedChatMember) -> T) = asBannedChatMember()?.let(block) @PreviewFeature -inline fun ChatMember.asBannedChatMember(): BannedChatMember? = this as? BannedChatMember +inline fun ChatMember.asBannedChatMember(): RestrictedChatMember? = this as? RestrictedChatMember @PreviewFeature -inline fun ChatMember.requireBannedChatMember(): BannedChatMember = this as BannedChatMember +inline fun ChatMember.requireBannedChatMember(): RestrictedChatMember = this as RestrictedChatMember @PreviewFeature inline fun ChatMember.whenSpecialRightsChatMember(block: (SpecialRightsChatMember) -> T) = 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 15f8028446..fd0516c334 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 @@ -161,7 +161,6 @@ import dev.inmo.tgbotapi.types.chat.UnknownExtendedChat import dev.inmo.tgbotapi.types.chat.User import dev.inmo.tgbotapi.types.chat.UsernameChat import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember -import dev.inmo.tgbotapi.types.chat.member.BannedChatMember import dev.inmo.tgbotapi.types.chat.member.ChatMember import dev.inmo.tgbotapi.types.chat.member.ChatMemberUpdated import dev.inmo.tgbotapi.types.chat.member.KickedChatMember @@ -691,15 +690,6 @@ public inline fun OptionallyWithUser.ifAdministratorChatMember(block: (AdministratorChatMember) -> T): T? = administratorChatMemberOrNull() ?.let(block) -public inline fun OptionallyWithUser.bannedChatMemberOrNull(): BannedChatMember? = this as? - dev.inmo.tgbotapi.types.chat.member.BannedChatMember - -public inline fun OptionallyWithUser.bannedChatMemberOrThrow(): BannedChatMember = this as - dev.inmo.tgbotapi.types.chat.member.BannedChatMember - -public inline fun OptionallyWithUser.ifBannedChatMember(block: (BannedChatMember) -> T): T? = - bannedChatMemberOrNull() ?.let(block) - public inline fun OptionallyWithUser.chatMemberOrNull(): ChatMember? = this as? dev.inmo.tgbotapi.types.chat.member.ChatMember diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/ChatMember.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/ChatMember.kt new file mode 100644 index 0000000000..0050726d3a --- /dev/null +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/ChatMember.kt @@ -0,0 +1,81 @@ +package dev.inmo.tgbotapi.extensions.utils.extensions + +import dev.inmo.tgbotapi.types.chat.member.* + +/** + * Check if receiver object is [LeftChatMember] + */ +val ChatMember.isLeft: Boolean get() = this is LeftChatMember + + +/** + * Check if receiver object is [MemberChatMember] + */ +val ChatMember.isMember: Boolean get() = this is MemberChatMember + +/** + * Check if receiver object is [RestrictedMemberChatMember] + */ +val ChatMember.isRestrictedMember: Boolean get() = this is RestrictedMemberChatMember + +/** + * Check if receiver object is [MemberChatMemberImpl] + */ +val ChatMember.isCommonMember: Boolean get() = this is MemberChatMemberImpl + +/** + * Check if receiver object is [SubscriptionMemberChatMember] + */ +val ChatMember.isSubscriberMember: Boolean get() = this is SubscriptionMemberChatMember + + +/** + * Check if receiver object is [RestrictedChatMember] + */ +val ChatMember.isRestricted: Boolean get() = this is RestrictedChatMember + +/** + * Check if receiver object is [KickedChatMember] + */ +val ChatMember.isKicked: Boolean get() = this is KickedChatMember + +/** + * Check if receiver object [isLeft] or [isKicked] + */ +val ChatMember.isLeftOrKicked: Boolean get() = isLeft || isKicked + +/** + * Check if receiver object [isRestricted] and not [isKicked] + */ +val ChatMember.isRestrictedAndNotKicked: Boolean get() = isRestricted && !isKicked + + +/** + * Check if receiver object is [SpecialRightsChatMember] + */ +val ChatMember.isSpecialRightsMember: Boolean get() = this is SpecialRightsChatMember + +/** + * Check if receiver object is [AdministratorChatMember] + */ +val ChatMember.isAdministrator: Boolean get() = this is AdministratorChatMember + +/** + * Check if receiver object is [OwnerChatMember] + */ +val ChatMember.isOwner: Boolean get() = this is OwnerChatMember + +/** + * Check if receiver object is [AdministratorChatMemberImpl] + */ +val ChatMember.isCommonAdministrator: Boolean get() = this is AdministratorChatMemberImpl + +/** + * Check that member is [KickedChatMember] + */ +val ChatMember.isBanned: Boolean get() = this is KickedChatMember + +/** + * Check that member is [RestrictedChatMember] + */ +val ChatMember.isKickedOrRestricted: Boolean get() = this is RestrictedChatMember diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/extensions/ChatMemberUpdated.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/ChatMemberUpdated.kt similarity index 77% rename from tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/extensions/ChatMemberUpdated.kt rename to tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/ChatMemberUpdated.kt index b1be6cbae8..d11148b144 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/extensions/ChatMemberUpdated.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/ChatMemberUpdated.kt @@ -1,4 +1,4 @@ -package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.extensions +package dev.inmo.tgbotapi.extensions.utils.extensions import dev.inmo.tgbotapi.types.chat.member.* @@ -15,17 +15,24 @@ val ChatMemberUpdated.leftChat get() = !oldChatMemberState.isLeftOrKicked && new /** * Member became a chat subscriber */ -val ChatMemberUpdated.subscribed: Boolean get() = !oldChatMemberState.isSubscriber && newChatMemberState.isSubscriber +val ChatMemberUpdated.subscribed: Boolean get() = !oldChatMemberState.isSubscriberMember && newChatMemberState.isSubscriberMember /** * Member became a chat subscriber or renewed their subscription */ -val ChatMemberUpdated.subscriptionChanged: Boolean get() = newChatMemberState.isSubscriber +val ChatMemberUpdated.subscriptionUpdated: Boolean get() = newChatMemberState.isSubscriberMember /** - * Member subscription was expired + * Member subscription was expired. User still can be a member + * + * @see unsubscribedAndLeft */ -val ChatMemberUpdated.unsubscribed: Boolean get() = oldChatMemberState.isSubscriber && !newChatMemberState.isSubscriber +val ChatMemberUpdated.unsubscribed: Boolean get() = oldChatMemberState.isSubscriberMember && !newChatMemberState.isSubscriberMember + +/** + * Member subscription was expired and user left the chat + */ +val ChatMemberUpdated.unsubscribedAndLeft: Boolean get() = oldChatMemberState.isSubscriberMember && !newChatMemberState.isMember /** * Member was promoted to chat administrator (or owner)