mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 00:57:13 +00:00
add support of ChatAdministratorRights
This commit is contained in:
parent
7bac4a3a32
commit
2dcbc0df32
@ -0,0 +1,13 @@
|
||||
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
|
||||
) = execute(ClearMyDefaultAdministratorRights(forChannels))
|
||||
|
||||
suspend fun TelegramBot.clearMyDefaultAdministratorRightsForChannels() = clearMyDefaultAdministratorRights(forChannels = true)
|
||||
|
||||
suspend fun TelegramBot.clearMyDefaultAdministratorRightsForGroupsAndSupergroups() = clearMyDefaultAdministratorRights(forChannels = false)
|
@ -0,0 +1,12 @@
|
||||
package dev.inmo.tgbotapi.extensions.api.bot
|
||||
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.requests.bot.GetMyDefaultAdministratorRights
|
||||
|
||||
suspend fun TelegramBot.getMyDefaultAdministratorRights(
|
||||
forChannels: Boolean? = null
|
||||
) = execute(GetMyDefaultAdministratorRights(forChannels))
|
||||
|
||||
suspend fun TelegramBot.getMyDefaultAdministratorRightsForChannels() = getMyDefaultAdministratorRights(forChannels = true)
|
||||
|
||||
suspend fun TelegramBot.getMyDefaultAdministratorRightsForGroupsAndSupergroups() = getMyDefaultAdministratorRights(forChannels = false)
|
@ -0,0 +1,18 @@
|
||||
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
|
||||
|
||||
suspend fun TelegramBot.setMyDefaultAdministratorRights(
|
||||
rights: ChatAdministratorRightsImpl,
|
||||
forChannels: Boolean? = null
|
||||
) = execute(SetMyDefaultAdministratorRights(rights, forChannels))
|
||||
|
||||
suspend fun TelegramBot.setMyDefaultAdministratorRightsForChannels(
|
||||
rights: ChatAdministratorRightsImpl
|
||||
) = setMyDefaultAdministratorRights(rights, forChannels = true)
|
||||
|
||||
suspend fun TelegramBot.setMyDefaultAdministratorRightsForGroupsAndSupergroups(
|
||||
rights: ChatAdministratorRightsImpl
|
||||
) = setMyDefaultAdministratorRights(rights, forChannels = false)
|
@ -18,7 +18,7 @@ suspend fun TelegramBot.promoteChatMember(
|
||||
canRestrictMembers: Boolean? = null,
|
||||
canPinMessages: Boolean? = null,
|
||||
canPromoteMembers: Boolean? = null,
|
||||
canManageVoiceChats: Boolean? = null,
|
||||
canManageVideoChats: Boolean? = null,
|
||||
canManageChat: Boolean?
|
||||
) = execute(
|
||||
PromoteChatMember(
|
||||
@ -34,7 +34,7 @@ suspend fun TelegramBot.promoteChatMember(
|
||||
canRestrictMembers,
|
||||
canPinMessages,
|
||||
canPromoteMembers,
|
||||
canManageVoiceChats,
|
||||
canManageVideoChats,
|
||||
canManageChat
|
||||
)
|
||||
)
|
||||
@ -52,7 +52,7 @@ suspend fun TelegramBot.promoteChatMember(
|
||||
canRestrictMembers: Boolean? = null,
|
||||
canPinMessages: Boolean? = null,
|
||||
canPromoteMembers: Boolean? = null,
|
||||
canManageVoiceChats: Boolean? = null,
|
||||
canManageVideoChats: Boolean? = null,
|
||||
canManageChat: Boolean? = null
|
||||
) = promoteChatMember(
|
||||
chat.id,
|
||||
@ -67,7 +67,7 @@ suspend fun TelegramBot.promoteChatMember(
|
||||
canRestrictMembers,
|
||||
canPinMessages,
|
||||
canPromoteMembers,
|
||||
canManageVoiceChats,
|
||||
canManageVideoChats,
|
||||
canManageChat
|
||||
)
|
||||
|
||||
@ -84,7 +84,7 @@ suspend fun TelegramBot.promoteChatMember(
|
||||
canRestrictMembers: Boolean? = null,
|
||||
canPinMessages: Boolean? = null,
|
||||
canPromoteMembers: Boolean? = null,
|
||||
canManageVoiceChats: Boolean? = null,
|
||||
canManageVideoChats: Boolean? = null,
|
||||
canManageChat: Boolean? = null
|
||||
) = promoteChatMember(
|
||||
chatId,
|
||||
@ -99,7 +99,7 @@ suspend fun TelegramBot.promoteChatMember(
|
||||
canRestrictMembers,
|
||||
canPinMessages,
|
||||
canPromoteMembers,
|
||||
canManageVoiceChats,
|
||||
canManageVideoChats,
|
||||
canManageChat
|
||||
)
|
||||
|
||||
@ -116,7 +116,7 @@ suspend fun TelegramBot.promoteChatMember(
|
||||
canRestrictMembers: Boolean? = null,
|
||||
canPinMessages: Boolean? = null,
|
||||
canPromoteMembers: Boolean? = null,
|
||||
canManageVoiceChats: Boolean? = null,
|
||||
canManageVideoChats: Boolean? = null,
|
||||
canManageChat: Boolean? = null
|
||||
) = promoteChatMember(
|
||||
chat.id,
|
||||
@ -131,6 +131,6 @@ suspend fun TelegramBot.promoteChatMember(
|
||||
canRestrictMembers,
|
||||
canPinMessages,
|
||||
canPromoteMembers,
|
||||
canManageVoiceChats,
|
||||
canManageVideoChats,
|
||||
canManageChat
|
||||
)
|
||||
|
@ -0,0 +1,18 @@
|
||||
package dev.inmo.tgbotapi.requests.bot
|
||||
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
@Serializable
|
||||
class ClearMyDefaultAdministratorRights(
|
||||
@SerialName(forChannelsField)
|
||||
val forChannels: Boolean? = null
|
||||
) : SimpleRequest<Boolean> {
|
||||
override fun method(): String = "setMyDefaultAdministratorRights"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
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 kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class GetMyDefaultAdministratorRights(
|
||||
@SerialName(forChannelsField)
|
||||
val forChannels: Boolean? = null
|
||||
) : SimpleRequest<AdministratorChatMemberImpl> {
|
||||
override fun method(): String = "getMyDefaultAdministratorRights"
|
||||
override val resultDeserializer: DeserializationStrategy<AdministratorChatMemberImpl>
|
||||
get() = AdministratorChatMemberImpl.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
companion object {
|
||||
val ForChannels = GetMyDefaultAdministratorRights(true)
|
||||
val ForGroups = GetMyDefaultAdministratorRights(false)
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package dev.inmo.tgbotapi.requests.bot
|
||||
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
@Serializable
|
||||
class SetMyDefaultAdministratorRights(
|
||||
@SerialName(rightsField)
|
||||
val rights: ChatAdministratorRightsImpl,
|
||||
@SerialName(forChannelsField)
|
||||
val forChannels: Boolean? = null
|
||||
) : SimpleRequest<Boolean> {
|
||||
override fun method(): String = "setMyDefaultAdministratorRights"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = Boolean.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
@ -32,8 +32,8 @@ data class PromoteChatMember(
|
||||
private val canPinMessages: Boolean? = null,
|
||||
@SerialName(canPromoteMembersField)
|
||||
private val canPromoteMembers: Boolean? = null,
|
||||
@SerialName(canManageVoiceChatsField)
|
||||
private val canManageVoiceChats: Boolean? = null,
|
||||
@SerialName(canManageVideoChatsField)
|
||||
private val canManageVideoChats: Boolean? = null,
|
||||
@SerialName(canManageChatField)
|
||||
private val canManageChat: Boolean? = null
|
||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||
|
@ -0,0 +1,31 @@
|
||||
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
|
@ -26,8 +26,8 @@ data class AdministratorChatMemberImpl(
|
||||
override val canPinMessages: Boolean = false,
|
||||
@SerialName(canPromoteMembersField)
|
||||
override val canPromoteMembers: Boolean = false,
|
||||
@SerialName(canManageVoiceChatsField)
|
||||
override val canManageVoiceChats: Boolean = false,
|
||||
@SerialName(canManageVideoChatsField)
|
||||
override val canManageVideoChats: Boolean = false,
|
||||
@SerialName(canManageChatField)
|
||||
override val canManageChat: Boolean = false,
|
||||
@SerialName(isAnonymousField)
|
||||
|
@ -31,7 +31,7 @@ data class CreatorChatMember(
|
||||
@Transient
|
||||
override val canPromoteMembers: Boolean = true
|
||||
@Transient
|
||||
override val canManageVoiceChats: Boolean = true
|
||||
override val canManageVideoChats: Boolean = true
|
||||
@Transient
|
||||
override val canManageChat: Boolean = true
|
||||
@SerialName(statusField)
|
||||
|
@ -8,17 +8,12 @@ import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
@Serializable(AdministratorChatMemberSerializer::class)
|
||||
interface AdministratorChatMember : SpecialRightsChatMember {
|
||||
interface AdministratorChatMember : SpecialRightsChatMember, ChatAdministratorRights {
|
||||
val canBeEdited: Boolean
|
||||
val canPostMessages: Boolean
|
||||
val canEditMessages: Boolean
|
||||
val canRemoveMessages: Boolean
|
||||
val canRestrictMembers: Boolean
|
||||
val canPromoteMembers: Boolean
|
||||
val canManageVoiceChats: Boolean
|
||||
val canManageChat: Boolean
|
||||
val isAnonymous: Boolean
|
||||
val customTitle: String?
|
||||
|
||||
val canManageVoiceChats: Boolean
|
||||
get() = canManageVideoChats
|
||||
}
|
||||
|
||||
@RiskFeature
|
||||
|
@ -0,0 +1,18 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||
|
||||
sealed interface SpecialChatAdministratorRights {
|
||||
val canChangeInfo: Boolean
|
||||
val canInviteUsers: Boolean
|
||||
val canPinMessages: Boolean
|
||||
}
|
||||
|
||||
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
|
||||
}
|
@ -3,8 +3,4 @@ package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(ChatMemberSerializer::class)
|
||||
interface SpecialRightsChatMember : ChatMember {
|
||||
val canChangeInfo: Boolean
|
||||
val canInviteUsers: Boolean
|
||||
val canPinMessages: Boolean
|
||||
}
|
||||
interface SpecialRightsChatMember : ChatMember, SpecialChatAdministratorRights
|
||||
|
@ -270,6 +270,9 @@ const val canRestrictMembersField = "can_restrict_members"
|
||||
const val canPinMessagesField = "can_pin_messages"
|
||||
const val canPromoteMembersField = "can_promote_members"
|
||||
const val canManageVoiceChatsField = "can_manage_voice_chats"
|
||||
const val canManageVideoChatsField = "can_manage_video_chats"
|
||||
const val rightsField = "rights"
|
||||
const val forChannelsField = "for_channels"
|
||||
const val canManageChatField = "can_manage_chat"
|
||||
const val pngStickerField = "png_sticker"
|
||||
const val tgsStickerField = "tgs_sticker"
|
||||
|
Loading…
Reference in New Issue
Block a user