-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
382 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.idea/ | ||
.github/ | ||
.editorconfig | ||
README.md | ||
LICENSE | ||
config.json | ||
config.json.example | ||
config.toml | ||
config.example.toml |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Docker | ||
|
||
on: [ push ] | ||
|
||
jobs: | ||
docker: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ghcr.io/${{ github.repository }} | ||
tags: | | ||
type=ref,event=branch | ||
type=ref,event=tag | ||
type=ref,event=pr | ||
type=sha,prefix= | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8 | ||
push: true | ||
build-args: VERSION=${{ steps.meta.outputs.version }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Test | ||
|
||
on: [ push ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.22.x | ||
- name: Test | ||
run: go test -v ./... | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.22.x | ||
- name: Lint | ||
uses: golangci/golangci-lint-action@v6 | ||
with: | ||
version: latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
.idea/ | ||
config.json | ||
config.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[linters] | ||
disable-all = true | ||
enable = [ | ||
"gosimple", | ||
"govet", | ||
"gofmt", | ||
"ineffassign", | ||
"staticcheck", | ||
"sloglint", | ||
"whitespace", | ||
"errname", | ||
"errorlint", | ||
"importas" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,65 @@ | ||
[![Docker](https://github.com/disgoorg/bot-template/actions/workflows/docker-build.yml/badge.svg)](https://github.com/disgoorg/bot-template/actions/workflows/docker-build.yml) | ||
[![Test](https://github.com/disgoorg/bot-template/actions/workflows/go-test.yml/badge.svg)](https://github.com/disgoorg/bot-template/actions/workflows/go-test.yml) | ||
[![Go Report][0]][1] | ||
[![Go Version][2]][3] | ||
[![License][4]][5] | ||
[![Docker][6]][7] | ||
[![Test][8]][9] | ||
|
||
# bot-template | ||
|
||
This is a simple bot template for creating a bot which includes a config, application commands, components modals(using [handler](https://github.com/disgoorg/disgo/tree/master/handler) and event listeners. | ||
|
||
Optional CLI Flags: | ||
CLI Flags: | ||
- `--config-path=your-config-path`: Path to the config file. | ||
- `--sync-commands=true`: Synchronize commands with the discord. | ||
|
||
## Usage | ||
|
||
1. Click on the `Use this template` button to create a new repository from this template. | ||
2. Clone the repository to your local machine. | ||
3. Open the project in your favorite IDE. | ||
4. Copy the `config.example.toml` file to `config.toml` and fill in the required fields. | ||
5. Run the bot using `go run .` | ||
6. Invite the bot to your server using the invite link generated by [discord developer portal][10]. | ||
7. | ||
|
||
## Configuration | ||
|
||
The configuration file is in TOML format. The format is as follows: | ||
|
||
```toml | ||
[log] | ||
# valid levels are "debug", "info", "warn", "error" | ||
level = "info" | ||
# valid formats are "text" and "json" | ||
format = "text" | ||
# whether to add the log source to the log message | ||
add_source = true | ||
|
||
[bot] | ||
# add guild ids the commands should sync to, leave empty to sync globally | ||
dev_guilds = [] | ||
# the bot token | ||
token = "..." | ||
``` | ||
|
||
## License | ||
|
||
The bot template is licensed under the [Apache License 2.0][5]. | ||
|
||
|
||
[0]: https://goreportcard.com/badge/github.com/disgoorg/bot-template | ||
[1]: https://goreportcard.com/report/github.com/disgoorg/bot-template | ||
|
||
[2]: https://img.shields.io/github/go-mod/go-version/disgoorg/bot-template | ||
[3]: https://golang.org/doc/devel/release.html | ||
|
||
[4]: https://img.shields.io/github/license/disgoorg/bot-template | ||
[5]: LICENSE | ||
|
||
[6]: https://github.com/disgoorg/bot-template/actions/workflows/docker.yml/badge.svg | ||
[7]: https://github.com/disgoorg/bot-template/actions/workflows/docker.yml | ||
|
||
[8]: https://github.com/disgoorg/bot-template/actions/workflows/test.yml/badge.svg | ||
[9]: https://github.com/disgoorg/bot-template/actions/workflows/test.yml | ||
|
||
[10]: https://discord.com/developers/applications |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,56 @@ | ||
package dbot | ||
package bottemplate | ||
|
||
import ( | ||
"context" | ||
"log/slog" | ||
"time" | ||
|
||
"github.com/disgoorg/disgo" | ||
"github.com/disgoorg/disgo/bot" | ||
"github.com/disgoorg/disgo/cache" | ||
"github.com/disgoorg/disgo/discord" | ||
"github.com/disgoorg/disgo/events" | ||
"github.com/disgoorg/disgo/gateway" | ||
"github.com/disgoorg/log" | ||
"github.com/disgoorg/paginator" | ||
) | ||
|
||
func New(logger log.Logger, version string, config Config) *Bot { | ||
func New(cfg Config, version string, commit string) *Bot { | ||
return &Bot{ | ||
Logger: logger, | ||
Config: config, | ||
Cfg: cfg, | ||
Paginator: paginator.New(), | ||
Version: version, | ||
Commit: commit, | ||
} | ||
} | ||
|
||
type Bot struct { | ||
Logger log.Logger | ||
Cfg Config | ||
Client bot.Client | ||
Paginator *paginator.Manager | ||
Config Config | ||
Version string | ||
Commit string | ||
} | ||
|
||
func (b *Bot) SetupBot(listeners ...bot.EventListener) { | ||
var err error | ||
b.Client, err = disgo.New(b.Config.Token, | ||
bot.WithLogger(b.Logger), | ||
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 { | ||
b.Logger.Fatal("Failed to setup b: ", err) | ||
return err | ||
} | ||
|
||
b.Client = client | ||
return nil | ||
} | ||
|
||
func (b *Bot) OnReady(_ *events.Ready) { | ||
b.Logger.Infof("Butler ready") | ||
if err := b.Client.SetPresence(context.TODO(), gateway.WithListeningActivity("you"), gateway.WithOnlineStatus(discord.OnlineStatusOnline)); err != nil { | ||
b.Logger.Errorf("Failed to set presence: %s", err) | ||
slog.Info("bot-template ready") | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
if err := b.Client.SetPresence(ctx, gateway.WithListeningActivity("you"), gateway.WithOnlineStatus(discord.OnlineStatusOnline)); err != nil { | ||
slog.Error("Failed to set presence", slog.Any("err", err)) | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.