Skip to content

Commit

Permalink
Merge pull request #57 from yanzay/restrict-permissions
Browse files Browse the repository at this point in the history
User new ChatPermissions for RestrictChatMember.
  • Loading branch information
yanzay committed Dec 2, 2019
2 parents e9d198e + 0606e72 commit 1615493
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,26 +1025,16 @@ func (c *Client) UnbanChatMember(chatID string, userID int) error {
return c.doRequest("unbanChatMember", req, &unbanned)
}

// Restrictions for user in supergroup
type Restrictions struct {
CanSendMessages bool
CanSendMediaMessages bool
CanSendOtherMessages bool
CanAddWebPagePreviews bool
}

/*
RestrictChatMember restrict a user in a supergroup. Available options:
- OptUntilDate(date time.Time)
*/
func (c *Client) RestrictChatMember(chatID string, userID int, r *Restrictions, opts ...sendOption) error {
func (c *Client) RestrictChatMember(chatID string, userID int, perm *ChatPermissions, opts ...sendOption) error {
req := url.Values{}
req.Set("chat_id", chatID)
req.Set("user_id", fmt.Sprint(userID))
req.Set("can_send_messages", fmt.Sprint(r.CanSendMessages))
req.Set("can_send_media_messages", fmt.Sprint(r.CanSendMediaMessages))
req.Set("can_send_other_messages", fmt.Sprint(r.CanSendOtherMessages))
req.Set("can_add_web_page_previews", fmt.Sprint(r.CanAddWebPagePreviews))
marshalledPermissions, _ := json.Marshal(perm)
req.Set("permissions", string(marshalledPermissions))
for _, opt := range opts {
opt(req)
}
Expand Down

0 comments on commit 1615493

Please sign in to comment.