Revert "Add SOCKS5 proxy support to bot"
This reverts commit b52a0c34b8
.
This commit is contained in:
parent
22481ad7ec
commit
67cdb3edb5
@ -8,11 +8,6 @@ database_connection:
|
|||||||
user: "i2_bot"
|
user: "i2_bot"
|
||||||
password: "i2_bot"
|
password: "i2_bot"
|
||||||
database: "i2_bot"
|
database: "i2_bot"
|
||||||
socks_proxy:
|
|
||||||
enabled: true
|
|
||||||
address: "127.0.0.1:1337"
|
|
||||||
username: "proxy"
|
|
||||||
password: "proxy"
|
|
||||||
special_chats:
|
special_chats:
|
||||||
academy_id: "group_id"
|
academy_id: "group_id"
|
||||||
bastion_id: "group_id"
|
bastion_id: "group_id"
|
||||||
|
@ -30,14 +30,6 @@ type TelegramConnection struct {
|
|||||||
ListenAddress string `yaml:"listen_address"`
|
ListenAddress string `yaml:"listen_address"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProxySettings handles settings for SOCKS5 proxy in config.yml
|
|
||||||
type ProxySettings struct {
|
|
||||||
Enabled bool `yaml:"enabled"`
|
|
||||||
Address string `yaml:"address,omitempty"`
|
|
||||||
Username string `yaml:"username,omitempty"`
|
|
||||||
Password string `yaml:"password,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// SpecialChats handles settings for special chats
|
// SpecialChats handles settings for special chats
|
||||||
type SpecialChats struct {
|
type SpecialChats struct {
|
||||||
AcademyID string `yaml:"academy_id"`
|
AcademyID string `yaml:"academy_id"`
|
||||||
@ -56,7 +48,6 @@ type LoggingConfig struct {
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
Telegram TelegramConnection `yaml:"telegram_connection"`
|
Telegram TelegramConnection `yaml:"telegram_connection"`
|
||||||
Database DatabaseConnection `yaml:"database_connection"`
|
Database DatabaseConnection `yaml:"database_connection"`
|
||||||
Proxy ProxySettings `yaml:"socks_proxy"`
|
|
||||||
SpecialChats SpecialChats `yaml:"special_chats"`
|
SpecialChats SpecialChats `yaml:"special_chats"`
|
||||||
Logs LoggingConfig `yaml:"logs"`
|
Logs LoggingConfig `yaml:"logs"`
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,11 @@ import (
|
|||||||
_ "github.com/go-sql-driver/mysql" // MySQL driver for sqlx
|
_ "github.com/go-sql-driver/mysql" // MySQL driver for sqlx
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"golang.org/x/net/proxy"
|
|
||||||
"net/http"
|
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/config"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// botInitDirect used when no proxy in config file
|
// BotInit initializes connection to Telegram
|
||||||
func botInitDirect(cfg *config.Config, lg *mogrus.LoggerHandler) *tgbotapi.BotAPI {
|
func BotInit(cfg *config.Config, lg *mogrus.LoggerHandler) *tgbotapi.BotAPI {
|
||||||
bot, err := tgbotapi.NewBotAPI(cfg.Telegram.APIToken)
|
bot, err := tgbotapi.NewBotAPI(cfg.Telegram.APIToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lg.Fatal(err.Error())
|
lg.Fatal(err.Error())
|
||||||
@ -28,57 +26,6 @@ func botInitDirect(cfg *config.Config, lg *mogrus.LoggerHandler) *tgbotapi.BotAP
|
|||||||
return bot
|
return bot
|
||||||
}
|
}
|
||||||
|
|
||||||
// botInitWithProxy used when there is proxy in config file
|
|
||||||
func botInitWithProxy(cfg *config.Config, lg *mogrus.LoggerHandler) *tgbotapi.BotAPI {
|
|
||||||
proxyAuth := proxy.Auth{}
|
|
||||||
if cfg.Proxy.Username != "" {
|
|
||||||
proxyAuth.User = cfg.Proxy.Username
|
|
||||||
proxyAuth.Password = cfg.Proxy.Password
|
|
||||||
}
|
|
||||||
|
|
||||||
var dialProxy proxy.Dialer
|
|
||||||
var err error
|
|
||||||
if cfg.Proxy.Username != "" {
|
|
||||||
dialProxy, err = proxy.SOCKS5("tcp", cfg.Proxy.Address, &proxyAuth, proxy.Direct)
|
|
||||||
if err != nil {
|
|
||||||
lg.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dialProxy, err = proxy.SOCKS5("tcp", cfg.Proxy.Address, &proxyAuth, proxy.Direct)
|
|
||||||
if err != nil {
|
|
||||||
lg.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
proxyTransport := &http.Transport{Dial: dialProxy.Dial}
|
|
||||||
proxyClient := http.Client{Transport: proxyTransport}
|
|
||||||
|
|
||||||
bot, err := tgbotapi.NewBotAPIWithClient(cfg.Telegram.APIToken, &proxyClient)
|
|
||||||
if err != nil {
|
|
||||||
lg.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
bot.Debug = true
|
|
||||||
|
|
||||||
lg.Info("Bot version: " + config.VERSION)
|
|
||||||
lg.Info("Authorized on account @", bot.Self.UserName)
|
|
||||||
|
|
||||||
return bot
|
|
||||||
}
|
|
||||||
|
|
||||||
// External functions
|
|
||||||
|
|
||||||
// BotInit initializes connection to Telegram
|
|
||||||
func BotInit(cfg *config.Config, lg *mogrus.LoggerHandler) *tgbotapi.BotAPI {
|
|
||||||
if cfg.Proxy.Enabled {
|
|
||||||
lg.Info("Using proxy for bot: " + cfg.Proxy.Address)
|
|
||||||
return botInitWithProxy(cfg, lg)
|
|
||||||
}
|
|
||||||
|
|
||||||
lg.Info("Using direct connection to Telegram")
|
|
||||||
return botInitDirect(cfg, lg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DBInit initializes database connection
|
// DBInit initializes database connection
|
||||||
func DBInit(cfg *config.Config, lg *mogrus.LoggerHandler) *sqlx.DB {
|
func DBInit(cfg *config.Config, lg *mogrus.LoggerHandler) *sqlx.DB {
|
||||||
database, err := sqlx.Connect("mysql", cfg.Database.User+":"+cfg.Database.Password+"@tcp("+cfg.Database.Host+":"+cfg.Database.Port+")/"+cfg.Database.Database+"?parseTime=true&charset=utf8mb4,utf8")
|
database, err := sqlx.Connect("mysql", cfg.Database.User+":"+cfg.Database.Password+"@tcp("+cfg.Database.Host+":"+cfg.Database.Port+")/"+cfg.Database.Database+"?parseTime=true&charset=utf8mb4,utf8")
|
||||||
|
Reference in New Issue
Block a user