summaryrefslogtreecommitdiffstats
path: root/bridge/sshchat
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-12-12 23:47:07 +0100
committerGitHub <noreply@github.com>2018-12-12 23:47:07 +0100
commit2f7b4d7f68076f45d74900d5dec8648fbf783b9e (patch)
treecd836509699e5b42d191a499a0660bb933ae4ef3 /bridge/sshchat
parentd887855e166d863f3fa06d2244d698415d743b77 (diff)
downloadmatterbridge-msglm-2f7b4d7f68076f45d74900d5dec8648fbf783b9e.tar.gz
matterbridge-msglm-2f7b4d7f68076f45d74900d5dec8648fbf783b9e.tar.bz2
matterbridge-msglm-2f7b4d7f68076f45d74900d5dec8648fbf783b9e.zip
Refactor sshchat bridge (#650)
* Decrease complexity in Send() * Add handleUploadFile() function
Diffstat (limited to 'bridge/sshchat')
-rw-r--r--bridge/sshchat/sshchat.go38
1 files changed, 20 insertions, 18 deletions
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
+}