mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
Merge pull request #715 from madhead/feature/replace_can_send_media_messages_field
Replaced the fields `can_send_media_messages`…
This commit is contained in:
commit
4ddced8e26
@ -2,9 +2,10 @@
|
||||
|
||||
## 5.1.0
|
||||
|
||||
[Bot API 6.5](https://core.telegram.org/bots/api-changelog#february-3-2023) support
|
||||
|
||||
* `Core`:
|
||||
* [Bot API 6.5](https://core.telegram.org/bots/api#february-3-2023) support
|
||||
* Added the field `user_chat_id` to the class `ChatJoinRequest`.
|
||||
|
||||
## 5.0.2
|
||||
|
||||
|
@ -14,27 +14,31 @@ suspend fun TelegramBot.restrictChatMember(
|
||||
chatId: ChatIdentifier,
|
||||
userId: UserId,
|
||||
untilDate: TelegramDate? = null,
|
||||
permissions: ChatPermissions = ChatPermissions()
|
||||
) = execute(RestrictChatMember(chatId, userId, untilDate, permissions))
|
||||
permissions: ChatPermissions = ChatPermissions(),
|
||||
useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
|
||||
) = execute(RestrictChatMember(chatId, userId, untilDate, permissions, useIndependentChatPermissions))
|
||||
|
||||
suspend fun TelegramBot.restrictChatMember(
|
||||
chat: PublicChat,
|
||||
userId: UserId,
|
||||
untilDate: TelegramDate? = null,
|
||||
permissions: ChatPermissions = ChatPermissions()
|
||||
) = restrictChatMember(chat.id, userId, untilDate, permissions)
|
||||
permissions: ChatPermissions = ChatPermissions(),
|
||||
useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
|
||||
) = restrictChatMember(chat.id, userId, untilDate, permissions, useIndependentChatPermissions)
|
||||
|
||||
suspend fun TelegramBot.restrictChatMember(
|
||||
chatId: IdChatIdentifier,
|
||||
user: User,
|
||||
untilDate: TelegramDate? = null,
|
||||
permissions: ChatPermissions = ChatPermissions()
|
||||
) = restrictChatMember(chatId, user.id, untilDate, permissions)
|
||||
permissions: ChatPermissions = ChatPermissions(),
|
||||
useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
|
||||
) = restrictChatMember(chatId, user.id, untilDate, permissions, useIndependentChatPermissions)
|
||||
|
||||
suspend fun TelegramBot.restrictChatMember(
|
||||
chat: PublicChat,
|
||||
user: User,
|
||||
untilDate: TelegramDate? = null,
|
||||
permissions: ChatPermissions = ChatPermissions()
|
||||
) = restrictChatMember(chat.id, user.id, untilDate, permissions)
|
||||
permissions: ChatPermissions = ChatPermissions(),
|
||||
useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
|
||||
) = restrictChatMember(chat.id, user.id, untilDate, permissions, useIndependentChatPermissions)
|
||||
|
||||
|
@ -8,10 +8,12 @@ import dev.inmo.tgbotapi.types.chat.PublicChat
|
||||
|
||||
suspend fun TelegramBot.setDefaultChatMembersPermissions(
|
||||
chatId: ChatIdentifier,
|
||||
permissions: ChatPermissions
|
||||
) = execute(SetChatPermissions(chatId, permissions))
|
||||
permissions: ChatPermissions,
|
||||
useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
|
||||
) = execute(SetChatPermissions(chatId, permissions, useIndependentChatPermissions))
|
||||
|
||||
suspend fun TelegramBot.setDefaultChatMembersPermissions(
|
||||
chat: PublicChat,
|
||||
permissions: ChatPermissions
|
||||
) = setDefaultChatMembersPermissions(chat.id, permissions)
|
||||
permissions: ChatPermissions,
|
||||
useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
|
||||
) = setDefaultChatMembersPermissions(chat.id, permissions, useIndependentChatPermissions)
|
||||
|
@ -16,7 +16,9 @@ data class RestrictChatMember(
|
||||
@SerialName(untilDateField)
|
||||
override val untilDate: TelegramDate? = null,
|
||||
@SerialName(permissionsField)
|
||||
val permissions: ChatPermissions = ChatPermissions()
|
||||
val permissions: ChatPermissions = ChatPermissions(),
|
||||
@SerialName(useIndependentChatPermissionsField)
|
||||
val useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
|
||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||
override fun method(): String = "restrictChatMember"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
|
@ -12,7 +12,9 @@ data class SetChatPermissions (
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(permissionsField)
|
||||
val permissions: ChatPermissions
|
||||
val permissions: ChatPermissions,
|
||||
@SerialName(useIndependentChatPermissionsField)
|
||||
val useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "setChatPermissions"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
|
@ -340,7 +340,12 @@ const val scopeField = "scope"
|
||||
const val isMemberField = "is_member"
|
||||
const val isForumField = "is_forum"
|
||||
const val canSendMessagesField = "can_send_messages"
|
||||
const val canSendMediaMessagesField = "can_send_media_messages"
|
||||
const val canSendAudiosField = "can_send_audios"
|
||||
const val canSendDocumentsField = "can_send_documents"
|
||||
const val canSendPhotosField = "can_send_photos"
|
||||
const val canSendVideosField = "can_send_videos"
|
||||
const val canSendVideoNotesField = "can_send_video_notes"
|
||||
const val canSendVoiceNotesField = "can_send_voice_notes"
|
||||
const val canSendOtherMessagesField = "can_send_other_messages"
|
||||
const val canSendPollsField = "can_send_polls"
|
||||
const val canAddWebPagePreviewsField = "can_add_web_page_previews"
|
||||
@ -358,6 +363,7 @@ 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 useIndependentChatPermissionsField = "use_independent_chat_permissions"
|
||||
const val rightsField = "rights"
|
||||
const val forChannelsField = "for_channels"
|
||||
const val canManageChatField = "can_manage_chat"
|
||||
|
@ -1,32 +1,113 @@
|
||||
package dev.inmo.tgbotapi.types.chat
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.Transient
|
||||
|
||||
@Serializable
|
||||
data class ChatPermissions(
|
||||
@SerialName(canSendMessagesField)
|
||||
val canSendMessages: Boolean = false,
|
||||
@SerialName(canSendMediaMessagesField)
|
||||
val canSendMediaMessages: Boolean = false,
|
||||
val canSendMessages: Boolean? = null,
|
||||
@SerialName(canSendAudiosField)
|
||||
val canSendAudios: Boolean? = null,
|
||||
@SerialName(canSendDocumentsField)
|
||||
val canSendDocuments: Boolean? = null,
|
||||
@SerialName(canSendPhotosField)
|
||||
val canSendPhotos: Boolean? = null,
|
||||
@SerialName(canSendVideosField)
|
||||
val canSendVideos: Boolean? = null,
|
||||
@SerialName(canSendVideoNotesField)
|
||||
val canSendVideoNotes: Boolean? = null,
|
||||
@SerialName(canSendVoiceNotesField)
|
||||
val canSendVoiceNotes: Boolean? = null,
|
||||
@SerialName(canSendPollsField)
|
||||
val canSendPolls: Boolean = false,
|
||||
val canSendPolls: Boolean? = null,
|
||||
@SerialName(canSendOtherMessagesField)
|
||||
val canSendOtherMessages: Boolean = false,
|
||||
val canSendOtherMessages: Boolean? = null,
|
||||
@SerialName(canAddWebPagePreviewsField)
|
||||
val canAddWebPagePreviews: Boolean = false,
|
||||
val canAddWebPagePreviews: Boolean? = null,
|
||||
@SerialName(canChangeInfoField)
|
||||
val canChangeInfo: Boolean = false,
|
||||
val canChangeInfo: Boolean? = null,
|
||||
@SerialName(canInviteUsersField)
|
||||
val canInviteUsers: Boolean = false,
|
||||
val canInviteUsers: Boolean? = null,
|
||||
@SerialName(canPinMessagesField)
|
||||
val canPinMessages: Boolean = false
|
||||
)
|
||||
val canPinMessages: Boolean? = null
|
||||
) {
|
||||
@Transient
|
||||
val isGranular
|
||||
get() = canSendAudios != null ||
|
||||
canSendDocuments != null ||
|
||||
canSendVideoNotes != null ||
|
||||
canSendPhotos != null ||
|
||||
canSendVideos != null ||
|
||||
canSendVoiceNotes != null
|
||||
|
||||
companion object {
|
||||
fun Granular(
|
||||
canSendMessages: Boolean? = null,
|
||||
canSendAudios: Boolean? = null,
|
||||
canSendDocuments: Boolean? = null,
|
||||
canSendPhotos: Boolean? = null,
|
||||
canSendVideos: Boolean? = null,
|
||||
canSendVideoNotes: Boolean? = null,
|
||||
canSendVoiceNotes: Boolean? = null,
|
||||
canSendPolls: Boolean? = null,
|
||||
canSendOtherMessages: Boolean? = null,
|
||||
canAddWebPagePreviews: Boolean? = null,
|
||||
canChangeInfo: Boolean? = null,
|
||||
canInviteUsers: Boolean? = null,
|
||||
canPinMessages: Boolean? = null
|
||||
) = ChatPermissions(
|
||||
canSendMessages = canSendMessages,
|
||||
canSendAudios = canSendAudios,
|
||||
canSendDocuments = canSendDocuments,
|
||||
canSendPhotos = canSendPhotos,
|
||||
canSendVideos = canSendVideos,
|
||||
canSendVideoNotes = canSendVideoNotes,
|
||||
canSendVoiceNotes = canSendVoiceNotes,
|
||||
canSendPolls = canSendPolls,
|
||||
canSendOtherMessages = canSendOtherMessages,
|
||||
canAddWebPagePreviews = canAddWebPagePreviews,
|
||||
canChangeInfo = canChangeInfo,
|
||||
canInviteUsers = canInviteUsers,
|
||||
canPinMessages = canPinMessages
|
||||
)
|
||||
|
||||
fun Commonized(
|
||||
canSendPolls: Boolean? = null,
|
||||
canSendOtherMessages: Boolean? = null,
|
||||
canAddWebPagePreviews: Boolean? = null,
|
||||
canChangeInfo: Boolean? = null,
|
||||
canInviteUsers: Boolean? = null,
|
||||
canPinMessages: Boolean? = null
|
||||
) = ChatPermissions(
|
||||
canSendMessages = canSendPolls,
|
||||
canSendAudios = null,
|
||||
canSendDocuments = null,
|
||||
canSendPhotos = null,
|
||||
canSendVideos = null,
|
||||
canSendVideoNotes = null,
|
||||
canSendVoiceNotes = null,
|
||||
canSendPolls = canSendPolls,
|
||||
canSendOtherMessages = canSendOtherMessages,
|
||||
canAddWebPagePreviews = canAddWebPagePreviews,
|
||||
canChangeInfo = canChangeInfo,
|
||||
canInviteUsers = canInviteUsers,
|
||||
canPinMessages = canPinMessages
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val LeftRestrictionsChatPermissions = ChatPermissions(
|
||||
canSendMessages = true,
|
||||
canSendMediaMessages = true,
|
||||
canSendAudios = true,
|
||||
canSendDocuments = true,
|
||||
canSendPhotos = true,
|
||||
canSendVideos = true,
|
||||
canSendVideoNotes = true,
|
||||
canSendVoiceNotes = true,
|
||||
canSendPolls = true,
|
||||
canSendOtherMessages = true,
|
||||
canAddWebPagePreviews = true,
|
||||
@ -37,7 +118,12 @@ val LeftRestrictionsChatPermissions = ChatPermissions(
|
||||
|
||||
val RestrictionsChatPermissions = ChatPermissions(
|
||||
canSendMessages = false,
|
||||
canSendMediaMessages = false,
|
||||
canSendAudios = false,
|
||||
canSendDocuments = false,
|
||||
canSendPhotos = false,
|
||||
canSendVideos = false,
|
||||
canSendVideoNotes = false,
|
||||
canSendVoiceNotes = false,
|
||||
canSendPolls = false,
|
||||
canSendOtherMessages = false,
|
||||
canAddWebPagePreviews = false,
|
||||
|
@ -14,8 +14,18 @@ data class RestrictedChatMember(
|
||||
val isMember: Boolean = false,
|
||||
@SerialName(canSendMessagesField)
|
||||
val canSendMessages: Boolean = false,
|
||||
@SerialName(canSendMediaMessagesField)
|
||||
val canSendMediaMessages: Boolean = false,
|
||||
@SerialName(canSendAudiosField)
|
||||
val canSendAudios: Boolean = false,
|
||||
@SerialName(canSendDocumentsField)
|
||||
val canSendDocuments: Boolean = false,
|
||||
@SerialName(canSendPhotosField)
|
||||
val canSendPhotos: Boolean = false,
|
||||
@SerialName(canSendVideosField)
|
||||
val canSendVideos: Boolean = false,
|
||||
@SerialName(canSendVideoNotesField)
|
||||
val canSendVideoNotes: Boolean = false,
|
||||
@SerialName(canSendVoiceNotesField)
|
||||
val canSendVoiceNotes: Boolean = false,
|
||||
@SerialName(canSendPollsField)
|
||||
val canSendPolls: Boolean = false,
|
||||
@SerialName(canSendOtherMessagesField)
|
||||
|
Loading…
Reference in New Issue
Block a user