diff --git a/bridge/irc/handlers.go b/bridge/irc/handlers.go index 613a5d91..886e20df 100644 --- a/bridge/irc/handlers.go +++ b/bridge/irc/handlers.go @@ -296,6 +296,7 @@ func (b *Birc) handlePrivMsg(client *girc.Client, event girc.Event) { b.activeUsers[event.Source.Name] = time.Now().Unix() } b.Remote <- rmsg + b.cleanActiveMap() } func (b *Birc) handleRunCommands() { diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go index c7ada599..886ad6a0 100644 --- a/bridge/irc/irc.go +++ b/bridge/irc/irc.go @@ -28,6 +28,7 @@ type Birc struct { Nick string names map[string][]string activeUsers map[string]int64 + activeUsersLastCleaned int64 connected chan error Local chan config.Message // local queue for flood control FirstConnection, authDone bool @@ -68,6 +69,7 @@ func New(cfg *bridge.Config) bridge.Bridger { } else { b.ActivityTimeout = int64(b.GetInt("ActivityTimeout")) } + b.activeUsersLastCleaned = time.Now().Unix() } else { b.ActivityTimeout = 0 // Disable } @@ -89,6 +91,10 @@ func (b *Birc) Connect() error { return errors.New("you can't enable SASL and TLSClientCertificate at the same time") } + if b.GetBool("NoSendJoinPart") && b.GetBool("ShowActiveUserEvents") { + return errors.New("you must disable NoSendJoinPart to use ShowActiveUserEvents") + } + b.Local = make(chan config.Message, b.MessageQueue+10) b.Log.Infof("Connecting %s", b.GetString("Server")) @@ -451,3 +457,16 @@ func (b *Birc) getPseudoChannel() string { b.Log.Warningf("Bot not active in any channels!") return "" } + +func (b *Birc) cleanActiveMap() { + now := time.Now().Unix() + if b.ActivityTimeout == 0 || (b.activeUsersLastCleaned-now < b.ActivityTimeout) { + return + } + for nick, activeTime := range b.activeUsers { + if now-activeTime > b.ActivityTimeout { + b.Log.Debugf("last activity for %s was %d, currently %d. Deleting.", nick, activeTime, now) + delete(b.activeUsers, nick) + } + } +} diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample index 41ab44bf..0d7e78a1 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -191,6 +191,14 @@ RemoteNickFormat="[{PROTOCOL}] <{NICK}> " #OPTIONAL (default false) ShowJoinPart=false +#Only show join/part/quit information for users who have been active recently. +#OPTIONAL (default false) +ShowActiveUserEvents=false + +#A user is considered active for ShowActiveUserEvents if they've spoken within this number of seconds. +#OPTIONAL (default 1800, which is 30 minutes) +ActivityTimeout=1800 + #Enable to show verbose users joins/parts (ident@host) from other bridges #Currently works for messages from the following bridges: irc #OPTIONAL (default false)