-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstructs.go
277 lines (244 loc) · 6.55 KB
/
structs.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
package govkbot
import (
"strings"
)
// Mention - user mention in message
type Mention struct {
ID int64
Name string
}
// Button for keyboard, which sends to user
type Button struct {
Action struct {
Type string `json:"type"`
Payload string `json:"payload"`
Label string `json:"label"`
} `json:"action"`
Color string `json:"color"`
}
// Keyboard to send for user
type Keyboard struct {
OneTime bool `json:"one_time"`
Buttons [][]Button `json:"buttons"`
}
// Reply for message
type Reply struct {
Msg string
Keyboard *Keyboard
}
// Message - VK message struct
type Message struct {
ID int64
Date int
Out int
UserID int64 `json:"user_id"`
ChatID int64 `json:"chat_id"`
PeerID int64 `json:"peer_id"`
ReadState int `json:"read_state"`
Title string
Body string
Action string
ActionMID int64 `json:"action_mid"`
Flags int
Timestamp int64
Payload string
FwdMessages []Message `json:"fwd_messages"`
}
// Messages - VK Messages
type Messages struct {
Count int
Items []*Message
}
// MessagesResponse - VK messages response
type MessagesResponse struct {
Response Messages
Error *VKError
}
// Geo - City and Country info
type Geo struct {
ID int `json:"id"`
Title string `json:"title"`
}
// User - simple VK user struct
type User struct {
ID int64 `json:"id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
ScreenName string `json:"screen_name"`
Photo string `json:"photo"`
InvitedBy int64 `json:"invited_by"`
City Geo `json:"city"`
Country Geo `json:"country"`
Sex int `json:"sex"`
BDate string `json:"bdate"`
Photo50 string `json:"photo_50"`
Photo100 string `json:"photo_100"`
Status string `json:"status"`
About string `json:"about"`
Relation int `json:"relation"`
Hidden int `json:"hidden"`
Closed bool `json:"is_closed"`
CanAccessClosed bool `json:"can_access_closed"`
Deactivated string `json:"deactivated"`
IsAdmin bool `json:"is_admin"`
IsOwner bool `json:"is_owner"`
}
// FullName - returns full name of user
func (u *User) FullName() string {
if u != nil {
return strings.Trim(u.FirstName+" "+u.LastName, " ")
}
return ""
}
// VKUsers - Users list. Can be sort by full name
type VKUsers []*User
// MemberItem - conversation item
type MemberItem struct {
MemberID int64 `json:"member_id"`
JoinDate int `json:"join_date"`
IsOwner bool `json:"is_owner"`
IsAdmin bool `json:"is_admin"`
InvitedBy int64 `json:"invited_by"`
}
// UserProfile - conversation user profile
type UserProfile struct {
ID int64
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
IsClosed bool `json:"is_closed"`
CanAccessClosed bool `json:"can_access_closed"`
Sex int
ScreenName string `json:"screen_name"`
BDate string `json:"bdate"`
Photo string
Online int
City Geo
Country Geo
}
// GroupProfile - conversation group profile
type GroupProfile struct {
ID int64 `json:"id"`
Name string `json:"name"`
ScreenName string `json:"screen_name"`
IsClosed int `json:"is_closed"`
Type string `json:"type"`
Photo50 string `json:"photo50"`
Photo100 string `json:"photo100"`
Photo200 string `json:"photo200"`
}
// VKMembers - conversation members info
type VKMembers struct {
Items []MemberItem `json:"items"`
Profiles []UserProfile `json:"profiles"`
Groups []GroupProfile `json:"groups"`
}
// UsersResponse - VK user response
type UsersResponse struct {
Response VKUsers
Error *VKError
}
// MembersResponse - VK user response
type MembersResponse struct {
Response VKMembers
Error *VKError
}
// FriendRequests - VK friend requests
type FriendRequests struct {
Count int
Items []int64
}
// FriendRequestsResponse - VK friend requests response
type FriendRequestsResponse struct {
Response FriendRequests
Error *VKError
}
// FriendDeleteResponse - VK friend delete response
type FriendDeleteResponse struct {
Response map[string]int
Error *VKError
}
// SimpleResponse - simple int response
type SimpleResponse struct {
Response int64
Error *VKError
}
// ErrorResponse - need to parse VK error
type ErrorResponse struct {
Error *VKError
}
// ChatInfo - chat info
type ChatInfo struct {
ID int64 `json:"id"`
Type string `json:"type"`
Title string `json:"title"`
Kicked int `json:"kicked"`
AdminID int64 `json:"admin_id"`
Users VKUsers `json:"users"`
}
// VKError - error info
type VKError struct {
ErrorCode int `json:"error_code"`
ErrorMsg string `json:"error_msg"`
// RequestParams
}
// VKError - error with response content
type ResponseError struct {
err error
content string
}
func (err ResponseError) Error() string {
return err.err.Error()
}
// Content - error content
func (err ResponseError) Content() string {
return err.content
}
// ConversationInfo - conversation info
type ConversationInfo struct {
Peer struct {
ID int64
Type string
LocalID int `json:"local_id"`
}
InRead int `json:"in_read"`
OutRead int `json:"out_read"`
LastMessageID int `json:"last_message_id"`
CanWrite struct {
Allowed bool
} `json:"can_write"`
ChatSettings struct {
Title string
MembersCount int `json:"members_count"`
State string
ActiveIDs []int `json:"active_ids"`
ACL struct {
CanInvite bool `json:"can_invite"`
CanChangeInfo bool `json:"can_change_info"`
CanChangePin bool `json:"can_change_pin"`
CanPromoteUsers bool `json:"can_promote_users"`
CanSeeInviteLink bool `json:"can_see_invite_link"`
CanChangeInviteLink bool `json:"can_change_invite_link"`
}
IsGroupChannel bool `json:"is_group_channel"`
OwnerID int64 `json:"owner_id"`
} `json:"chat_settings"`
}
// ConversationsResponse - resonse of confersations info
type ConversationsResponse struct {
Response struct {
Items []ConversationInfo
Profiles []UserProfile
}
Error *VKError
}
// ChatInfoResponse - chat info vk struct
type ChatInfoResponse struct {
Response ChatInfo
Error *VKError
}
func (err VKError) Error() string {
return "vk: " + err.ErrorMsg
}
func (a VKUsers) Len() int { return len(a) }
func (a VKUsers) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a VKUsers) Less(i, j int) bool { return a[i].FullName() < a[j].FullName() }