From 2f7b4d7f68076f45d74900d5dec8648fbf783b9e Mon Sep 17 00:00:00 2001 From: Wim Date: Wed, 12 Dec 2018 23:47:07 +0100 Subject: Refactor sshchat bridge (#650) * Decrease complexity in Send() * Add handleUploadFile() function --- bridge/sshchat/sshchat.go | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'bridge') diff --git a/bridge/sshchat/sshchat.go b/bridge/sshchat/sshchat.go index 555759bf..79ba9fb5 100644 --- a/bridge/sshchat/sshchat.go +++ b/bridge/sshchat/sshchat.go @@ -64,24 +64,7 @@ func (b *Bsshchat) Send(msg config.Message) (string, error) { b.Log.Errorf("Could not send extra message: %#v", err) } } - if len(msg.Extra["file"]) > 0 { - for _, f := range msg.Extra["file"] { - fi := f.(config.FileInfo) - if fi.Comment != "" { - msg.Text += fi.Comment + ": " - } - if fi.URL != "" { - msg.Text = fi.URL - if fi.Comment != "" { - msg.Text = fi.Comment + ": " + fi.URL - } - } - if _, err := b.w.Write([]byte(msg.Username + msg.Text)); err != nil { - b.Log.Errorf("Could not send file message: %#v", err) - } - } - return "", nil - } + return b.handleUploadFile(&msg) } _, err := b.w.Write([]byte(msg.Username + msg.Text + "\r\n")) return "", err @@ -144,3 +127,22 @@ func (b *Bsshchat) handleSSHChat() error { } } } + +func (b *Bsshchat) handleUploadFile(msg *config.Message) (string, error) { + for _, f := range msg.Extra["file"] { + fi := f.(config.FileInfo) + if fi.Comment != "" { + msg.Text += fi.Comment + ": " + } + if fi.URL != "" { + msg.Text = fi.URL + if fi.Comment != "" { + msg.Text = fi.Comment + ": " + fi.URL + } + } + if _, err := b.w.Write([]byte(msg.Username + msg.Text)); err != nil { + b.Log.Errorf("Could not send file message: %#v", err) + } + } + return "", nil +} -- cgit v1.2.3