1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +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:
InsanusMokrassar 2023-02-06 00:25:40 +06:00 committed by GitHub
commit 4ddced8e26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 143 additions and 30 deletions

View File

@ -2,9 +2,10 @@
## 5.1.0 ## 5.1.0
[Bot API 6.5](https://core.telegram.org/bots/api-changelog#february-3-2023) support
* `Core`: * `Core`:
* [Bot API 6.5](https://core.telegram.org/bots/api#february-3-2023) support * [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 ## 5.0.2

View File

@ -14,27 +14,31 @@ suspend fun TelegramBot.restrictChatMember(
chatId: ChatIdentifier, chatId: ChatIdentifier,
userId: UserId, userId: UserId,
untilDate: TelegramDate? = null, untilDate: TelegramDate? = null,
permissions: ChatPermissions = ChatPermissions() permissions: ChatPermissions = ChatPermissions(),
) = execute(RestrictChatMember(chatId, userId, untilDate, permissions)) useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
) = execute(RestrictChatMember(chatId, userId, untilDate, permissions, useIndependentChatPermissions))
suspend fun TelegramBot.restrictChatMember( suspend fun TelegramBot.restrictChatMember(
chat: PublicChat, chat: PublicChat,
userId: UserId, userId: UserId,
untilDate: TelegramDate? = null, untilDate: TelegramDate? = null,
permissions: ChatPermissions = ChatPermissions() permissions: ChatPermissions = ChatPermissions(),
) = restrictChatMember(chat.id, userId, untilDate, permissions) useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
) = restrictChatMember(chat.id, userId, untilDate, permissions, useIndependentChatPermissions)
suspend fun TelegramBot.restrictChatMember( suspend fun TelegramBot.restrictChatMember(
chatId: IdChatIdentifier, chatId: IdChatIdentifier,
user: User, user: User,
untilDate: TelegramDate? = null, untilDate: TelegramDate? = null,
permissions: ChatPermissions = ChatPermissions() permissions: ChatPermissions = ChatPermissions(),
) = restrictChatMember(chatId, user.id, untilDate, permissions) useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
) = restrictChatMember(chatId, user.id, untilDate, permissions, useIndependentChatPermissions)
suspend fun TelegramBot.restrictChatMember( suspend fun TelegramBot.restrictChatMember(
chat: PublicChat, chat: PublicChat,
user: User, user: User,
untilDate: TelegramDate? = null, untilDate: TelegramDate? = null,
permissions: ChatPermissions = ChatPermissions() permissions: ChatPermissions = ChatPermissions(),
) = restrictChatMember(chat.id, user.id, untilDate, permissions) useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
) = restrictChatMember(chat.id, user.id, untilDate, permissions, useIndependentChatPermissions)

View File

@ -8,10 +8,12 @@ import dev.inmo.tgbotapi.types.chat.PublicChat
suspend fun TelegramBot.setDefaultChatMembersPermissions( suspend fun TelegramBot.setDefaultChatMembersPermissions(
chatId: ChatIdentifier, chatId: ChatIdentifier,
permissions: ChatPermissions permissions: ChatPermissions,
) = execute(SetChatPermissions(chatId, permissions)) useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
) = execute(SetChatPermissions(chatId, permissions, useIndependentChatPermissions))
suspend fun TelegramBot.setDefaultChatMembersPermissions( suspend fun TelegramBot.setDefaultChatMembersPermissions(
chat: PublicChat, chat: PublicChat,
permissions: ChatPermissions permissions: ChatPermissions,
) = setDefaultChatMembersPermissions(chat.id, permissions) useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
) = setDefaultChatMembersPermissions(chat.id, permissions, useIndependentChatPermissions)

View File

@ -16,7 +16,9 @@ data class RestrictChatMember(
@SerialName(untilDateField) @SerialName(untilDateField)
override val untilDate: TelegramDate? = null, override val untilDate: TelegramDate? = null,
@SerialName(permissionsField) @SerialName(permissionsField)
val permissions: ChatPermissions = ChatPermissions() val permissions: ChatPermissions = ChatPermissions(),
@SerialName(useIndependentChatPermissionsField)
val useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
) : ChatMemberRequest<Boolean>, UntilDate { ) : ChatMemberRequest<Boolean>, UntilDate {
override fun method(): String = "restrictChatMember" override fun method(): String = "restrictChatMember"
override val resultDeserializer: DeserializationStrategy<Boolean> override val resultDeserializer: DeserializationStrategy<Boolean>

View File

@ -12,7 +12,9 @@ data class SetChatPermissions (
@SerialName(chatIdField) @SerialName(chatIdField)
override val chatId: ChatIdentifier, override val chatId: ChatIdentifier,
@SerialName(permissionsField) @SerialName(permissionsField)
val permissions: ChatPermissions val permissions: ChatPermissions,
@SerialName(useIndependentChatPermissionsField)
val useIndependentChatPermissions: Boolean? = permissions.isGranular.takeIf { it }
): ChatRequest, SimpleRequest<Boolean> { ): ChatRequest, SimpleRequest<Boolean> {
override fun method(): String = "setChatPermissions" override fun method(): String = "setChatPermissions"
override val resultDeserializer: DeserializationStrategy<Boolean> override val resultDeserializer: DeserializationStrategy<Boolean>

View File

@ -340,7 +340,12 @@ const val scopeField = "scope"
const val isMemberField = "is_member" const val isMemberField = "is_member"
const val isForumField = "is_forum" const val isForumField = "is_forum"
const val canSendMessagesField = "can_send_messages" 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 canSendOtherMessagesField = "can_send_other_messages"
const val canSendPollsField = "can_send_polls" const val canSendPollsField = "can_send_polls"
const val canAddWebPagePreviewsField = "can_add_web_page_previews" 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 canPromoteMembersField = "can_promote_members"
const val canManageVoiceChatsField = "can_manage_voice_chats" const val canManageVoiceChatsField = "can_manage_voice_chats"
const val canManageVideoChatsField = "can_manage_video_chats" const val canManageVideoChatsField = "can_manage_video_chats"
const val useIndependentChatPermissionsField = "use_independent_chat_permissions"
const val rightsField = "rights" const val rightsField = "rights"
const val forChannelsField = "for_channels" const val forChannelsField = "for_channels"
const val canManageChatField = "can_manage_chat" const val canManageChatField = "can_manage_chat"

View File

@ -1,32 +1,113 @@
package dev.inmo.tgbotapi.types.chat package dev.inmo.tgbotapi.types.chat
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
@Serializable @Serializable
data class ChatPermissions( data class ChatPermissions(
@SerialName(canSendMessagesField) @SerialName(canSendMessagesField)
val canSendMessages: Boolean = false, val canSendMessages: Boolean? = null,
@SerialName(canSendMediaMessagesField) @SerialName(canSendAudiosField)
val canSendMediaMessages: Boolean = false, 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) @SerialName(canSendPollsField)
val canSendPolls: Boolean = false, val canSendPolls: Boolean? = null,
@SerialName(canSendOtherMessagesField) @SerialName(canSendOtherMessagesField)
val canSendOtherMessages: Boolean = false, val canSendOtherMessages: Boolean? = null,
@SerialName(canAddWebPagePreviewsField) @SerialName(canAddWebPagePreviewsField)
val canAddWebPagePreviews: Boolean = false, val canAddWebPagePreviews: Boolean? = null,
@SerialName(canChangeInfoField) @SerialName(canChangeInfoField)
val canChangeInfo: Boolean = false, val canChangeInfo: Boolean? = null,
@SerialName(canInviteUsersField) @SerialName(canInviteUsersField)
val canInviteUsers: Boolean = false, val canInviteUsers: Boolean? = null,
@SerialName(canPinMessagesField) @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( val LeftRestrictionsChatPermissions = ChatPermissions(
canSendMessages = true, canSendMessages = true,
canSendMediaMessages = true, canSendAudios = true,
canSendDocuments = true,
canSendPhotos = true,
canSendVideos = true,
canSendVideoNotes = true,
canSendVoiceNotes = true,
canSendPolls = true, canSendPolls = true,
canSendOtherMessages = true, canSendOtherMessages = true,
canAddWebPagePreviews = true, canAddWebPagePreviews = true,
@ -37,7 +118,12 @@ val LeftRestrictionsChatPermissions = ChatPermissions(
val RestrictionsChatPermissions = ChatPermissions( val RestrictionsChatPermissions = ChatPermissions(
canSendMessages = false, canSendMessages = false,
canSendMediaMessages = false, canSendAudios = false,
canSendDocuments = false,
canSendPhotos = false,
canSendVideos = false,
canSendVideoNotes = false,
canSendVoiceNotes = false,
canSendPolls = false, canSendPolls = false,
canSendOtherMessages = false, canSendOtherMessages = false,
canAddWebPagePreviews = false, canAddWebPagePreviews = false,

View File

@ -14,8 +14,18 @@ data class RestrictedChatMember(
val isMember: Boolean = false, val isMember: Boolean = false,
@SerialName(canSendMessagesField) @SerialName(canSendMessagesField)
val canSendMessages: Boolean = false, val canSendMessages: Boolean = false,
@SerialName(canSendMediaMessagesField) @SerialName(canSendAudiosField)
val canSendMediaMessages: Boolean = false, 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) @SerialName(canSendPollsField)
val canSendPolls: Boolean = false, val canSendPolls: Boolean = false,
@SerialName(canSendOtherMessagesField) @SerialName(canSendOtherMessagesField)