Add documentation and periodic cleanup.

This commit is contained in:
Kufat 2022-08-06 18:01:28 -04:00
parent a8d99c119e
commit 5a6d2abc23
3 changed files with 28 additions and 0 deletions

View File

@ -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() {

View File

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

View File

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