mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
replace of ChatMember
This commit is contained in:
parent
cdd5649c04
commit
323c4de858
@ -9,6 +9,8 @@ __All the `tgbotapi.extensions.*` packages have been removed__
|
||||
* `Core`:
|
||||
* **`Ktor` package renamed. Migration:** `dev.inmo.tgbotapi.bot.Ktor` -> `dev.inmo.tgbotapi.bot.ktor`
|
||||
* **`CallbackQuery` package renamed. Migration:** `dev.inmo.tgbotapi.types.CallbackQuery([\s\\.])` -> `dev.inmo.tgbotapi.types.queries.callback$1`
|
||||
* **`ChatMember` package renamed. Migration:** `dev.inmo.tgbotapi.types.ChatMember([\s\\.])` -> `dev.inmo.tgbotapi.types.chat.member$1`
|
||||
* **`ChatAdministratorRightsImpl` replaced. Migration:** `dev.inmo.tgbotapi.types.ChatAdministratorRightsImpl` -> `dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRightsImpl`
|
||||
* Constructor of `UnknownInlineKeyboardButton` is not internal and can be created with any `json` ([#563](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/563))
|
||||
* All the interfaces from `dev.inmo.tgbotapi.types.files.abstracts` have been replaced to `dev.inmo.tgbotapi.types.files` and converted to sealed ([#550](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/550))
|
||||
* `PassportFile` has been replaced to `dev.inmo.tgbotapi.types.files`
|
||||
|
@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.extensions.api.bot
|
||||
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.requests.bot.ClearMyDefaultAdministratorRights
|
||||
import dev.inmo.tgbotapi.types.ChatAdministratorRightsImpl
|
||||
|
||||
suspend fun TelegramBot.clearMyDefaultAdministratorRights(
|
||||
forChannels: Boolean? = null
|
||||
|
@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.extensions.api.bot
|
||||
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.requests.bot.SetMyDefaultAdministratorRights
|
||||
import dev.inmo.tgbotapi.types.ChatAdministratorRightsImpl
|
||||
import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRightsImpl
|
||||
|
||||
suspend fun TelegramBot.setMyDefaultAdministratorRights(
|
||||
rights: ChatAdministratorRightsImpl,
|
||||
|
@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.requests.bot
|
||||
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.AdministratorChatMemberImpl
|
||||
import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMemberImpl
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
|
@ -3,8 +3,8 @@ package dev.inmo.tgbotapi.requests.chat.get
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.types.ChatRequest
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.AdministratorChatMember
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.AdministratorChatMemberSerializer
|
||||
import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember
|
||||
import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMemberSerializer
|
||||
import dev.inmo.tgbotapi.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.ListSerializer
|
||||
|
@ -2,8 +2,8 @@ package dev.inmo.tgbotapi.requests.chat.members
|
||||
|
||||
import dev.inmo.tgbotapi.requests.chat.abstracts.ChatMemberRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMemberSerializer
|
||||
import dev.inmo.tgbotapi.types.chat.member.ChatMember
|
||||
import dev.inmo.tgbotapi.types.chat.member.ChatMemberSerializer
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
|
@ -1,31 +1,4 @@
|
||||
package dev.inmo.tgbotapi.types
|
||||
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatAdministratorRights
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ChatAdministratorRightsImpl(
|
||||
@SerialName(canChangeInfoField)
|
||||
override val canChangeInfo: Boolean = false,
|
||||
@SerialName(canPostMessagesField)
|
||||
override val canPostMessages: Boolean = false,
|
||||
@SerialName(canEditMessagesField)
|
||||
override val canEditMessages: Boolean = false,
|
||||
@SerialName(canDeleteMessagesField)
|
||||
override val canRemoveMessages: Boolean = false,
|
||||
@SerialName(canInviteUsersField)
|
||||
override val canInviteUsers: Boolean = false,
|
||||
@SerialName(canRestrictMembersField)
|
||||
override val canRestrictMembers: Boolean = false,
|
||||
@SerialName(canPinMessagesField)
|
||||
override val canPinMessages: Boolean = false,
|
||||
@SerialName(canPromoteMembersField)
|
||||
override val canPromoteMembers: Boolean = false,
|
||||
@SerialName(canManageVideoChatsField)
|
||||
override val canManageVideoChats: Boolean = false,
|
||||
@SerialName(canManageChatField)
|
||||
override val canManageChat: Boolean = false,
|
||||
@SerialName(isAnonymousField)
|
||||
override val isAnonymous: Boolean = false
|
||||
) : ChatAdministratorRights
|
||||
@Deprecated("Renamed", ReplaceWith("ChatAdministratorRightsImpl", "dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRightsImpl"))
|
||||
typealias ChatAdministratorRightsImpl = dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRightsImpl
|
||||
|
@ -1,41 +1,4 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.AdministratorChatMember
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class AdministratorChatMemberImpl(
|
||||
@SerialName(userField)
|
||||
override val user: User,
|
||||
@SerialName(canBeEditedField)
|
||||
override val canBeEdited: Boolean = false,
|
||||
@SerialName(canChangeInfoField)
|
||||
override val canChangeInfo: Boolean = false,
|
||||
@SerialName(canPostMessagesField)
|
||||
override val canPostMessages: Boolean = false,
|
||||
@SerialName(canEditMessagesField)
|
||||
override val canEditMessages: Boolean = false,
|
||||
@SerialName(canDeleteMessagesField)
|
||||
override val canRemoveMessages: Boolean = false,
|
||||
@SerialName(canInviteUsersField)
|
||||
override val canInviteUsers: Boolean = false,
|
||||
@SerialName(canRestrictMembersField)
|
||||
override val canRestrictMembers: Boolean = false,
|
||||
@SerialName(canPinMessagesField)
|
||||
override val canPinMessages: Boolean = false,
|
||||
@SerialName(canPromoteMembersField)
|
||||
override val canPromoteMembers: Boolean = false,
|
||||
@SerialName(canManageVideoChatsField)
|
||||
override val canManageVideoChats: Boolean = false,
|
||||
@SerialName(canManageChatField)
|
||||
override val canManageChat: Boolean = false,
|
||||
@SerialName(isAnonymousField)
|
||||
override val isAnonymous: Boolean = false,
|
||||
@SerialName(customTitleField)
|
||||
override val customTitle: String? = null
|
||||
) : AdministratorChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "administrator"
|
||||
}
|
||||
@Deprecated("AdministratorChatMemberImpl", ReplaceWith("AdministratorChatMemberImpl", "dev.inmo.tgbotapi.types.chat.member.AdministratorChatMemberImpl"))
|
||||
typealias AdministratorChatMemberImpl = dev.inmo.tgbotapi.types.chat.member.AdministratorChatMemberImpl
|
||||
|
@ -1,40 +1,4 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.AdministratorChatMember
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class CreatorChatMember(
|
||||
override val user: User,
|
||||
@SerialName(isAnonymousField)
|
||||
override val isAnonymous: Boolean = false,
|
||||
@SerialName(customTitleField)
|
||||
override val customTitle: String? = null
|
||||
) : AdministratorChatMember {
|
||||
@Transient
|
||||
override val canBeEdited: Boolean = true
|
||||
@Transient
|
||||
override val canChangeInfo: Boolean = true
|
||||
@Transient
|
||||
override val canPostMessages: Boolean = true
|
||||
@Transient
|
||||
override val canEditMessages: Boolean = true
|
||||
@Transient
|
||||
override val canRemoveMessages: Boolean = true
|
||||
@Transient
|
||||
override val canInviteUsers: Boolean = true
|
||||
@Transient
|
||||
override val canRestrictMembers: Boolean = true
|
||||
@Transient
|
||||
override val canPinMessages: Boolean = true
|
||||
@Transient
|
||||
override val canPromoteMembers: Boolean = true
|
||||
@Transient
|
||||
override val canManageVideoChats: Boolean = true
|
||||
@Transient
|
||||
override val canManageChat: Boolean = true
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "creator"
|
||||
}
|
||||
@Deprecated("CreatorChatMember", ReplaceWith("CreatorChatMember", "dev.inmo.tgbotapi.types.chat.member.CreatorChatMember"))
|
||||
typealias CreatorChatMember = dev.inmo.tgbotapi.types.chat.member.CreatorChatMember
|
||||
|
@ -1,17 +1,4 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.BannedChatMember
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class KickedChatMember(
|
||||
@SerialName(userField)
|
||||
override val user: User,
|
||||
@SerialName(untilDateField)
|
||||
override val untilDate: TelegramDate? = null
|
||||
) : BannedChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "kicked"
|
||||
}
|
||||
@Deprecated("KickedChatMember", ReplaceWith("KickedChatMember", "dev.inmo.tgbotapi.types.chat.member.KickedChatMember"))
|
||||
typealias KickedChatMember = dev.inmo.tgbotapi.types.chat.member.KickedChatMember
|
||||
|
@ -1,12 +1,4 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.LeftChatMember
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class LeftChatMemberImpl(@SerialName(userField) override val user: User) : LeftChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "left"
|
||||
}
|
||||
@Deprecated("LeftChatMemberImpl", ReplaceWith("LeftChatMemberImpl", "dev.inmo.tgbotapi.types.chat.member.LeftChatMemberImpl"))
|
||||
typealias LeftChatMemberImpl = dev.inmo.tgbotapi.types.chat.member.LeftChatMemberImpl
|
||||
|
@ -1,12 +1,4 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.MemberChatMember
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class MemberChatMemberImpl(@SerialName(userField) override val user: User) : MemberChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "member"
|
||||
}
|
||||
@Deprecated("MemberChatMemberImpl", ReplaceWith("MemberChatMemberImpl", "dev.inmo.tgbotapi.types.chat.member.MemberChatMemberImpl"))
|
||||
typealias MemberChatMemberImpl = dev.inmo.tgbotapi.types.chat.member.MemberChatMemberImpl
|
||||
|
@ -1,36 +1,4 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.BannedChatMember
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.SpecialRightsChatMember
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@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)
|
||||
val canSendMessages: Boolean = false,
|
||||
@SerialName(canSendMediaMessagesField)
|
||||
val canSendMediaMessages: Boolean = false,
|
||||
@SerialName(canSendPollsField)
|
||||
val canSendPolls: Boolean = false,
|
||||
@SerialName(canSendOtherMessagesField)
|
||||
val canSendOtherMessages: Boolean = false,
|
||||
@SerialName(canAddWebPagePreviewsField)
|
||||
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
|
||||
) : BannedChatMember, SpecialRightsChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "restricted"
|
||||
}
|
||||
@Deprecated("RestrictedChatMember", ReplaceWith("RestrictedChatMember", "dev.inmo.tgbotapi.types.chat.member.RestrictedChatMember"))
|
||||
typealias RestrictedChatMember = dev.inmo.tgbotapi.types.chat.member.RestrictedChatMember
|
||||
|
@ -1,25 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
@Deprecated("AdministratorChatMember", ReplaceWith("AdministratorChatMember", "dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember"))
|
||||
typealias AdministratorChatMember = dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember
|
||||
|
||||
@Serializable(AdministratorChatMemberSerializer::class)
|
||||
interface AdministratorChatMember : SpecialRightsChatMember, ChatAdministratorRights {
|
||||
val canBeEdited: Boolean
|
||||
val customTitle: String?
|
||||
|
||||
val canManageVoiceChats: Boolean
|
||||
get() = canManageVideoChats
|
||||
}
|
||||
|
||||
@RiskFeature
|
||||
object AdministratorChatMemberSerializer : KSerializer<AdministratorChatMember> {
|
||||
override val descriptor: SerialDescriptor = ChatMemberSerializer.descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): AdministratorChatMember = ChatMemberSerializer.deserialize(decoder) as AdministratorChatMember
|
||||
override fun serialize(encoder: Encoder, value: AdministratorChatMember) = ChatMemberSerializer.serialize(encoder, value)
|
||||
}
|
||||
@Deprecated("AdministratorChatMemberSerializer", ReplaceWith("AdministratorChatMemberSerializer", "dev.inmo.tgbotapi.types.chat.member.AdministratorChatMemberSerializer"))
|
||||
typealias AdministratorChatMemberSerializer = dev.inmo.tgbotapi.types.chat.member.AdministratorChatMemberSerializer
|
||||
|
@ -1,7 +1,4 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.types.UntilDate
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(ChatMemberSerializer::class)
|
||||
interface BannedChatMember : ChatMember, UntilDate
|
||||
@Deprecated("BannedChatMember", ReplaceWith("BannedChatMember", "dev.inmo.tgbotapi.types.chat.member.BannedChatMember"))
|
||||
typealias BannedChatMember = dev.inmo.tgbotapi.types.chat.member.BannedChatMember
|
||||
|
@ -1,18 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||
|
||||
sealed interface SpecialChatAdministratorRights {
|
||||
val canChangeInfo: Boolean
|
||||
val canInviteUsers: Boolean
|
||||
val canPinMessages: Boolean
|
||||
}
|
||||
@Deprecated("SpecialChatAdministratorRights", ReplaceWith("SpecialChatAdministratorRights", "dev.inmo.tgbotapi.types.chat.member.SpecialChatAdministratorRights"))
|
||||
typealias SpecialChatAdministratorRights = dev.inmo.tgbotapi.types.chat.member.SpecialChatAdministratorRights
|
||||
|
||||
interface ChatAdministratorRights : SpecialChatAdministratorRights {
|
||||
val isAnonymous: Boolean
|
||||
val canManageChat: Boolean
|
||||
val canRemoveMessages: Boolean
|
||||
val canManageVideoChats: Boolean
|
||||
val canRestrictMembers: Boolean
|
||||
val canPromoteMembers: Boolean
|
||||
val canPostMessages: Boolean
|
||||
val canEditMessages: Boolean
|
||||
}
|
||||
@Deprecated("ChatAdministratorRights", ReplaceWith("ChatAdministratorRights", "dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRights"))
|
||||
typealias ChatAdministratorRights = dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRights
|
||||
|
@ -1,47 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.WithUser
|
||||
import dev.inmo.tgbotapi.types.ChatMember.*
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
import dev.inmo.tgbotapi.types.statusField
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
@Deprecated("ChatMember", ReplaceWith("ChatMember", "dev.inmo.tgbotapi.types.chat.member.ChatMember"))
|
||||
typealias ChatMember = dev.inmo.tgbotapi.types.chat.member.ChatMember
|
||||
|
||||
@Serializable(ChatMemberSerializer::class)
|
||||
sealed interface ChatMember : WithUser
|
||||
|
||||
@RiskFeature
|
||||
object ChatMemberSerializer : KSerializer<ChatMember> {
|
||||
override val descriptor: SerialDescriptor = JsonObject.serializer().descriptor
|
||||
|
||||
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(CreatorChatMember.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")
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: ChatMember) {
|
||||
when (value) {
|
||||
is CreatorChatMember -> CreatorChatMember.serializer()
|
||||
is AdministratorChatMemberImpl -> AdministratorChatMemberImpl.serializer()
|
||||
is MemberChatMember -> MemberChatMemberImpl.serializer()
|
||||
is RestrictedChatMember -> RestrictedChatMember.serializer()
|
||||
is LeftChatMember -> LeftChatMemberImpl.serializer()
|
||||
is KickedChatMember -> KickedChatMember.serializer()
|
||||
}
|
||||
}
|
||||
}
|
||||
@Deprecated("ChatMemberSerializer", ReplaceWith("ChatMemberSerializer", "dev.inmo.tgbotapi.types.chat.member.ChatMemberSerializer"))
|
||||
typealias ChatMemberSerializer = dev.inmo.tgbotapi.types.chat.member.ChatMemberSerializer
|
||||
|
@ -1,3 +1,4 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||
|
||||
interface LeftChatMember : ChatMember
|
||||
@Deprecated("LeftChatMember", ReplaceWith("LeftChatMember", "dev.inmo.tgbotapi.types.chat.member.LeftChatMember"))
|
||||
typealias LeftChatMember = dev.inmo.tgbotapi.types.chat.member.LeftChatMember
|
||||
|
@ -1,3 +1,4 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||
|
||||
interface MemberChatMember : ChatMember
|
||||
@Deprecated("MemberChatMember", ReplaceWith("MemberChatMember", "dev.inmo.tgbotapi.types.chat.member.MemberChatMember"))
|
||||
typealias MemberChatMember = dev.inmo.tgbotapi.types.chat.member.MemberChatMember
|
||||
|
@ -1,6 +1,4 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(ChatMemberSerializer::class)
|
||||
interface SpecialRightsChatMember : ChatMember, SpecialChatAdministratorRights
|
||||
@Deprecated("SpecialRightsChatMember", ReplaceWith("SpecialRightsChatMember", "dev.inmo.tgbotapi.types.chat.member.SpecialRightsChatMember"))
|
||||
typealias SpecialRightsChatMember = dev.inmo.tgbotapi.types.chat.member.SpecialRightsChatMember
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types
|
||||
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember
|
||||
import dev.inmo.tgbotapi.types.chat.member.ChatMember
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
@ -0,0 +1,26 @@
|
||||
package dev.inmo.tgbotapi.types.chat.member
|
||||
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
@Serializable(AdministratorChatMemberSerializer::class)
|
||||
sealed interface AdministratorChatMember : SpecialRightsChatMember, ChatAdministratorRights {
|
||||
val canBeEdited: Boolean
|
||||
val customTitle: String?
|
||||
|
||||
val canManageVoiceChats: Boolean
|
||||
get() = canManageVideoChats
|
||||
}
|
||||
|
||||
@RiskFeature
|
||||
object AdministratorChatMemberSerializer : KSerializer<AdministratorChatMember> {
|
||||
override val descriptor: SerialDescriptor = ChatMemberSerializer.descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): AdministratorChatMember = ChatMemberSerializer.deserialize(decoder) as AdministratorChatMember
|
||||
override fun serialize(encoder: Encoder, value: AdministratorChatMember) =
|
||||
ChatMemberSerializer.serialize(encoder, value)
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package dev.inmo.tgbotapi.types.chat.member
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class AdministratorChatMemberImpl(
|
||||
@SerialName(userField)
|
||||
override val user: User,
|
||||
@SerialName(canBeEditedField)
|
||||
override val canBeEdited: Boolean = false,
|
||||
@SerialName(canChangeInfoField)
|
||||
override val canChangeInfo: Boolean = false,
|
||||
@SerialName(canPostMessagesField)
|
||||
override val canPostMessages: Boolean = false,
|
||||
@SerialName(canEditMessagesField)
|
||||
override val canEditMessages: Boolean = false,
|
||||
@SerialName(canDeleteMessagesField)
|
||||
override val canRemoveMessages: Boolean = false,
|
||||
@SerialName(canInviteUsersField)
|
||||
override val canInviteUsers: Boolean = false,
|
||||
@SerialName(canRestrictMembersField)
|
||||
override val canRestrictMembers: Boolean = false,
|
||||
@SerialName(canPinMessagesField)
|
||||
override val canPinMessages: Boolean = false,
|
||||
@SerialName(canPromoteMembersField)
|
||||
override val canPromoteMembers: Boolean = false,
|
||||
@SerialName(canManageVideoChatsField)
|
||||
override val canManageVideoChats: Boolean = false,
|
||||
@SerialName(canManageChatField)
|
||||
override val canManageChat: Boolean = false,
|
||||
@SerialName(isAnonymousField)
|
||||
override val isAnonymous: Boolean = false,
|
||||
@SerialName(customTitleField)
|
||||
override val customTitle: String? = null
|
||||
) : AdministratorChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "administrator"
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.chat.member
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.types.UntilDate
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(ChatMemberSerializer::class)
|
||||
sealed interface BannedChatMember : ChatMember, UntilDate
|
@ -0,0 +1,18 @@
|
||||
package dev.inmo.tgbotapi.types.chat.member
|
||||
|
||||
sealed interface SpecialChatAdministratorRights {
|
||||
val canChangeInfo: Boolean
|
||||
val canInviteUsers: Boolean
|
||||
val canPinMessages: Boolean
|
||||
}
|
||||
|
||||
sealed interface ChatAdministratorRights : SpecialChatAdministratorRights {
|
||||
val isAnonymous: Boolean
|
||||
val canManageChat: Boolean
|
||||
val canRemoveMessages: Boolean
|
||||
val canManageVideoChats: Boolean
|
||||
val canRestrictMembers: Boolean
|
||||
val canPromoteMembers: Boolean
|
||||
val canPostMessages: Boolean
|
||||
val canEditMessages: Boolean
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package dev.inmo.tgbotapi.types.chat.member
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ChatAdministratorRightsImpl(
|
||||
@SerialName(canChangeInfoField)
|
||||
override val canChangeInfo: Boolean = false,
|
||||
@SerialName(canPostMessagesField)
|
||||
override val canPostMessages: Boolean = false,
|
||||
@SerialName(canEditMessagesField)
|
||||
override val canEditMessages: Boolean = false,
|
||||
@SerialName(canDeleteMessagesField)
|
||||
override val canRemoveMessages: Boolean = false,
|
||||
@SerialName(canInviteUsersField)
|
||||
override val canInviteUsers: Boolean = false,
|
||||
@SerialName(canRestrictMembersField)
|
||||
override val canRestrictMembers: Boolean = false,
|
||||
@SerialName(canPinMessagesField)
|
||||
override val canPinMessages: Boolean = false,
|
||||
@SerialName(canPromoteMembersField)
|
||||
override val canPromoteMembers: Boolean = false,
|
||||
@SerialName(canManageVideoChatsField)
|
||||
override val canManageVideoChats: Boolean = false,
|
||||
@SerialName(canManageChatField)
|
||||
override val canManageChat: Boolean = false,
|
||||
@SerialName(isAnonymousField)
|
||||
override val isAnonymous: Boolean = false
|
||||
) : ChatAdministratorRights
|
@ -0,0 +1,45 @@
|
||||
package dev.inmo.tgbotapi.types.chat.member
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.WithUser
|
||||
import dev.inmo.tgbotapi.types.statusField
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
@Serializable(ChatMemberSerializer::class)
|
||||
sealed interface ChatMember : WithUser
|
||||
|
||||
@RiskFeature
|
||||
object ChatMemberSerializer : KSerializer<ChatMember> {
|
||||
override val descriptor: SerialDescriptor = JsonObject.serializer().descriptor
|
||||
|
||||
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(CreatorChatMember.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")
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: ChatMember) {
|
||||
when (value) {
|
||||
is CreatorChatMember -> CreatorChatMember.serializer()
|
||||
is AdministratorChatMemberImpl -> AdministratorChatMemberImpl.serializer()
|
||||
is MemberChatMember -> MemberChatMemberImpl.serializer()
|
||||
is RestrictedChatMember -> RestrictedChatMember.serializer()
|
||||
is LeftChatMember -> LeftChatMemberImpl.serializer()
|
||||
is KickedChatMember -> KickedChatMember.serializer()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package dev.inmo.tgbotapi.types.chat.member
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class CreatorChatMember(
|
||||
override val user: User,
|
||||
@SerialName(isAnonymousField)
|
||||
override val isAnonymous: Boolean = false,
|
||||
@SerialName(customTitleField)
|
||||
override val customTitle: String? = null
|
||||
) : AdministratorChatMember {
|
||||
@Transient
|
||||
override val canBeEdited: Boolean = true
|
||||
@Transient
|
||||
override val canChangeInfo: Boolean = true
|
||||
@Transient
|
||||
override val canPostMessages: Boolean = true
|
||||
@Transient
|
||||
override val canEditMessages: Boolean = true
|
||||
@Transient
|
||||
override val canRemoveMessages: Boolean = true
|
||||
@Transient
|
||||
override val canInviteUsers: Boolean = true
|
||||
@Transient
|
||||
override val canRestrictMembers: Boolean = true
|
||||
@Transient
|
||||
override val canPinMessages: Boolean = true
|
||||
@Transient
|
||||
override val canPromoteMembers: Boolean = true
|
||||
@Transient
|
||||
override val canManageVideoChats: Boolean = true
|
||||
@Transient
|
||||
override val canManageChat: Boolean = true
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "creator"
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package dev.inmo.tgbotapi.types.chat.member
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class KickedChatMember(
|
||||
@SerialName(userField)
|
||||
override val user: User,
|
||||
@SerialName(untilDateField)
|
||||
override val untilDate: TelegramDate? = null
|
||||
) : BannedChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "kicked"
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types.chat.member
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(ChatMemberSerializer::class)
|
||||
sealed interface LeftChatMember : ChatMember
|
@ -0,0 +1,11 @@
|
||||
package dev.inmo.tgbotapi.types.chat.member
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class LeftChatMemberImpl(@SerialName(userField) override val user: User) : LeftChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "left"
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types.chat.member
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(ChatMemberSerializer::class)
|
||||
sealed interface MemberChatMember : ChatMember
|
@ -0,0 +1,11 @@
|
||||
package dev.inmo.tgbotapi.types.chat.member
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class MemberChatMemberImpl(@SerialName(userField) override val user: User) : MemberChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "member"
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package dev.inmo.tgbotapi.types.chat.member
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@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)
|
||||
val canSendMessages: Boolean = false,
|
||||
@SerialName(canSendMediaMessagesField)
|
||||
val canSendMediaMessages: Boolean = false,
|
||||
@SerialName(canSendPollsField)
|
||||
val canSendPolls: Boolean = false,
|
||||
@SerialName(canSendOtherMessagesField)
|
||||
val canSendOtherMessages: Boolean = false,
|
||||
@SerialName(canAddWebPagePreviewsField)
|
||||
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
|
||||
) : BannedChatMember, SpecialRightsChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "restricted"
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types.chat.member
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(ChatMemberSerializer::class)
|
||||
sealed interface SpecialRightsChatMember : ChatMember, SpecialChatAdministratorRights
|
@ -6,8 +6,7 @@ import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.payments.SendInvoice
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.queries.callback.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.*
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.chat.member.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
|
||||
@ -28,6 +27,11 @@ import dev.inmo.tgbotapi.types.buttons.*
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.*
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.extended.*
|
||||
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.MemberChatMember
|
||||
import dev.inmo.tgbotapi.types.chat.member.SpecialRightsChatMember
|
||||
import dev.inmo.tgbotapi.types.dice.*
|
||||
import dev.inmo.tgbotapi.types.files.*
|
||||
import dev.inmo.tgbotapi.types.files.Sticker
|
||||
|
@ -1,7 +1,7 @@
|
||||
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
|
||||
|
||||
import dev.inmo.tgbotapi.types.ChatInviteLink
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember
|
||||
import dev.inmo.tgbotapi.types.chat.member.ChatMember
|
||||
import dev.inmo.tgbotapi.types.ChatMemberUpdated
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user