1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

ChatAdministratorRights -> ChatAdministratorRightsImpl in reply keyboards

This commit is contained in:
InsanusMokrassar 2023-09-24 20:08:46 +06:00
parent fa4d264df4
commit 73a748d8b3
12 changed files with 97 additions and 35 deletions

View File

@ -2,6 +2,8 @@
## 9.2.0 ## 9.2.0
* All the request chat keyboards has changed their parameters `ChatAdministratorRights` to `ChatAdministratorRightsImpl`
## 9.1.2 ## 9.1.2
* `Core`: * `Core`:

View File

@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.types.buttons
import dev.inmo.tgbotapi.types.botAdministratorRightsField import dev.inmo.tgbotapi.types.botAdministratorRightsField
import dev.inmo.tgbotapi.types.botIsMemberField import dev.inmo.tgbotapi.types.botIsMemberField
import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRights import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRights
import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRightsImpl
import dev.inmo.tgbotapi.types.chatHasUsernameField import dev.inmo.tgbotapi.types.chatHasUsernameField
import dev.inmo.tgbotapi.types.chatIsChannelField import dev.inmo.tgbotapi.types.chatIsChannelField
import dev.inmo.tgbotapi.types.chatIsCreatedField import dev.inmo.tgbotapi.types.chatIsCreatedField
@ -30,9 +31,9 @@ data class KeyboardButtonRequestChat(
@SerialName(chatIsCreatedField) @SerialName(chatIsCreatedField)
val isOwnedBy: Boolean? = null, val isOwnedBy: Boolean? = null,
@SerialName(userAdministratorRightsField) @SerialName(userAdministratorRightsField)
val userRightsInChat: ChatAdministratorRights? = null, val userRightsInChat: ChatAdministratorRightsImpl? = null,
@SerialName(botAdministratorRightsField) @SerialName(botAdministratorRightsField)
val botRightsInChat: ChatAdministratorRights? = null, val botRightsInChat: ChatAdministratorRightsImpl? = null,
@SerialName(botIsMemberField) @SerialName(botIsMemberField)
val botIsMember: Boolean? = null val botIsMember: Boolean? = null
) { ) {
@ -41,8 +42,8 @@ data class KeyboardButtonRequestChat(
requestId: RequestId, requestId: RequestId,
isPublic: Boolean? = null, isPublic: Boolean? = null,
isOwnedBy: Boolean? = null, isOwnedBy: Boolean? = null,
userRightsInChat: ChatAdministratorRights? = null, userRightsInChat: ChatAdministratorRightsImpl? = null,
botRightsInChat: ChatAdministratorRights? = null, botRightsInChat: ChatAdministratorRightsImpl? = null,
botIsMember: Boolean? = null botIsMember: Boolean? = null
) = KeyboardButtonRequestChat( ) = KeyboardButtonRequestChat(
requestId = requestId, requestId = requestId,
@ -60,8 +61,8 @@ data class KeyboardButtonRequestChat(
isForum: Boolean? = null, isForum: Boolean? = null,
isPublic: Boolean? = null, isPublic: Boolean? = null,
isOwnedBy: Boolean? = null, isOwnedBy: Boolean? = null,
userRightsInChat: ChatAdministratorRights? = null, userRightsInChat: ChatAdministratorRightsImpl? = null,
botRightsInChat: ChatAdministratorRights? = null, botRightsInChat: ChatAdministratorRightsImpl? = null,
botIsMember: Boolean? = null botIsMember: Boolean? = null
) = KeyboardButtonRequestChat( ) = KeyboardButtonRequestChat(
requestId = requestId, requestId = requestId,

View File

@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.buttons.reply
import dev.inmo.tgbotapi.types.buttons.* import dev.inmo.tgbotapi.types.buttons.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.*
import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRights import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRightsImpl
import dev.inmo.tgbotapi.types.request.RequestId import dev.inmo.tgbotapi.types.request.RequestId
import dev.inmo.tgbotapi.types.webapps.WebAppInfo import dev.inmo.tgbotapi.types.webapps.WebAppInfo
@ -120,8 +120,8 @@ inline fun requestChatReplyButton(
isForum: Boolean? = null, isForum: Boolean? = null,
isPublic: Boolean? = null, isPublic: Boolean? = null,
isOwnedBy: Boolean? = null, isOwnedBy: Boolean? = null,
userRightsInChat: ChatAdministratorRights? = null, userRightsInChat: ChatAdministratorRightsImpl? = null,
botRightsInChat: ChatAdministratorRights? = null, botRightsInChat: ChatAdministratorRightsImpl? = null,
botIsMember: Boolean = false botIsMember: Boolean = false
) = requestChatReplyButton( ) = requestChatReplyButton(
text, text,
@ -145,8 +145,8 @@ inline fun requestChannelReplyButton(
requestId: RequestId, requestId: RequestId,
isPublic: Boolean? = null, isPublic: Boolean? = null,
isOwnedBy: Boolean? = null, isOwnedBy: Boolean? = null,
userRightsInChat: ChatAdministratorRights? = null, userRightsInChat: ChatAdministratorRightsImpl? = null,
botRightsInChat: ChatAdministratorRights? = null, botRightsInChat: ChatAdministratorRightsImpl? = null,
botIsMember: Boolean = false botIsMember: Boolean = false
) = requestChatReplyButton( ) = requestChatReplyButton(
text, text,
@ -170,8 +170,8 @@ inline fun requestChannelReplyButton(
isForum: Boolean? = null, isForum: Boolean? = null,
isPublic: Boolean? = null, isPublic: Boolean? = null,
isOwnedBy: Boolean? = null, isOwnedBy: Boolean? = null,
userRightsInChat: ChatAdministratorRights? = null, userRightsInChat: ChatAdministratorRightsImpl? = null,
botRightsInChat: ChatAdministratorRights? = null, botRightsInChat: ChatAdministratorRightsImpl? = null,
botIsMember: Boolean? = null botIsMember: Boolean? = null
) = requestChatReplyButton( ) = requestChatReplyButton(
text, text,

View File

@ -45,5 +45,6 @@ data class AdministratorChatMemberImpl(
) : AdministratorChatMember { ) : AdministratorChatMember {
@SerialName(statusField) @SerialName(statusField)
@Required @Required
private val type: String = "administrator" override val status: ChatMember.Status
get() = ChatMember.Status.Administrator
} }

View File

@ -1,5 +1,8 @@
package dev.inmo.tgbotapi.types.chat.member package dev.inmo.tgbotapi.types.chat.member
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.SerialName
sealed interface SpecialChatAdministratorRights { sealed interface SpecialChatAdministratorRights {
val canChangeInfo: Boolean val canChangeInfo: Boolean
val canInviteUsers: Boolean val canInviteUsers: Boolean
@ -19,4 +22,40 @@ sealed interface ChatAdministratorRights : SpecialChatAdministratorRights {
val canPostStories: Boolean val canPostStories: Boolean
val canEditStories: Boolean val canEditStories: Boolean
val canDeleteStories: Boolean val canDeleteStories: Boolean
companion object {
operator fun invoke(
canChangeInfo: Boolean = false,
canPostMessages: Boolean = false,
canEditMessages: Boolean = false,
canRemoveMessages: Boolean = false,
canInviteUsers: Boolean = false,
canRestrictMembers: Boolean = false,
canPinMessages: Boolean = false,
canPromoteMembers: Boolean = false,
canManageVideoChats: Boolean = false,
canManageChat: Boolean = false,
isAnonymous: Boolean = false,
canManageTopics: Boolean = false,
canPostStories: Boolean = false,
canEditStories: Boolean = false,
canDeleteStories: Boolean = false
) = ChatAdministratorRightsImpl(
canChangeInfo = canChangeInfo,
canPostMessages = canPostMessages,
canEditMessages = canEditMessages,
canRemoveMessages = canRemoveMessages,
canInviteUsers = canInviteUsers,
canRestrictMembers = canRestrictMembers,
canPinMessages = canPinMessages,
canPromoteMembers = canPromoteMembers,
canManageVideoChats = canManageVideoChats,
canManageChat = canManageChat,
isAnonymous = isAnonymous,
canManageTopics = canManageTopics,
canPostStories = canPostStories,
canEditStories = canEditStories,
canDeleteStories = canDeleteStories
)
}
} }

View File

@ -13,7 +13,18 @@ import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonPrimitive import kotlinx.serialization.json.jsonPrimitive
@Serializable(ChatMemberSerializer::class) @Serializable(ChatMemberSerializer::class)
sealed interface ChatMember : WithUser sealed interface ChatMember : WithUser {
@Serializable
enum class Status(val status: String) {
Creator("creator"),
Administrator("administrator"),
Member("member"),
Restricted("restricted"),
Left("left"),
Kicked("kicked")
}
val status: Status
}
@RiskFeature @RiskFeature
object ChatMemberSerializer : KSerializer<ChatMember> { object ChatMemberSerializer : KSerializer<ChatMember> {
@ -21,14 +32,16 @@ object ChatMemberSerializer : KSerializer<ChatMember> {
override fun deserialize(decoder: Decoder): ChatMember { override fun deserialize(decoder: Decoder): ChatMember {
val json = JsonObject.serializer().deserialize(decoder) val json = JsonObject.serializer().deserialize(decoder)
return when (json[statusField] ?.jsonPrimitive ?.content ?: error("Status field of chat member must be specified, but incoming json contains next: $json")) { val status = ChatMember.Status.valueOf(
"creator" -> nonstrictJsonFormat.decodeFromJsonElement(OwnerChatMember.serializer(), json) json[statusField] ?.jsonPrimitive ?.content ?: error("Status field of chat member must be specified, but incoming json contains next: $json")
"administrator" -> nonstrictJsonFormat.decodeFromJsonElement(AdministratorChatMemberImpl.serializer(), json) )
"member" -> nonstrictJsonFormat.decodeFromJsonElement(MemberChatMemberImpl.serializer(), json) return when (status) {
"restricted" -> nonstrictJsonFormat.decodeFromJsonElement(RestrictedChatMember.serializer(), json) ChatMember.Status.Creator -> nonstrictJsonFormat.decodeFromJsonElement(OwnerChatMember.serializer(), json)
"left" -> nonstrictJsonFormat.decodeFromJsonElement(LeftChatMemberImpl.serializer(), json) ChatMember.Status.Administrator -> nonstrictJsonFormat.decodeFromJsonElement(AdministratorChatMemberImpl.serializer(), json)
"kicked" -> nonstrictJsonFormat.decodeFromJsonElement(KickedChatMember.serializer(), json) ChatMember.Status.Member -> nonstrictJsonFormat.decodeFromJsonElement(MemberChatMemberImpl.serializer(), json)
else -> error("Unknown type of chat member in json: $json") ChatMember.Status.Restricted -> nonstrictJsonFormat.decodeFromJsonElement(RestrictedChatMember.serializer(), json)
ChatMember.Status.Left -> nonstrictJsonFormat.decodeFromJsonElement(LeftChatMemberImpl.serializer(), json)
ChatMember.Status.Kicked -> nonstrictJsonFormat.decodeFromJsonElement(KickedChatMember.serializer(), json)
} }
} }

View File

@ -13,5 +13,6 @@ data class KickedChatMember(
) : BannedChatMember { ) : BannedChatMember {
@SerialName(statusField) @SerialName(statusField)
@Required @Required
private val type: String = "kicked" override val status: ChatMember.Status
get() = ChatMember.Status.Kicked
} }

View File

@ -8,5 +8,6 @@ import kotlinx.serialization.*
data class LeftChatMemberImpl(@SerialName(userField) override val user: User) : LeftChatMember { data class LeftChatMemberImpl(@SerialName(userField) override val user: User) : LeftChatMember {
@SerialName(statusField) @SerialName(statusField)
@Required @Required
private val type: String = "left" override val status: ChatMember.Status
get() = ChatMember.Status.Left
} }

View File

@ -8,5 +8,6 @@ import kotlinx.serialization.*
data class MemberChatMemberImpl(@SerialName(userField) override val user: User) : MemberChatMember { data class MemberChatMemberImpl(@SerialName(userField) override val user: User) : MemberChatMember {
@SerialName(statusField) @SerialName(statusField)
@Required @Required
private val type: String = "member" override val status: ChatMember.Status
get() = ChatMember.Status.Member
} }

View File

@ -42,7 +42,9 @@ data class OwnerChatMember(
override val canEditStories: Boolean = true override val canEditStories: Boolean = true
@Transient @Transient
override val canDeleteStories: Boolean = true override val canDeleteStories: Boolean = true
@SerialName(statusField) @SerialName(statusField)
@Required @Required
private val type: String = "creator" override val status: ChatMember.Status
get() = ChatMember.Status.Creator
} }

View File

@ -44,5 +44,6 @@ data class RestrictedChatMember(
) : BannedChatMember, SpecialRightsChatMember, ChatPermissions { ) : BannedChatMember, SpecialRightsChatMember, ChatPermissions {
@SerialName(statusField) @SerialName(statusField)
@Required @Required
private val type: String = "restricted" override val status: ChatMember.Status
get() = ChatMember.Status.Restricted
} }

View File

@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.extensions.utils.types.buttons
import dev.inmo.tgbotapi.types.buttons.* import dev.inmo.tgbotapi.types.buttons.*
import dev.inmo.tgbotapi.types.buttons.reply.requestChatReplyButton import dev.inmo.tgbotapi.types.buttons.reply.requestChatReplyButton
import dev.inmo.tgbotapi.types.buttons.reply.requestUserReplyButton import dev.inmo.tgbotapi.types.buttons.reply.requestUserReplyButton
import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRights import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRightsImpl
import dev.inmo.tgbotapi.types.request.RequestId import dev.inmo.tgbotapi.types.request.RequestId
import dev.inmo.tgbotapi.types.webapps.WebAppInfo import dev.inmo.tgbotapi.types.webapps.WebAppInfo
import dev.inmo.tgbotapi.utils.* import dev.inmo.tgbotapi.utils.*
@ -220,8 +220,8 @@ inline fun ReplyKeyboardRowBuilder.requestChatButton(
isForum: Boolean? = null, isForum: Boolean? = null,
isPublic: Boolean? = null, isPublic: Boolean? = null,
isOwnedBy: Boolean? = null, isOwnedBy: Boolean? = null,
userRightsInChat: ChatAdministratorRights? = null, userRightsInChat: ChatAdministratorRightsImpl? = null,
botRightsInChat: ChatAdministratorRights? = null, botRightsInChat: ChatAdministratorRightsImpl? = null,
botIsMember: Boolean? = null botIsMember: Boolean? = null
) = requestChatButton( ) = requestChatButton(
text, text,
@ -248,8 +248,8 @@ inline fun ReplyKeyboardRowBuilder.requestChannelButton(
requestId: RequestId, requestId: RequestId,
isPublic: Boolean? = null, isPublic: Boolean? = null,
isOwnedBy: Boolean? = null, isOwnedBy: Boolean? = null,
userRightsInChat: ChatAdministratorRights? = null, userRightsInChat: ChatAdministratorRightsImpl? = null,
botRightsInChat: ChatAdministratorRights? = null, botRightsInChat: ChatAdministratorRightsImpl? = null,
botIsMember: Boolean? = null botIsMember: Boolean? = null
) = requestChatButton( ) = requestChatButton(
text, text,
@ -275,8 +275,8 @@ inline fun ReplyKeyboardRowBuilder.requestGroupButton(
isForum: Boolean? = null, isForum: Boolean? = null,
isPublic: Boolean? = null, isPublic: Boolean? = null,
isOwnedBy: Boolean? = null, isOwnedBy: Boolean? = null,
userRightsInChat: ChatAdministratorRights? = null, userRightsInChat: ChatAdministratorRightsImpl? = null,
botRightsInChat: ChatAdministratorRights? = null, botRightsInChat: ChatAdministratorRightsImpl? = null,
botIsMember: Boolean? = null botIsMember: Boolean? = null
) = requestChatButton( ) = requestChatButton(
text, text,