-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
92 lines (76 loc) · 1.95 KB
/
types.go
File metadata and controls
92 lines (76 loc) · 1.95 KB
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
package dlist
import (
"encoding/json"
"strconv"
"time"
)
type GatewayOP uint64
const (
HelloOP GatewayOP = iota + 1 // client <- gateway
IdentifyOP // client -> gateway
ReadyOP // client <- gateway
DisconnectOP // client <- gateway
EventOP // client <- gateway
)
func (o GatewayOP) String() string {
return []string{"-", "HELLO", "IDENTIFY", "READY", "DISCONNECT", "EVENT"}[o]
}
type GatewayEvent string
const (
VoteEvent GatewayEvent = "VOTE"
RateEvent GatewayEvent = "RATE"
)
type gatewayPayload struct {
Op GatewayOP `json:"op"`
Data json.RawMessage `json:"data"`
Event GatewayEvent `json:"event,omitempty"`
}
type sendData struct {
Op GatewayOP `json:"op"`
Data interface{} `json:"data"`
}
type identify struct {
Token string `json:"token"`
}
type EntityType string
const (
BotType EntityType = "bots"
ServerType EntityType = "servers"
)
type Entity struct {
Type EntityType `json:"type"`
ID string `json:"id"`
Name string `json:"name"`
}
type VoteData struct {
UserID string `json:"authorID"`
EntityType EntityType `json:"entityType"`
EntityID string `json:"entityID"`
Date Timestamp `json:"date"`
// Total votes of entity NOT only this user
TotalVotes uint64 `json:"totalVotes"`
UserVotes uint64 `json:"userVotes"`
}
type Timestamp struct {
time.Time
}
func (t *Timestamp) UnmarshalJSON(bytes []byte) error {
date, err := strconv.ParseInt(string(bytes), 10, 64)
if err != nil {
return err
}
*t = Timestamp{
Time: time.Unix(date/1000, 0),
}
return nil
}
type RateData struct {
// number of "stars"
Rating uint8 `json:"rating"`
// message that the user added to the review
Details string `json:"details"`
UserID string `json:"authorID"`
EntityType EntityType `json:"entityType"`
EntityID string `json:"entityID"`
Date Timestamp `json:"date"`
}