mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-02-03 02:07:20 +00:00
Discord: add support for string based OverwriteTypes as used in GuildCreate
This commit is contained in:
parent
d9a159d948
commit
d940a97a0f
|
@ -1,8 +1,8 @@
|
|||
package discord
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 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
|
||||
// can't even handle 1s and 0s properly.
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue