diff --git a/CHANGELOG.md b/CHANGELOG.md index 28e54c384a..5f6aa38769 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,9 @@ [Bot API 6.5](https://core.telegram.org/bots/api-changelog#february-3-2023) support * `Core`: - * [Bot API 6.5](https://core.telegram.org/bots/api#february-3-2023) support + * `ChatPermissions` now is interface and have two main realizations: `ChatPermissions.Granular` and + `ChatPermissions.Common` + * `RestrictedChatMember` now implements `ChatPermissions` too ## 5.0.2 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/request/RequestId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/request/RequestId.kt index 5263de2366..048b7a5ff4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/request/RequestId.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/request/RequestId.kt @@ -7,7 +7,7 @@ import kotlin.random.Random @Serializable @JvmInline value class RequestId( - val float: Int + val int: Int ) { companion object { fun random() = RequestId(Random.nextInt()) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/request/RequestResponse.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/request/RequestResponse.kt index 2c4c846942..028c9be4cd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/request/RequestResponse.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/request/RequestResponse.kt @@ -1,5 +1,8 @@ package dev.inmo.tgbotapi.types.request +import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded + +@ClassCastsIncluded sealed interface RequestResponse { val requestId: RequestId } 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 f11affb701..d6595ef0fa 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 @@ -436,6 +436,7 @@ import dev.inmo.tgbotapi.types.queries.callback.MessageGameShortNameCallbackQuer import dev.inmo.tgbotapi.types.queries.callback.UnknownCallbackQueryType import dev.inmo.tgbotapi.types.request.ChatShared import dev.inmo.tgbotapi.types.request.ChatSharedRequest +import dev.inmo.tgbotapi.types.request.RequestResponse import dev.inmo.tgbotapi.types.request.UserShared import dev.inmo.tgbotapi.types.update.CallbackQueryUpdate import dev.inmo.tgbotapi.types.update.ChannelPostUpdate @@ -4718,6 +4719,33 @@ public inline fun Poll.quizPollOrThrow(): QuizPoll = this as dev.inmo.tgbotapi.t public inline fun Poll.ifQuizPoll(block: (QuizPoll) -> T): T? = quizPollOrNull() ?.let(block) +public inline fun RequestResponse.chatSharedOrNull(): ChatShared? = this as? + dev.inmo.tgbotapi.types.request.ChatShared + +public inline fun RequestResponse.chatSharedOrThrow(): ChatShared = this as + dev.inmo.tgbotapi.types.request.ChatShared + +public inline fun RequestResponse.ifChatShared(block: (ChatShared) -> T): T? = + chatSharedOrNull() ?.let(block) + +public inline fun RequestResponse.chatSharedRequestOrNull(): ChatSharedRequest? = this as? + dev.inmo.tgbotapi.types.request.ChatSharedRequest + +public inline fun RequestResponse.chatSharedRequestOrThrow(): ChatSharedRequest = this as + dev.inmo.tgbotapi.types.request.ChatSharedRequest + +public inline fun RequestResponse.ifChatSharedRequest(block: (ChatSharedRequest) -> T): T? = + chatSharedRequestOrNull() ?.let(block) + +public inline fun RequestResponse.userSharedOrNull(): UserShared? = this as? + dev.inmo.tgbotapi.types.request.UserShared + +public inline fun RequestResponse.userSharedOrThrow(): UserShared = this as + dev.inmo.tgbotapi.types.request.UserShared + +public inline fun RequestResponse.ifUserShared(block: (UserShared) -> T): T? = + userSharedOrNull() ?.let(block) + public inline fun Update.callbackQueryUpdateOrNull(): CallbackQueryUpdate? = this as? dev.inmo.tgbotapi.types.update.CallbackQueryUpdate