Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
deprecated Update(..) in favour of UpdateBuilder(..) + avoid breaking…
Browse files Browse the repository at this point in the history
… change with deprecate note
  • Loading branch information
andersfylling committed Jan 17, 2021
1 parent 2209632 commit cc60bb8
Show file tree
Hide file tree
Showing 14 changed files with 828 additions and 741 deletions.
5 changes: 4 additions & 1 deletion channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ type ChannelQueryBuilder interface {
// a channel on success, and a 400 BAD REQUEST on invalid parameters. Fires a Channel Update Gateway event. If
// modifying a category, individual Channel Update events will fire for each child channel that also changes.
// For the PATCH method, all the JSON Params are optional.
UpdateBuilder(flags ...Flag) *updateChannelBuilder

// Deprecated: use UpdateBuilder
Update(flags ...Flag) *updateChannelBuilder

// DeleteChannel Delete a channel, or close a private message. Requires the 'MANAGE_CHANNELS' permission for
Expand Down Expand Up @@ -373,7 +376,7 @@ func (c channelQueryBuilder) Get(flags ...Flag) (*Channel, error) {
// Discord documentation https://discord.com/developers/docs/resources/channel#modify-channel
// Reviewed 2018-06-07
// Comment andersfylling: only implemented the patch method, as its parameters are optional.
func (c channelQueryBuilder) Update(flags ...Flag) (builder *updateChannelBuilder) {
func (c channelQueryBuilder) UpdateBuilder(flags ...Flag) (builder *updateChannelBuilder) {
builder = &updateChannelBuilder{}
builder.r.itemFactory = func() interface{} {
return c.client.pool.channel.Get()
Expand Down
54 changes: 54 additions & 0 deletions deprecated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package disgord

// Deprecated: use UpdateBuilder
func (m messageQueryBuilder) Update(flags ...Flag) (builder *updateMessageBuilder) {
return m.UpdateBuilder(flags...)
}

// Deprecated: use UpdateBuilder
func (g guildMemberQueryBuilder) Update(flags ...Flag) UpdateGuildMemberBuilder {
return g.UpdateBuilder(flags...)
}

// Deprecated: use UpdateBuilder
func (g guildQueryBuilder) Update(flags ...Flag) UpdateGuildBuilder { return g.UpdateBuilder(flags...) }

// Deprecated: use UpdateBuilder
func (g guildEmojiQueryBuilder) Update(flags ...Flag) UpdateGuildEmojiBuilder {
return g.UpdateBuilder(flags...)
}

// Deprecated: use UpdateBuilder
func (c channelQueryBuilder) Update(flags ...Flag) (builder *updateChannelBuilder) {
return c.UpdateBuilder(flags...)
}

// Deprecated: use UpdateBuilder
func (guildQueryBuilderNop) Update(flags ...Flag) UpdateGuildBuilder {
return nil
}

// Deprecated: use UpdateBuilder
func (currentUserQueryBuilderNop) Update(_ ...Flag) UpdateCurrentUserBuilder {
return nil
}

// Deprecated: use UpdateBuilder
func (g guildRoleQueryBuilder) Update(flags ...Flag) UpdateGuildRoleBuilder {
return g.UpdateBuilder(flags...)
}

// Deprecated: use UpdateBuilder
func (c currentUserQueryBuilder) Update(flags ...Flag) UpdateCurrentUserBuilder {
return c.UpdateBuilder(flags...)
}

// Deprecated: use UpdateBuilder
func (w webhookQueryBuilder) Update(flags ...Flag) (builder *updateWebhookBuilder) {
return w.UpdateBuilder(flags...)
}

// Deprecated: use UpdateBuilder
func (w webhookWithTokenQueryBuilder) Update(flags ...Flag) (builder *updateWebhookBuilder) {
return w.UpdateBuilder(flags...)
}
7 changes: 5 additions & 2 deletions emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ type GuildEmojiQueryBuilder interface {
WithContext(ctx context.Context) GuildEmojiQueryBuilder

Get(flags ...Flag) (*Emoji, error)
Update(flags ...Flag) UpdateGuildEmojiBuilder
UpdateBuilder(flags ...Flag) UpdateGuildEmojiBuilder
Delete(flags ...Flag) error

// Deprecated: use UpdateBuilder
Update(flags ...Flag) UpdateGuildEmojiBuilder
}

func (g guildQueryBuilder) Emoji(emojiID Snowflake) GuildEmojiQueryBuilder {
Expand Down Expand Up @@ -111,7 +114,7 @@ func (g guildEmojiQueryBuilder) Get(flags ...Flag) (*Emoji, error) {

// UpdateEmoji Modify the given emoji. Requires the 'MANAGE_EMOJIS' permission.
// Returns the updated emoji object on success. Fires a Guild Emojis Update Gateway event.
func (g guildEmojiQueryBuilder) Update(flags ...Flag) UpdateGuildEmojiBuilder {
func (g guildEmojiQueryBuilder) UpdateBuilder(flags ...Flag) UpdateGuildEmojiBuilder {
builder := &updateGuildEmojiBuilder{}
builder.r.itemFactory = func() interface{} {
return &Emoji{}
Expand Down
23 changes: 13 additions & 10 deletions guild.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,8 @@ type GuildQueryBuilderCaller interface {
}

func (m *Member) UpdateNick(ctx context.Context, client GuildQueryBuilderCaller, nickname string, flags ...Flag) error {
return client.
Guild(m.GuildID).
Member(m.UserID).
WithContext(ctx).
Update(flags...).
builder := client.Guild(m.GuildID).Member(m.UserID).WithContext(ctx).UpdateBuilder(flags...)
return builder.
SetNick(nickname).
Execute()
}
Expand Down Expand Up @@ -670,9 +667,12 @@ type GuildQueryBuilder interface {
// TODO: For GetMembers, it might sense to have the option for a function to filter before each member ends up deep copied.
// TODO-2: This could be much more performant in larger guilds where this is needed.
GetMembers(params *GetMembersParams, flags ...Flag) ([]*Member, error)
Update(flags ...Flag) UpdateGuildBuilder
UpdateBuilder(flags ...Flag) UpdateGuildBuilder
Delete(flags ...Flag) error

// Deprecated: Use UpdateBuilder
Update(flags ...Flag) UpdateGuildBuilder

CreateChannel(name string, params *CreateGuildChannelParams, flags ...Flag) (*Channel, error)
UpdateChannelPositions(params []UpdateGuildChannelPositionsParams, flags ...Flag) error
CreateMember(userID Snowflake, accessToken string, params *AddGuildMemberParams, flags ...Flag) (*Member, error)
Expand Down Expand Up @@ -703,7 +703,7 @@ type GuildQueryBuilder interface {
SyncIntegration(integrationID Snowflake, flags ...Flag) error

GetEmbed(flags ...Flag) (*GuildEmbed, error)
UpdateEmbed(flags ...Flag) UpdateGuildEmbedBuilder
UpdateEmbedBuilder(flags ...Flag) UpdateGuildEmbedBuilder
GetVanityURL(flags ...Flag) (*PartialInvite, error)
GetAuditLogs(flags ...Flag) GuildAuditLogsBuilder

Expand Down Expand Up @@ -756,7 +756,7 @@ func (g guildQueryBuilder) Get(flags ...Flag) (guild *Guild, err error) {
}

// Update is used to create a guild update builder.
func (g guildQueryBuilder) Update(flags ...Flag) UpdateGuildBuilder {
func (g guildQueryBuilder) UpdateBuilder(flags ...Flag) UpdateGuildBuilder {
builder := &updateGuildBuilder{}
builder.r.itemFactory = func() interface{} {
return &Guild{}
Expand Down Expand Up @@ -1292,7 +1292,7 @@ func (g guildQueryBuilder) GetEmbed(flags ...Flag) (*GuildEmbed, error) {

// UpdateEmbed Modify a guild embed object for the guild. All attributes may be passed in with JSON and
// modified. Requires the 'MANAGE_GUILD' permission. Returns the updated guild embed object.
func (g guildQueryBuilder) UpdateEmbed(flags ...Flag) UpdateGuildEmbedBuilder {
func (g guildQueryBuilder) UpdateEmbedBuilder(flags ...Flag) UpdateGuildEmbedBuilder {
builder := &updateGuildEmbedBuilder{}
builder.r.itemFactory = func() interface{} {
return &GuildEmbed{}
Expand Down Expand Up @@ -1409,7 +1409,10 @@ func (g guildQueryBuilder) CreateEmoji(params *CreateGuildEmojiParams, flags ...

// KickVoiceParticipant is used to kick someone from voice.
func (g guildQueryBuilder) KickVoiceParticipant(userID Snowflake) error {
return g.Member(userID).WithContext(g.ctx).Update().KickFromVoice().Execute()
builder := g.Member(userID).WithContext(g.ctx).UpdateBuilder()
return builder.
KickFromVoice().
Execute()
}

// GetWebhooks Returns a list of guild webhook objects. Requires the 'MANAGE_WEBHOOKS' permission.
Expand Down
Loading

0 comments on commit cc60bb8

Please sign in to comment.