aboutsummaryrefslogtreecommitdiffstats
path: root/telebot/telebot.go
diff options
context:
space:
mode:
Diffstat (limited to 'telebot/telebot.go')
-rw-r--r--telebot/telebot.go44
1 files changed, 35 insertions, 9 deletions
diff --git a/telebot/telebot.go b/telebot/telebot.go
index 5cf2045..d4a8255 100644
--- a/telebot/telebot.go
+++ b/telebot/telebot.go
@@ -33,23 +33,50 @@ type server struct {
}
func GetProxiedClient() (*http.Client, error) {
+ var isProxied bool
proxyURL := os.Getenv("ALL_PROXY")
if proxyURL == "" {
proxyURL = os.Getenv("HTTPS_PROXY")
}
- dialer, err := proxy.SOCKS5("tcp", proxyURL, nil, proxy.Direct)
- if err != nil {
- return nil, fmt.Errorf("[GetProxiedClient] : %w", err)
+ if proxyURL == "" {
+ isProxied = false
}
- dialContext := func(ctx context.Context, network, address string) (net.Conn, error) {
- netConn, err := dialer.Dial(network, address)
- if err == nil {
- return netConn, nil
+ var dialer_proxy proxy.Dialer
+ var dialer net.Dialer
+ var err error
+
+ if isProxied {
+ dialer_proxy, err = proxy.SOCKS5("tcp", proxyURL, nil, proxy.Direct)
+ if err != nil {
+ return nil, fmt.Errorf("[GetProxiedClient] : %w", err)
}
+ } else {
+ dialer = net.Dialer{
+ Timeout: 5 * time.Second,
+ }
+ if err != nil {
+ return nil, fmt.Errorf("[GetProxiedClient] : %w", err)
+ }
+ }
- return netConn, fmt.Errorf("[dialContext] : %w", err)
+ dialContext := func(ctx context.Context, network, address string) (net.Conn, error) {
+ if isProxied {
+ netConn, err := dialer_proxy.Dial(network, address)
+ if err == nil {
+ return netConn, nil
+ }
+
+ return netConn, fmt.Errorf("[dialContext] : %w", err)
+ } else {
+ netConn, err := dialer.Dial(network, address)
+ if err == nil {
+ return netConn, nil
+ }
+
+ return netConn, fmt.Errorf("[dialContext] : %w", err)
+ }
}
transport := &http.Transport{
@@ -85,7 +112,6 @@ func getTGBot() *tgbotapi.BotAPI {
func sendMessage(bot *tgbotapi.BotAPI, msgText string, channelID int64) error {
msg := tgbotapi.NewMessage(channelID, msgText)
- fmt.Println("XXXXXXXXXXXXXXXXXX", msg)
_, err := bot.Send(msg)
return err