diff --git a/Dockerfile b/Dockerfile index 582a883..165f0b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,8 @@ ENV CGO_ENABLED=1 \ GOOS=linux \ GOARCH=amd64 \ CC=x86_64-linux-musl-gcc \ - CXX=x86_64-linux-musl-g++ \ - GOPROXY=https://goproxy.cn,direct + CXX=x86_64-linux-musl-g++ + # GOPROXY=https://goproxy.cn,direct RUN go mod download RUN go mod verify diff --git a/telegram/root.go b/telegram/root.go index 9cf2b0f..4a7e594 100644 --- a/telegram/root.go +++ b/telegram/root.go @@ -1,11 +1,13 @@ package telegram import ( + "log" + "os" + "time" + "github.com/assimon/captcha-bot/util/config" ulog "github.com/assimon/captcha-bot/util/log" tb "gopkg.in/telebot.v3" - "log" - "time" ) var Bot *tb.Bot @@ -13,8 +15,12 @@ var Bot *tb.Bot // BotStart 机器人启动 func BotStart() { setting := tb.Settings{ - Token: func() string { - config.TelegramC.BotToken, + Token: func() string { + if token := os.Getenv("bot_token"); len(token) > 0 { + return token + } else { + return config.TelegramC.BotToken + } }(), Updates: 100, Poller: &tb.LongPoller{Timeout: 10 * time.Second, AllowedUpdates: []string{ @@ -94,7 +100,7 @@ func isManage(chat *tb.Chat, userId int64) bool { // isRoot 判断是否为超管 func isRoot(userid int64) bool { - for _, id := range config.TelegramC.ManageUsers { + for _, id := range config.TelegramC.GetManageUsers() { if userid == id { return true } diff --git a/util/config/config.go b/util/config/config.go index 00dd733..e6c6e8d 100644 --- a/util/config/config.go +++ b/util/config/config.go @@ -1,9 +1,12 @@ package config import ( - "github.com/spf13/viper" "log" "os" + "strconv" + "strings" + + "github.com/spf13/viper" ) var AppPath string @@ -22,6 +25,21 @@ type Telegram struct { ManageUsers []int64 `mapstructure:"manage_users"` } +func (tel *Telegram) GetManageUsers() []int64 { + if len(tel.ManageUsers) == 0 { + if users := os.Getenv("managers"); len(users) > 0 { + if userArr := strings.Split(users, ","); len(userArr) > 0 { + tel.ManageUsers = make([]int64, len(userArr)) + for i, uid := range userArr { + uid64, _ := strconv.Atoi(uid) + tel.ManageUsers[i] = int64(uid64) + } + } + } + } + return tel.ManageUsers +} + var TelegramC Telegram type Log struct {