Skip to content

Commit

Permalink
Merge pull request #21 from DisgoOrg/development
Browse files Browse the repository at this point in the history
fixed npe on buttons without emote
  • Loading branch information
topi314 authored May 30, 2021
2 parents a295955 + a8ed37f commit 368a96f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
24 changes: 24 additions & 0 deletions api/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package api

import (
"runtime/debug"
"strings"
)

// Github is the disgo github url
const Github = "https://github.com/DisgoOrg/disgo"

// Version returns the current used disgo version in the format vx.x.x
var Version = getVersion()

func getVersion() string {
bi, ok := debug.ReadBuildInfo()
if ok {
for _, dep := range bi.Deps {
if strings.Contains(Github, dep.Path) {
return dep.Version
}
}
}
return "unknown"
}
4 changes: 2 additions & 2 deletions api/interaction_followup.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ func (b *FollowupMessageBuilder) SetFlags(flags MessageFlags) *FollowupMessageBu
// SetEphemeral adds/removes MessageFlagEphemeral to the message flags
func (b *FollowupMessageBuilder) SetEphemeral(ephemeral bool) *FollowupMessageBuilder {
if ephemeral {
b.Flags &= MessageFlagEphemeral
b.Flags = b.Flags.Add(MessageFlagEphemeral)
} else {
b.Flags |= MessageFlagEphemeral
b.Flags = b.Flags.Remove(MessageFlagEphemeral)
}
return b
}
Expand Down
4 changes: 2 additions & 2 deletions api/interaction_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ func (b *InteractionResponseBuilder) SetFlags(flags MessageFlags) *InteractionRe
// SetEphemeral adds/removes MessageFlagEphemeral to the message flags
func (b *InteractionResponseBuilder) SetEphemeral(ephemeral bool) *InteractionResponseBuilder {
if ephemeral {
b.Data.Flags &= MessageFlagEphemeral
b.Data.Flags = b.Data.Flags.Add(MessageFlagEphemeral)

} else {
b.Data.Flags |= MessageFlagEphemeral
b.Data.Flags = b.Data.Flags.Remove(MessageFlagEphemeral)
}
return b
}
Expand Down
3 changes: 3 additions & 0 deletions api/restclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ var (
ErrTooMuchCommands = errors.New("you can provide a max of 100 application commands")
)

// UserAgent is the global useragent disgo uses for all its requests
var UserAgent = "DiscordBot (" + Github + ", " + Version + ")"

// ErrorResponse contains custom errors from discord
type ErrorResponse struct {
Code int
Expand Down
3 changes: 2 additions & 1 deletion example/examplebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ var client = http.DefaultClient

func main() {
logger.SetLevel(logrus.DebugLevel)
logger.Info("starting TestBot...")
logger.Info("starting ExampleBot...")
logger.Infof("disgo %s", api.Version)

dgo, err := disgo.NewBuilder(os.Getenv("token")).
SetLogger(logger).
Expand Down
7 changes: 5 additions & 2 deletions internal/entity_builder_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,20 @@ func (b *EntityBuilderImpl) createComponent(unmarshalComponent *api.UnmarshalCom
}

case api.ComponentTypeButton:
return &api.Button{
button := &api.Button{
ComponentImpl: api.ComponentImpl{
ComponentType: api.ComponentTypeButton,
},
Style: unmarshalComponent.Style,
Label: unmarshalComponent.Label,
Emote: b.CreateEmote("", unmarshalComponent.Emote, updateCache),
CustomID: unmarshalComponent.CustomID,
URL: unmarshalComponent.URL,
Disabled: unmarshalComponent.Disabled,
}
if unmarshalComponent.Emote != nil {
button.Emote = b.CreateEmote("", unmarshalComponent.Emote, updateCache)
}
return button

default:
b.Disgo().Logger().Errorf("unexpected component type %d received", unmarshalComponent.ComponentType)
Expand Down
3 changes: 2 additions & 1 deletion internal/restclient_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"github.com/DisgoOrg/restclient"
)


func newRestClientImpl(disgo api.Disgo, httpClient *http.Client) api.RestClient {
if httpClient == nil {
httpClient = http.DefaultClient
}
return &RestClientImpl{
RestClient: restclient.NewRestClient(httpClient, disgo.Logger(), "DiscordBot (https://github.com/disgoorg/disgo, 0.0.1)", http.Header{"Authorization": []string{"Bot " + disgo.Token()}}),
RestClient: restclient.NewRestClient(httpClient, disgo.Logger(), api.UserAgent, http.Header{"Authorization": []string{"Bot " + disgo.Token()}}),
disgo: disgo,
}
}
Expand Down

0 comments on commit 368a96f

Please sign in to comment.