mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
ChatAdministratorRights -> ChatAdministratorRightsImpl in reply keyboards
This commit is contained in:
parent
fa4d264df4
commit
73a748d8b3
@ -2,6 +2,8 @@
|
||||
|
||||
## 9.2.0
|
||||
|
||||
* All the request chat keyboards has changed their parameters `ChatAdministratorRights` to `ChatAdministratorRightsImpl`
|
||||
|
||||
## 9.1.2
|
||||
|
||||
* `Core`:
|
||||
|
@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.types.buttons
|
||||
import dev.inmo.tgbotapi.types.botAdministratorRightsField
|
||||
import dev.inmo.tgbotapi.types.botIsMemberField
|
||||
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.chatIsChannelField
|
||||
import dev.inmo.tgbotapi.types.chatIsCreatedField
|
||||
@ -30,9 +31,9 @@ data class KeyboardButtonRequestChat(
|
||||
@SerialName(chatIsCreatedField)
|
||||
val isOwnedBy: Boolean? = null,
|
||||
@SerialName(userAdministratorRightsField)
|
||||
val userRightsInChat: ChatAdministratorRights? = null,
|
||||
val userRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
@SerialName(botAdministratorRightsField)
|
||||
val botRightsInChat: ChatAdministratorRights? = null,
|
||||
val botRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
@SerialName(botIsMemberField)
|
||||
val botIsMember: Boolean? = null
|
||||
) {
|
||||
@ -41,8 +42,8 @@ data class KeyboardButtonRequestChat(
|
||||
requestId: RequestId,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botIsMember: Boolean? = null
|
||||
) = KeyboardButtonRequestChat(
|
||||
requestId = requestId,
|
||||
@ -60,8 +61,8 @@ data class KeyboardButtonRequestChat(
|
||||
isForum: Boolean? = null,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botIsMember: Boolean? = null
|
||||
) = KeyboardButtonRequestChat(
|
||||
requestId = requestId,
|
||||
|
@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.buttons.reply
|
||||
|
||||
import dev.inmo.tgbotapi.types.buttons.*
|
||||
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.webapps.WebAppInfo
|
||||
|
||||
@ -120,8 +120,8 @@ inline fun requestChatReplyButton(
|
||||
isForum: Boolean? = null,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botIsMember: Boolean = false
|
||||
) = requestChatReplyButton(
|
||||
text,
|
||||
@ -145,8 +145,8 @@ inline fun requestChannelReplyButton(
|
||||
requestId: RequestId,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botIsMember: Boolean = false
|
||||
) = requestChatReplyButton(
|
||||
text,
|
||||
@ -170,8 +170,8 @@ inline fun requestChannelReplyButton(
|
||||
isForum: Boolean? = null,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botIsMember: Boolean? = null
|
||||
) = requestChatReplyButton(
|
||||
text,
|
||||
|
@ -45,5 +45,6 @@ data class AdministratorChatMemberImpl(
|
||||
) : AdministratorChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "administrator"
|
||||
override val status: ChatMember.Status
|
||||
get() = ChatMember.Status.Administrator
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package dev.inmo.tgbotapi.types.chat.member
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.SerialName
|
||||
|
||||
sealed interface SpecialChatAdministratorRights {
|
||||
val canChangeInfo: Boolean
|
||||
val canInviteUsers: Boolean
|
||||
@ -19,4 +22,40 @@ sealed interface ChatAdministratorRights : SpecialChatAdministratorRights {
|
||||
val canPostStories: Boolean
|
||||
val canEditStories: 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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,18 @@ import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
@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
|
||||
object ChatMemberSerializer : KSerializer<ChatMember> {
|
||||
@ -21,14 +32,16 @@ object ChatMemberSerializer : KSerializer<ChatMember> {
|
||||
|
||||
override fun deserialize(decoder: Decoder): ChatMember {
|
||||
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")) {
|
||||
"creator" -> nonstrictJsonFormat.decodeFromJsonElement(OwnerChatMember.serializer(), json)
|
||||
"administrator" -> nonstrictJsonFormat.decodeFromJsonElement(AdministratorChatMemberImpl.serializer(), json)
|
||||
"member" -> nonstrictJsonFormat.decodeFromJsonElement(MemberChatMemberImpl.serializer(), json)
|
||||
"restricted" -> nonstrictJsonFormat.decodeFromJsonElement(RestrictedChatMember.serializer(), json)
|
||||
"left" -> nonstrictJsonFormat.decodeFromJsonElement(LeftChatMemberImpl.serializer(), json)
|
||||
"kicked" -> nonstrictJsonFormat.decodeFromJsonElement(KickedChatMember.serializer(), json)
|
||||
else -> error("Unknown type of chat member in json: $json")
|
||||
val status = ChatMember.Status.valueOf(
|
||||
json[statusField] ?.jsonPrimitive ?.content ?: error("Status field of chat member must be specified, but incoming json contains next: $json")
|
||||
)
|
||||
return when (status) {
|
||||
ChatMember.Status.Creator -> nonstrictJsonFormat.decodeFromJsonElement(OwnerChatMember.serializer(), json)
|
||||
ChatMember.Status.Administrator -> nonstrictJsonFormat.decodeFromJsonElement(AdministratorChatMemberImpl.serializer(), json)
|
||||
ChatMember.Status.Member -> nonstrictJsonFormat.decodeFromJsonElement(MemberChatMemberImpl.serializer(), 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,5 +13,6 @@ data class KickedChatMember(
|
||||
) : BannedChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "kicked"
|
||||
override val status: ChatMember.Status
|
||||
get() = ChatMember.Status.Kicked
|
||||
}
|
||||
|
@ -8,5 +8,6 @@ import kotlinx.serialization.*
|
||||
data class LeftChatMemberImpl(@SerialName(userField) override val user: User) : LeftChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "left"
|
||||
override val status: ChatMember.Status
|
||||
get() = ChatMember.Status.Left
|
||||
}
|
||||
|
@ -8,5 +8,6 @@ import kotlinx.serialization.*
|
||||
data class MemberChatMemberImpl(@SerialName(userField) override val user: User) : MemberChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "member"
|
||||
override val status: ChatMember.Status
|
||||
get() = ChatMember.Status.Member
|
||||
}
|
||||
|
@ -42,7 +42,9 @@ data class OwnerChatMember(
|
||||
override val canEditStories: Boolean = true
|
||||
@Transient
|
||||
override val canDeleteStories: Boolean = true
|
||||
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "creator"
|
||||
override val status: ChatMember.Status
|
||||
get() = ChatMember.Status.Creator
|
||||
}
|
||||
|
@ -44,5 +44,6 @@ data class RestrictedChatMember(
|
||||
) : BannedChatMember, SpecialRightsChatMember, ChatPermissions {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "restricted"
|
||||
override val status: ChatMember.Status
|
||||
get() = ChatMember.Status.Restricted
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.extensions.utils.types.buttons
|
||||
import dev.inmo.tgbotapi.types.buttons.*
|
||||
import dev.inmo.tgbotapi.types.buttons.reply.requestChatReplyButton
|
||||
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.webapps.WebAppInfo
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
@ -220,8 +220,8 @@ inline fun ReplyKeyboardRowBuilder.requestChatButton(
|
||||
isForum: Boolean? = null,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botIsMember: Boolean? = null
|
||||
) = requestChatButton(
|
||||
text,
|
||||
@ -248,8 +248,8 @@ inline fun ReplyKeyboardRowBuilder.requestChannelButton(
|
||||
requestId: RequestId,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botIsMember: Boolean? = null
|
||||
) = requestChatButton(
|
||||
text,
|
||||
@ -275,8 +275,8 @@ inline fun ReplyKeyboardRowBuilder.requestGroupButton(
|
||||
isForum: Boolean? = null,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botRightsInChat: ChatAdministratorRightsImpl? = null,
|
||||
botIsMember: Boolean? = null
|
||||
) = requestChatButton(
|
||||
text,
|
||||
|
Loading…
Reference in New Issue
Block a user