From 262e8ba52b48ae1fcebd8b6a595631e8ce9f746c Mon Sep 17 00:00:00 2001 From: Wynell <65278392+uWynell@users.noreply.github.com> Date: Sat, 13 Aug 2022 23:42:42 +0300 Subject: [PATCH] Add dialer property in config (#1179) Co-authored-by: eeWynell --- discord.go | 3 +++ structs.go | 3 +++ wsapi.go | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/discord.go b/discord.go index 61d4e3339..336b3d225 100644 --- a/discord.go +++ b/discord.go @@ -17,6 +17,8 @@ import ( "net/http" "runtime" "time" + + "github.com/gorilla/websocket" ) // VERSION of DiscordGo, follows Semantic Versioning. (http://semver.org/) @@ -41,6 +43,7 @@ func New(token string) (s *Session, err error) { ShardCount: 1, MaxRestRetries: 3, Client: &http.Client{Timeout: (20 * time.Second)}, + Dialer: websocket.DefaultDialer, UserAgent: "DiscordBot (https://github.com/bwmarrin/discordgo, v" + VERSION + ")", sequence: new(int64), LastHeartbeatAck: time.Now().UTC(), diff --git a/structs.go b/structs.go index 781dff173..c8e476c23 100644 --- a/structs.go +++ b/structs.go @@ -95,6 +95,9 @@ type Session struct { // The http client used for REST requests Client *http.Client + // The dialer used for WebSocket connection + Dialer *websocket.Dialer + // The user agent used for REST APIs UserAgent string diff --git a/wsapi.go b/wsapi.go index dad3fb989..2579ee42c 100644 --- a/wsapi.go +++ b/wsapi.go @@ -77,7 +77,7 @@ func (s *Session) Open() error { s.log(LogInformational, "connecting to gateway %s", s.gateway) header := http.Header{} header.Add("accept-encoding", "zlib") - s.wsConn, _, err = websocket.DefaultDialer.Dial(s.gateway, header) + s.wsConn, _, err = s.Dialer.Dial(s.gateway, header) if err != nil { s.log(LogError, "error connecting to gateway %s, %s", s.gateway, err) s.gateway = "" // clear cached gateway