From 13c58b61ac6eb69055b0ef1fcd4d294a523f3d04 Mon Sep 17 00:00:00 2001 From: topi314 Date: Wed, 3 Sep 2025 22:54:50 +0200 Subject: [PATCH 1/2] update dependencies and Docker configurations to latest versions --- .github/workflows/docker.yml | 12 +++++----- .github/workflows/test.yml | 8 +++---- Dockerfile | 4 ++-- bottemplate/bot.go | 18 +++++---------- bottemplate/commands/version.go | 2 +- bottemplate/components/test_component.go | 4 ++-- go.mod | 14 ++++++------ go.sum | 28 ++++++++++++------------ main.go | 14 +++++++++--- 9 files changed, 53 insertions(+), 51 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 5c2b085..b97fad3 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -7,13 +7,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v5 with: fetch-depth: 0 - name: Docker meta id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository }} tags: | @@ -23,20 +23,20 @@ jobs: type=sha,prefix= - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v6 with: context: . platforms: linux/amd64,linux/arm/v7,linux/arm64/v8 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6099728..7b95133 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,23 +7,23 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Set up Go uses: actions/setup-go@v5 with: - go-version: 1.22.x + go-version: 1.25.x - name: Test run: go test -v ./... lint: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Set up Go uses: actions/setup-go@v5 with: go-version: 1.22.x - name: Lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v8 with: version: latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index c002480..7c6d2b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM golang:1.22-alpine AS build +FROM --platform=$BUILDPLATFORM golang:1.25-alpine AS build WORKDIR /build @@ -18,7 +18,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \ CGO_ENABLED=0 \ GOOS=$TARGETOS \ GOARCH=$TARGETARCH \ - go build -ldflags="-X 'main.Version=${VERSION}' -X 'main.Commit=${COMMIT}'" -o bot github.com/disgoorg/bot-template + go build -o bot github.com/disgoorg/bot-template FROM alpine diff --git a/bottemplate/bot.go b/bottemplate/bot.go index 3dea807..704cc0d 100644 --- a/bottemplate/bot.go +++ b/bottemplate/bot.go @@ -11,31 +11,25 @@ import ( "github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/events" "github.com/disgoorg/disgo/gateway" - "github.com/disgoorg/paginator" ) -func New(cfg Config, version string, commit string) *Bot { +func New(cfg Config, version string) *Bot { return &Bot{ - Cfg: cfg, - Paginator: paginator.New(), - Version: version, - Commit: commit, + Cfg: cfg, + Version: version, } } type Bot struct { - Cfg Config - Client bot.Client - Paginator *paginator.Manager - Version string - Commit string + Cfg Config + Client *bot.Client + Version string } func (b *Bot) SetupBot(listeners ...bot.EventListener) error { client, err := disgo.New(b.Cfg.Bot.Token, bot.WithGatewayConfigOpts(gateway.WithIntents(gateway.IntentGuilds, gateway.IntentGuildMessages, gateway.IntentMessageContent)), bot.WithCacheConfigOpts(cache.WithCaches(cache.FlagGuilds)), - bot.WithEventListeners(b.Paginator), bot.WithEventListeners(listeners...), ) if err != nil { diff --git a/bottemplate/commands/version.go b/bottemplate/commands/version.go index d2290a9..4791006 100644 --- a/bottemplate/commands/version.go +++ b/bottemplate/commands/version.go @@ -17,7 +17,7 @@ var version = discord.SlashCommandCreate{ func VersionHandler(b *bottemplate.Bot) handler.CommandHandler { return func(e *handler.CommandEvent) error { return e.CreateMessage(discord.MessageCreate{ - Content: fmt.Sprintf("Version: %s\nCommit: %s", b.Version, b.Commit), + Content: fmt.Sprintf("Version: %s", b.Version), }) } } diff --git a/bottemplate/components/test_component.go b/bottemplate/components/test_component.go index a5b82e6..c254e8e 100644 --- a/bottemplate/components/test_component.go +++ b/bottemplate/components/test_component.go @@ -3,11 +3,11 @@ package components import ( "github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/handler" - "github.com/disgoorg/json" + "github.com/disgoorg/omit" ) func TestComponent(e *handler.ComponentEvent) error { return e.UpdateMessage(discord.MessageUpdate{ - Content: json.Ptr("This is a test button update"), + Content: omit.Ptr("This is a test button update"), }) } diff --git a/go.mod b/go.mod index 8f3df35..7bfa5f3 100644 --- a/go.mod +++ b/go.mod @@ -1,18 +1,18 @@ module github.com/disgoorg/bot-template -go 1.22 +go 1.25 require ( - github.com/disgoorg/disgo v0.18.14 - github.com/disgoorg/json v1.2.0 - github.com/disgoorg/paginator v0.0.0-20240725182907-1bdf780b5586 + github.com/disgoorg/disgo v0.19.0-rc.2.0.20250826065848-3cb3c74a5b19 + github.com/disgoorg/omit v1.0.0 github.com/disgoorg/snowflake/v2 v2.0.3 - github.com/pelletier/go-toml/v2 v2.2.3 + github.com/pelletier/go-toml/v2 v2.2.4 ) require ( + github.com/disgoorg/json/v2 v2.0.0 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad // indirect - golang.org/x/crypto v0.31.0 // indirect - golang.org/x/sys v0.28.0 // indirect + golang.org/x/crypto v0.41.0 // indirect + golang.org/x/sys v0.35.0 // indirect ) diff --git a/go.sum b/go.sum index c3877a7..f37cada 100644 --- a/go.sum +++ b/go.sum @@ -1,26 +1,26 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/disgoorg/disgo v0.18.14 h1:ipalZjUGeCYjL/Qa7djlGZU5Dk0TicECZPSeNW774Q8= -github.com/disgoorg/disgo v0.18.14/go.mod h1:wZ/ZW6x43QivIVrYrJxwSeFbIbrMqpi5vAU1ovsod8o= -github.com/disgoorg/json v1.2.0 h1:6e/j4BCfSHIvucG1cd7tJPAOp1RgnnMFSqkvZUtEd1Y= -github.com/disgoorg/json v1.2.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA= -github.com/disgoorg/paginator v0.0.0-20240725182907-1bdf780b5586 h1:GcdAmaZYq/iHmeV8iSPEeN1JHB3dgfq6EcujSsHfZFg= -github.com/disgoorg/paginator v0.0.0-20240725182907-1bdf780b5586/go.mod h1:6dmOx00CV/GNYip5FZbe9k2mw39trmpdY6meXdCrfrw= +github.com/disgoorg/disgo v0.19.0-rc.2.0.20250826065848-3cb3c74a5b19 h1:ut4zctXidHQV8icU7vjeDidxT9eTXsPh9ihG5VOsYRY= +github.com/disgoorg/disgo v0.19.0-rc.2.0.20250826065848-3cb3c74a5b19/go.mod h1:Gc5o9M0pNcdPd4YhQszhdKMRJwmVVIv3IVlHsvtAwpQ= +github.com/disgoorg/json/v2 v2.0.0 h1:U16yy/ARK7/aEpzjjqK1b/KaqqGHozUdeVw/DViEzQI= +github.com/disgoorg/json/v2 v2.0.0/go.mod h1:jZTBC0nIE1WeetSEI3/Dka8g+qglb4FPVmp5I5HpEfI= +github.com/disgoorg/omit v1.0.0 h1:y0LkVUOyUHT8ZlnhIAeOZEA22UYykeysK8bLJ0SfT78= +github.com/disgoorg/omit v1.0.0/go.mod h1:RTmSARkf6PWT/UckwI0bV8XgWkWQoPppaT01rYKLcFQ= github.com/disgoorg/snowflake/v2 v2.0.3 h1:3B+PpFjr7j4ad7oeJu4RlQ+nYOTadsKapJIzgvSI2Ro= github.com/disgoorg/snowflake/v2 v2.0.3/go.mod h1:W6r7NUA7DwfZLwr00km6G4UnZ0zcoLBRufhkFWgAc4c= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= -github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= +github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= +github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= 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-20240107134140-fcbab37b09ad h1:qIQkSlF5vAUHxEmTbaqt1hkJ/t6skqEGYiMag343ucI= github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= -golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4= +golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc= +golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= +golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index 97e91f4..9c3d0b4 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "log/slog" "os" "os/signal" + "runtime/debug" "syscall" "time" @@ -20,9 +21,16 @@ import ( var ( Version = "dev" - Commit = "unknown" ) +func init() { + bi, ok := debug.ReadBuildInfo() + if !ok { + return + } + Version = bi.Main.Version +} + func main() { shouldSyncCommands := flag.Bool("sync-commands", false, "Whether to sync commands to discord") path := flag.String("config", "config.toml", "path to config") @@ -35,10 +43,10 @@ func main() { } setupLogger(cfg.Log) - slog.Info("Starting bot-template...", slog.String("version", Version), slog.String("commit", Commit)) + slog.Info("Starting bot-template...", slog.String("version", Version)) slog.Info("Syncing commands", slog.Bool("sync", *shouldSyncCommands)) - b := bottemplate.New(*cfg, Version, Commit) + b := bottemplate.New(*cfg, Version) h := handler.New() h.Command("/test", commands.TestHandler) From ae05f24258ee6f80350aa343a77728096b61d172 Mon Sep 17 00:00:00 2001 From: topi314 Date: Wed, 3 Sep 2025 22:58:36 +0200 Subject: [PATCH 2/2] migrate golangci-lint config --- .golangci.toml | 51 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/.golangci.toml b/.golangci.toml index c5cf3e3..c3b190c 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -1,14 +1,41 @@ +version = '2' + [linters] -disable-all = true +default = 'none' enable = [ - "gosimple", - "govet", - "gofmt", - "ineffassign", - "staticcheck", - "sloglint", - "whitespace", - "errname", - "errorlint", - "importas" -] \ No newline at end of file + 'errname', + 'errorlint', + 'govet', + 'importas', + 'ineffassign', + 'sloglint', + 'staticcheck', + 'whitespace' +] + +[linters.exclusions] +generated = 'lax' +presets = [ + 'comments', + 'common-false-positives', + 'legacy', + 'std-error-handling' +] +paths = [ + 'third_party$', + 'builtin$', + 'examples$' +] + +[formatters] +enable = [ + 'gofmt' +] + +[formatters.exclusions] +generated = 'lax' +paths = [ + 'third_party$', + 'builtin$', + 'examples$' +]