Add various sshchat fixes (#675)

* SSH-Chat: set quiet mode to filter joins/quits
* SSH-Chat: Trim newlines in the end of relayed messages
* SSH-Chat: fix media links
* SSH-Chat: do not relay "Rate limiting is in effect" message
This commit is contained in:
ValdikSS 2019-01-05 17:42:36 +03:00 committed by Wim
parent 8522d8f29c
commit 7326b9e10d
1 changed files with 6 additions and 3 deletions

View File

@ -33,7 +33,7 @@ func (b *Bsshchat) Connect() error {
b.r = bufio.NewScanner(r) b.r = bufio.NewScanner(r)
b.r.Scan() b.r.Scan()
b.w = w b.w = w
if _, err := b.w.Write([]byte("/theme mono\r\n")); err != nil { if _, err := b.w.Write([]byte("/theme mono\r\n/quiet\r\n")); err != nil {
return err return err
} }
close(connSignal) // Connection is established so we can signal the success. close(connSignal) // Connection is established so we can signal the success.
@ -128,6 +128,9 @@ func (b *Bsshchat) handleSSHChat() error {
if !strings.Contains(b.r.Text(), "\033[K") { if !strings.Contains(b.r.Text(), "\033[K") {
continue continue
} }
if strings.Contains(b.r.Text(), "Rate limiting is in effect") {
continue
}
res := strings.Split(stripPrompt(b.r.Text()), ":") res := strings.Split(stripPrompt(b.r.Text()), ":")
if res[0] == "-> Set theme" { if res[0] == "-> Set theme" {
wait = false wait = false
@ -136,7 +139,7 @@ func (b *Bsshchat) handleSSHChat() error {
} }
if !wait { if !wait {
b.Log.Debugf("<= Message %#v", res) b.Log.Debugf("<= Message %#v", res)
rmsg := config.Message{Username: res[0], Text: strings.Join(res[1:], ":"), Channel: "sshchat", Account: b.Account, UserID: "nick"} rmsg := config.Message{Username: res[0], Text: strings.TrimSpace(strings.Join(res[1:], ":")), Channel: "sshchat", Account: b.Account, UserID: "nick"}
b.Remote <- rmsg b.Remote <- rmsg
} }
} }
@ -155,7 +158,7 @@ func (b *Bsshchat) handleUploadFile(msg *config.Message) (string, error) {
msg.Text = fi.Comment + ": " + fi.URL msg.Text = fi.Comment + ": " + fi.URL
} }
} }
if _, err := b.w.Write([]byte(msg.Username + msg.Text)); err != nil { if _, err := b.w.Write([]byte(msg.Username + msg.Text + "\r\n")); err != nil {
b.Log.Errorf("Could not send file message: %#v", err) b.Log.Errorf("Could not send file message: %#v", err)
} }
} }