andersfylling / disgord

Go module for interacting with the documented Discord's bot interface; Gateway, REST requests and voice
BSD 3-Clause "New" or "Revised" License
502 stars 71 forks source link

feat!: new REST update methods with struct param using nullable fields #420

Closed andersfylling closed 2 years ago

andersfylling commented 2 years ago

Description

Introduce a new way to do update calls instead of the builder. Dealing with default values/partial json, pointers are now used for each field allowing disgord to identify if a field was populated or not, regardless of it being a default value.

https://stackoverflow.com/questions/48021945/how-to-handle-patch-request-with-unset-value-in-golang

This is also a bit of an experiment to see what the end result looks like.

example

func NullStr(s string) *string {
  return &s
}
// before
msg, err := client.Channel(23).Message(24642).UpdateBuilder().
    SetContent("hello world").
    SetFlags(disgord.MessageFlagSupressEmbeds).
    Execute()

// after
msg, err := client.Channel(23).Message(24642).Update(&UpdateMessage{
    Content: NullStr("hello world"),
    Flags: &disgord.MessageFlagSupressEmbeds,
})
// before
channel, err := client.Channel(23).UpdateBuilder().
    SetTitle("new channel name").
    Execute()

// after
channel, err := client.Channel(23).Update(&UpdateChannel{
    Title: NullStr("new channel name"),
})

Breaking Change

yes. The previous functionality marked deprecated will be removed.

GetAuditLogs will not have backwards compatibility.

Checklist: