diff --git a/_examples/test/listeners.go b/_examples/test/listeners.go index c9270ad9..01bc7ff7 100644 --- a/_examples/test/listeners.go +++ b/_examples/test/listeners.go @@ -44,11 +44,11 @@ func modalListener(event *events.ModalSubmitInteractionCreate) { func componentListener(event *events.ComponentInteractionCreate) { switch data := event.Data.(type) { case discord.ButtonInteractionData: - ids := strings.Split(data.CustomID().String(), ":") + ids := strings.Split(data.CustomID(), ":") switch ids[0] { case "modal": _ = event.CreateModal(discord.ModalCreate{ - CustomID: discord.CustomID("test" + ids[1]), + CustomID: "test" + ids[1], Title: "Test" + ids[1] + " Modal", Components: []discord.ContainerComponent{ discord.ActionRowComponent{ @@ -66,7 +66,7 @@ func componentListener(event *events.ComponentInteractionCreate) { case "test1": _ = event.CreateMessage(discord.NewMessageCreateBuilder(). - SetContent(data.CustomID().String()). + SetContent(data.CustomID()). Build(), ) @@ -78,7 +78,7 @@ func componentListener(event *events.ComponentInteractionCreate) { case "test4": _ = event.UpdateMessage(discord.NewMessageUpdateBuilder(). - SetContent(data.CustomID().String()). + SetContent(data.CustomID()). Build(), ) } diff --git a/discord/component.go b/discord/component.go index 57259d3f..be0ab920 100644 --- a/discord/component.go +++ b/discord/component.go @@ -18,12 +18,6 @@ const ( ComponentTypeTextInput ) -type CustomID string - -func (c CustomID) String() string { - return string(c) -} - type Component interface { json.Marshaler Type() ComponentType @@ -38,7 +32,7 @@ type ContainerComponent interface { type InteractiveComponent interface { Component - ID() CustomID + ID() string interactiveComponent() } @@ -183,7 +177,7 @@ func (c ActionRowComponent) TextInputs() []TextInputComponent { } // UpdateComponent returns a new ActionRowComponent with the Component which has the customID replaced -func (c ActionRowComponent) UpdateComponent(customID CustomID, component InteractiveComponent) ActionRowComponent { +func (c ActionRowComponent) UpdateComponent(customID string, component InteractiveComponent) ActionRowComponent { for i, cc := range c { if cc.ID() == customID { c[i] = component @@ -219,7 +213,7 @@ const ( ) // NewButton creates a new ButtonComponent with the provided parameters. Link ButtonComponent(s) need a URL and other ButtonComponent(s) need a customID -func NewButton(style ButtonStyle, label string, customID CustomID, url string) ButtonComponent { +func NewButton(style ButtonStyle, label string, customID string, url string) ButtonComponent { return ButtonComponent{ Style: style, CustomID: customID, @@ -229,22 +223,22 @@ func NewButton(style ButtonStyle, label string, customID CustomID, url string) B } // NewPrimaryButton creates a new ButtonComponent with ButtonStylePrimary & the provided parameters -func NewPrimaryButton(label string, customID CustomID) ButtonComponent { +func NewPrimaryButton(label string, customID string) ButtonComponent { return NewButton(ButtonStylePrimary, label, customID, "") } // NewSecondaryButton creates a new ButtonComponent with ButtonStyleSecondary & the provided parameters -func NewSecondaryButton(label string, customID CustomID) ButtonComponent { +func NewSecondaryButton(label string, customID string) ButtonComponent { return NewButton(ButtonStyleSecondary, label, customID, "") } // NewSuccessButton creates a new ButtonComponent with ButtonStyleSuccess & the provided parameters -func NewSuccessButton(label string, customID CustomID) ButtonComponent { +func NewSuccessButton(label string, customID string) ButtonComponent { return NewButton(ButtonStyleSuccess, label, customID, "") } // NewDangerButton creates a new ButtonComponent with ButtonStyleDanger & the provided parameters -func NewDangerButton(label string, customID CustomID) ButtonComponent { +func NewDangerButton(label string, customID string) ButtonComponent { return NewButton(ButtonStyleDanger, label, customID, "") } @@ -262,7 +256,7 @@ type ButtonComponent struct { Style ButtonStyle `json:"style"` Label string `json:"label,omitempty"` Emoji *ComponentEmoji `json:"emoji,omitempty"` - CustomID CustomID `json:"custom_id,omitempty"` + CustomID string `json:"custom_id,omitempty"` URL string `json:"url,omitempty"` Disabled bool `json:"disabled,omitempty"` } @@ -282,11 +276,11 @@ func (ButtonComponent) Type() ComponentType { return ComponentTypeButton } -func (c ButtonComponent) ID() CustomID { +func (c ButtonComponent) ID() string { return c.CustomID } -func (c ButtonComponent) SetID(id CustomID) InteractiveComponent { +func (c ButtonComponent) SetID(id string) InteractiveComponent { c.CustomID = id return c } @@ -313,7 +307,7 @@ func (c ButtonComponent) WithEmoji(emoji ComponentEmoji) ButtonComponent { } // WithCustomID returns a new ButtonComponent with the provided custom id -func (c ButtonComponent) WithCustomID(customID CustomID) ButtonComponent { +func (c ButtonComponent) WithCustomID(customID string) ButtonComponent { c.CustomID = customID return c } @@ -343,7 +337,7 @@ func (c ButtonComponent) WithDisabled(disabled bool) ButtonComponent { } // NewSelectMenu builds a new SelectMenuComponent from the provided values -func NewSelectMenu(customID CustomID, placeholder string, options ...SelectMenuOption) SelectMenuComponent { +func NewSelectMenu(customID string, placeholder string, options ...SelectMenuOption) SelectMenuComponent { return SelectMenuComponent{ CustomID: customID, Placeholder: placeholder, @@ -357,7 +351,7 @@ var ( ) type SelectMenuComponent struct { - CustomID CustomID `json:"custom_id"` + CustomID string `json:"custom_id"` Placeholder string `json:"placeholder,omitempty"` MinValues *int `json:"min_values,omitempty"` MaxValues int `json:"max_values,omitempty"` @@ -380,7 +374,7 @@ func (SelectMenuComponent) Type() ComponentType { return ComponentTypeSelectMenu } -func (c SelectMenuComponent) ID() CustomID { +func (c SelectMenuComponent) ID() string { return c.CustomID } @@ -388,7 +382,7 @@ func (SelectMenuComponent) component() {} func (SelectMenuComponent) interactiveComponent() {} // WithCustomID returns a new SelectMenuComponent with the provided customID -func (c SelectMenuComponent) WithCustomID(customID CustomID) SelectMenuComponent { +func (c SelectMenuComponent) WithCustomID(customID string) SelectMenuComponent { c.CustomID = customID return c } @@ -512,7 +506,7 @@ var ( _ InteractiveComponent = (*TextInputComponent)(nil) ) -func NewTextInput(customID CustomID, style TextInputStyle, label string) TextInputComponent { +func NewTextInput(customID string, style TextInputStyle, label string) TextInputComponent { return TextInputComponent{ CustomID: customID, Style: style, @@ -520,16 +514,16 @@ func NewTextInput(customID CustomID, style TextInputStyle, label string) TextInp } } -func NewShortTextInput(customID CustomID, label string) TextInputComponent { +func NewShortTextInput(customID string, label string) TextInputComponent { return NewTextInput(customID, TextInputStyleShort, label) } -func NewParagraphTextInput(customID CustomID, label string) TextInputComponent { +func NewParagraphTextInput(customID string, label string) TextInputComponent { return NewTextInput(customID, TextInputStyleParagraph, label) } type TextInputComponent struct { - CustomID CustomID `json:"custom_id"` + CustomID string `json:"custom_id"` Style TextInputStyle `json:"style"` Label string `json:"label"` MinLength *int `json:"min_length,omitempty"` @@ -554,7 +548,7 @@ func (TextInputComponent) Type() ComponentType { return ComponentTypeTextInput } -func (c TextInputComponent) ID() CustomID { +func (c TextInputComponent) ID() string { return c.CustomID } @@ -562,7 +556,7 @@ func (TextInputComponent) component() {} func (TextInputComponent) interactiveComponent() {} // WithCustomID returns a new SelectMenuComponent with the provided customID -func (c TextInputComponent) WithCustomID(customID CustomID) TextInputComponent { +func (c TextInputComponent) WithCustomID(customID string) TextInputComponent { c.CustomID = customID return c } diff --git a/discord/interaction_component.go b/discord/interaction_component.go index 5498d6d6..f450525e 100644 --- a/discord/interaction_component.go +++ b/discord/interaction_component.go @@ -83,17 +83,17 @@ func (ComponentInteraction) interaction() {} type ComponentInteractionData interface { Type() ComponentType - CustomID() CustomID + CustomID() string componentInteractionData() } type rawButtonInteractionData struct { - Custom CustomID `json:"custom_id"` + Custom string `json:"custom_id"` } type ButtonInteractionData struct { - customID CustomID + customID string } func (d *ButtonInteractionData) UnmarshalJSON(data []byte) error { @@ -115,7 +115,7 @@ func (ButtonInteractionData) Type() ComponentType { return ComponentTypeButton } -func (d ButtonInteractionData) CustomID() CustomID { +func (d ButtonInteractionData) CustomID() string { return d.customID } @@ -126,12 +126,12 @@ var ( ) type rawSelectMenuInteractionData struct { - Custom CustomID `json:"custom_id"` + Custom string `json:"custom_id"` Values []string `json:"values"` } type SelectMenuInteractionData struct { - customID CustomID + customID string Values []string } @@ -156,7 +156,7 @@ func (SelectMenuInteractionData) Type() ComponentType { return ComponentTypeSelectMenu } -func (d SelectMenuInteractionData) CustomID() CustomID { +func (d SelectMenuInteractionData) CustomID() string { return d.customID } diff --git a/discord/interaction_modal_submit.go b/discord/interaction_modal_submit.go index 59fb20da..d85606aa 100644 --- a/discord/interaction_modal_submit.go +++ b/discord/interaction_modal_submit.go @@ -36,8 +36,8 @@ func (ModalSubmitInteraction) Type() InteractionType { func (ModalSubmitInteraction) interaction() {} type ModalSubmitInteractionData struct { - CustomID CustomID `json:"custom_id"` - Components map[CustomID]InteractiveComponent `json:"components"` + CustomID string `json:"custom_id"` + Components map[string]InteractiveComponent `json:"components"` } func (d *ModalSubmitInteractionData) UnmarshalJSON(data []byte) error { @@ -54,7 +54,7 @@ func (d *ModalSubmitInteractionData) UnmarshalJSON(data []byte) error { *d = ModalSubmitInteractionData(iData.modalSubmitInteractionData) if len(iData.Components) > 0 { - d.Components = make(map[CustomID]InteractiveComponent, len(iData.Components)) + d.Components = make(map[string]InteractiveComponent, len(iData.Components)) for _, containerComponent := range iData.Components { for _, component := range containerComponent.Component.(ContainerComponent).Components() { d.Components[component.ID()] = component @@ -64,12 +64,12 @@ func (d *ModalSubmitInteractionData) UnmarshalJSON(data []byte) error { return nil } -func (d ModalSubmitInteractionData) Component(customID CustomID) (InteractiveComponent, bool) { +func (d ModalSubmitInteractionData) Component(customID string) (InteractiveComponent, bool) { component, ok := d.Components[customID] return component, ok } -func (d ModalSubmitInteractionData) TextInputComponent(customID CustomID) (TextInputComponent, bool) { +func (d ModalSubmitInteractionData) TextInputComponent(customID string) (TextInputComponent, bool) { if component, ok := d.Component(customID); ok { textInputComponent, ok := component.(TextInputComponent) return textInputComponent, ok @@ -77,14 +77,14 @@ func (d ModalSubmitInteractionData) TextInputComponent(customID CustomID) (TextI return TextInputComponent{}, false } -func (d ModalSubmitInteractionData) OptText(customID CustomID) (string, bool) { +func (d ModalSubmitInteractionData) OptText(customID string) (string, bool) { if textInputComponent, ok := d.TextInputComponent(customID); ok { return textInputComponent.Value, true } return "", false } -func (d ModalSubmitInteractionData) Text(customID CustomID) string { +func (d ModalSubmitInteractionData) Text(customID string) string { if text, ok := d.OptText(customID); ok { return text } diff --git a/discord/message.go b/discord/message.go index 1b7bcee6..0157dcac 100644 --- a/discord/message.go +++ b/discord/message.go @@ -141,7 +141,7 @@ func (m *Message) InteractiveComponents() []InteractiveComponent { } // ComponentByID returns the Component with the specific CustomID -func (m *Message) ComponentByID(customID CustomID) InteractiveComponent { +func (m *Message) ComponentByID(customID string) InteractiveComponent { for i := range m.Components { for ii := range m.Components[i].Components() { if m.Components[i].Components()[ii].ID() == customID { @@ -166,7 +166,7 @@ func (m *Message) Buttons() []ButtonComponent { } // ButtonByID returns a ButtonComponent with the specific customID from this Message -func (m *Message) ButtonByID(customID CustomID) *ButtonComponent { +func (m *Message) ButtonByID(customID string) *ButtonComponent { for i := range m.Components { for ii := range m.Components[i].Components() { if button, ok := m.Components[i].Components()[ii].(*ButtonComponent); ok && button.ID() == customID { @@ -191,7 +191,7 @@ func (m *Message) SelectMenus() []SelectMenuComponent { } // SelectMenuByID returns a SelectMenuComponent with the specific customID from this Message -func (m *Message) SelectMenuByID(customID CustomID) *SelectMenuComponent { +func (m *Message) SelectMenuByID(customID string) *SelectMenuComponent { for i := range m.Components { for ii := range m.Components[i].Components() { if button, ok := m.Components[i].Components()[ii].(*SelectMenuComponent); ok && button.ID() == customID { @@ -223,7 +223,7 @@ type MessageReaction struct { // MessageActivityType is the type of MessageActivity https://com/developers/docs/resources/channel#message-object-message-activity-types type MessageActivityType int -//Constants for MessageActivityType +// Constants for MessageActivityType const ( MessageActivityTypeJoin MessageActivityType = iota + 1 MessageActivityTypeSpectate @@ -232,13 +232,13 @@ const ( MessageActivityTypeJoinRequest ) -//MessageActivity is used for rich presence-related chat embeds in a Message +// MessageActivity is used for rich presence-related chat embeds in a Message type MessageActivity struct { Type MessageActivityType `json:"type"` PartyID *string `json:"party_id,omitempty"` } -//MessageApplication is used for rich presence-related chat embeds in a Message +// MessageApplication is used for rich presence-related chat embeds in a Message type MessageApplication struct { ID snowflake.ID `json:"id"` CoverImage *string `json:"cover_image,omitempty"` diff --git a/discord/modal_create.go b/discord/modal_create.go index 67fde94e..21291e36 100644 --- a/discord/modal_create.go +++ b/discord/modal_create.go @@ -3,7 +3,7 @@ package discord var _ InteractionResponseData = (*ModalCreate)(nil) type ModalCreate struct { - CustomID CustomID `json:"custom_id"` + CustomID string `json:"custom_id"` Title string `json:"title"` Components []ContainerComponent `json:"components"` } @@ -20,7 +20,7 @@ type ModalCreateBuilder struct { } // SetCustomID sets the CustomID of the ModalCreate -func (b *ModalCreateBuilder) SetCustomID(customID CustomID) *ModalCreateBuilder { +func (b *ModalCreateBuilder) SetCustomID(customID string) *ModalCreateBuilder { b.CustomID = customID return b }