mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-09-11 20:50:06 +00:00
feat(tgbot): Add validate for API Server URL
This commit is contained in:
parent
85da8300f9
commit
d04db44190
1 changed files with 22 additions and 11 deletions
|
@ -137,6 +137,7 @@ func (t *Tgbot) NewBot(token string, proxyUrl string, apiServerUrl string) (*tel
|
|||
return telego.NewBot(token)
|
||||
}
|
||||
|
||||
if proxyUrl != "" {
|
||||
if !strings.HasPrefix(proxyUrl, "socks5://") {
|
||||
logger.Warning("Invalid socks5 URL, starting with default")
|
||||
return telego.NewBot(token)
|
||||
|
@ -148,11 +149,21 @@ func (t *Tgbot) NewBot(token string, proxyUrl string, apiServerUrl string) (*tel
|
|||
return telego.NewBot(token)
|
||||
}
|
||||
|
||||
if proxyUrl != "" {
|
||||
return telego.NewBot(token, telego.WithFastHTTPClient(&fasthttp.Client{
|
||||
Dial: fasthttpproxy.FasthttpSocksDialer(proxyUrl),
|
||||
}))
|
||||
} else {
|
||||
if !strings.HasPrefix(proxyUrl, "http") {
|
||||
logger.Warning("Invalid http(s) URL, starting with default")
|
||||
return telego.NewBot(token)
|
||||
}
|
||||
|
||||
_, err := url.Parse(proxyUrl)
|
||||
if err != nil {
|
||||
logger.Warning("Can't parse API server URL, using default instance for tgbot:", err)
|
||||
return telego.NewBot(token)
|
||||
}
|
||||
|
||||
return telego.NewBot(token, telego.WithAPIServer(apiServerUrl))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue