diff --git a/admin.go b/admin.go index d58a34d..cc8b33a 100644 --- a/admin.go +++ b/admin.go @@ -21,13 +21,29 @@ type Rights struct { CanRestrictMembers bool `json:"can_restrict_members"` CanPromoteMembers bool `json:"can_promote_members"` CanSendMessages bool `json:"can_send_messages"` - CanSendMedia bool `json:"can_send_media_messages"` CanSendPolls bool `json:"can_send_polls"` CanSendOther bool `json:"can_send_other_messages"` CanAddPreviews bool `json:"can_add_web_page_previews"` CanManageVideoChats bool `json:"can_manage_video_chats"` CanManageChat bool `json:"can_manage_chat"` CanManageTopics bool `json:"can_manage_topics"` + + CanSendMedia bool `json:"can_send_media_messages,omitempty"` // deprecated + CanSendAudios bool `json:"can_send_audios"` + CanSendDocuments bool `json:"can_send_documents"` + CanSendPhotos bool `json:"can_send_photos"` + CanSendVideos bool `json:"can_send_videos"` + CanSendVideoNotes bool `json:"can_send_video_notes"` + CanSendVoiceNotes bool `json:"can_send_voice_notes"` + + // Independent defines whether the chat permissions are set independently. + // If not, the can_send_other_messages and can_add_web_page_previews permissions + // will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, + // can_send_videos, can_send_video_notes, and can_send_voice_notes permissions; + // the can_send_polls permission will imply the can_send_messages permission. + // + // Works for Restrict and SetGroupPermissions methods only. + Independent bool `json:"-"` } // NoRights is the default Rights{}. @@ -50,13 +66,18 @@ func NoRestrictions() Rights { CanPinMessages: false, CanPromoteMembers: false, CanSendMessages: true, - CanSendMedia: true, CanSendPolls: true, CanSendOther: true, CanAddPreviews: true, CanManageVideoChats: false, CanManageChat: false, CanManageTopics: false, + CanSendAudios: true, + CanSendDocuments: true, + CanSendPhotos: true, + CanSendVideos: true, + CanSendVideoNotes: true, + CanSendVoiceNotes: true, } } @@ -73,13 +94,18 @@ func AdminRights() Rights { CanPinMessages: true, CanPromoteMembers: true, CanSendMessages: true, - CanSendMedia: true, CanSendPolls: true, CanSendOther: true, CanAddPreviews: true, CanManageVideoChats: true, CanManageChat: true, CanManageTopics: true, + CanSendAudios: true, + CanSendDocuments: true, + CanSendPhotos: true, + CanSendVideos: true, + CanSendVideoNotes: true, + CanSendVoiceNotes: true, } } @@ -127,14 +153,17 @@ func (b *Bot) Unban(chat *Chat, user *User, forBanned ...bool) error { // - can send other // - can add web page previews func (b *Bot) Restrict(chat *Chat, member *ChatMember) error { - prv, until := member.Rights, member.RestrictedUntil + perms, until := member.Rights, member.RestrictedUntil params := map[string]interface{}{ - "chat_id": chat.Recipient(), - "user_id": member.User.Recipient(), - "until_date": strconv.FormatInt(until, 10), + "chat_id": chat.Recipient(), + "user_id": member.User.Recipient(), + "until_date": strconv.FormatInt(until, 10), + "permissions": perms, + } + if perms.Independent { + params["use_independent_chat_permissions"] = true } - embedRights(params, prv) _, err := b.Raw("restrictChatMember", params) return err @@ -151,14 +180,12 @@ func (b *Bot) Restrict(chat *Chat, member *ChatMember) error { // - can pin messages // - can promote members func (b *Bot) Promote(chat *Chat, member *ChatMember) error { - prv := member.Rights - params := map[string]interface{}{ "chat_id": chat.Recipient(), "user_id": member.User.Recipient(), "is_anonymous": member.Anonymous, } - embedRights(params, prv) + embedRights(params, member.Rights) _, err := b.Raw("promoteChatMember", params) return err diff --git a/admin_test.go b/admin_test.go index 5fd2412..886e794 100644 --- a/admin_test.go +++ b/admin_test.go @@ -20,7 +20,6 @@ func TestEmbedRights(t *testing.T) { "user_id": "2", "can_be_edited": true, "can_send_messages": true, - "can_send_media_messages": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, @@ -34,6 +33,13 @@ func TestEmbedRights(t *testing.T) { "can_promote_members": false, "can_manage_video_chats": false, "can_manage_chat": false, + "can_manage_topics": false, + "can_send_audios": true, + "can_send_documents": true, + "can_send_photos": true, + "can_send_videos": true, + "can_send_video_notes": true, + "can_send_voice_notes": true, } assert.Equal(t, expected, params) } diff --git a/chat.go b/chat.go index 988578c..a30c11a 100644 --- a/chat.go +++ b/chat.go @@ -432,6 +432,9 @@ func (b *Bot) SetGroupPermissions(chat *Chat, perms Rights) error { "chat_id": chat.Recipient(), "permissions": perms, } + if perms.Independent { + params["use_independent_chat_permissions"] = true + } _, err := b.Raw("setChatPermissions", params) return err