diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 8bb6eb38..89635783 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.15 + go-version: 1.16 - name: Build run: go build -v ./... diff --git a/api/application_command.go b/api/slash_command.go similarity index 71% rename from api/application_command.go rename to api/slash_command.go index 71de8cd5..7d556ef1 100644 --- a/api/application_command.go +++ b/api/slash_command.go @@ -1,30 +1,5 @@ package api -import ( - "bytes" - "encoding/json" -) - -// SlashCommands is a slice of SlashCommand -type SlashCommands []SlashCommand - -// MarshalJSON is used for marshalling multiple commands into a []byte -func (commands SlashCommands) MarshalJSON() ([]byte, error) { - buffer := bytes.NewBufferString("[") - for i, command := range commands { - commandBytes, err := json.Marshal(command) - if err != nil { - return nil, err - } - buffer.Write(commandBytes) - if i < len(commands) { - buffer.WriteString(",") - } - } - buffer.WriteString("]") - return buffer.Bytes(), nil -} - // SlashCommand is the base "command" model that belongs to an application. type SlashCommand struct { ID Snowflake `json:"id,omitempty"` diff --git a/go.mod b/go.mod index 7d68722b..72783e3e 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,10 @@ module github.com/DisgoOrg/disgo -go 1.15 +go 1.16 require ( github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.4.2 github.com/sirupsen/logrus v1.8.1 github.com/stretchr/testify v1.7.0 - golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect ) diff --git a/go.sum b/go.sum index 42e8223b..5af0c914 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,6 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/internal/gateway.go b/internal/gateway.go index 3a88c904..4b202655 100644 --- a/internal/gateway.go +++ b/internal/gateway.go @@ -149,6 +149,9 @@ func (g *GatewayImpl) heartbeat() { // Close cleans up the gateway internals func (g *GatewayImpl) Close() { + if g.quit == nil { + return + } log.Info("closing gateway goroutines...") close(g.quit) log.Info("closed gateway goroutines") diff --git a/internal/restclient.go b/internal/restclient.go index d1d2bfdc..d6e763d6 100644 --- a/internal/restclient.go +++ b/internal/restclient.go @@ -352,7 +352,7 @@ func (r RestClientImpl) SetGlobalCommands(applicationID api.Snowflake, commands err = api.ErrTooMuchApplicationCommands return } - return rCommands, r.Request(endpoints.SetGlobalCommands.Compile(applicationID), api.SlashCommands(commands), &rCommands) + return rCommands, r.Request(endpoints.SetGlobalCommands.Compile(applicationID), commands, &rCommands) } // GetGlobalCommand gets you a specific global global command diff --git a/testbot/testbot.go b/testbot/testbot.go index 824b0dce..5a6724ea 100644 --- a/testbot/testbot.go +++ b/testbot/testbot.go @@ -17,8 +17,6 @@ func main() { token := os.Getenv("token") publicKey := os.Getenv("public-key") - log.Print(publicKey) - dgo, err := disgo.NewBuilder(token). SetLogLevel(log.InfoLevel). SetIntents(api.IntentsGuilds|api.IntentsGuildMessages|api.IntentsGuildMembers). @@ -35,7 +33,7 @@ func main() { return } - /*_, err = dgo.RestClient().SetGuildCommands(dgo.ApplicationID(), "817327181659111454", + _, err = dgo.RestClient().SetGuildCommands(dgo.ApplicationID(), "817327181659111454", api.SlashCommand{ Name: "test", Description: "test test test test test test", @@ -91,7 +89,7 @@ func main() { ) if err != nil { log.Errorf("error while registering guild commands: %s", err) - }*/ + } err = dgo.Start() if err != nil {