mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-09-29 13:48:53 +00:00
fix unmarshal IntegerOption
This commit is contained in:
parent
2ec439a63f
commit
8689105c58
|
@ -539,21 +539,23 @@ var optionSupportedSnowflakeTypes = map[reflect.Type]CommandOptionType{
|
||||||
reflect.TypeOf(Snowflake(0)): MentionableOptionType,
|
reflect.TypeOf(Snowflake(0)): MentionableOptionType,
|
||||||
}
|
}
|
||||||
|
|
||||||
var optionKindMap = map[reflect.Kind]CommandOptionType{
|
func optionKindSwitch(kind reflect.Kind, typ CommandOptionType) (expectType CommandOptionType) {
|
||||||
reflect.Int: NumberOptionType,
|
switch kind {
|
||||||
reflect.Int8: NumberOptionType,
|
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
||||||
reflect.Int16: NumberOptionType,
|
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||||
reflect.Int32: NumberOptionType,
|
if typ == IntegerOptionType || typ == NumberOptionType {
|
||||||
reflect.Int64: NumberOptionType,
|
return typ
|
||||||
reflect.Uint: NumberOptionType,
|
}
|
||||||
reflect.Uint8: NumberOptionType,
|
return IntegerOptionType
|
||||||
reflect.Uint16: NumberOptionType,
|
case reflect.Float32, reflect.Float64:
|
||||||
reflect.Uint32: NumberOptionType,
|
return NumberOptionType
|
||||||
reflect.Uint64: NumberOptionType,
|
case reflect.String:
|
||||||
reflect.Float32: NumberOptionType,
|
return StringOptionType
|
||||||
reflect.Float64: NumberOptionType,
|
case reflect.Bool:
|
||||||
reflect.String: StringOptionType,
|
return BooleanOptionType
|
||||||
reflect.Bool: BooleanOptionType,
|
default:
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal unmarshals the options into the struct pointer v. Each struct field
|
// Unmarshal unmarshals the options into the struct pointer v. Each struct field
|
||||||
|
@ -573,8 +575,8 @@ var optionKindMap = map[reflect.Kind]CommandOptionType{
|
||||||
// - Snowflake (MentionableOptionType)
|
// - Snowflake (MentionableOptionType)
|
||||||
// - string (StringOptionType)
|
// - string (StringOptionType)
|
||||||
// - bool (BooleanOptionType)
|
// - bool (BooleanOptionType)
|
||||||
// - int* (int, int8, int16, int32, int64) (NumberOptionType)
|
// - int* (int, int8, int16, int32, int64) (NumberOptionType, IntegerOptionType)
|
||||||
// - uint* (uint, uint8, uint16, uint32, uint64) (NumberOptionType)
|
// - uint* (uint, uint8, uint16, uint32, uint64) (NumberOptionType, IntegerOptionType)
|
||||||
// - float* (float32, float64) (NumberOptionType)
|
// - float* (float32, float64) (NumberOptionType)
|
||||||
// - (any struct and struct pointer) (not Discord-type-checked)
|
// - (any struct and struct pointer) (not Discord-type-checked)
|
||||||
//
|
//
|
||||||
|
@ -670,11 +672,9 @@ func unmarshalOptions(find func(string) unmarshalingOption, rv reflect.Value) er
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldk := fieldt.Kind()
|
fieldk := fieldt.Kind()
|
||||||
if expectType, ok := optionKindMap[fieldk]; ok {
|
if expectType := optionKindSwitch(fieldk, option.Type); option.Type != expectType {
|
||||||
if option.Type != expectType {
|
|
||||||
return fmt.Errorf("option %q expecting type %v, got %v", name, expectType, option.Type)
|
return fmt.Errorf("option %q expecting type %v, got %v", name, expectType, option.Type)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
switch fieldk {
|
switch fieldk {
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
|
|
Loading…
Reference in a new issue