From b80bda2da026086523f1de8f460637a376c53bf2 Mon Sep 17 00:00:00 2001 From: Mel Date: Mon, 4 Apr 2022 00:18:04 +0200 Subject: Grab bot token from enviroment variables --- .env.example | 1 + Taskfile.yml | 2 ++ cmd/bot/main.go | 13 ++++++++++--- pkg/bot/bot.go | 6 ++---- 4 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..2f2fca7 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +BOT_TOKEN="12345678910" diff --git a/Taskfile.yml b/Taskfile.yml index e421547..c8c7960 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,5 +1,7 @@ version: "3" +dotenv: [".env"] + tasks: build: desc: "Builds Jinx binaries." diff --git a/cmd/bot/main.go b/cmd/bot/main.go index b709ffc..51661e8 100644 --- a/cmd/bot/main.go +++ b/cmd/bot/main.go @@ -1,11 +1,18 @@ package main -import "jinx/pkg/bot" +import ( + "jinx/pkg/bot" + "log" + "os" +) func main() { - err := bot.Start() + token := os.Getenv("BOT_TOKEN") + if token == "" { + log.Fatal("`BOT_TOKEN` is not set.") + } - if err != nil { + if err := bot.Start(token); err != nil { panic(err) } } diff --git a/pkg/bot/bot.go b/pkg/bot/bot.go index a0c0808..71eb0e9 100644 --- a/pkg/bot/bot.go +++ b/pkg/bot/bot.go @@ -6,12 +6,10 @@ import ( "jinx/pkg/discord" ) -const TOKEN = "123567890123456789012345678901234567890" - -func Start() error { +func Start(token string) error { fmt.Println("hi..!") - client := discord.NewClient(TOKEN) + client := discord.NewClient(token) ctx, cancel := context.WithCancel(context.Background()) defer cancel() -- cgit 1.4.1