Skip to content

Commit

Permalink
from env
Browse files Browse the repository at this point in the history
  • Loading branch information
fanhousanbu committed Mar 16, 2024
1 parent df67445 commit 99eeb67
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions telegram/root.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
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

// 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{
Expand Down Expand Up @@ -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
}
Expand Down
20 changes: 19 additions & 1 deletion util/config/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package config

import (
"github.com/spf13/viper"
"log"
"os"
"strconv"
"strings"

"github.com/spf13/viper"
)

var AppPath string
Expand All @@ -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 {
Expand Down

0 comments on commit 99eeb67

Please sign in to comment.