feat: api and proxy optional

This commit is contained in:
Vaala Cat
2023-06-27 12:45:55 +08:00
parent ac593ddbc8
commit d4f070f9ec
3 changed files with 16 additions and 6 deletions

View File

@@ -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)