mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-07-26 23:40:57 +00:00
Compare commits
3 commits
f7618fb720
...
e952881e17
Author | SHA1 | Date | |
---|---|---|---|
|
e952881e17 | ||
|
2e657c318a | ||
|
744c10f330 |
|
@ -720,6 +720,8 @@ type UserSelectComponent struct {
|
||||||
ValueLimits [2]int `json:"-"`
|
ValueLimits [2]int `json:"-"`
|
||||||
// Disabled disables the select if true.
|
// Disabled disables the select if true.
|
||||||
Disabled bool `json:"disabled,omitempty"`
|
Disabled bool `json:"disabled,omitempty"`
|
||||||
|
// SelectedUsers is the slice of UserIDs that are marked as selected by default
|
||||||
|
SelectedUsers []UserID `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ID implements the Component interface.
|
// ID implements the Component interface.
|
||||||
|
@ -737,11 +739,17 @@ func (s *UserSelectComponent) _icp() {}
|
||||||
func (s *UserSelectComponent) MarshalJSON() ([]byte, error) {
|
func (s *UserSelectComponent) MarshalJSON() ([]byte, error) {
|
||||||
type sel UserSelectComponent
|
type sel UserSelectComponent
|
||||||
|
|
||||||
|
type DefaultValue struct {
|
||||||
|
Id UserID `json:"id"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
type Msg struct {
|
type Msg struct {
|
||||||
Type ComponentType `json:"type"`
|
Type ComponentType `json:"type"`
|
||||||
*sel
|
*sel
|
||||||
MinValues *int `json:"min_values,omitempty"`
|
MinValues *int `json:"min_values,omitempty"`
|
||||||
MaxValues *int `json:"max_values,omitempty"`
|
MaxValues *int `json:"max_values,omitempty"`
|
||||||
|
DefaultValues []DefaultValue `json:"default_values,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := Msg{
|
msg := Msg{
|
||||||
|
@ -749,6 +757,16 @@ func (s *UserSelectComponent) MarshalJSON() ([]byte, error) {
|
||||||
sel: (*sel)(s),
|
sel: (*sel)(s),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var defaultValues []DefaultValue
|
||||||
|
|
||||||
|
if len(s.SelectedUsers) > 0 {
|
||||||
|
for _, userId := range s.SelectedUsers {
|
||||||
|
defaultValues = append(defaultValues, DefaultValue{Id: userId, Type: "user"})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.DefaultValues = defaultValues
|
||||||
|
|
||||||
if s.ValueLimits != [2]int{0, 0} {
|
if s.ValueLimits != [2]int{0, 0} {
|
||||||
msg.MinValues = new(int)
|
msg.MinValues = new(int)
|
||||||
msg.MaxValues = new(int)
|
msg.MaxValues = new(int)
|
||||||
|
@ -840,8 +858,9 @@ type MentionableSelectComponent struct {
|
||||||
ValueLimits [2]int `json:"-"`
|
ValueLimits [2]int `json:"-"`
|
||||||
// Disabled disables the select if true.
|
// Disabled disables the select if true.
|
||||||
Disabled bool `json:"disabled,omitempty"`
|
Disabled bool `json:"disabled,omitempty"`
|
||||||
// SelectedUsers is the slice of UserIDs that are marked as selected by default
|
// SelectedMentions is the slice of discord.UserID's and discord.RoleID's
|
||||||
SelectedUsers []UserID `json:"-"`
|
// that are marked as selected by default
|
||||||
|
SelectedMentions []interface{} `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ID implements the Component interface.
|
// ID implements the Component interface.
|
||||||
|
@ -860,7 +879,7 @@ func (s *MentionableSelectComponent) MarshalJSON() ([]byte, error) {
|
||||||
type sel MentionableSelectComponent
|
type sel MentionableSelectComponent
|
||||||
|
|
||||||
type DefaultValue struct {
|
type DefaultValue struct {
|
||||||
Id UserID `json:"id"`
|
Id Snowflake `json:"id"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -879,9 +898,16 @@ func (s *MentionableSelectComponent) MarshalJSON() ([]byte, error) {
|
||||||
|
|
||||||
var defaultValues []DefaultValue
|
var defaultValues []DefaultValue
|
||||||
|
|
||||||
if len(s.SelectedUsers) > 0 {
|
if len(s.SelectedMentions) > 0 {
|
||||||
for _, userId := range s.SelectedUsers {
|
for _, mentionId := range s.SelectedMentions {
|
||||||
defaultValues = append(defaultValues, DefaultValue{Id: userId, Type: "user"})
|
switch id := mentionId.(type) {
|
||||||
|
case UserID:
|
||||||
|
defaultValues =
|
||||||
|
append(defaultValues, DefaultValue{Id: Snowflake(id), Type: "user"})
|
||||||
|
case RoleID:
|
||||||
|
defaultValues =
|
||||||
|
append(defaultValues, DefaultValue{Id: Snowflake(id), Type: "role"})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue