Several bug fixes causing json unmarshal errors.
This commit is contained in:
parent
ecbaed46ab
commit
3d9e980619
3 changed files with 66 additions and 30 deletions
35
guild.go
35
guild.go
|
@ -7,7 +7,7 @@ type Guild struct {
|
||||||
Region string `json:"region"`
|
Region string `json:"region"`
|
||||||
Joined_at string `json:"joined_at"` // make time stamp
|
Joined_at string `json:"joined_at"` // make time stamp
|
||||||
Afk_timeout int `json:"afk_timeout"`
|
Afk_timeout int `json:"afk_timeout"`
|
||||||
Afk_channel_id int `json:"afk_channel_id"`
|
Afk_channel_id int `json:"afk_channel_id,string"`
|
||||||
Embed_channel_id int `json:"embed_channel_id"`
|
Embed_channel_id int `json:"embed_channel_id"`
|
||||||
Embed_enabled bool `json:"embed_enabled"`
|
Embed_enabled bool `json:"embed_enabled"`
|
||||||
Owner_id int `json:"owner_id,string"`
|
Owner_id int `json:"owner_id,string"`
|
||||||
|
@ -18,7 +18,16 @@ type Guild struct {
|
||||||
Presences []Presence `json:"presences"`
|
Presences []Presence `json:"presences"`
|
||||||
Channels []Channel `json:"channels"`
|
Channels []Channel `json:"channels"`
|
||||||
VoiceStates []VoiceState `json:"voice_states"`
|
VoiceStates []VoiceState `json:"voice_states"`
|
||||||
Session *Session // I got to be doing it wrong here.
|
}
|
||||||
|
|
||||||
|
type Role struct {
|
||||||
|
Id int `json:"id,string"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Managed bool `json:"managed"`
|
||||||
|
Color int `json:"color"`
|
||||||
|
Hoist bool `json:"hoist"`
|
||||||
|
Position int `json:"position"`
|
||||||
|
Permissions int `json:"permissions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type VoiceState struct {
|
type VoiceState struct {
|
||||||
|
@ -45,18 +54,20 @@ type Member struct {
|
||||||
Deaf bool `json:"deaf"`
|
Deaf bool `json:"deaf"`
|
||||||
mute bool `json:"mute"`
|
mute bool `json:"mute"`
|
||||||
User User `json:"user"`
|
User User `json:"user"`
|
||||||
Roles []Role `json:"roles"`
|
Roles []string `json:"roles"` // TODO: See below
|
||||||
}
|
}
|
||||||
|
|
||||||
type Role struct {
|
//Roles []string `json:"roles"` // TODO: Should be ints, see below
|
||||||
Id int `json:"id,string"`
|
// Above "Roles" should be an array of ints
|
||||||
Name string `json:"name"`
|
// TODO: Figure out how to make it be one.
|
||||||
Managed bool `json:"managed"`
|
/*
|
||||||
Color int `json:"color"`
|
{
|
||||||
Hoist bool `json:"hoist"`
|
"roles": [
|
||||||
Position int `json:"position"`
|
"89544728336416768",
|
||||||
Permissions int `json:"permissions"`
|
"110429733396676608"
|
||||||
}
|
],
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Channels returns an array of Channel structures for channels within
|
// Channels returns an array of Channel structures for channels within
|
||||||
// this Server
|
// this Server
|
||||||
|
|
11
users.go
11
users.go
|
@ -6,9 +6,18 @@ type User struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Avatar string `json:"Avatar"`
|
Avatar string `json:"Avatar"`
|
||||||
Verified bool `json:"verified"`
|
Verified bool `json:"verified"`
|
||||||
Discriminator string `json:"discriminator"`
|
//Discriminator int `json:"discriminator,string"` // TODO: See below
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Discriminator sometimes comes as a string
|
||||||
|
// and sometimes it comes as a int. Weird.
|
||||||
|
// to avoid errors I've just commented it out
|
||||||
|
// but it doesn't seem to just kill the whole
|
||||||
|
// program. Heartbeat is taken on READY even
|
||||||
|
// with error and the system continues to read
|
||||||
|
// it just doesn't seem able to handle this one
|
||||||
|
// field correctly. Need to research this more.
|
||||||
|
|
||||||
type PrivateChannel struct {
|
type PrivateChannel struct {
|
||||||
Id int `json:"id,string"`
|
Id int `json:"id,string"`
|
||||||
IsPrivate bool `json:"is_private"`
|
IsPrivate bool `json:"is_private"`
|
||||||
|
|
22
wsapi.go
22
wsapi.go
|
@ -57,11 +57,23 @@ type TypingStart struct {
|
||||||
type PresenceUpdate struct {
|
type PresenceUpdate struct {
|
||||||
User User `json:"user"`
|
User User `json:"user"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Roles []Role `json:"roles"`
|
Roles []string `json:"roles"` // TODO: Should be ints, see below
|
||||||
GuildId int `json:"guild_id,string"`
|
GuildId int `json:"guild_id,string"`
|
||||||
GameId int `json:"game_id"`
|
GameId int `json:"game_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Roles []string `json:"roles"` // TODO: Should be ints, see below
|
||||||
|
// Above "Roles" should be an array of ints
|
||||||
|
// TODO: Figure out how to make it be one.
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
"roles": [
|
||||||
|
"89544728336416768",
|
||||||
|
"110429733396676608"
|
||||||
|
],
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
type MessageAck struct {
|
type MessageAck struct {
|
||||||
MessageId int `json:"message_id,string"`
|
MessageId int `json:"message_id,string"`
|
||||||
ChannelId int `json:"channel_id,string"`
|
ChannelId int `json:"channel_id,string"`
|
||||||
|
@ -167,8 +179,9 @@ func event(s *Session, messageType int, message []byte) (err error) {
|
||||||
if s.OnReady != nil {
|
if s.OnReady != nil {
|
||||||
var st Ready
|
var st Ready
|
||||||
if err := json.Unmarshal(e.RawData, &st); err != nil {
|
if err := json.Unmarshal(e.RawData, &st); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
printJSON(e.RawData) // TODO: Better error logging
|
printJSON(e.RawData) // TODO: Better error logging
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
s.OnReady(s, st)
|
s.OnReady(s, st)
|
||||||
return
|
return
|
||||||
|
@ -177,8 +190,9 @@ func event(s *Session, messageType int, message []byte) (err error) {
|
||||||
if s.OnVoiceStateUpdate != nil {
|
if s.OnVoiceStateUpdate != nil {
|
||||||
var st VoiceState
|
var st VoiceState
|
||||||
if err := json.Unmarshal(e.RawData, &st); err != nil {
|
if err := json.Unmarshal(e.RawData, &st); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
printJSON(e.RawData) // TODO: Better error logging
|
printJSON(e.RawData) // TODO: Better error logging
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
s.OnVoiceStateUpdate(s, st)
|
s.OnVoiceStateUpdate(s, st)
|
||||||
return
|
return
|
||||||
|
@ -187,6 +201,7 @@ func event(s *Session, messageType int, message []byte) (err error) {
|
||||||
if s.OnPresenceUpdate != nil {
|
if s.OnPresenceUpdate != nil {
|
||||||
var st PresenceUpdate
|
var st PresenceUpdate
|
||||||
if err := json.Unmarshal(e.RawData, &st); err != nil {
|
if err := json.Unmarshal(e.RawData, &st); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
printJSON(e.RawData) // TODO: Better error logging
|
printJSON(e.RawData) // TODO: Better error logging
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -231,6 +246,7 @@ func event(s *Session, messageType int, message []byte) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.OnMessageDelete(s, st)
|
s.OnMessageDelete(s, st)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
case "MESSAGE_ACK":
|
case "MESSAGE_ACK":
|
||||||
if s.OnMessageAck != nil {
|
if s.OnMessageAck != nil {
|
||||||
|
|
Loading…
Reference in a new issue