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 {
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

View File

@ -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