Skip to content

Commit a295955

Browse files
authored
Merge pull request #20 from DisgoOrg/development
buttons release
2 parents d4c3991 + ad67e2d commit a295955

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1048
-1050
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
version: 2
22
updates:
3-
- package-ecosystem: gomod
4-
directory: "/"
5-
schedule:
6-
interval: daily
7-
open-pull-requests-limit: 10
8-
target-branch: development
9-
- package-ecosystem: gomod
10-
directory: "/example"
11-
schedule:
12-
interval: daily
13-
open-pull-requests-limit: 10
3+
- package-ecosystem: gomod
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10
8+
target-branch: development
9+
- package-ecosystem: gomod
10+
directory: "/example"
11+
schedule:
12+
interval: daily
13+
open-pull-requests-limit: 10

api/action_row.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package api
2+
3+
// NewActionRow creates a new ActionRow holding th provided Component(s)
4+
func NewActionRow(components ...Component) *ActionRow {
5+
return &ActionRow{
6+
ComponentImpl: newComponentImpl(ComponentTypeActionRow),
7+
Components: components,
8+
}
9+
}
10+
11+
// ActionRow holds up to 5 Component(s) in a row
12+
type ActionRow struct {
13+
ComponentImpl
14+
Components []Component `json:"components"`
15+
}

api/button.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package api
2+
3+
// ButtonStyle defines how the Button looks like (https://discord.com/assets/7bb017ce52cfd6575e21c058feb3883b.png)
4+
type ButtonStyle int
5+
6+
// Supported ButtonStyle(s)
7+
const (
8+
ButtonStylePrimary = iota + 1
9+
ButtonStyleSecondary
10+
ButtonStyleSuccess
11+
ButtonStyleDanger
12+
ButtonStyleLink
13+
)
14+
15+
// NewButton creates a new Button with the provided parameters. Link Button(s) need a url and other Button(s) need a customID
16+
func NewButton(style ButtonStyle, label *string, customID string, url string, emote *Emote, disabled bool) *Button {
17+
return &Button{
18+
ComponentImpl: newComponentImpl(ComponentTypeButton),
19+
Style: style,
20+
CustomID: customID,
21+
URL: url,
22+
Label: label,
23+
Emote: emote,
24+
Disabled: disabled,
25+
}
26+
}
27+
28+
// NewPrimaryButton creates a new Button with ButtonStylePrimary & the provided parameters
29+
func NewPrimaryButton(label string, customID string, emote *Emote, disabled bool) *Button {
30+
return NewButton(ButtonStylePrimary, &label, customID, "", emote, disabled)
31+
}
32+
33+
// NewSecondaryButton creates a new Button with ButtonStyleSecondary & the provided parameters
34+
func NewSecondaryButton(label string, customID string, emote *Emote, disabled bool) *Button {
35+
return NewButton(ButtonStyleSecondary, &label, customID, "", emote, disabled)
36+
}
37+
38+
// NewSuccessButton creates a new Button with ButtonStyleSuccess & the provided parameters
39+
func NewSuccessButton(label string, customID string, emote *Emote, disabled bool) *Button {
40+
return NewButton(ButtonStyleSuccess, &label, customID, "", emote, disabled)
41+
}
42+
43+
// NewDangerButton creates a new Button with ButtonStyleDanger & the provided parameters
44+
func NewDangerButton(label string, customID string, emote *Emote, disabled bool) *Button {
45+
return NewButton(ButtonStyleDanger, &label, customID, "", emote, disabled)
46+
}
47+
48+
// NewLinkButton creates a new link Button with ButtonStyleLink & the provided parameters
49+
func NewLinkButton(label string, url string, emote *Emote, disabled bool) *Button {
50+
return NewButton(ButtonStyleLink, &label, "", url, emote, disabled)
51+
}
52+
53+
// Button can be attacked to all messages & be clicked by a User. If clicked it fires a events.ButtonClickEvent with the declared customID
54+
type Button struct {
55+
ComponentImpl
56+
Style ButtonStyle `json:"style,omitempty"`
57+
Label *string `json:"label,omitempty"`
58+
Emote *Emote `json:"emoji,omitempty"`
59+
CustomID string `json:"custom_id,omitempty"`
60+
URL string `json:"url,omitempty"`
61+
Disabled bool `json:"disabled,omitempty"`
62+
}

api/component.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package api
2+
3+
// ComponentType defines different Component(s)
4+
type ComponentType int
5+
6+
// Supported ComponentType(s)
7+
const (
8+
ComponentTypeActionRow = iota + 1
9+
ComponentTypeButton
10+
)
11+
12+
// Component is a general interface each Component needs to implement
13+
type Component interface {
14+
Type() ComponentType
15+
}
16+
17+
func newComponentImpl(componentType ComponentType) ComponentImpl {
18+
return ComponentImpl{ComponentType: componentType}
19+
}
20+
21+
// ComponentImpl is used to embed in each different ComponentType
22+
type ComponentImpl struct {
23+
ComponentType ComponentType `json:"type"`
24+
}
25+
26+
// Type returns the ComponentType of this Component
27+
func (t ComponentImpl) Type() ComponentType {
28+
return t.ComponentType
29+
}
30+
31+
// UnmarshalComponent is used for easier unmarshalling of different Component(s)
32+
type UnmarshalComponent struct {
33+
ComponentType ComponentType `json:"type"`
34+
Style ButtonStyle `json:"style"`
35+
Label *string `json:"label"`
36+
Emote *Emote `json:"emoji"`
37+
CustomID string `json:"custom_id"`
38+
URL string `json:"url"`
39+
Disabled bool `json:"disabled"`
40+
Components []*UnmarshalComponent `json:"components"`
41+
}

api/emote.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
package api
22

3-
// An Emote allows you to interact with custom emojis in discord.
3+
// NewEmote creates a new custom Emote with the given parameters
4+
func NewEmote(name string, emoteID Snowflake) *Emote {
5+
return &Emote{Name: name, ID: emoteID, Animated: false}
6+
}
7+
8+
// NewAnimatedEmote creates a new animated custom Emote with the given parameters
9+
func NewAnimatedEmote(name string, emoteID Snowflake) *Emote {
10+
return &Emote{Name: name, ID: emoteID, Animated: true}
11+
}
12+
13+
// NewEmoji creates a new emoji with the given unicode
14+
func NewEmoji(name string) *Emote {
15+
return &Emote{Name: name}
16+
}
17+
18+
// Emote allows you to interact with emojis & emotes
419
type Emote struct {
520
Disgo Disgo
6-
ID Snowflake
7-
GuildID Snowflake
8-
Name string
9-
Animated bool
21+
GuildID Snowflake `json:"guild_id,omitempty"`
22+
Name string `json:"name,omitempty"`
23+
ID Snowflake `json:"id,omitempty"`
24+
Animated bool `json:"animated,omitempty"`
1025
}
1126

1227
// Guild returns the Guild of the Emote from the Cache

api/endpoints/api_route.go

Lines changed: 0 additions & 47 deletions
This file was deleted.

api/endpoints/cdn_route.go

Lines changed: 0 additions & 66 deletions
This file was deleted.

api/endpoints/custom_route.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)