From c6fcc4229c4d73dde217f32e77b55ac216e1f2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=B6=85=E8=B6=8A?= <993921@qq.com> Date: Sun, 17 Mar 2024 17:02:35 +0800 Subject: [PATCH] config from env --- .gitignore | 1 - telegram/root.go | 2 +- util/config/config.go | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index e538900..625331e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ runtime/ .env dist/ config.*.toml -config.toml db/geecaptcha.db captcha-bot dict/dec_* diff --git a/telegram/root.go b/telegram/root.go index a4264e6..86f4570 100644 --- a/telegram/root.go +++ b/telegram/root.go @@ -35,7 +35,7 @@ func BotStart() { ulog.Sugar.Error(err) }, } - // 反向代理 + // 代理 if config.TelegramC.ApiProxy != "" { trans := &http.Transport{ Proxy: func(_ *http.Request) (*url.URL, error) { diff --git a/util/config/config.go b/util/config/config.go index 002d7af..367e549 100644 --- a/util/config/config.go +++ b/util/config/config.go @@ -59,6 +59,21 @@ type Message struct { var MessageC Message +func (msg *Message) FromEnv() { + if joinHint := os.Getenv("msg__join_hint"); len(joinHint) > 0 { + msg.JoinHint = joinHint + } + if captchaImage := os.Getenv("msg__captcha_image"); len(captchaImage) > 0 { + msg.CaptchaImage = captchaImage + } + if verificationComplete := os.Getenv("msg__verification_complete"); len(verificationComplete) > 0 { + msg.VerificationComplete = verificationComplete + } + if blockHint := os.Getenv("msg__block_hint"); len(blockHint) > 0 { + msg.BlockHint = blockHint + } +} + type AdBlock struct { NumberOfForbiddenWords int `mapstructure:"number_of_forbidden_words"` BlockTime int64 `mapstructure:"block_time"` @@ -97,6 +112,8 @@ func InitConfig() { err = viper.UnmarshalKey("message", &MessageC) if err != nil { log.Fatal("load config message err:", err) + } else { + MessageC.FromEnv() } err = viper.UnmarshalKey("adblock", &AdBlockC) if err != nil {