diff --git a/main.go b/cmd/bot.go similarity index 96% rename from main.go rename to cmd/bot.go index bffbf0c..75ba03b 100644 --- a/main.go +++ b/cmd/bot.go @@ -6,29 +6,26 @@ import ( "fmt" "log" "os" - "strings" "os/exec" - "github.com/joho/godotenv" + "rodleyserverbot/slack-bot/config" + "strings" "github.com/slack-go/slack" "github.com/slack-go/slack/slackevents" "github.com/slack-go/slack/socketmode" ) func main() { - - // Load Env variables from .dot file - godotenv.Load(".env") - - token := os.Getenv("SLACK_AUTH_TOKEN") - appToken := os.Getenv("SLACK_APP_TOKEN") // Create a new client to slack by giving token // Set debug to true while developing // Also add a ApplicationToken option to the client - client := slack.New(token, slack.OptionDebug(false), slack.OptionAppLevelToken(appToken)) + client := slack.New( + config.Config.SlackAppToken, + slack.OptionDebug(false), + slack.OptionAppLevelToken(config.Config.SlackAppToken)) // go-slack comes with a SocketMode package that we need to use that accepts a Slack client and outputs a Socket mode client instead socketClient := socketmode.New( client, - socketmode.OptionDebug(true), + socketmode.OptionDebug(false), // Option to set a custom logger socketmode.OptionLog(log.New(os.Stdout, "socketmode: ", log.Lshortfile|log.LstdFlags)), ) diff --git a/config/app.go b/config/app.go new file mode 100644 index 0000000..35f93f7 --- /dev/null +++ b/config/app.go @@ -0,0 +1,24 @@ +package config + +import ( + "os" + + "github.com/joho/godotenv" +) + +type ConfigEntries struct { + SlackAuthToken string + SlackAppToken string + ActionScript1 string + ActionScript2 string +} + +var Config ConfigEntries + +func init(){ + // fmt.Println("init de config!") + // Load Env variables from .dot file + godotenv.Load(".env") + Config.SlackAuthToken = os.Getenv("SLACK_AUTH_TOKEN") + Config.SlackAppToken = os.Getenv("SLACK_APP_TOKEN") +} diff --git a/go.mod b/go.mod index af6a051..42f5951 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,6 @@ go 1.13 require ( github.com/gorilla/websocket v1.5.0 // indirect - github.com/joho/godotenv v1.4.0 // indirect + github.com/joho/godotenv v1.4.0 github.com/slack-go/slack v0.11.0 // indirect )