From 449ed31e25f2c21ac9db258999a5a893889983eb Mon Sep 17 00:00:00 2001 From: Wim Date: Mon, 14 Nov 2016 22:53:06 +0100 Subject: [PATCH] Fix ShowJoinPart from irc bridge. Closes #72 --- bridge/config/config.go | 5 ++ bridge/irc/irc.go | 13 ++++ changelog.md | 12 +++- gateway/gateway.go | 8 +++ matterbridge.toml.sample | 134 ++++++++++++++++++++++++--------------- 5 files changed, 120 insertions(+), 52 deletions(-) diff --git a/bridge/config/config.go b/bridge/config/config.go index c577e340..d3d88115 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -8,12 +8,17 @@ import ( "strings" ) +const ( + EVENT_JOIN_LEAVE = "join_leave" +) + type Message struct { Text string Channel string Username string Avatar string Account string + Event string } type Protocol struct { diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go index d6b6c5f6..1540c56f 100644 --- a/bridge/irc/irc.go +++ b/bridge/irc/irc.go @@ -156,11 +156,24 @@ func (b *Birc) handleNewConnection(event *irc.Event) { i.SendRaw("PONG :" + e.Message()) flog.Debugf("PING/PONG") }) + i.AddCallback("JOIN", b.handleJoinPart) + i.AddCallback("PART", b.handleJoinPart) + i.AddCallback("QUIT", b.handleJoinPart) i.AddCallback("*", b.handleOther) // we are now fully connected b.connected <- struct{}{} } +func (b *Birc) handleJoinPart(event *irc.Event) { + flog.Debugf("Sending JOIN_LEAVE event from %s to gateway", b.Account) + channel := event.Arguments[0] + if event.Code == "QUIT" { + channel = "" + } + b.Remote <- config.Message{Username: "system", Text: event.Nick + " " + strings.ToLower(event.Code) + "s", Channel: channel, Account: b.Account, Event: config.EVENT_JOIN_LEAVE} + flog.Debugf("handle %#v", event) +} + func (b *Birc) handleNotice(event *irc.Event) { if strings.Contains(event.Message(), "This nickname is registered") && event.Nick == b.Config.NickServNick { b.i.Privmsg(b.Config.NickServNick, "IDENTIFY "+b.Config.NickServPassword) diff --git a/changelog.md b/changelog.md index 42bca6d1..c7815069 100644 --- a/changelog.md +++ b/changelog.md @@ -1,9 +1,17 @@ -# v0.8 +# v0.9.0-dev +## General +* discord: add "Bot " tag to discord tokens automatically + +## Bugfix +* general: fix ShowJoinPart for messages from irc bridge #72 +* irc: fix !users command #78 + +# v0.8.0 Release because of breaking mattermost API changes ## New features * Supports mattermost v3.5.0 -# v0.7 +# v0.7.0 ## Breaking config changes from 0.6 to 0.7 Matterbridge now uses TOML configuration (https://github.com/toml-lang/toml) See matterbridge.toml.sample for an example diff --git a/gateway/gateway.go b/gateway/gateway.go index 580e129d..63da4bba 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -106,6 +106,10 @@ func (gw *Gateway) mapIgnores() { func (gw *Gateway) getDestChannel(msg *config.Message, dest string) []string { channels := gw.ChannelsIn[msg.Account] + // broadcast to every out channel (irc QUIT) + if msg.Event == config.EVENT_JOIN_LEAVE && msg.Channel == "" { + return gw.ChannelsOut[dest] + } for _, channel := range channels { if channel == msg.Channel { return gw.ChannelsOut[dest] @@ -118,6 +122,10 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) { if gw.ignoreMessage(&msg) { return } + // only relay join/part when configged + if msg.Event == config.EVENT_JOIN_LEAVE && !gw.Bridges[dest.Account].Config.ShowJoinPart { + return + } originchannel := msg.Channel channels := gw.getDestChannel(&msg, dest.Account) for _, channel := range channels { diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample index 3eb05760..831e99f2 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -37,18 +37,6 @@ Nick="matterbot" NickServNick="nickserv" NickServPassword="secret" -#RemoteNickFormat defines how remote users appear on this bridge -#The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. -#The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge -#The string "{PROTOCOL}" (case sensitive) will be replaced by the protocol used by the bridge -#OPTIONAL (default empty) -RemoteNickFormat="[{PROTOCOL}] <{NICK}> " - -#Nicks you want to ignore. -#Messages from those users will not be sent to other bridges. -#OPTIONAL -IgnoreNicks="ircspammer1 ircspammer2" - #Flood control #Delay in milliseconds between each message send to the IRC server #OPTIONAL (default 1300) @@ -60,6 +48,22 @@ MessageDelay=1300 #OPTIONAL (default 30) MessageQueue=30 +#Nicks you want to ignore. +#Messages from those users will not be sent to other bridges. +#OPTIONAL +IgnoreNicks="ircspammer1 ircspammer2" + +#RemoteNickFormat defines how remote users appear on this bridge +#The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. +#The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge +#The string "{PROTOCOL}" (case sensitive) will be replaced by the protocol used by the bridge +#OPTIONAL (default empty) +RemoteNickFormat="[{PROTOCOL}] <{NICK}> " + +#Enable to show users joins/parts from other bridges (only from irc-bridge at the moment) +#OPTIONAL (default false) +ShowJoinPart=false + ################################################################### #XMPP section ################################################################### @@ -89,6 +93,21 @@ Muc="conference.jabber.example.com" #REQUIRED Nick="xmppbot" +#Nicks you want to ignore. +#Messages from those users will not be sent to other bridges. +#OPTIONAL +IgnoreNicks="ircspammer1 ircspammer2" + +#RemoteNickFormat defines how remote users appear on this bridge +#The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. +#The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge +#The string "{PROTOCOL}" (case sensitive) will be replaced by the protocol used by the bridge +#OPTIONAL (default empty) +RemoteNickFormat="[{PROTOCOL}] <{NICK}> " + +#Enable to show users joins/parts from other bridges (only from irc-bridge at the moment) +#OPTIONAL (default false) +ShowJoinPart=false ################################################################### #mattermost section @@ -150,9 +169,13 @@ NoTLS=false #OPTIONAL (default false) SkipTLSVerify=true -#Enable to show IRC joins/parts in mattermost. -#OPTIONAL (default false) -ShowJoinPart=false +#how to format the list of IRC nicks when displayed in mattermost. +#Possible options are "table" and "plain" +#OPTIONAL (default plain) +NickFormatter="plain" +#How many nicks to list per row for formatters that support this. +#OPTIONAL (default 4) +NicksPerRow=4 #Whether to prefix messages from other bridges to mattermost with the sender's nick. #Useful if username overrides for incoming webhooks isn't enabled on the @@ -162,6 +185,11 @@ ShowJoinPart=false #OPTIONAL (default false) PrefixMessagesWithNick=false +#Nicks you want to ignore. +#Messages from those users will not be sent to other bridges. +#OPTIONAL +IgnoreNicks="ircspammer1 ircspammer2" + #RemoteNickFormat defines how remote users appear on this bridge #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. #The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge @@ -169,17 +197,9 @@ PrefixMessagesWithNick=false #OPTIONAL (default empty) RemoteNickFormat="[{PROTOCOL}] <{NICK}> " -#how to format the list of IRC nicks when displayed in mattermost. -#Possible options are "table" and "plain" -#OPTIONAL (default plain) -NickFormatter="plain" -#How many nicks to list per row for formatters that support this. -#OPTIONAL (default 4) -NicksPerRow=4 - -#Nicks you want to ignore. Messages from those users will not be bridged. -#OPTIONAL -IgnoreNicks="mmbot spammer2" +#Enable to show users joins/parts from other bridges (only from irc-bridge at the moment) +#OPTIONAL (default false) +ShowJoinPart=false ################################################################### #Gitter section @@ -197,9 +217,10 @@ IgnoreNicks="mmbot spammer2" #REQUIRED Token="Yourtokenhere" -#Nicks you want to ignore. Messages of those users will not be bridged. -#OPTIONAL -IgnoreNicks="spammer1 spammer2" +#Nicks you want to ignore. +#Messages from those users will not be sent to other bridges. +#OPTIONAL +IgnoreNicks="ircspammer1 ircspammer2" #RemoteNickFormat defines how remote users appear on this bridge #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. @@ -208,6 +229,10 @@ IgnoreNicks="spammer1 spammer2" #OPTIONAL (default empty) RemoteNickFormat="[{PROTOCOL}] <{NICK}> " +#Enable to show users joins/parts from other bridges (only from irc-bridge at the moment) +#OPTIONAL (default false) +ShowJoinPart=false + ################################################################### #slack section ################################################################### @@ -251,21 +276,6 @@ Token="yourslacktoken" #OPTIONAL IconURL="https://robohash.org/{NICK}.png?size=48x48" -#Whether to prefix messages from other bridges to mattermost with RemoteNickFormat -#Useful if username overrides for incoming webhooks isn't enabled on the -#slack server. If you set PrefixMessagesWithNick to true, each message -#from bridge to Slack will by default be prefixed by "bridge-" + nick. You can, -#however, modify how the messages appear, by setting (and modifying) RemoteNickFormat -#OPTIONAL (default false) -PrefixMessagesWithNick=false - -#RemoteNickFormat defines how remote users appear on this bridge -#The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. -#The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge -#The string "{PROTOCOL}" (case sensitive) will be replaced by the protocol used by the bridge -#OPTIONAL (default empty) -RemoteNickFormat="[{PROTOCOL}] <{NICK}> " - #how to format the list of IRC nicks when displayed in slack #Possible options are "table" and "plain" #OPTIONAL (default plain) @@ -274,9 +284,29 @@ NickFormatter="plain" #OPTIONAL (default 4) NicksPerRow=4 -#Nicks you want to ignore. Messages from those users will not be bridged. -#OPTIONAL -IgnoreNicks="mmbot spammer2" +#Whether to prefix messages from other bridges to mattermost with RemoteNickFormat +#Useful if username overrides for incoming webhooks isn't enabled on the +#slack server. If you set PrefixMessagesWithNick to true, each message +#from bridge to Slack will by default be prefixed by "bridge-" + nick. You can, +#however, modify how the messages appear, by setting (and modifying) RemoteNickFormat +#OPTIONAL (default false) +PrefixMessagesWithNick=false + +#Nicks you want to ignore. +#Messages from those users will not be sent to other bridges. +#OPTIONAL +IgnoreNicks="ircspammer1 ircspammer2" + +#RemoteNickFormat defines how remote users appear on this bridge +#The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. +#The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge +#The string "{PROTOCOL}" (case sensitive) will be replaced by the protocol used by the bridge +#OPTIONAL (default empty) +RemoteNickFormat="[{PROTOCOL}] <{NICK}> " + +#Enable to show users joins/parts from other bridges (only from irc-bridge at the moment) +#OPTIONAL (default false) +ShowJoinPart=false ################################################################### #discord section @@ -296,9 +326,10 @@ Token="Yourtokenhere" #REQUIRED Server="yourservername" -#Nicks you want to ignore. Messages of those users will not be bridged. -#OPTIONAL -IgnoreNicks="spammer1 spammer2" +#Nicks you want to ignore. +#Messages from those users will not be sent to other bridges. +#OPTIONAL +IgnoreNicks="ircspammer1 ircspammer2" #RemoteNickFormat defines how remote users appear on this bridge #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. @@ -307,6 +338,9 @@ IgnoreNicks="spammer1 spammer2" #OPTIONAL (default empty) RemoteNickFormat="[{PROTOCOL}] <{NICK}> " +#Enable to show users joins/parts from other bridges (only from irc-bridge at the moment) +#OPTIONAL (default false) +ShowJoinPart=false ################################################################### #Gateway configuration