mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-09-27 12:48:47 +00:00
Gateway: Added a custom GuildFolderID type
This commit is contained in:
parent
eb46a89e6c
commit
c819b56170
|
@ -1,6 +1,11 @@
|
||||||
package gateway
|
package gateway
|
||||||
|
|
||||||
import "github.com/diamondburned/arikawa/discord"
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/diamondburned/arikawa/discord"
|
||||||
|
)
|
||||||
|
|
||||||
type ReadyEvent struct {
|
type ReadyEvent struct {
|
||||||
Version int `json:"version"`
|
Version int `json:"version"`
|
||||||
|
@ -108,7 +113,36 @@ type SettingsChannelOverride struct {
|
||||||
// GuildFolder holds a single folder that you see in the left guild panel.
|
// GuildFolder holds a single folder that you see in the left guild panel.
|
||||||
type GuildFolder struct {
|
type GuildFolder struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
ID int64 `json:"id,string"`
|
ID GuildFolderID `json:"id"`
|
||||||
GuildIDs []discord.GuildID `json:"guild_ids"`
|
GuildIDs []discord.GuildID `json:"guild_ids"`
|
||||||
Color discord.Color `json:"color"`
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue