Skip to content

Commit

Permalink
Merge branch 'master' into patch/update-connections
Browse files Browse the repository at this point in the history
  • Loading branch information
sebm253 committed May 14, 2024
2 parents 5d8a6f2 + 1d47f18 commit 42131de
Show file tree
Hide file tree
Showing 167 changed files with 3,344 additions and 1,156 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
name: Go

on: [ push ]
on:
push:
pull_request_target:

jobs:
gobuild:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.21
- uses: actions/checkout@v3
- name: go build
run: go build -v ./...
Expand All @@ -18,7 +20,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.21
- uses: actions/checkout@v3
- name: go build
run: go test -v ./...
Expand All @@ -28,7 +30,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.21
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ A full Ping Pong example can also be found [here](https://github.com/disgoorg/di

### Logging

DisGo uses our own small [logging interface](https://github.com/disgoorg/log) which you can use with most other logging libraries. This lib also comes with a default logger which is based on the standard log package.
DisGo uses [slog](https://pkg.go.dev/log/slog) for logging.

## Documentation

Expand Down Expand Up @@ -156,10 +156,6 @@ Being used in production by FredBoat, Dyno, LewdBot, and more.

Is a [Lavalink-Client](https://github.com/freyacodes/Lavalink) which can be used to communicate with Lavalink to play/search tracks

### [DisLog](https://github.com/disgoorg/dislog)

Is a Discord webhook logger hook for [logrus](https://github.com/sirupsen/logrus)

## Other Golang Discord Libraries

* [discordgo](https://github.com/bwmarrin/discordgo)
Expand Down
20 changes: 9 additions & 11 deletions _examples/application_commands/gateway/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package main

import (
"context"
"log/slog"
"os"
"os/signal"
"syscall"

"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"

"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/snowflake/v2"
)

var (
Expand Down Expand Up @@ -40,30 +39,29 @@ var (
)

func main() {
log.SetLevel(log.LevelInfo)
log.Info("starting example...")
log.Info("disgo version: ", disgo.Version)
slog.Info("starting example...")
slog.Info("disgo version", slog.String("version", disgo.Version))

client, err := disgo.New(token,
bot.WithDefaultGateway(),
bot.WithEventListenerFunc(commandListener),
)
if err != nil {
log.Fatal("error while building disgo instance: ", err)
slog.Error("error while building disgo instance", slog.Any("err", err))
return
}

defer client.Close(context.TODO())

if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), guildID, commands); err != nil {
log.Fatal("error while registering commands: ", err)
slog.Error("error while registering commands", slog.Any("err", err))
}

if err = client.OpenGateway(context.TODO()); err != nil {
log.Fatal("error while connecting to gateway: ", err)
slog.Error("error while connecting to gateway", slog.Any("err", err))
}

log.Infof("example is now running. Press CTRL-C to exit.")
slog.Info("example is now running. Press CTRL-C to exit.")
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-s
Expand All @@ -78,7 +76,7 @@ func commandListener(event *events.ApplicationCommandInteractionCreate) {
Build(),
)
if err != nil {
event.Client().Logger().Error("error on sending response: ", err)
slog.Error("error on sending response", slog.Any("err", err))
}
}
}
23 changes: 10 additions & 13 deletions _examples/application_commands/http/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ package main

import (
"context"
"log/slog"
"os"
"os/signal"
"syscall"

"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"
"github.com/oasisprotocol/curve25519-voi/primitives/ed25519"

"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/disgo/httpserver"
"github.com/disgoorg/snowflake/v2"
"github.com/oasisprotocol/curve25519-voi/primitives/ed25519"
)

var (
Expand Down Expand Up @@ -43,9 +42,8 @@ var (
)

func main() {
log.SetLevel(log.LevelDebug)
log.Info("starting example...")
log.Info("disgo version: ", disgo.Version)
slog.Info("starting example...")
slog.Info("disgo version", slog.String("version", disgo.Version))

// use custom ed25519 verify implementation
httpserver.Verify = func(publicKey httpserver.PublicKey, message, sig []byte) bool {
Expand All @@ -60,21 +58,20 @@ func main() {
bot.WithEventListenerFunc(commandListener),
)
if err != nil {
log.Fatal("error while building disgo instance: ", err)
return
panic("error while building disgo instance: " + err.Error())
}

defer client.Close(context.TODO())

if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), guildID, commands); err != nil {
log.Fatal("error while registering commands: ", err)
panic("error while registering commands: " + err.Error())
}

if err = client.OpenHTTPServer(); err != nil {
log.Fatal("error while starting http server: ", err)
panic("error while starting http server: " + err.Error())
}

log.Info("example is now running. Press CTRL-C to exit.")
slog.Info("example is now running. Press CTRL-C to exit.")
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-s
Expand All @@ -88,7 +85,7 @@ func commandListener(event *events.ApplicationCommandInteractionCreate) {
SetEphemeral(data.Bool("ephemeral")).
Build(),
); err != nil {
event.Client().Logger().Error("error on sending response: ", err)
event.Client().Logger().Error("error on sending response", slog.Any("err", err))
}
}
}
14 changes: 7 additions & 7 deletions _examples/application_commands/http/go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module github.com/disgoorg/disgo/_examples/application_commands/http

go 1.18
go 1.21

replace github.com/disgoorg/disgo => ../../../

require (
github.com/disgoorg/disgo v0.16.8
github.com/disgoorg/log v1.2.1
github.com/disgoorg/snowflake/v2 v2.0.1
github.com/oasisprotocol/curve25519-voi v0.0.0-20230110094441-db37f07504ce
)

require (
github.com/disgoorg/json v1.1.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b // indirect
golang.org/x/sys v0.11.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/sys v0.16.0 // indirect
)
19 changes: 12 additions & 7 deletions _examples/application_commands/http/go.sum
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/disgoorg/disgo v0.16.8 h1:tvUeX+3Iu8U6koDc8RAgcQadRciWJwsI95Y7edHqq2g=
github.com/disgoorg/disgo v0.16.8/go.mod h1:5fsaUpfu6Yv0p+PfmsAeQkV395KQskVu/d1bdq8vsNI=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys=
github.com/disgoorg/json v1.1.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA=
github.com/disgoorg/log v1.2.1 h1:kZYAWkUBcGy4LbZcgYtgYu49xNVLy+xG5Uq3yz5VVQs=
github.com/disgoorg/log v1.2.1/go.mod h1:hhQWYTFTnIGzAuFPZyXJEi11IBm9wq+/TVZt/FEwX0o=
github.com/disgoorg/snowflake/v2 v2.0.1 h1:CuUxGLwggUxEswZOmZ+mZ5i0xSumQdXW9tXW7uGqe+0=
github.com/disgoorg/snowflake/v2 v2.0.1/go.mod h1:SPU9c2CNn5DSyb86QcKtdZgix9osEtKrHLW4rMhfLCs=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/oasisprotocol/curve25519-voi v0.0.0-20230110094441-db37f07504ce h1:/pEpMk55wH0X+E5zedGEMOdLuWmV8P4+4W3+LZaM6kg=
github.com/oasisprotocol/curve25519-voi v0.0.0-20230110094441-db37f07504ce/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b h1:qYTY2tN72LhgDj2rtWG+LI6TXFl2ygFQQ4YezfVaGQE=
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI=
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
21 changes: 9 additions & 12 deletions _examples/application_commands/localization/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package main

import (
"context"
"log/slog"
"os"
"os/signal"
"syscall"

"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"

"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/snowflake/v2"
)

var (
Expand Down Expand Up @@ -64,30 +63,28 @@ var (
)

func main() {
log.SetLevel(log.LevelTrace)
log.Info("starting example...")
log.Infof("disgo version: %s", disgo.Version)
slog.Info("starting example...")
slog.Info("disgo version", slog.String("version", disgo.Version))

client, err := disgo.New(token,
bot.WithDefaultGateway(),
bot.WithEventListenerFunc(commandListener),
)
if err != nil {
log.Fatal("error while building disgo instance: ", err)
return
panic("error while building disgo instance: " + err.Error())
}

defer client.Close(context.TODO())

if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), guildID, commands); err != nil {
log.Fatal("error while registering commands: ", err)
panic("error while registering commands: " + err.Error())
}

if err = client.OpenGateway(context.TODO()); err != nil {
log.Fatal("error while connecting to gateway: ", err)
panic("error while connecting to gateway: " + err.Error())
}

log.Infof("example is now running. Press CTRL-C to exit.")
slog.Info("example is now running. Press CTRL-C to exit.")
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-s
Expand All @@ -102,7 +99,7 @@ func commandListener(event *events.ApplicationCommandInteractionCreate) {
Build(),
)
if err != nil {
event.Client().Logger().Error("error on sending response: ", err)
event.Client().Logger().Error("error on sending response", slog.Any("err", err))
}
}
}

0 comments on commit 42131de

Please sign in to comment.