feat: api and proxy optional
This commit is contained in:
parent
ac593ddbc8
commit
d4f070f9ec
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
.env
|
||||
run.sh
|
||||
mcbot
|
@ -12,6 +12,7 @@ type botSettings struct {
|
||||
MCBotName string `env:"MC_BOT_NAME"`
|
||||
GroupID int64 `env:"GROUP_ID"`
|
||||
DBPath string `env:"DB_PATH"`
|
||||
BotAPI string `env:"TG_BOT_API"`
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -16,18 +16,26 @@ import (
|
||||
func Run(sendFunc func(string)) {
|
||||
var err error
|
||||
|
||||
api := conf.GetBotSettings().BotAPI
|
||||
if len(api) == 0 {
|
||||
api = tgbotapi.APIEndpoint
|
||||
}
|
||||
|
||||
HttpProxy := conf.GetBotSettings().HTTPProxy
|
||||
proxyUrl, err := url.Parse(HttpProxy)
|
||||
if err != nil {
|
||||
log.Panic(err, "HTTP_PROXY environment variable is not set correctly")
|
||||
}
|
||||
|
||||
client := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)}}
|
||||
conf.Bot, err = tgbotapi.NewBotAPIWithClient(
|
||||
conf.GetBotSettings().BotToken,
|
||||
tgbotapi.APIEndpoint,
|
||||
// conf.GetBotSettings().TGBotApi,
|
||||
client)
|
||||
if len(HttpProxy) != 0 {
|
||||
client := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)}}
|
||||
conf.Bot, err = tgbotapi.NewBotAPIWithClient(
|
||||
conf.GetBotSettings().BotToken,
|
||||
api,
|
||||
client)
|
||||
} else {
|
||||
conf.Bot, err = tgbotapi.NewBotAPIWithAPIEndpoint(conf.GetBotSettings().BotToken, api)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user