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