Proxy discord requests
This commit is contained in:
parent
5afbe58d17
commit
c727b9efaf
@ -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)
|
||||
|
||||
|
@ -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"),
|
||||
|
2
go.mod
2
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
|
||||
|
16
utils/proxyhook.go
Normal file
16
utils/proxyhook.go
Normal file
@ -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
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user