1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-01-20 11:37:56 +00:00

discord: Modified MentionableSelectComponent to take in DefaultMention union type

This commit is contained in:
Barani Kumar S 2024-10-25 23:48:41 +05:30
parent 6c06bb797e
commit 9c8f1549e8

View file

@ -847,6 +847,22 @@ func (s *RoleSelectComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(msg) return json.Marshal(msg)
} }
// DefaultMention type is a Union type which packs both UserID and RoleID
type DefaultMention struct {
userId UserID `json:"-"`
roleId RoleID `json:"-"`
}
// Creates new DefaultMention type with only UserID
func UserMention (userId UserID) DefaultMention {
return DefaultMention{userId: userId}
}
// Creates new DefaultMention type with only RoleID
func RoleMention(roleId RoleID) DefaultMention {
return DefaultMention{roleId: roleId}
}
type MentionableSelectComponent struct { type MentionableSelectComponent struct {
// CustomID is the custom unique ID. // CustomID is the custom unique ID.
CustomID ComponentID `json:"custom_id,omitempty"` CustomID ComponentID `json:"custom_id,omitempty"`
@ -858,11 +874,10 @@ 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"`
// DefaultMentions is the slice of discord.UserID's and discord.RoleID's // DefaultMentions is the slice of User / Role Mentions that are selected by default
// that are marked as selected by default
// Example: // Example:
// DefaultMentions: []interface{}{ discord.RoleID(78402180381208302), discord.UserID(87028080234556) } // DefaultMentions: []DefaultMention{ NewUserMention(0382080830233), NewRoleMention(4820380382080) }
DefaultMentions []interface{} `json:"-"` DefaultMentions []DefaultMention `json:"-"`
} }
// ID implements the Component interface. // ID implements the Component interface.
@ -901,14 +916,14 @@ func (s *MentionableSelectComponent) MarshalJSON() ([]byte, error) {
var defaultValues []DefaultValue var defaultValues []DefaultValue
if len(s.DefaultMentions) > 0 { if len(s.DefaultMentions) > 0 {
for _, mentionId := range s.DefaultMentions { for _, mention := range s.DefaultMentions {
switch id := mentionId.(type) { if mention.userId.IsValid() {
case UserID:
defaultValues = defaultValues =
append(defaultValues, DefaultValue{Id: Snowflake(id), Type: "user"}) append(defaultValues, DefaultValue{Id: Snowflake(mention.userId), Type: "user"})
case RoleID: }
if mention.roleId.IsValid() {
defaultValues = defaultValues =
append(defaultValues, DefaultValue{Id: Snowflake(id), Type: "role"}) append(defaultValues, DefaultValue{Id: Snowflake(mention.roleId), Type: "role"})
} }
} }
} }