Add dialer property in config (#1179)

Co-authored-by: eeWynell <eewynell@gmail.com>
This commit is contained in:
Wynell 2022-08-13 23:42:42 +03:00 committed by GitHub
parent c0803d021f
commit 262e8ba52b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 1 deletions

View file

@ -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(),

View file

@ -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

View file

@ -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