From 2ad56bf822d11024744f856879a0b0fce02cb12b Mon Sep 17 00:00:00 2001 From: Ivanq Date: Wed, 29 Dec 2021 18:55:37 +0300 Subject: [PATCH 1/3] Add support for bidirectional formatting for IRC --- bridge/irc/handlers.go | 4 ++++ bridge/irc/irc.go | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/bridge/irc/handlers.go b/bridge/irc/handlers.go index b90fa3af92..9d75c91f00 100644 --- a/bridge/irc/handlers.go +++ b/bridge/irc/handlers.go @@ -238,6 +238,10 @@ func (b *Birc) handlePrivMsg(client *girc.Client, event girc.Event) { rmsg.Text = string(output) } + rmsg.Text = strings.Replace(rmsg.Text, "\x02", "**", -1) + rmsg.Text = strings.Replace(rmsg.Text, "\x1d", "*", -1) + rmsg.Text = strings.Replace(rmsg.Text, "\x1e", "~~", -1) + b.Log.Debugf("<= Sending message from %s on %s to gateway", event.Params[0], b.Account) b.Remote <- rmsg } diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go index 260f66df46..a776d7c4c5 100644 --- a/bridge/irc/irc.go +++ b/bridge/irc/irc.go @@ -6,6 +6,7 @@ import ( "hash/crc32" "io/ioutil" "net" + "regexp" "sort" "strconv" "strings" @@ -164,6 +165,12 @@ func (b *Birc) Send(msg config.Message) (string, error) { var msgLines []string if b.GetBool("StripMarkdown") { msg.Text = stripmd.Strip(msg.Text) + } else { + re := regexp.MustCompile(`\b(\*\*|__)|(\*\*|__)\b`) + msg.Text = re.ReplaceAllString(msg.Text, "\x02") + + re = regexp.MustCompile(`\b(\*|_)|(\*|_)\b`) + msg.Text = re.ReplaceAllString(msg.Text, "\x1d") } if b.GetBool("MessageSplit") { From 83677fceac2d8b5d70f784c7c94da60ef82b6c57 Mon Sep 17 00:00:00 2001 From: Ivanq Date: Wed, 29 Dec 2021 19:17:27 +0300 Subject: [PATCH 2/3] Handle event user actions for ssh-chat --- bridge/sshchat/sshchat.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bridge/sshchat/sshchat.go b/bridge/sshchat/sshchat.go index c7e848ed8b..f60bce8d1e 100644 --- a/bridge/sshchat/sshchat.go +++ b/bridge/sshchat/sshchat.go @@ -72,17 +72,29 @@ func (b *Bsshchat) Send(msg config.Message) (string, error) { return "", nil } b.Log.Debugf("=> Receiving %#v", msg) + + prefix := msg.Username + if msg.Event == config.EventUserAction { + prefix += "/me " + } + string_message := "" for _, line := range strings.Split(msg.Text, "\n") { if strings.TrimSpace(line) != "" { - string_message += msg.Username + line + "\r\n" + if line[0] == '/' { + line = " " + line + } + string_message += prefix + line + "\r\n" } } if msg.Extra != nil { for _, rmsg := range helper.HandleExtra(&msg, b.General) { for _, line := range strings.Split(rmsg.Text, "\n") { if strings.TrimSpace(line) != "" { - string_message += rmsg.Username + line + "\r\n" + if line[0] == '/' { + line = " " + line + } + string_message += prefix + line + "\r\n" } } } From 712e1dfd1ed204e50322a07a82c12d2eaecd8bfd Mon Sep 17 00:00:00 2001 From: Ivanq Date: Wed, 29 Dec 2021 20:05:22 +0300 Subject: [PATCH 3/3] Handle spaces in emote names --- bridge/sshchat/sshchat.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bridge/sshchat/sshchat.go b/bridge/sshchat/sshchat.go index f60bce8d1e..074240d519 100644 --- a/bridge/sshchat/sshchat.go +++ b/bridge/sshchat/sshchat.go @@ -170,9 +170,15 @@ func (b *Bsshchat) handleSSHChat() error { b.Log.Debugf("<= Message %#v", res) if strings.HasPrefix(text, "** ") { // Emote - res := strings.Split(text[3:], " ") - rmsg := config.Message{Username: res[0], Text: strings.TrimSpace(strings.Join(res[1:], " ")), Channel: "sshchat", Account: b.Account, UserID: "nick", Event: config.EventUserAction} - b.Remote <- rmsg + if text[3] == '"' { + res := strings.Split(text[3:], "\"") + rmsg := config.Message{Username: res[1], Text: strings.TrimSpace(strings.Join(res[2:], "\"")), Channel: "sshchat", Account: b.Account, UserID: "nick", Event: config.EventUserAction} + b.Remote <- rmsg + } else { + res := strings.Split(text[3:], " ") + rmsg := config.Message{Username: res[0], Text: strings.TrimSpace(strings.Join(res[1:], " ")), Channel: "sshchat", Account: b.Account, UserID: "nick", Event: config.EventUserAction} + b.Remote <- rmsg + } } else { // Normal message rmsg := config.Message{Username: res[0], Text: strings.TrimSpace(strings.Join(res[1:], ":")), Channel: "sshchat", Account: b.Account, UserID: "nick"}