Skip to content

Commit

Permalink
renamed MessageCreate/UpdateBuilder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Jul 8, 2021
1 parent 49a20ff commit 40ab7ff
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 86 deletions.
13 changes: 3 additions & 10 deletions api/guild.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,9 @@ func (g *Guild) Roles() []*Role {
return g.Disgo.Cache().Roles(g.ID)
}

// SelfMember returns the Member for the current logged in User for this Guild
func (g *Guild) SelfMember() *SelfMember {
return &SelfMember{
Member: g.Disgo.Cache().Member(g.ID, g.Disgo.ClientID()),
}
// SelfMember returns the Member for the current logged-in User for this Guild
func (g *Guild) SelfMember() *Member {
return g.Disgo.Cache().Member(g.ID, g.Disgo.ClientID())
}

// Disconnect sends a api.GatewayCommand to disconnect from this Guild
Expand Down Expand Up @@ -218,11 +216,6 @@ func (g *Guild) DeleteRole(roleID Snowflake) restclient.RestError {
return g.Disgo.RestClient().DeleteRole(g.ID, roleID)
}

// GetSelfMember returns the SelfMember for this Guild
func (g *Guild) GetSelfMember() *SelfMember {
return &SelfMember{Member: g.GetMember(g.Disgo.ClientID())}
}

// Leave leaves the Guild
func (g *Guild) Leave() restclient.RestError {
return g.Disgo.RestClient().LeaveGuild(g.ID)
Expand Down
87 changes: 62 additions & 25 deletions api/message_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func NewMessageCreateBuilder() *MessageCreateBuilder {
}
}

// NewMessageBuilderByMessage returns a new MessageCreateBuilder and takes an existing Message
func NewMessageBuilderByMessage(message *Message) *MessageCreateBuilder {
// NewMessageCreateBuilderByMessage returns a new MessageCreateBuilder and takes an existing Message
func NewMessageCreateBuilderByMessage(message *Message) *MessageCreateBuilder {
msg := MessageCreate{
TTS: message.TTS,
Components: message.Components,
Expand All @@ -66,8 +66,7 @@ func (b *MessageCreateBuilder) SetContent(content string) *MessageCreateBuilder

// SetContentf sets content of the Message
func (b *MessageCreateBuilder) SetContentf(content string, a ...interface{}) *MessageCreateBuilder {
b.Content = fmt.Sprintf(content, a...)
return b
return b.SetContent(fmt.Sprintf(content, a...))
}

// ClearContent removes content of the Message
Expand All @@ -81,12 +80,20 @@ func (b *MessageCreateBuilder) SetTTS(tts bool) *MessageCreateBuilder {
return b
}

// SetEmbeds sets the embeds of the Message
// SetEmbeds sets the Embed(s) of the Message
func (b *MessageCreateBuilder) SetEmbeds(embeds ...Embed) *MessageCreateBuilder {
b.Embeds = embeds
return b
}

// SetEmbed sets the provided Embed at the index of the Message
func (b *MessageCreateBuilder) SetEmbed(i int, embed Embed) *MessageCreateBuilder {
if len(b.Embeds) > i {
b.Embeds[i] = embed
}
return b
}

// AddEmbeds adds multiple embeds to the Message
func (b *MessageCreateBuilder) AddEmbeds(embeds ...Embed) *MessageCreateBuilder {
b.Embeds = append(b.Embeds, embeds...)
Expand All @@ -100,52 +107,74 @@ func (b *MessageCreateBuilder) ClearEmbeds() *MessageCreateBuilder {
}

// RemoveEmbed removes an embed from the Message
func (b *MessageCreateBuilder) RemoveEmbed(index int) *MessageCreateBuilder {
if b != nil && len(b.Embeds) > index {
b.Embeds = append(b.Embeds[:index], b.Embeds[index+1:]...)
func (b *MessageCreateBuilder) RemoveEmbed(i int) *MessageCreateBuilder {
if len(b.Embeds) > i {
b.Embeds = append(b.Embeds[:i], b.Embeds[i+1:]...)
}
return b
}

// SetComponents sets the Component(s) of the Message
func (b *MessageCreateBuilder) SetComponents(components ...Component) *MessageCreateBuilder {
b.Components = components
// SetActionRows sets the ActionRow(s) of the Message
func (b *MessageCreateBuilder) SetActionRows(actionRows ...ActionRow) *MessageCreateBuilder {
b.Components = actionRowsToComponents(actionRows)
return b
}

// AddComponents adds the Component(s) to the Message
func (b *MessageCreateBuilder) AddComponents(components ...Component) *MessageCreateBuilder {
b.Components = append(b.Components, components...)
// SetActionRow sets the provided ActionRow at the index of Component(s)
func (b *MessageCreateBuilder) SetActionRow(i int, actionRow ActionRow) *MessageCreateBuilder {
if len(b.Components) > i {
b.Components[i] = actionRow
}
return b
}

// ClearComponents removes all of the Component(s) of the Message
func (b *MessageCreateBuilder) ClearComponents() *MessageCreateBuilder {
b.Components = []Component{}
// AddActionRow adds a new ActionRow with the provided Component(s) to the Message
func (b *MessageCreateBuilder) AddActionRow(components ...Component) *MessageCreateBuilder {
b.Components = append(b.Components, NewActionRow(components...))
return b
}

// RemoveComponent removes a Component from the Message
func (b *MessageCreateBuilder) RemoveComponent(i int) *MessageCreateBuilder {
if b != nil && len(b.Components) > i {
// AddActionRows adds the ActionRow(s) to the Message
func (b *MessageCreateBuilder) AddActionRows(actionRows ...ActionRow) *MessageCreateBuilder {
b.Components = append(b.Components, actionRowsToComponents(actionRows)...)
return b
}

// RemoveActionRow removes a ActionRow from the Message
func (b *MessageCreateBuilder) RemoveActionRow(i int) *MessageCreateBuilder {
if len(b.Components) > i {
b.Components = append(b.Components[:i], b.Components[i+1:]...)
}
return b
}

// SetFiles sets the files for this WebhookMessageCreate
// ClearActionRows removes all of the ActionRow(s) of the Message
func (b *MessageCreateBuilder) ClearActionRows() *MessageCreateBuilder {
b.Components = []Component{}
return b
}

// SetFiles sets the restclient.File(s) for this MessageCreate
func (b *MessageCreateBuilder) SetFiles(files ...restclient.File) *MessageCreateBuilder {
b.Files = files
return b
}

// AddFiles adds the files to the WebhookMessageCreate
// SetFile sets the restclient.File at the index for this MessageCreate
func (b *MessageCreateBuilder) SetFile(i int, file restclient.File) *MessageCreateBuilder {
if len(b.Files) > i {
b.Files[i] = file
}
return b
}

// AddFiles adds the restclient.File(s) to the MessageCreate
func (b *MessageCreateBuilder) AddFiles(files ...restclient.File) *MessageCreateBuilder {
b.Files = append(b.Files, files...)
return b
}

// AddFile adds a file to the WebhookMessageCreate
// AddFile adds a restclient.File to the MessageCreate
func (b *MessageCreateBuilder) AddFile(name string, reader io.Reader, flags ...restclient.FileFlags) *MessageCreateBuilder {
b.Files = append(b.Files, restclient.File{
Name: name,
Expand All @@ -155,15 +184,15 @@ func (b *MessageCreateBuilder) AddFile(name string, reader io.Reader, flags ...r
return b
}

// ClearFiles removes all files of this WebhookMessageCreate
// ClearFiles removes all files of this MessageCreate
func (b *MessageCreateBuilder) ClearFiles() *MessageCreateBuilder {
b.Files = []restclient.File{}
return b
}

// RemoveFiles removes the file at this index
func (b *MessageCreateBuilder) RemoveFiles(i int) *MessageCreateBuilder {
if b != nil && len(b.Files) > i {
if len(b.Files) > i {
b.Files = append(b.Files[:i], b.Files[i+1:]...)
}
return b
Expand Down Expand Up @@ -232,3 +261,11 @@ func (b *MessageCreateBuilder) SetEphemeral(ephemeral bool) *MessageCreateBuilde
func (b *MessageCreateBuilder) Build() MessageCreate {
return b.MessageCreate
}

func actionRowsToComponents(actionRows []ActionRow) []Component {
components := make([]Component, len(actionRows))
for i := range actionRows {
components[i] = components[i]
}
return components
}
76 changes: 53 additions & 23 deletions api/message_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,20 @@ func (b *MessageUpdateBuilder) ClearContent() *MessageUpdateBuilder {
return b.SetContent("")
}

// SetEmbeds sets the embeds of the Message
// SetEmbeds sets the Embed(s) of the Message
func (b *MessageUpdateBuilder) SetEmbeds(embeds ...Embed) *MessageUpdateBuilder {
b.Embeds = embeds
return b
}

// SetEmbed sets the provided Embed at the index of the Message
func (b *MessageUpdateBuilder) SetEmbed(i int, embed Embed) *MessageUpdateBuilder {
if len(b.Embeds) > i {
b.Embeds[i] = embed
}
return b
}

// AddEmbeds adds multiple embeds to the Message
func (b *MessageUpdateBuilder) AddEmbeds(embeds ...Embed) *MessageUpdateBuilder {
b.Embeds = append(b.Embeds, embeds...)
Expand All @@ -75,52 +83,74 @@ func (b *MessageUpdateBuilder) ClearEmbeds() *MessageUpdateBuilder {
}

// RemoveEmbed removes an embed from the Message
func (b *MessageUpdateBuilder) RemoveEmbed(index int) *MessageUpdateBuilder {
if b != nil && len(b.Embeds) > index {
b.Embeds = append(b.Embeds[:index], b.Embeds[index+1:]...)
func (b *MessageUpdateBuilder) RemoveEmbed(i int) *MessageUpdateBuilder {
if len(b.Embeds) > i {
b.Embeds = append(b.Embeds[:i], b.Embeds[i+1:]...)
}
return b
}

// SetComponents sets the Component(s) of the Message
func (b *MessageUpdateBuilder) SetComponents(components ...Component) *MessageUpdateBuilder {
b.Components = components
// SetActionRows sets the ActionRow(s) of the Message
func (b *MessageUpdateBuilder) SetActionRows(actionRows ...ActionRow) *MessageUpdateBuilder {
b.Components = actionRowsToComponents(actionRows)
return b
}

// SetActionRow sets the provided ActionRow at the index of Component(s)
func (b *MessageUpdateBuilder) SetActionRow(i int, actionRow ActionRow) *MessageUpdateBuilder {
if len(b.Components) > i {
b.Components[i] = actionRow
}
return b
}

// AddComponents adds the Component(s) to the Message
func (b *MessageUpdateBuilder) AddComponents(components ...Component) *MessageUpdateBuilder {
b.Components = append(b.Components, components...)
// AddActionRow adds a new ActionRow with the provided Component(s) to the Message
func (b *MessageUpdateBuilder) AddActionRow(components ...Component) *MessageUpdateBuilder {
b.Components = append(b.Components, NewActionRow(components...))
return b
}

// ClearComponents removes all of the Component(s) of the Message
func (b *MessageUpdateBuilder) ClearComponents() *MessageUpdateBuilder {
b.Components = []Component{}
// AddActionRows adds the ActionRow(s) to the Message
func (b *MessageUpdateBuilder) AddActionRows(actionRows ...ActionRow) *MessageUpdateBuilder {
b.Components = append(b.Components, actionRowsToComponents(actionRows)...)
return b
}

// RemoveComponent removes a Component from the Message
func (b *MessageUpdateBuilder) RemoveComponent(i int) *MessageUpdateBuilder {
// RemoveActionRow removes a ActionRow from the Message
func (b *MessageUpdateBuilder) RemoveActionRow(i int) *MessageUpdateBuilder {
if len(b.Components) > i {
b.Components = append(b.Components[:i], b.Components[i+1:]...)
}
return b
}

// SetFiles sets the files for this Message
// ClearActionRows removes all of the ActionRow(s) of the Message
func (b *MessageUpdateBuilder) ClearActionRows() *MessageUpdateBuilder {
b.Components = []Component{}
return b
}

// SetFiles sets the restclient.File(s) for this MessageCreate
func (b *MessageUpdateBuilder) SetFiles(files ...restclient.File) *MessageUpdateBuilder {
b.Files = files
return b
}

// AddFiles adds the files to the Message
// SetFile sets the restclient.File at the index for this MessageCreate
func (b *MessageUpdateBuilder) SetFile(i int, file restclient.File) *MessageUpdateBuilder {
if len(b.Files) > i {
b.Files[i] = file
}
return b
}

// AddFiles adds the restclient.File(s) to the MessageCreate
func (b *MessageUpdateBuilder) AddFiles(files ...restclient.File) *MessageUpdateBuilder {
b.Files = append(b.Files, files...)
return b
}

// AddFile adds a file to the Message
// AddFile adds a restclient.File to the MessageCreate
func (b *MessageUpdateBuilder) AddFile(name string, reader io.Reader, flags ...restclient.FileFlags) *MessageUpdateBuilder {
b.Files = append(b.Files, restclient.File{
Name: name,
Expand All @@ -130,7 +160,7 @@ func (b *MessageUpdateBuilder) AddFile(name string, reader io.Reader, flags ...r
return b
}

// ClearFiles removes all files of this Message
// ClearFiles removes all files of this MessageCreate
func (b *MessageUpdateBuilder) ClearFiles() *MessageUpdateBuilder {
b.Files = []restclient.File{}
return b
Expand Down Expand Up @@ -168,12 +198,12 @@ func (b *MessageUpdateBuilder) SetAllowedMentions(allowedMentions *AllowedMentio

// ClearAllowedMentions clears the allowed mentions of the Message
func (b *MessageUpdateBuilder) ClearAllowedMentions() *MessageUpdateBuilder {
return b.SetAllowedMentions(&AllowedMentions{})
return b.SetAllowedMentions(nil)
}

// SetFlags sets the MessageFlags of the Message
func (b *MessageUpdateBuilder) SetFlags(flags ...MessageFlags) *MessageUpdateBuilder {
*b.Flags = MessageFlagNone.Add(flags...)
// SetFlags sets the message flags of the Message
func (b *MessageUpdateBuilder) SetFlags(flags MessageFlags) *MessageUpdateBuilder {
*b.Flags = flags
return b
}

Expand Down
6 changes: 0 additions & 6 deletions api/self_member.go

This file was deleted.

6 changes: 6 additions & 0 deletions api/self_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ var ErrDMChannelToYourself = restclient.NewError(nil, errors.New("can't open a d
// SelfUser represents the current logged in User
type SelfUser struct {
*User
MfaEnabled *bool `json:"mfa_enabled"`
Locale *string `json:"locale"`
Verified *bool `json:"verified"`
Email *string `json:"email"`
Flags *int `json:"flags"`
PremiumType *int `json:"premium_type"`
}

// Update updates the SelfUser with the given payload
Expand Down
Loading

0 comments on commit 40ab7ff

Please sign in to comment.