1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-09-03 15:19:30 +00:00

improvements and breaking changes in ChatMember hierarchy

This commit is contained in:
2024-08-29 17:54:00 +06:00
parent 2d40af21fe
commit 10d92c2fdb
15 changed files with 266 additions and 131 deletions

View File

@@ -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;

View File

@@ -1961,14 +1961,14 @@ inline fun ChatMember.asMemberChatMember(): MemberChatMember? = this as? MemberC
inline fun ChatMember.requireMemberChatMember(): MemberChatMember = this as MemberChatMember
@PreviewFeature
inline fun <T> ChatMember.whenRestrictedChatMember(block: (RestrictedChatMember) -> T) =
inline fun <T> 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 <T> 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 <T> ChatMember.whenBannedChatMember(block: (BannedChatMember) -> T) = asBannedChatMember()?.let(block)
inline fun <T> 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 <T> ChatMember.whenSpecialRightsChatMember(block: (SpecialRightsChatMember) -> T) =

View File

@@ -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 <T>
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 <T> OptionallyWithUser.ifBannedChatMember(block: (BannedChatMember) -> T): T? =
bannedChatMemberOrNull() ?.let(block)
public inline fun OptionallyWithUser.chatMemberOrNull(): ChatMember? = this as?
dev.inmo.tgbotapi.types.chat.member.ChatMember

View File

@@ -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

View File

@@ -0,0 +1,75 @@
package dev.inmo.tgbotapi.extensions.utils.extensions
import dev.inmo.tgbotapi.types.chat.member.*
/**
* User joined a chat
*/
val ChatMemberUpdated.joinedChat get() = oldChatMemberState.isLeftOrKicked && !newChatMemberState.isLeftOrKicked
/**
* Member left a chat for any reason
*/
val ChatMemberUpdated.leftChat get() = !oldChatMemberState.isLeftOrKicked && newChatMemberState.isLeftOrKicked
/**
* Member became a chat subscriber
*/
val ChatMemberUpdated.subscribed: Boolean get() = !oldChatMemberState.isSubscriberMember && newChatMemberState.isSubscriberMember
/**
* Member became a chat subscriber or renewed their subscription
*/
val ChatMemberUpdated.subscriptionUpdated: Boolean get() = newChatMemberState.isSubscriberMember
/**
* Member subscription was expired. User still can be a member
*
* @see unsubscribedAndLeft
*/
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)
*/
val ChatMemberUpdated.gotPromoted: Boolean get() = !oldChatMemberState.isAdministrator && newChatMemberState.isAdministrator
/**
* Member was promoted to chat administrator (or owner) or got it permissions/title changed
*/
val ChatMemberUpdated.gotPromotionChanged: Boolean get() = newChatMemberState.isAdministrator
/**
* Member was demoted from administrators (or ceased chat ownership)
*/
val ChatMemberUpdated.gotDemoted: Boolean get() = oldChatMemberState.isAdministrator && !newChatMemberState.isAdministrator
/**
* Member became a chat owner
*/
val ChatMemberUpdated.becameOwner: Boolean get() = !oldChatMemberState.isOwner && newChatMemberState.isOwner
/**
* Member ceased their chat ownership
*/
val ChatMemberUpdated.ceasedOwnership: Boolean get() = oldChatMemberState.isOwner && !newChatMemberState.isOwner
/**
* Member was restricted or some restrictions have changed
*/
val ChatMemberUpdated.gotRestricted: Boolean get() = !oldChatMemberState.isRestricted && newChatMemberState.isRestricted
/**
* Member restrictions were changed (but not removed)
*/
val ChatMemberUpdated.gotRestrictionsChanged: Boolean get() = newChatMemberState.isRestricted
/**
* All member restrictions were removed
*/
val ChatMemberUpdated.gotUnrestricted: Boolean get() = oldChatMemberState.isRestricted && !newChatMemberState.isRestricted