From 4a38cb7b3948bef418a757c1dff669c481feef4d Mon Sep 17 00:00:00 2001 From: mappu Date: Tue, 5 Jun 2018 17:49:24 +1200 Subject: [PATCH] ignorenicks: use array, BC is not a concern at this stage --- NTFConfig.go | 2 +- NTFServer.go | 34 +++++++++++++--------------------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/NTFConfig.go b/NTFConfig.go index e6d5dfe..c5a84d4 100644 --- a/NTFConfig.go +++ b/NTFConfig.go @@ -10,7 +10,7 @@ import ( type NTFConfig struct { HubAddr 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 BotAPIKey string GroupChatID int64 diff --git a/NTFServer.go b/NTFServer.go index e7fa328..a912c29 100644 --- a/NTFServer.go +++ b/NTFServer.go @@ -22,16 +22,15 @@ const ( // NTFServer methods all run on the same thread, so no mutexes are needed for field access type NTFServer struct { - bot *telegram.BotAPI - hubMessages chan upstreamMessage - botName string - chatName string - inviteLink string - configFile string - config NTFConfig - conns map[string]*libnmdc.HubConnection // hubnick -> hubconn - verbose bool - ignoreHubNicks map[string]struct{} + bot *telegram.BotAPI + hubMessages chan upstreamMessage + botName string + chatName string + inviteLink string + configFile string + config NTFConfig + conns map[string]*libnmdc.HubConnection // hubnick -> hubconn + verbose bool // Except the coalesce buffer, that requires a background worker. coalesceBufferMut sync.Mutex @@ -66,15 +65,6 @@ func NewNTFServer(configFile string, verbose bool) (*NTFServer, error) { 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 go ret.coalesceWorker() @@ -312,8 +302,10 @@ func (this *NTFServer) HandleHubMessage(msg upstreamMessage) { } case libnmdc.EVENT_PUBLIC: - if _, ok := this.ignoreHubNicks[msg.evt.Nick]; ok { - return // ignore + for _, ignoreNick := range this.config.HubIgnoreNicks { + if ignoreNick == msg.evt.Nick { + return // ignore + } } // Coalesce from multiple connections