1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-07-23 13:20:51 +00:00

Compare commits

...

2 commits

Author SHA1 Message Date
Barani Kumar S 2e657c318a discord: Minor comment change 2024-10-24 22:43:03 +05:30
Barani Kumar S 744c10f330 discord: Modified MentionableSelectComponent to accept both RoleID and UserID as SelectedMentions 2024-10-24 22:41:30 +05:30

View file

@ -720,6 +720,8 @@ type UserSelectComponent struct {
ValueLimits [2]int `json:"-"`
// Disabled disables the select if true.
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.
@ -737,11 +739,17 @@ func (s *UserSelectComponent) _icp() {}
func (s *UserSelectComponent) MarshalJSON() ([]byte, error) {
type sel UserSelectComponent
type DefaultValue struct {
Id UserID `json:"id"`
Type string `json:"type"`
}
type Msg struct {
Type ComponentType `json:"type"`
*sel
MinValues *int `json:"min_values,omitempty"`
MaxValues *int `json:"max_values,omitempty"`
DefaultValues []DefaultValue `json:"default_values,omitempty"`
}
msg := Msg{
@ -749,6 +757,16 @@ func (s *UserSelectComponent) MarshalJSON() ([]byte, error) {
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} {
msg.MinValues = new(int)
msg.MaxValues = new(int)
@ -840,8 +858,9 @@ type MentionableSelectComponent struct {
ValueLimits [2]int `json:"-"`
// Disabled disables the select if true.
Disabled bool `json:"disabled,omitempty"`
// SelectedUsers is the slice of UserIDs that are marked as selected by default
SelectedUsers []UserID `json:"-"`
// SelectedMentions is the slice of discord.UserID's and discord.RoleID's
// that are marked as selected by default
SelectedMentions []interface{} `json:"-"`
}
// ID implements the Component interface.
@ -860,7 +879,7 @@ func (s *MentionableSelectComponent) MarshalJSON() ([]byte, error) {
type sel MentionableSelectComponent
type DefaultValue struct {
Id UserID `json:"id"`
Id Snowflake `json:"id"`
Type string `json:"type"`
}
@ -879,9 +898,16 @@ func (s *MentionableSelectComponent) MarshalJSON() ([]byte, error) {
var defaultValues []DefaultValue
if len(s.SelectedUsers) > 0 {
for _, userId := range s.SelectedUsers {
defaultValues = append(defaultValues, DefaultValue{Id: userId, Type: "user"})
if len(s.SelectedMentions) > 0 {
for _, mentionId := range s.SelectedMentions {
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"})
}
}
}