support multiple ignore nicks (comma-separated for backwards compatibility)
This commit is contained in:
parent
c27708bb9b
commit
bb1fa987fc
@ -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
|
||||
|
12
NTFServer.go
12
NTFServer.go
@ -31,6 +31,7 @@ type NTFServer struct {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user