1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

chat permissions adding

This commit is contained in:
InsanusMokrassar 2019-08-12 13:46:16 +06:00
parent cb94a3a389
commit 394bec1805
8 changed files with 61 additions and 5 deletions

View File

@ -15,6 +15,7 @@ like this
Changes according to [July 29, 2019 Telegram Bot API update](https://core.telegram.org/bots/api#july-29-2019):
* `Sticker` and `StickerSet` now have field `isAnimated`
* `ChatPermissions` object was added, `GroupChat` interface got `permissions` field, request `SetChatPermissions` was added
## 0.16.0 Bot API 4.3

View File

@ -0,0 +1,19 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions
import kotlinx.serialization.*
import kotlinx.serialization.internal.BooleanSerializer
@Serializable
data class SetChatPermissions (
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(permissionsField)
val permissions: ChatPermissions
): ChatRequest, SimpleRequest<Boolean> {
override fun method(): String = "setChatPermissions"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -146,6 +146,7 @@ const val isMemberField = "is_member"
const val canSendMessagesField = "can_send_messages"
const val canSendMediaMessagesField = "can_send_media_messages"
const val canSendOtherMessagesField = "can_send_other_messages"
const val canSendPollsField = "can_send_polls"
const val canAddWebPagePreviewsField = "can_add_web_page_previews"
const val canBeEditedField = "can_be_edited"
@ -202,6 +203,7 @@ const val certificateField = "certificate"
const val questionField = "question"
const val optionsField = "options"
const val payField = "pay"
const val permissionsField = "permissions"
const val pointField = "point"
const val xShiftField = "x_shift"

View File

@ -0,0 +1,25 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class ChatPermissions(
@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)
val canChangeInfo: Boolean = false,
@SerialName(canInviteUsersField)
val canInviteUsers: Boolean = false,
@SerialName(canPinMessagesField)
val canPinMessages: Boolean = false
)

View File

@ -11,5 +11,6 @@ data class GroupChatImpl(
override val allMembersAreAdmins: Boolean,
override val inviteLink: String? = null,
override val chatPhoto: ChatPhoto? = null,
override val pinnedMessage: RawMessage? = null
override val pinnedMessage: RawMessage? = null,
override val permissions: ChatPermissions? = null
) : GroupChat

View File

@ -21,7 +21,8 @@ data class RawChat(
private val sticker_set_name: String? = null,
private val can_set_sticker_set: Boolean? = null,
@SerialName("photo")
override val chatPhoto: ChatPhoto? = null
override val chatPhoto: ChatPhoto? = null,
private val permissions: ChatPermissions? = null
) : Chat {
fun extractChat(): Chat {
return when (type) {
@ -31,7 +32,9 @@ data class RawChat(
title,
all_members_are_administrators ?: false,
invite_link,
chatPhoto
chatPhoto,
pinned_message,
permissions
)
"supergroup" -> SupergroupChat(
id,
@ -43,7 +46,8 @@ data class RawChat(
chatPhoto,
pinned_message,
sticker_set_name,
can_set_sticker_set ?: false
can_set_sticker_set ?: false,
permissions
)
"channel" -> ChannelChat(
id,

View File

@ -15,5 +15,6 @@ data class SupergroupChat(
override val chatPhoto: ChatPhoto? = null,
override val pinnedMessage: RawMessage? = null,
val stickerSetName: String? = null,
val canSetStickerSet: Boolean
val canSetStickerSet: Boolean = false,
override val permissions: ChatPermissions? = null
) : GroupChat, UsernameChat, DescriptionChat

View File

@ -1,5 +1,8 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions
interface GroupChat : PublicChat {
val allMembersAreAdmins: Boolean
val permissions: ChatPermissions?
}