1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-02-03 10:18:23 +00:00

Discord: add support for string based OverwriteTypes as used in GuildCreate

This commit is contained in:
mavolin 2021-01-10 20:07:04 +01:00 committed by diamondburned
parent d9a159d948
commit d940a97a0f

View file

@ -1,8 +1,8 @@
package discord package discord
import ( import (
"bytes"
"strconv" "strconv"
"strings"
) )
// https://discord.com/developers/docs/resources/channel#channel-object // https://discord.com/developers/docs/resources/channel#channel-object
@ -133,9 +133,21 @@ const (
// into OverwriteType. We need to do this because Discord is so bad that they // into OverwriteType. We need to do this because Discord is so bad that they
// can't even handle 1s and 0s properly. // can't even handle 1s and 0s properly.
func (otype *OverwriteType) UnmarshalJSON(b []byte) error { func (otype *OverwriteType) UnmarshalJSON(b []byte) error {
b = bytes.Trim(b, `"`) s := strings.Trim(string(b), `"`)
u, err := strconv.ParseUint(string(b), 10, 8) // It has been observed that discord still uses the "legacy" string
// overwrite types in at least the guild create event.
// Therefore this string check.
switch s {
case "role":
*otype = OverwriteRole
return nil
case "member":
*otype = OverwriteMember
return nil
}
u, err := strconv.ParseUint(s, 10, 8)
if err != nil { if err != nil {
return err return err
} }