1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-30 18:53:30 +00:00

discord: Use json.Unmarshal instead for CommandInteractionOption (#292)

This ensures valid JSON strings are processed using the JSON rules, not
the Go rules.
This commit is contained in:
Tadeo Kondrak 2021-11-13 16:18:52 -07:00 committed by GitHub
parent c98e2f8730
commit 2ec0e6b011
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,8 +1,6 @@
package discord package discord
import ( import (
"strconv"
"github.com/diamondburned/arikawa/v3/utils/json" "github.com/diamondburned/arikawa/v3/utils/json"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -285,14 +283,11 @@ type CommandInteractionOption struct {
// String will return the value if the option's value is a valid string. // String will return the value if the option's value is a valid string.
// Otherwise, it will return the raw JSON value of the other type. // Otherwise, it will return the raw JSON value of the other type.
func (o CommandInteractionOption) String() string { func (o CommandInteractionOption) String() string {
val := string(o.Value) var value string
if err := json.Unmarshal(o.Value, &value); err != nil {
s, err := strconv.Unquote(val) return string(o.Value)
if err != nil {
return val
} }
return value
return s
} }
// IntValue reads the option's value as an int. // IntValue reads the option's value as an int.