ignorenicks: use array, BC is not a concern at this stage
This commit is contained in:
parent
4ffcbadf5c
commit
4a38cb7b39
@ -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
|
||||||
|
34
NTFServer.go
34
NTFServer.go
@ -22,16 +22,15 @@ const (
|
|||||||
|
|
||||||
// NTFServer methods all run on the same thread, so no mutexes are needed for field access
|
// NTFServer methods all run on the same thread, so no mutexes are needed for field access
|
||||||
type NTFServer struct {
|
type NTFServer struct {
|
||||||
bot *telegram.BotAPI
|
bot *telegram.BotAPI
|
||||||
hubMessages chan upstreamMessage
|
hubMessages chan upstreamMessage
|
||||||
botName string
|
botName string
|
||||||
chatName string
|
chatName string
|
||||||
inviteLink string
|
inviteLink string
|
||||||
configFile string
|
configFile string
|
||||||
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,8 +302,10 @@ 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 {
|
||||||
return // ignore
|
if ignoreNick == msg.evt.Nick {
|
||||||
|
return // ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Coalesce from multiple connections
|
// Coalesce from multiple connections
|
||||||
|
Loading…
Reference in New Issue
Block a user