Thumbnail

rani/matterbridge.git

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

commit c178b1707085f25341696683a6d34474c59d5f1d Author: Wim <wim@42.be> Date: Sat Jan 21 21:00:40 2017 +0000 Fix IgnoreNicks (global). Closes #115 diff --git a/gateway/gateway.go b/gateway/gateway.go index 4177973..82a76ef 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -167 +166 @@ type Gateway struct {   Bridges map[string]*bridge.Bridge   ChannelsOut map[string][]string   ChannelsIn map[string][]string - ignoreNicks map[string][]string   ChannelOptions map[string]config.ChannelOptions   Name string   Message chan config.Message @@ -698 +686 @@ func (gw *Gateway) Start() error {   return err   }   } - //TODO fix mapIgnores - //gw.mapIgnores()   go gw.handleReceive()   return nil  } @@ -798 +7610 @@ func (gw *Gateway) handleReceive() {   for {   select {   case msg := <-gw.Message: - for _, br := range gw.Bridges { - gw.handleMessage(msg, br) + if !gw.ignoreMessage(&msg) { + for _, br := range gw.Bridges { + gw.handleMessage(msg, br) + }   }   }   } @@ -11015 +1096 @@ func (gw *Gateway) mapChannels() error {   return nil  }   -func (gw *Gateway) mapIgnores() { - m := make(map[string][]string) - for _, br := range gw.MyConfig.In { - accInfo := strings.Split(br.Account, ".") - m[br.Account] = strings.Fields(gw.Config.IRC[accInfo[1]].IgnoreNicks) - } - gw.ignoreNicks = m -} -  func (gw *Gateway) getDestChannel(msg *config.Message, dest string) []string {   channels := gw.ChannelsIn[msg.Account]   // broadcast to every out channel (irc QUIT) @@ -1349 +1246 @@ func (gw *Gateway) getDestChannel(msg *config.Message, dest string) []string {  }    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 @@ -1639 +1509 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) {  }    func (gw *Gateway) ignoreMessage(msg *config.Message) bool { - // should we discard messages ? - for _, entry := range gw.ignoreNicks[msg.Account] { + for _, entry := range strings.Fields(gw.Bridges[msg.Account].Config.IgnoreNicks) {   if msg.Username == entry { + log.Debugf("ignoring %s from %s", msg.Username, msg.Account)   return true   }   } diff --git a/gateway/samechannel/samechannel.go b/gateway/samechannel/samechannel.go index 5ea58b8..bd8e360 100644 --- a/gateway/samechannel/samechannel.go +++ b/gateway/samechannel/samechannel.go @@ -478 +4710 @@ func (gw *SameChannelGateway) handleReceive(c chan config.Message) {   for {   select {   case msg := <-c: - for _, br := range gw.Bridges { - gw.handleMessage(msg, br) + if !gw.ignoreMessage(&msg) { + for _, br := range gw.Bridges { + gw.handleMessage(msg, br) + }   }   }   } @@ -716 +7316 @@ func (gw *SameChannelGateway) handleMessage(msg config.Message, dest *bridge.Bri   }  }   +func (gw *SameChannelGateway) ignoreMessage(msg *config.Message) bool { + for _, entry := range strings.Fields(gw.Bridges[msg.Account].Config.IgnoreNicks) { + if msg.Username == entry { + log.Debugf("ignoring %s from %s", msg.Username, msg.Account) + return true + } + } + return false +} +  func (gw *SameChannelGateway) modifyUsername(msg *config.Message, dest *bridge.Bridge) {   br := gw.Bridges[msg.Account]   nick := gw.Config.General.RemoteNickFormat