1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-07-28 16:32:24 +00:00

Compare commits

...

4 commits

Author SHA1 Message Date
Barani Kumar S 6466037947 comments: Fix format 2024-10-26 00:40:38 +05:30
Barani Kumar S cb28e470c2 discord: Minor wordings and comment fix 2024-10-26 00:38:54 +05:30
Barani Kumar S 59550eee47 comments: Little typo fix 2024-10-26 00:04:59 +05:30
Barani Kumar S 9c8f1549e8 discord: Modified MentionableSelectComponent to take in DefaultMention union type 2024-10-25 23:48:41 +05:30

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:"-"`
}
// DefaultUserMention creates a new DefaultMention type with only UserID
func DefaultUserMention (userId UserID) DefaultMention {
return DefaultMention{userId: userId}
}
// DefaultRoleMention creates a new DefaultMention type with only RoleID
func DefaultRoleMention(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,14 @@ 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: []DefaultMention{
// DefaultMentions: []interface{}{ discord.RoleID(78402180381208302), discord.UserID(87028080234556) } // discord.DefaultUserMention(0382080830233),
DefaultMentions []interface{} `json:"-"` // discord.DefaultRoleMention(4820380382080),
// ...
// }
DefaultMentions []DefaultMention `json:"-"`
} }
// ID implements the Component interface. // ID implements the Component interface.
@ -901,14 +920,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"})
} }
} }
} }