From c819b561706211e193267d1287195d5bcb64e0b0 Mon Sep 17 00:00:00 2001 From: diamondburned Date: Fri, 14 Aug 2020 18:13:35 -0700 Subject: [PATCH] Gateway: Added a custom GuildFolderID type --- gateway/ready.go | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/gateway/ready.go b/gateway/ready.go index ba43b5d..a192c91 100644 --- a/gateway/ready.go +++ b/gateway/ready.go @@ -1,6 +1,11 @@ package gateway -import "github.com/diamondburned/arikawa/discord" +import ( + "strconv" + "strings" + + "github.com/diamondburned/arikawa/discord" +) type ReadyEvent struct { Version int `json:"version"` @@ -108,7 +113,36 @@ type SettingsChannelOverride struct { // GuildFolder holds a single folder that you see in the left guild panel. type GuildFolder struct { Name string `json:"name"` - ID int64 `json:"id,string"` + ID GuildFolderID `json:"id"` GuildIDs []discord.GuildID `json:"guild_ids"` Color discord.Color `json:"color"` } + +// GuildFolderID is possibly a snowflake. It can also be 0 (null) or a low +// number of unknown significance. +type GuildFolderID uint64 + +func (g *GuildFolderID) UnmarshalJSON(b []byte) error { + var body = string(b) + if body == "null" { + return nil + } + + body = strings.Trim(body, `"`) + + u, err := strconv.ParseUint(body, 10, 64) + if err != nil { + return err + } + + *g = GuildFolderID(u) + return nil +} + +func (g GuildFolderID) MarshalJSON() ([]byte, error) { + if g == 0 { + return []byte("null"), nil + } + + return []byte(strconv.FormatUint(uint64(g), 10)), nil +}