-
Notifications
You must be signed in to change notification settings - Fork 1
/
gifts.go
56 lines (43 loc) Β· 1.27 KB
/
gifts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package api
import (
"fmt"
"net/url"
"github.com/botscommunity/vkgo/internal/pkg/responses"
"github.com/botscommunity/vkgo/types"
)
func (bot *Bot) GetGifts(properties ...any) (count int, gifts []responses.Gift, err *responses.Error) {
query, installed := make(url.Values), make(map[string]bool)
for _, property := range properties {
switch property := property.(type) {
case types.Gifts:
if property.UserID != 0 {
query.Set("user_id", fmt.Sprintf("%d", property.UserID))
installed["userID"] = true
}
if property.Offset != 0 {
query.Set("offset", fmt.Sprintf("%d", property.Offset))
installed["offset"] = true
}
if property.Count != 0 {
query.Set("count", fmt.Sprintf("%d", property.Count))
}
case int:
switch {
case !installed["userID"]:
query.Set("user_id", fmt.Sprintf("%d", property))
installed["userID"] = true
case !installed["offset"]:
query.Set("offset", fmt.Sprintf("%d", property))
installed["offset"] = true
default:
query.Set("count", fmt.Sprintf("%d", property))
}
}
}
reply := responses.GiftsReply{}
err = responses.NewInternalError(bot.Call("gifts.get", query.Encode(), &gifts))
if reply.Error != nil {
err = reply.Error
}
return reply.Response.Count, reply.Response.Gifts, err
}