Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 77d5dcf95c7cfc043beccafe0acdab163e8e19f1 Author: Wim <wim@42.be> Date: Sun Nov 22 22:21:02 2020 +0000 Add support for irc to irc notice (irc). Fixes #754 (#1305) diff --git a/bridge/config/config.go b/bridge/config/config.go index 7f8d3a4..7dbbc80 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -266 +267 @@ const (   EventAPIConnected = "api_connected"   EventUserTyping = "user_typing"   EventGetChannelMembers = "get_channel_members" + EventNoticeIRC = "notice_irc"  )    type Message struct { diff --git a/bridge/irc/handlers.go b/bridge/irc/handlers.go index 9089c9a..aaaf42f 100644 --- a/bridge/irc/handlers.go +++ b/bridge/irc/handlers.go @@ -1707 +17014 @@ func (b *Birc) handlePrivMsg(client *girc.Client, event girc.Event) {   if b.skipPrivMsg(event) {   return   } - rmsg := config.Message{Username: event.Source.Name, Channel: strings.ToLower(event.Params[0]), Account: b.Account, UserID: event.Source.Ident + "@" + event.Source.Host} + + rmsg := config.Message{ + Username: event.Source.Name, + Channel: strings.ToLower(event.Params[0]), + Account: b.Account, + UserID: event.Source.Ident + "@" + event.Source.Host, + } +   b.Log.Debugf("== Receiving PRIVMSG: %s %s %#v", event.Source.Name, event.Last(), event)     // set action event @@ -1786 +18511 @@ func (b *Birc) handlePrivMsg(client *girc.Client, event girc.Event) {   rmsg.Event = config.EventUserAction   }   + // set NOTICE event + if event.Command == "NOTICE" { + rmsg.Event = config.EventNoticeIRC + } +   // strip action, we made an event if it was an action   rmsg.Text += event.StripAction()   diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go index 4be15b5..8470a1c 100644 --- a/bridge/irc/irc.go +++ b/bridge/irc/irc.go @@ -2129 +21214 @@ func (b *Birc) doSend() {   colorCode := checksum%14 + 2 // quick fix - prevent white or black color codes   username = fmt.Sprintf("\x03%02d%s\x0F", colorCode, msg.Username)   } - if msg.Event == config.EventUserAction { + + switch msg.Event { + case config.EventUserAction:   b.i.Cmd.Action(msg.Channel, username+msg.Text) - } else { + case config.EventNoticeIRC: + b.Log.Debugf("Sending notice to channel %s", msg.Channel) + b.i.Cmd.Notice(msg.Channel, username+msg.Text) + default:   b.Log.Debugf("Sending to channel %s", msg.Channel)   b.i.Cmd.Message(msg.Channel, username+msg.Text)   } @@ -2917 +2967 @@ func (b *Birc) skipPrivMsg(event girc.Event) bool {   b.Nick = b.i.GetNick()     // freenode doesn't send 001 as first reply - if event.Command == "NOTICE" { + if event.Command == "NOTICE" && len(event.Params) != 2 {   return true   }   // don't forward queries to the bot diff --git a/gateway/gateway.go b/gateway/gateway.go index c1440c0..1508ced 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -4306 +43011 @@ func (gw *Gateway) SendMessage(   }   }   + // Only send irc notices to irc + if msg.Event == config.EventNoticeIRC && dest.Protocol != "irc" { + return "", nil + } +   // Too noisy to log like other events   debugSendMessage := ""   if msg.Event != config.EventUserTyping {