Skip to content

Commit

Permalink
Merge pull request #11 from DisgoOrg/development
Browse files Browse the repository at this point in the history
  • Loading branch information
Skye-31 authored Apr 26, 2021
2 parents 6189700 + 62da4d1 commit 490e24c
Show file tree
Hide file tree
Showing 39 changed files with 675 additions and 539 deletions.
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
58 changes: 23 additions & 35 deletions api/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Command struct {
ApplicationID Snowflake `json:"application_id,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
DefaultPermission bool `json:"default_permission"`
DefaultPermission *bool `json:"default_permission,omitempty"`
Options []*CommandOption `json:"options,omitempty"`
}

Expand All @@ -30,26 +30,6 @@ func (c Command) FromGuild() bool {
return c.GuildID == nil
}

// Create creates the Command either as global or guild Command depending on if GuildID is set
func (c *Command) Create() error {
if c.Disgo == nil {
return errNoDisgoInstance
}
var rC *Command
var err error
if c.GuildID == nil {
rC, err = c.Disgo.RestClient().CreateGlobalCommand(c.Disgo.ApplicationID(), *c)

} else {
rC, err = c.Disgo.RestClient().CreateGuildCommand(c.Disgo.ApplicationID(), *c.GuildID, *c)
}
if err != nil {
return err
}
*c = *rC
return nil
}

// Fetch updates/fetches the current Command from discord
func (c *Command) Fetch() error {
if c.Disgo == nil {
Expand All @@ -71,7 +51,7 @@ func (c *Command) Fetch() error {
}

// Update updates the current Command with the given fields
func (c *Command) Update(command UpdateCommand) error {
func (c *Command) Update(command *CommandUpdate) error {
if c.Disgo == nil {
return errNoDisgoInstance
}
Expand All @@ -91,8 +71,8 @@ func (c *Command) Update(command UpdateCommand) 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 @@ -146,8 +126,8 @@ type CommandOption struct {
Name string `json:"name"`
Description string `json:"description"`
Required bool `json:"required,omitempty"`
Choices []OptionChoice `json:"choices,omitempty"`
Options []CommandOption `json:"options,omitempty"`
Choices []*OptionChoice `json:"choices,omitempty"`
Options []*CommandOption `json:"options,omitempty"`
}

// OptionChoice contains the data for a user using your command
Expand All @@ -159,10 +139,10 @@ type OptionChoice struct {
// GuildCommandPermissions holds all permissions for a Command
type GuildCommandPermissions struct {
Disgo Disgo
ID Snowflake `json:"id"`
ApplicationID Snowflake `json:"application_id"`
GuildID Snowflake `json:"guild_id"`
Permissions []CommandPermission `json:"permissions"`
ID Snowflake `json:"id"`
ApplicationID Snowflake `json:"application_id"`
GuildID Snowflake `json:"guild_id"`
Permissions []*CommandPermission `json:"permissions"`
}

// TODO: add methods to update those
Expand All @@ -184,16 +164,24 @@ type CommandPermission struct {
}

// SetGuildCommandsPermissions holds a slice of SetGuildCommandPermissions
type SetGuildCommandsPermissions []SetGuildCommandPermissions
type SetGuildCommandsPermissions []*SetGuildCommandPermissions

// SetGuildCommandPermissions is used to update CommandPermission ID should be omitted fro bulk update
type SetGuildCommandPermissions struct {
ID Snowflake `json:"id,omitempty"`
Permissions []CommandPermission `json:"permissions"`
ID Snowflake `json:"id,omitempty"`
Permissions []*CommandPermission `json:"permissions"`
}

// 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"`
}

// UpdateCommand is used to update an existing Command. all fields are optional
type UpdateCommand struct {
// 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"`
Expand Down
11 changes: 5 additions & 6 deletions api/disgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"
"time"

"github.com/DisgoOrg/disgo/api/endpoints"
"github.com/DisgoOrg/log"
)

Expand All @@ -16,7 +15,7 @@ type Disgo interface {
Connect() error
Start()
Close()
Token() endpoints.Token
Token() string
Gateway() Gateway
RestClient() RestClient
WebhookServer() WebhookServer
Expand All @@ -36,10 +35,10 @@ type Disgo interface {

GetCommand(commandID Snowflake) (*Command, error)
GetCommands() ([]*Command, error)
CreateCommand(command Command) (*Command, error)
EditCommand(commandID Snowflake, command UpdateCommand) (*Command, error)
DeleteCommand(command Command) (*Command, error)
SetCommands(commands ...Command) ([]*Command, error)
CreateCommand(command *CommandCreate) (*Command, error)
EditCommand(commandID Snowflake, command *CommandUpdate) (*Command, error)
DeleteCommand(commandID Snowflake) error
SetCommands(commands ...*CommandCreate) ([]*Command, error)
}

// EventHandler provides info about the EventHandler
Expand Down
7 changes: 4 additions & 3 deletions api/disgo_builder.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package api

import (
"github.com/DisgoOrg/log"
"net/http"

"github.com/DisgoOrg/disgo/api/endpoints"
"github.com/DisgoOrg/log"
)

// DisgoBuilder allows you to create a Disgo client through a series of methods
type DisgoBuilder interface {
SetLogger(level log.Logger) DisgoBuilder
SetToken(token endpoints.Token) DisgoBuilder
SetToken(token string) DisgoBuilder
SetHTTPClient(httpClient *http.Client) DisgoBuilder
SetIntents(intents Intents) DisgoBuilder
SetRawGatewayEventsEnabled(enabled bool) DisgoBuilder
SetVoiceDispatchInterceptor(voiceDispatchInterceptor VoiceDispatchInterceptor) DisgoBuilder
Expand Down
158 changes: 7 additions & 151 deletions api/embed.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api

import (
"fmt"
"time"
)

Expand Down Expand Up @@ -35,13 +34,6 @@ type Embed struct {
Fields []*EmbedField `json:"fields,omitempty"`
}

// The EmbedFooter of an Embed
type EmbedFooter struct {
Text string `json:"text"`
IconURL *string `json:"icon_url,omitempty"`
ProxyIconURL *string `json:"proxy_icon_url,omitempty"`
}

// The EmbedResource of an Embed.Image/Embed.Thumbnail/Embed.Video
type EmbedResource struct {
URL *string `json:"url,omitempty"`
Expand All @@ -64,152 +56,16 @@ type EmbedAuthor struct {
ProxyIconURL *string `json:"proxy_icon_url,omitempty"`
}

// The EmbedFooter of an Embed
type EmbedFooter struct {
Text string `json:"text"`
IconURL *string `json:"icon_url,omitempty"`
ProxyIconURL *string `json:"proxy_icon_url,omitempty"`
}

// EmbedField (s) of an Embed
type EmbedField struct {
Name string `json:"name"`
Value string `json:"value"`
Inline *bool `json:"inline,omitempty"`
}

// NewEmbedBuilder returns a new embed builder
func NewEmbedBuilder() *EmbedBuilder {
return &EmbedBuilder{}
}

// EmbedBuilder allows you to create embeds and use methods to set values
type EmbedBuilder struct {
Embed
}

// SetTitle sets the title of the EmbedBuilder
func (b *EmbedBuilder) SetTitle(title string) *EmbedBuilder {
b.Title = &title
return b
}

// SetDescription sets the description of the EmbedBuilder
func (b *EmbedBuilder) SetDescription(description string) *EmbedBuilder {
b.Description = &description
return b
}

// SetDescriptionf sets the description of the EmbedBuilder with format
func (b *EmbedBuilder) SetDescriptionf(description string, a ...interface{}) *EmbedBuilder {
descriptionf := fmt.Sprintf(description, a...)
b.Description = &descriptionf
return b
}

// SetEmbedAuthor sets the author of the EmbedBuilder using an EmbedAuthor struct
func (b *EmbedBuilder) SetEmbedAuthor(author *EmbedAuthor) *EmbedBuilder {
b.Author = author
return b
}

// SetAuthor sets the author of the EmbedBuilder without an Icon URL
func (b *EmbedBuilder) SetAuthor(name string, url string) *EmbedBuilder {
b.Author = &EmbedAuthor{
Name: &name,
URL: &url,
}
return b
}

// SetAuthorI sets the author of the EmbedBuilder with all properties
func (b *EmbedBuilder) SetAuthorI(name string, url string, iconURL string) *EmbedBuilder {
b.Author = &EmbedAuthor{
Name: &name,
URL: &url,
IconURL: &iconURL,
}
return b
}

// SetColor sets the color of the EmbedBuilder
func (b *EmbedBuilder) SetColor(color int) *EmbedBuilder {
b.Color = &color
return b
}

// SetFooter sets the footer of the EmbedBuilder
func (b *EmbedBuilder) SetFooter(footer *EmbedFooter) *EmbedBuilder {
b.Footer = footer
return b
}

// SetFooterBy sets the footer of the EmbedBuilder by text and iconURL
func (b *EmbedBuilder) SetFooterBy(text string, iconURL *string) *EmbedBuilder {
b.Footer = &EmbedFooter{
Text: text,
IconURL: iconURL,
}
return b
}

// SetImage sets the image of the EmbedBuilder
func (b *EmbedBuilder) SetImage(i *string) *EmbedBuilder {
b.Image = &EmbedResource{
URL: i,
}
return b
}

// SetThumbnail sets the thumbnail of the EmbedBuilder
func (b *EmbedBuilder) SetThumbnail(i *string) *EmbedBuilder {
b.Thumbnail = &EmbedResource{
URL: i,
}
return b
}

// SetURL sets the URL of the EmbedBuilder
func (b *EmbedBuilder) SetURL(url string) *EmbedBuilder {
b.URL = &url
return b
}

// AddField adds a field to the EmbedBuilder by name and value
func (b *EmbedBuilder) AddField(name string, value string, inline bool) *EmbedBuilder {
b.Fields = append(b.Fields, &EmbedField{name, value, &inline})
return b
}

// SetField sets a field to the EmbedBuilder by name and value
func (b *EmbedBuilder) SetField(index int, name string, value string, inline bool) *EmbedBuilder {
if len(b.Fields) > index {
b.Fields[index] = &EmbedField{name, value, &inline}
}
return b
}

// AddFields adds multiple fields to the EmbedBuilder
func (b *EmbedBuilder) AddFields(f *EmbedField, fs ...*EmbedField) *EmbedBuilder {
b.Fields = append(b.Fields, f)
b.Fields = append(b.Fields, fs...)
return b
}

// SetFields sets fields of the EmbedBuilder
func (b *EmbedBuilder) SetFields(fs ...*EmbedField) *EmbedBuilder {
b.Fields = fs
return b
}

// ClearFields removes all of the fields from the EmbedBuilder
func (b *EmbedBuilder) ClearFields() *EmbedBuilder {
b.Fields = []*EmbedField{}
return b
}

// RemoveField removes a field from the EmbedBuilder
func (b *EmbedBuilder) RemoveField(index int) *EmbedBuilder {
if len(b.Fields) > index {
b.Fields = append(b.Fields[:index], b.Fields[index+1:]...)
}
return b
}

// Build returns your built Embed
func (b *EmbedBuilder) Build() Embed {
return b.Embed
}
Loading

0 comments on commit 490e24c

Please sign in to comment.