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") { diff --git a/bridge/sshchat/sshchat.go b/bridge/sshchat/sshchat.go index c7e848ed8b..074240d519 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" } } } @@ -158,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"}