Fix IgnoreNicks (global). Closes #115

This commit is contained in:
Wim 2017-01-21 21:00:40 +01:00
parent 9bf10e4b58
commit 991183e514
2 changed files with 20 additions and 21 deletions

View File

@ -16,7 +16,6 @@ type Gateway struct {
Bridges map[string]*bridge.Bridge Bridges map[string]*bridge.Bridge
ChannelsOut map[string][]string ChannelsOut map[string][]string
ChannelsIn map[string][]string ChannelsIn map[string][]string
ignoreNicks map[string][]string
ChannelOptions map[string]config.ChannelOptions ChannelOptions map[string]config.ChannelOptions
Name string Name string
Message chan config.Message Message chan config.Message
@ -69,8 +68,6 @@ func (gw *Gateway) Start() error {
return err return err
} }
} }
//TODO fix mapIgnores
//gw.mapIgnores()
go gw.handleReceive() go gw.handleReceive()
return nil return nil
} }
@ -79,11 +76,13 @@ func (gw *Gateway) handleReceive() {
for { for {
select { select {
case msg := <-gw.Message: case msg := <-gw.Message:
if !gw.ignoreMessage(&msg) {
for _, br := range gw.Bridges { for _, br := range gw.Bridges {
gw.handleMessage(msg, br) gw.handleMessage(msg, br)
} }
} }
} }
}
} }
func (gw *Gateway) mapChannels() error { func (gw *Gateway) mapChannels() error {
@ -110,15 +109,6 @@ func (gw *Gateway) mapChannels() error {
return nil 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 { func (gw *Gateway) getDestChannel(msg *config.Message, dest string) []string {
channels := gw.ChannelsIn[msg.Account] channels := gw.ChannelsIn[msg.Account]
// broadcast to every out channel (irc QUIT) // broadcast to every out channel (irc QUIT)
@ -134,9 +124,6 @@ func (gw *Gateway) getDestChannel(msg *config.Message, dest string) []string {
} }
func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) { func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) {
if gw.ignoreMessage(&msg) {
return
}
// only relay join/part when configged // only relay join/part when configged
if msg.Event == config.EVENT_JOIN_LEAVE && !gw.Bridges[dest.Account].Config.ShowJoinPart { if msg.Event == config.EVENT_JOIN_LEAVE && !gw.Bridges[dest.Account].Config.ShowJoinPart {
return return
@ -163,9 +150,9 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) {
} }
func (gw *Gateway) ignoreMessage(msg *config.Message) bool { func (gw *Gateway) ignoreMessage(msg *config.Message) bool {
// should we discard messages ? for _, entry := range strings.Fields(gw.Bridges[msg.Account].Config.IgnoreNicks) {
for _, entry := range gw.ignoreNicks[msg.Account] {
if msg.Username == entry { if msg.Username == entry {
log.Debugf("ignoring %s from %s", msg.Username, msg.Account)
return true return true
} }
} }

View File

@ -47,11 +47,13 @@ func (gw *SameChannelGateway) handleReceive(c chan config.Message) {
for { for {
select { select {
case msg := <-c: case msg := <-c:
if !gw.ignoreMessage(&msg) {
for _, br := range gw.Bridges { for _, br := range gw.Bridges {
gw.handleMessage(msg, br) gw.handleMessage(msg, br)
} }
} }
} }
}
} }
func (gw *SameChannelGateway) handleMessage(msg config.Message, dest *bridge.Bridge) { func (gw *SameChannelGateway) handleMessage(msg config.Message, dest *bridge.Bridge) {
@ -71,6 +73,16 @@ 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) { func (gw *SameChannelGateway) modifyUsername(msg *config.Message, dest *bridge.Bridge) {
br := gw.Bridges[msg.Account] br := gw.Bridges[msg.Account]
nick := gw.Config.General.RemoteNickFormat nick := gw.Config.General.RemoteNickFormat