From 3fc9fd5dcb3964de699e9a60f99c9414cb59a82e Mon Sep 17 00:00:00 2001 From: kolaente Date: Fri, 12 Apr 2019 08:42:33 +0000 Subject: [PATCH] Sync files with github (#5) --- bot.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/bot.go b/bot.go index 53204b0..32cd046 100644 --- a/bot.go +++ b/bot.go @@ -2,14 +2,13 @@ package main import ( "fmt" + "github.com/bwmarrin/discordgo" + "github.com/kiliankoe/openmensa" "os" "os/signal" "strings" "syscall" "time" - - "github.com/bwmarrin/discordgo" - "github.com/kiliankoe/openmensa" ) var ( @@ -32,13 +31,19 @@ var ( func main() { token := os.Getenv("MENSABOT_TOKEN") - if len(token) == 0 || token == "token" { - println("Please add token as environment variable: MENSABOT_TOKEN.") + if len(token) == 0 || token == "token" || len(os.Args) <= 0 { + println("Please add token as environment variable (MENSABOT_TOKEN) or cli argument.") return } + + if len(os.Args) > 0 { + token = os.Args[0] + } + dg, err := discordgo.New(fmt.Sprintf("Bot %s", token)) if err != nil { - fmt.Println("error creating dicord bot: ", err) + fmt.Println("error creating discord bot: ", err) + return } canteens, err := openmensa.GetCanteens(175) if err != nil {