ignorenicks: use array, BC is not a concern at this stage

This commit is contained in:
mappu 2018-06-05 17:49:24 +12:00
parent 4ffcbadf5c
commit 4a38cb7b39
2 changed files with 14 additions and 22 deletions

View File

@ -10,7 +10,7 @@ import (
type NTFConfig struct { type NTFConfig struct {
HubAddr string HubAddr string
HubDescription string HubDescription string
HubSecNick string // Nickname of Hub-Security to exclude (e.g. "PtokaX"). Separate multiple with commas HubIgnoreNicks []string // Nicknames of Hub-Security/bots to exclude (e.g. "PtokaX").
HubNickMinChars int HubNickMinChars int
BotAPIKey string BotAPIKey string
GroupChatID int64 GroupChatID int64

View File

@ -31,7 +31,6 @@ type NTFServer struct {
config NTFConfig config NTFConfig
conns map[string]*libnmdc.HubConnection // hubnick -> hubconn conns map[string]*libnmdc.HubConnection // hubnick -> hubconn
verbose bool verbose bool
ignoreHubNicks map[string]struct{}
// Except the coalesce buffer, that requires a background worker. // Except the coalesce buffer, that requires a background worker.
coalesceBufferMut sync.Mutex coalesceBufferMut sync.Mutex
@ -66,15 +65,6 @@ func NewNTFServer(configFile string, verbose bool) (*NTFServer, error) {
ret.config = cfg ret.config = cfg
ignoreHubNicks := strings.Split(cfg.HubSecNick, ",")
ret.ignoreHubNicks = make(map[string]struct{}, len(ignoreHubNicks))
for _, v := range ignoreHubNicks {
v := strings.Trim(v, " ")
if len(v) > 0 {
ret.ignoreHubNicks[v] = struct{}{}
}
}
// Coalesce background worker // Coalesce background worker
go ret.coalesceWorker() go ret.coalesceWorker()
@ -312,9 +302,11 @@ func (this *NTFServer) HandleHubMessage(msg upstreamMessage) {
} }
case libnmdc.EVENT_PUBLIC: case libnmdc.EVENT_PUBLIC:
if _, ok := this.ignoreHubNicks[msg.evt.Nick]; ok { for _, ignoreNick := range this.config.HubIgnoreNicks {
if ignoreNick == msg.evt.Nick {
return // ignore return // ignore
} }
}
// Coalesce from multiple connections // Coalesce from multiple connections
if this.Coalesce(msg.evt.Nick, msg.evt.Message) { if this.Coalesce(msg.evt.Nick, msg.evt.Message) {