Skip to content

Commit

Permalink
Merge pull request #28 from DisgoOrg/development
Browse files Browse the repository at this point in the history
new release
  • Loading branch information
Skye-31 authored Jun 13, 2021
2 parents c956200 + 249f061 commit 734cc16
Show file tree
Hide file tree
Showing 75 changed files with 1,813 additions and 1,529 deletions.
4 changes: 2 additions & 2 deletions api/action_row.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package api

// NewActionRow creates a new ActionRow holding th provided Component(s)
func NewActionRow(components ...Component) *ActionRow {
return &ActionRow{
func NewActionRow(components ...Component) ActionRow {
return ActionRow{
ComponentImpl: newComponentImpl(ComponentTypeActionRow),
Components: components,
}
Expand Down
11 changes: 0 additions & 11 deletions api/bit.go

This file was deleted.

28 changes: 14 additions & 14 deletions api/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,49 @@ const (
)

// 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{
func NewButton(style ButtonStyle, label *string, customID string, url string, emoji *Emoji, disabled bool) Button {
return Button{
ComponentImpl: newComponentImpl(ComponentTypeButton),
Style: style,
CustomID: customID,
URL: url,
Label: label,
Emote: emote,
Emoji: emoji,
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)
func NewPrimaryButton(label string, customID string, emoji *Emoji, disabled bool) Button {
return NewButton(ButtonStylePrimary, &label, customID, "", emoji, 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)
func NewSecondaryButton(label string, customID string, emoji *Emoji, disabled bool) Button {
return NewButton(ButtonStyleSecondary, &label, customID, "", emoji, 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)
func NewSuccessButton(label string, customID string, emoji *Emoji, disabled bool) Button {
return NewButton(ButtonStyleSuccess, &label, customID, "", emoji, 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)
func NewDangerButton(label string, customID string, emoji *Emoji, disabled bool) Button {
return NewButton(ButtonStyleDanger, &label, customID, "", emoji, 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)
func NewLinkButton(label string, url string, emoji *Emoji, disabled bool) Button {
return NewButton(ButtonStyleLink, &label, "", url, emoji, 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"`
Emoji *Emoji `json:"emoji,omitempty"`
CustomID string `json:"custom_id,omitempty"`
URL string `json:"url,omitempty"`
Disabled bool `json:"disabled,omitempty"`
Expand Down
24 changes: 24 additions & 0 deletions api/button_interaction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package api

// ButtonInteraction is a specific Interaction when CLicked on Button(s)
type ButtonInteraction struct {
*Interaction
Message *Message `json:"message,omitempty"`
Data *ButtonInteractionData `json:"data,omitempty"`
}

// DeferEdit replies to the api.ButtonInteraction with api.InteractionResponseTypeDeferredUpdateMessage and cancels the loading state
func (i *ButtonInteraction) DeferEdit() error {
return i.Respond(InteractionResponseTypeDeferredUpdateMessage, nil)
}

// Edit replies to the api.ButtonInteraction with api.InteractionResponseTypeUpdateMessage & api.MessageCreate which edits the original api.Message
func (i *ButtonInteraction) Edit(messageCreate MessageCreate) error {
return i.Respond(InteractionResponseTypeUpdateMessage, messageCreate)
}

// ButtonInteractionData is the command data payload
type ButtonInteractionData struct {
CustomID string `json:"custom_id"`
ComponentType ComponentType `json:"component_type"`
}
12 changes: 6 additions & 6 deletions api/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ type Cache interface {
FindCategory(Snowflake, func(*Category) bool) *Category
FindCategories(Snowflake, func(*Category) bool) []*Category

Emote(emoteID Snowflake) *Emote
EmotesByName(guildID Snowflake, name string, ignoreCase bool) []*Emote
Emotes(guildID Snowflake) []*Emote
EmoteCache(guildID Snowflake) map[Snowflake]*Emote
AllEmoteCache() map[Snowflake]map[Snowflake]*Emote
CacheEmote(*Emote) *Emote
Emote(emoteID Snowflake) *Emoji
EmotesByName(guildID Snowflake, name string, ignoreCase bool) []*Emoji
Emotes(guildID Snowflake) []*Emoji
EmoteCache(guildID Snowflake) map[Snowflake]*Emoji
AllEmoteCache() map[Snowflake]map[Snowflake]*Emoji
CacheEmote(*Emoji) *Emoji
UncacheEmote(guildID Snowflake, emoteID Snowflake)
}
19 changes: 10 additions & 9 deletions api/cache_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
CacheFlagVoiceChannels
CacheFlagStoreChannels
CacheFlagRoles
CacheFlagRoleTags
CacheFlagEmotes
CacheFlagVoiceState
CacheFlagCommands
Expand All @@ -27,27 +28,27 @@ const (
)

// Add allows you to add multiple bits together, producing a new bit
func (c CacheFlags) Add(bits ...Bit) Bit {
func (c CacheFlags) Add(bits ...CacheFlags) CacheFlags {
total := CacheFlags(0)
for _, bit := range bits {
total |= bit.(CacheFlags)
total |= bit
}
c |= total
return c
}

// Remove allows you to subtract multiple bits from the first, producing a new bit
func (c CacheFlags) Remove(bits ...Bit) Bit {
func (c CacheFlags) Remove(bits ...CacheFlags) CacheFlags {
total := CacheFlags(0)
for _, bit := range bits {
total |= bit.(CacheFlags)
total |= bit
}
c &^= total
return c
}

// HasAll will ensure that the bit includes all of the bits entered
func (c CacheFlags) HasAll(bits ...Bit) bool {
func (c CacheFlags) HasAll(bits ...CacheFlags) bool {
for _, bit := range bits {
if !c.Has(bit) {
return false
Expand All @@ -57,12 +58,12 @@ func (c CacheFlags) HasAll(bits ...Bit) bool {
}

// Has will check whether the Bit contains another bit
func (c CacheFlags) Has(bit Bit) bool {
return (c & bit.(CacheFlags)) == bit
func (c CacheFlags) Has(bit CacheFlags) bool {
return (c & bit) == bit
}

// MissingAny will check whether the bit is missing any one of the bits
func (c CacheFlags) MissingAny(bits ...Bit) bool {
func (c CacheFlags) MissingAny(bits ...CacheFlags) bool {
for _, bit := range bits {
if !c.Has(bit) {
return true
Expand All @@ -72,6 +73,6 @@ func (c CacheFlags) MissingAny(bits ...Bit) bool {
}

// Missing will do the inverse of Bit.Has
func (c CacheFlags) Missing(bit Bit) bool {
func (c CacheFlags) Missing(bit CacheFlags) bool {
return !c.Has(bit)
}
4 changes: 2 additions & 2 deletions api/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ type MessageChannel struct {
}

// SendMessage sends a Message to a TextChannel
func (c MessageChannel) SendMessage(message *MessageCreate) (*Message, error) {
func (c MessageChannel) SendMessage(message MessageCreate) (*Message, error) {
// Todo: attachments
return c.Disgo.RestClient().SendMessage(c.ID, message)
}

// EditMessage edits a Message in this TextChannel
func (c MessageChannel) EditMessage(messageID Snowflake, message *MessageUpdate) (*Message, error) {
func (c MessageChannel) EditMessage(messageID Snowflake, message MessageUpdate) (*Message, error) {
return c.Disgo.RestClient().EditMessage(c.ID, messageID, message)
}

Expand Down
4 changes: 0 additions & 4 deletions api/color.go

This file was deleted.

40 changes: 20 additions & 20 deletions api/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ var errNoDisgoInstance = errors.New("no disgo instance injected")
type Command struct {
Disgo Disgo
GuildPermissions map[Snowflake]*GuildCommandPermissions
GuildID *Snowflake `json:"guild_id"`
ID Snowflake `json:"id,omitempty"`
ApplicationID Snowflake `json:"application_id,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
DefaultPermission *bool `json:"default_permission,omitempty"`
Options []*CommandOption `json:"options,omitempty"`
GuildID *Snowflake `json:"guild_id"`
ID Snowflake `json:"id,omitempty"`
ApplicationID Snowflake `json:"application_id,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
DefaultPermission bool `json:"default_permission,omitempty"`
Options []CommandOption `json:"options,omitempty"`
}

// Guild returns the Guild the Command is from from the Cache or nil if it is a global Command
Expand All @@ -31,8 +31,8 @@ func (c Command) FromGuild() bool {
}

// ToCreate return the CommandCreate for this Command
func (c *Command) ToCreate() *CommandCreate {
return &CommandCreate{
func (c *Command) ToCreate() CommandCreate {
return CommandCreate{
Name: c.Name,
Description: c.Description,
DefaultPermission: c.DefaultPermission,
Expand Down Expand Up @@ -61,7 +61,7 @@ func (c *Command) Fetch() error {
}

// Update updates the current Command with the given fields
func (c *Command) Update(command *CommandUpdate) error {
func (c *Command) Update(command CommandUpdate) error {
if c.Disgo == nil {
return errNoDisgoInstance
}
Expand All @@ -81,8 +81,8 @@ func (c *Command) Update(command *CommandUpdate) error {
}

// SetPermissions sets the GuildCommandPermissions for a specific Guild. this overrides all existing CommandPermission(s). thx discord for that
func (c *Command) SetPermissions(guildID Snowflake, permissions ...*CommandPermission) error {
_, err := c.Disgo.RestClient().SetGuildCommandPermissions(c.Disgo.ApplicationID(), guildID, c.ID, &SetGuildCommandPermissions{Permissions: permissions})
func (c *Command) SetPermissions(guildID Snowflake, permissions ...CommandPermission) error {
_, err := c.Disgo.RestClient().SetGuildCommandPermissions(c.Disgo.ApplicationID(), guildID, c.ID, SetGuildCommandPermissions{Permissions: permissions})
if err != nil {
return err
}
Expand Down Expand Up @@ -117,16 +117,16 @@ func (c Command) Delete() error {

// CommandCreate is used to create an Command. all fields are optional
type CommandCreate struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
DefaultPermission *bool `json:"default_permission,omitempty"`
Options []*CommandOption `json:"options,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
DefaultPermission bool `json:"default_permission,omitempty"`
Options []CommandOption `json:"options,omitempty"`
}

// CommandUpdate is used to update an existing Command. all fields are optional
type CommandUpdate struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
DefaultPermission *bool `json:"default_permission,omitempty"`
Options []*CommandOption `json:"options,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
DefaultPermission *bool `json:"default_permission,omitempty"`
Options []CommandOption `json:"options,omitempty"`
}
Loading

0 comments on commit 734cc16

Please sign in to comment.