-
Notifications
You must be signed in to change notification settings - Fork 1
/
ban.go
71 lines (55 loc) Β· 1.57 KB
/
ban.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package api
import (
"fmt"
"net/url"
"github.com/botscommunity/vkgo/internal/pkg/responses"
"github.com/botscommunity/vkgo/types"
)
func (bot *Bot) Ban(objectID int) (ok bool, err *responses.Error) {
reply := responses.Ban{}
if err = responses.NewInternalError(bot.Call("account.ban", fmt.Sprintf("owner_id=%d", objectID), &reply)); reply.Error != nil {
err = reply.Error
}
if reply.Code == 1 {
ok = true
}
return ok, err
}
func (bot *Bot) Unban(objectID int) (ok bool, err *responses.Error) {
reply := responses.Ban{}
if err = responses.NewInternalError(bot.Call("account.unban", fmt.Sprintf("owner_id=%d", objectID), &reply)); reply.Error != nil {
err = reply.Error
}
if reply.Code == 1 {
ok = true
}
return ok, err
}
func (bot *Bot) GetBanned(properties ...any) (count int, bans []int, users []responses.User, err *responses.Error) {
query, offset := make(url.Values), false
for _, property := range properties {
switch property := property.(type) {
case types.Banned:
if property.Offset != 0 {
query.Set("offset", fmt.Sprint(property.Offset))
offset = true
}
if property.Count != 0 {
query.Set("count", fmt.Sprint(property.Count))
}
case int:
if !offset {
query.Set("offset", fmt.Sprint(property))
offset = true
} else {
query.Set("count", fmt.Sprint(property))
}
}
}
reply := responses.BannedReply{}
err = responses.NewInternalError(bot.Call("account.getBanned", "", &reply))
if reply.Error != nil {
err = reply.Error
}
return reply.Response.Count, reply.Response.Bans, reply.Response.Users, err
}