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
|
||||
|
30
NTFServer.go
30
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
|
||||
}
|
||||
|
||||
|
@ -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