Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
51 changes: 39 additions & 12 deletions .golangci.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
version = '2'

[linters]
disable-all = true
default = 'none'
enable = [
"gosimple",
"govet",
"gofmt",
"ineffassign",
"staticcheck",
"sloglint",
"whitespace",
"errname",
"errorlint",
"importas"
]
'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$'
]
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM golang:1.22-alpine AS build
FROM --platform=$BUILDPLATFORM golang:1.25-alpine AS build

WORKDIR /build

Expand All @@ -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

Expand Down
18 changes: 6 additions & 12 deletions bottemplate/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion bottemplate/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
}
}
4 changes: 2 additions & 2 deletions bottemplate/components/test_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
})
}
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
28 changes: 14 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
14 changes: 11 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log/slog"
"os"
"os/signal"
"runtime/debug"
"syscall"
"time"

Expand All @@ -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")
Expand All @@ -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)
Expand Down