Skip to content

Commit

Permalink
Merge pull request tucnak#316 from piggymoe/fix-embedrights-param-type
Browse files Browse the repository at this point in the history
Change param type of embedRights
  • Loading branch information
demget authored Jul 3, 2020
2 parents a3f6efa + 2b4e7ee commit bd4747d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (b *Bot) Unban(chat *Chat, user *User) error {
func (b *Bot) Restrict(chat *Chat, member *ChatMember) error {
prv, until := member.Rights, member.RestrictedUntil

params := map[string]string{
params := map[string]interface{}{
"chat_id": chat.Recipient(),
"user_id": member.User.Recipient(),
"until_date": strconv.FormatInt(until, 10),
Expand All @@ -136,7 +136,7 @@ func (b *Bot) Restrict(chat *Chat, member *ChatMember) error {
func (b *Bot) Promote(chat *Chat, member *ChatMember) error {
prv := member.Rights

params := map[string]string{
params := map[string]interface{}{
"chat_id": chat.Recipient(),
"user_id": member.User.Recipient(),
}
Expand Down
2 changes: 1 addition & 1 deletion bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ func (b *Bot) SetGroupStickerSet(chat *Chat, setName string) error {

// SetGroupPermissions sets default chat permissions for all members.
func (b *Bot) SetGroupPermissions(chat *Chat, perms Rights) error {
params := map[string]string{
params := map[string]interface{}{
"chat_id": chat.Recipient(),
}
embedRights(params, perms)
Expand Down
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func processButtons(keys [][]InlineButton) {
}
}

func embedRights(p map[string]string, rights Rights) {
func embedRights(p map[string]interface{}, rights Rights) {
data, _ := json.Marshal(rights)
_ = json.Unmarshal(data, &p)
}
Expand Down
21 changes: 21 additions & 0 deletions util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,24 @@ func TestExtractMessage(t *testing.T) {
_, err = extractMessage(data)
assert.NoError(t, err)
}

func TestEmbedRights(t *testing.T) {
rights := NoRestrictions()
params := map[string]interface{}{
"chat_id": "1",
"user_id": "2",
}
embedRights(params, rights)

expected := map[string]interface{}{
"chat_id": "1",
"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,
}
assert.Equal(t, expected, params)
}

0 comments on commit bd4747d

Please sign in to comment.