Skip to content

Commit

Permalink
config from env
Browse files Browse the repository at this point in the history
  • Loading branch information
fanhousanbu committed Mar 17, 2024
1 parent cfa2bef commit c6fcc42
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ runtime/
.env
dist/
config.*.toml
config.toml
db/geecaptcha.db
captcha-bot
dict/dec_*
Expand Down
2 changes: 1 addition & 1 deletion telegram/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func BotStart() {
ulog.Sugar.Error(err)
},
}
// 反向代理
// 代理
if config.TelegramC.ApiProxy != "" {
trans := &http.Transport{
Proxy: func(_ *http.Request) (*url.URL, error) {
Expand Down
17 changes: 17 additions & 0 deletions util/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c6fcc42

Please sign in to comment.