diff --git a/NTFConfig.go b/NTFConfig.go index 7524bc8..e6d5dfe 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") + HubSecNick string // Nickname of Hub-Security to exclude (e.g. "PtokaX"). Separate multiple with commas HubNickMinChars int BotAPIKey string GroupChatID int64 diff --git a/NTFServer.go b/NTFServer.go index 5963ded..7723b7f 100644 --- a/NTFServer.go +++ b/NTFServer.go @@ -22,15 +22,16 @@ 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 + 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{} // Except the coalesce buffer, that requires a background worker. coalesceBufferMut sync.Mutex @@ -65,6 +66,15 @@ 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() @@ -302,7 +312,7 @@ func (this *NTFServer) HandleHubMessage(msg upstreamMessage) { } case libnmdc.EVENT_PUBLIC: - if msg.evt.Nick == this.config.HubSecNick { + if _, ok := this.ignoreHubNicks[msg.evt.Nick]; ok { return // ignore } diff --git a/README.txt b/README.txt index a975084..6ceac24 100644 --- a/README.txt +++ b/README.txt @@ -6,7 +6,7 @@ Written in Go ## FEATURES - NMDC/ADC support -- Exclude messages from hub-security nicks +- Exclude messages from multiple hub nicks (e.g. hub-security, any helper bots that are unnecessary given telegram's features) - Standalone binary ## SETUP