mirror of
https://github.com/42wim/matterbridge.git
synced 2025-02-22 13:19:01 -08:00
Add documentation and periodic cleanup.
This commit is contained in:
parent
a8d99c119e
commit
5a6d2abc23
@ -296,6 +296,7 @@ func (b *Birc) handlePrivMsg(client *girc.Client, event girc.Event) {
|
|||||||
b.activeUsers[event.Source.Name] = time.Now().Unix()
|
b.activeUsers[event.Source.Name] = time.Now().Unix()
|
||||||
}
|
}
|
||||||
b.Remote <- rmsg
|
b.Remote <- rmsg
|
||||||
|
b.cleanActiveMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Birc) handleRunCommands() {
|
func (b *Birc) handleRunCommands() {
|
||||||
|
@ -28,6 +28,7 @@ type Birc struct {
|
|||||||
Nick string
|
Nick string
|
||||||
names map[string][]string
|
names map[string][]string
|
||||||
activeUsers map[string]int64
|
activeUsers map[string]int64
|
||||||
|
activeUsersLastCleaned int64
|
||||||
connected chan error
|
connected chan error
|
||||||
Local chan config.Message // local queue for flood control
|
Local chan config.Message // local queue for flood control
|
||||||
FirstConnection, authDone bool
|
FirstConnection, authDone bool
|
||||||
@ -68,6 +69,7 @@ func New(cfg *bridge.Config) bridge.Bridger {
|
|||||||
} else {
|
} else {
|
||||||
b.ActivityTimeout = int64(b.GetInt("ActivityTimeout"))
|
b.ActivityTimeout = int64(b.GetInt("ActivityTimeout"))
|
||||||
}
|
}
|
||||||
|
b.activeUsersLastCleaned = time.Now().Unix()
|
||||||
} else {
|
} else {
|
||||||
b.ActivityTimeout = 0 // Disable
|
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")
|
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.Local = make(chan config.Message, b.MessageQueue+10)
|
||||||
b.Log.Infof("Connecting %s", b.GetString("Server"))
|
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!")
|
b.Log.Warningf("Bot not active in any channels!")
|
||||||
return ""
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -191,6 +191,14 @@ RemoteNickFormat="[{PROTOCOL}] <{NICK}> "
|
|||||||
#OPTIONAL (default false)
|
#OPTIONAL (default false)
|
||||||
ShowJoinPart=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
|
#Enable to show verbose users joins/parts (ident@host) from other bridges
|
||||||
#Currently works for messages from the following bridges: irc
|
#Currently works for messages from the following bridges: irc
|
||||||
#OPTIONAL (default false)
|
#OPTIONAL (default false)
|
||||||
|
Loading…
Reference in New Issue
Block a user