diff --git a/cmd/panel/main.go b/cmd/panel/main.go index 4609d3d..8371029 100644 --- a/cmd/panel/main.go +++ b/cmd/panel/main.go @@ -15,6 +15,7 @@ import ( "github.com/TicketsBot/archiverclient" "github.com/TicketsBot/common/premium" "github.com/apex/log" + "github.com/rxdn/gdl/rest/request" "math/rand" "time" ) @@ -30,6 +31,7 @@ func main() { } config.LoadConfig() + database.ConnectToDatabase() cache.Instance = cache.NewCache() @@ -37,6 +39,10 @@ func main() { utils.LoadEmoji() + if config.Conf.Bot.ProxyUrl != "" { + request.RegisterHook(utils.ProxyHook) + } + messagequeue.Client = messagequeue.NewRedisClient() go Listen(messagequeue.Client) diff --git a/config/config.go b/config/config.go index 9d7b619..dcd5da8 100644 --- a/config/config.go +++ b/config/config.go @@ -55,6 +55,7 @@ type ( PremiumLookupProxyKey string `toml:"premium-lookup-proxy-key"` ObjectStore string AesKey string `toml:"aes-key"` + ProxyUrl string `toml:"discord-proxy-url"` } Redis struct { @@ -81,7 +82,7 @@ func LoadConfig() { } } -func fromToml() { +func fromToml() { if _, err := toml.DecodeFile("config.toml", &Conf); err != nil { panic(err) } @@ -144,6 +145,7 @@ func fromEnvvar() { PremiumLookupProxyKey: os.Getenv("PREMIUM_PROXY_KEY"), ObjectStore: os.Getenv("LOG_ARCHIVER_URL"), AesKey: os.Getenv("LOG_AES_KEY"), + ProxyUrl: os.Getenv("DISCORD_PROXY_URL"), }, Redis: Redis{ Host: os.Getenv("REDIS_HOST"), diff --git a/go.mod b/go.mod index d3a8110..d9de6d7 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/klauspost/compress v1.10.10 // indirect github.com/pasztorpisti/qs v0.0.0-20171216220353-8d6c33ee906c github.com/pkg/errors v0.9.1 - github.com/rxdn/gdl v0.0.0-20201027221415-e420474288d4 + github.com/rxdn/gdl v0.0.0-20201123164345-0469e0a3cea3 github.com/sirupsen/logrus v1.5.0 github.com/ulule/limiter/v3 v3.5.0 golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a diff --git a/utils/proxyhook.go b/utils/proxyhook.go new file mode 100644 index 0000000..6f76ce8 --- /dev/null +++ b/utils/proxyhook.go @@ -0,0 +1,16 @@ +package utils + +import ( + "github.com/TicketsBot/GoPanel/config" + "net/http" + "os" +) + +// Twilight's HTTP proxy doesn't support the typical HTTP proxy protocol - instead you send the request directly +// to the proxy's host in the URL. This is not how Go's proxy function should be used, but it works :) +func ProxyHook(token string, req *http.Request) { + if token == os.Getenv("WORKER_PUBLIC_TOKEN") { + req.URL.Scheme = "http" + req.URL.Host = config.Conf.Bot.ProxyUrl + } +}