From ea05d998f26b4ae39d2fde75df2ab3dd321c59ce Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 27 Oct 2020 08:57:00 +0800 Subject: [PATCH] load notification conf --- pkg/cmd/run.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index 4338725de..a166fa6d0 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -68,17 +68,21 @@ func compileRunFile(filepath string, config *bbgo.Config) error { func runConfig(ctx context.Context, userConfig *bbgo.Config) error { // configure notifiers + notifierSet := &bbgo.Notifiability{} + + // for slack slackToken := viper.GetString("slack-token") if len(slackToken) > 0 { - log.Infof("found slack configured, setting up log hook...") - log.AddHook(slacklog.NewLogHook(slackToken, viper.GetString("slack-error-channel"))) - } + if conf := userConfig.Notifications.Slack; conf != nil { + if conf.ErrorChannel != "" { + log.Infof("found slack configured, setting up log hook...") + log.AddHook(slacklog.NewLogHook(slackToken, conf.ErrorChannel)) + } - notifierSet := &bbgo.Notifiability{} - if len(slackToken) > 0 { - log.Infof("adding slack notifier...") - var notifier = slacknotifier.New(slackToken, viper.GetString("slack-channel")) - notifierSet.AddNotifier(notifier) + log.Infof("adding slack notifier...") + var notifier = slacknotifier.New(slackToken, conf.DefaultChannel) + notifierSet.AddNotifier(notifier) + } } db, err := cmdutil.ConnectMySQL()