-
Notifications
You must be signed in to change notification settings - Fork 1
/
longPoll.go
108 lines (83 loc) Β· 2.38 KB
/
longPoll.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package api
import (
"fmt"
"net/url"
"github.com/botscommunity/vkgo/internal/pkg/conv"
"github.com/botscommunity/vkgo/internal/pkg/responses"
"github.com/botscommunity/vkgo/types"
)
func (bot *Bot) GetUserLongPollServer(properties ...any) responses.LongPollServer {
query, installed := make(url.Values), make(map[string]bool)
for _, property := range properties {
switch property := property.(type) {
case types.UserLongPollServer:
if property.Version != 0 {
query.Set("lp_version", fmt.Sprint(property.Version))
installed["version"] = true
}
if property.GroupID > 0 {
query.Set("group_id", fmt.Sprint(property.GroupID))
installed["groupID"] = true
}
if property.NeedPTS {
query.Set("need_pts", fmt.Sprint(conv.BooleanToInteger(property.NeedPTS)))
}
case int:
if !installed["version"] {
query.Set("lp_version", fmt.Sprint(property))
installed["version"] = true
} else if !installed["groupID"] {
query.Set("group_id", fmt.Sprint(property))
installed["groupID"] = true
}
case bool:
query.Set("need_pts", fmt.Sprint(conv.BooleanToInteger(property)))
}
}
var (
reply = responses.LongPollServerReply{}
err = responses.NewInternalError(bot.Call("messages.getLongPollServer", query.Encode(), &reply))
)
if err != nil {
reply.Response.Error = err
return reply.Response
}
if reply.Error != nil {
reply.Response.Error = reply.Error
}
return reply.Response
}
func (bot *Bot) GetGroupLongPollServer(properties ...any) responses.LongPollServer {
query, installed := url.Values{}, make(map[string]bool)
for _, property := range properties {
switch property := property.(type) {
case types.GroupLongPollServer:
if property.GroupID != 0 {
query.Set("group_id", fmt.Sprint(property.GroupID))
installed["groupID"] = true
}
case int:
query.Set("group_id", fmt.Sprint(property))
installed["groupID"] = true
}
if bot.IsGroup {
query.Set("group_id", fmt.Sprint(bot.ID))
installed["groupID"] = true
}
}
if !installed["groupID"] {
query.Set("group_id", fmt.Sprint(bot.ID))
}
var (
reply = responses.LongPollServerReply{}
err = responses.NewInternalError(bot.Call("groups.getLongPollServer", query.Encode(), &reply))
)
if err != nil {
reply.Response.Error = err
return reply.Response
}
if reply.Error != nil {
reply.Response.Error = reply.Error
}
return reply.Response
}