-
Notifications
You must be signed in to change notification settings - Fork 1
/
status.go
79 lines (62 loc) Β· 1.65 KB
/
status.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
72
73
74
75
76
77
78
79
package api
import (
"fmt"
"net/url"
"github.com/botscommunity/vkgo/internal/pkg/responses"
"github.com/botscommunity/vkgo/types"
)
func (bot *Bot) GetStatus(properties ...any) (text string, err *responses.Error) {
query, installed := make(url.Values), make(map[string]bool)
for _, property := range properties {
switch property := property.(type) {
case types.Status:
if property.GroupID != 0 {
query.Set("group_id", fmt.Sprint(property.GroupID))
}
if property.UserID != 0 {
query.Set("user_id", fmt.Sprint(property.UserID))
installed["userID"] = true
}
case int:
if !installed["userID"] {
query.Set("user_id", fmt.Sprint(property))
installed["userID"] = true
} else {
query.Set("group_id", fmt.Sprint(property))
}
}
}
reply := responses.StatusReply{}
err = responses.NewInternalError(bot.Call("status.get", query.Encode(), &reply))
if reply.Error != nil {
err = reply.Error
}
return reply.Response.Text, err
}
func (bot *Bot) SetStatus(properties ...any) (ok bool, err *responses.Error) {
query := make(url.Values)
for _, property := range properties {
switch property := property.(type) {
case types.SetStatus:
if property.GroupID != 0 {
query.Set("group_id", fmt.Sprint(property.GroupID))
}
if property.Text != "" {
query.Set("text", property.Text)
}
case int:
query.Set("group_id", fmt.Sprint(property))
case string:
query.Set("text", property)
}
}
reply := responses.SetStatus{}
err = responses.NewInternalError(bot.Call("status.set", query.Encode(), &reply))
if reply.Error != nil {
err = reply.Error
}
if reply.Code == 1 {
ok = true
}
return ok, err
}