Skip to content

Commit

Permalink
Merge pull request #20 from DisgoOrg/development
Browse files Browse the repository at this point in the history
buttons release
  • Loading branch information
topi314 authored May 28, 2021
2 parents d4c3991 + ad67e2d commit a295955
Show file tree
Hide file tree
Showing 45 changed files with 1,048 additions and 1,050 deletions.
22 changes: 11 additions & 11 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
target-branch: development
- package-ecosystem: gomod
directory: "/example"
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
target-branch: development
- package-ecosystem: gomod
directory: "/example"
schedule:
interval: daily
open-pull-requests-limit: 10
15 changes: 15 additions & 0 deletions api/action_row.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package api

// NewActionRow creates a new ActionRow holding th provided Component(s)
func NewActionRow(components ...Component) *ActionRow {
return &ActionRow{
ComponentImpl: newComponentImpl(ComponentTypeActionRow),
Components: components,
}
}

// ActionRow holds up to 5 Component(s) in a row
type ActionRow struct {
ComponentImpl
Components []Component `json:"components"`
}
62 changes: 62 additions & 0 deletions api/button.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package api

// ButtonStyle defines how the Button looks like (https://discord.com/assets/7bb017ce52cfd6575e21c058feb3883b.png)
type ButtonStyle int

// Supported ButtonStyle(s)
const (
ButtonStylePrimary = iota + 1
ButtonStyleSecondary
ButtonStyleSuccess
ButtonStyleDanger
ButtonStyleLink
)

// NewButton creates a new Button with the provided parameters. Link Button(s) need a url and other Button(s) need a customID
func NewButton(style ButtonStyle, label *string, customID string, url string, emote *Emote, disabled bool) *Button {
return &Button{
ComponentImpl: newComponentImpl(ComponentTypeButton),
Style: style,
CustomID: customID,
URL: url,
Label: label,
Emote: emote,
Disabled: disabled,
}
}

// NewPrimaryButton creates a new Button with ButtonStylePrimary & the provided parameters
func NewPrimaryButton(label string, customID string, emote *Emote, disabled bool) *Button {
return NewButton(ButtonStylePrimary, &label, customID, "", emote, disabled)
}

// NewSecondaryButton creates a new Button with ButtonStyleSecondary & the provided parameters
func NewSecondaryButton(label string, customID string, emote *Emote, disabled bool) *Button {
return NewButton(ButtonStyleSecondary, &label, customID, "", emote, disabled)
}

// NewSuccessButton creates a new Button with ButtonStyleSuccess & the provided parameters
func NewSuccessButton(label string, customID string, emote *Emote, disabled bool) *Button {
return NewButton(ButtonStyleSuccess, &label, customID, "", emote, disabled)
}

// NewDangerButton creates a new Button with ButtonStyleDanger & the provided parameters
func NewDangerButton(label string, customID string, emote *Emote, disabled bool) *Button {
return NewButton(ButtonStyleDanger, &label, customID, "", emote, disabled)
}

// NewLinkButton creates a new link Button with ButtonStyleLink & the provided parameters
func NewLinkButton(label string, url string, emote *Emote, disabled bool) *Button {
return NewButton(ButtonStyleLink, &label, "", url, emote, disabled)
}

// Button can be attacked to all messages & be clicked by a User. If clicked it fires a events.ButtonClickEvent with the declared customID
type Button struct {
ComponentImpl
Style ButtonStyle `json:"style,omitempty"`
Label *string `json:"label,omitempty"`
Emote *Emote `json:"emoji,omitempty"`
CustomID string `json:"custom_id,omitempty"`
URL string `json:"url,omitempty"`
Disabled bool `json:"disabled,omitempty"`
}
41 changes: 41 additions & 0 deletions api/component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package api

// ComponentType defines different Component(s)
type ComponentType int

// Supported ComponentType(s)
const (
ComponentTypeActionRow = iota + 1
ComponentTypeButton
)

// Component is a general interface each Component needs to implement
type Component interface {
Type() ComponentType
}

func newComponentImpl(componentType ComponentType) ComponentImpl {
return ComponentImpl{ComponentType: componentType}
}

// ComponentImpl is used to embed in each different ComponentType
type ComponentImpl struct {
ComponentType ComponentType `json:"type"`
}

// Type returns the ComponentType of this Component
func (t ComponentImpl) Type() ComponentType {
return t.ComponentType
}

// UnmarshalComponent is used for easier unmarshalling of different Component(s)
type UnmarshalComponent struct {
ComponentType ComponentType `json:"type"`
Style ButtonStyle `json:"style"`
Label *string `json:"label"`
Emote *Emote `json:"emoji"`
CustomID string `json:"custom_id"`
URL string `json:"url"`
Disabled bool `json:"disabled"`
Components []*UnmarshalComponent `json:"components"`
}
25 changes: 20 additions & 5 deletions api/emote.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package api

// An Emote allows you to interact with custom emojis in discord.
// NewEmote creates a new custom Emote with the given parameters
func NewEmote(name string, emoteID Snowflake) *Emote {
return &Emote{Name: name, ID: emoteID, Animated: false}
}

// NewAnimatedEmote creates a new animated custom Emote with the given parameters
func NewAnimatedEmote(name string, emoteID Snowflake) *Emote {
return &Emote{Name: name, ID: emoteID, Animated: true}
}

// NewEmoji creates a new emoji with the given unicode
func NewEmoji(name string) *Emote {
return &Emote{Name: name}
}

// Emote allows you to interact with emojis & emotes
type Emote struct {
Disgo Disgo
ID Snowflake
GuildID Snowflake
Name string
Animated bool
GuildID Snowflake `json:"guild_id,omitempty"`
Name string `json:"name,omitempty"`
ID Snowflake `json:"id,omitempty"`
Animated bool `json:"animated,omitempty"`
}

// Guild returns the Guild of the Emote from the Cache
Expand Down
47 changes: 0 additions & 47 deletions api/endpoints/api_route.go

This file was deleted.

66 changes: 0 additions & 66 deletions api/endpoints/cdn_route.go

This file was deleted.

30 changes: 0 additions & 30 deletions api/endpoints/custom_route.go

This file was deleted.

Loading

0 comments on commit a295955

Please sign in to comment.