mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-03-22 09:59:37 +00:00
Discord: OverwriteType to accept numbers both stringed and not
Because Discord is so incompetent that they can't even handle 1s and 0s in JSON, we can't really predict when they quote a number and when they don't, because as it turns out, the documentation does not cover all cases. This commit adds a JSONUnmarshaler into OverwriteType to always trim the quotes around then parse the number manually.
This commit is contained in:
parent
21ac7972fa
commit
108913b701
|
@ -1,5 +1,10 @@
|
|||
package discord
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#channel-object
|
||||
type Channel struct {
|
||||
// ID is the id of this channel.
|
||||
|
@ -122,3 +127,18 @@ const (
|
|||
// OverwriteMember is an overwrite for a member.
|
||||
OverwriteMember
|
||||
)
|
||||
|
||||
// UnmarshalJSON unmarshals both a string-quoteed number and a regular number
|
||||
// into OverwriteType. We need to do this because Discord is so bad that they
|
||||
// can't even handle 1s and 0s properly.
|
||||
func (otype *OverwriteType) UnmarshalJSON(b []byte) error {
|
||||
b = bytes.Trim(b, `"`)
|
||||
|
||||
u, err := strconv.ParseUint(string(b), 10, 8)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*otype = OverwriteType(u)
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue