Kaynağa Gözat

Make connection timeout configurable

Tulir Asokan 6 yıl önce
ebeveyn
işleme
b5af35684d
2 değiştirilmiş dosya ile 7 ekleme ve 1 silme
  1. 2 0
      config/bridge.go
  2. 5 1
      user.go

+ 2 - 0
config/bridge.go

@@ -33,6 +33,8 @@ type BridgeConfig struct {
 	UsernameTemplate    string `yaml:"username_template"`
 	DisplaynameTemplate string `yaml:"displayname_template"`
 
+	ConnectionTimeout int `yaml:"connection_timeout"`
+
 	CommandPrefix string `yaml:"command_prefix"`
 
 	Permissions PermissionConfig `yaml:"permissions"`

+ 5 - 1
user.go

@@ -145,7 +145,11 @@ func (user *User) Connect(evenIfNoSession bool) bool {
 		return false
 	}
 	user.log.Debugln("Connecting to WhatsApp")
-	conn, err := whatsapp.NewConn(20 * time.Second)
+	timeout := time.Duration(user.bridge.Config.Bridge.ConnectionTimeout)
+	if timeout == 0 {
+		timeout = 20
+	}
+	conn, err := whatsapp.NewConn(timeout * time.Second)
 	if err != nil {
 		user.log.Errorln("Failed to connect to WhatsApp:", err)
 		return false