count how many users are actually in channel
This commit is contained in:
parent
c469a65ed6
commit
1e8a0a4165
@ -20,6 +20,7 @@ type BridgeState struct {
|
||||
Connected bool
|
||||
Client *gumble.Client
|
||||
DiscordUsers map[string]bool
|
||||
MumbleUsers map[string]bool
|
||||
MumbleUserCount int
|
||||
DiscordUserCount int
|
||||
AutoChan chan bool
|
||||
@ -47,6 +48,7 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
|
||||
}
|
||||
config.Attach(gumbleutil.Listener{
|
||||
Connect: mumbleConnect,
|
||||
UserChange: mumbleUserChange,
|
||||
})
|
||||
mumble, err := gumble.DialWithDialer(new(net.Dialer), mumbleAddr, config, &tlsConfig)
|
||||
|
||||
@ -157,9 +159,13 @@ func discordStatusUpdate(dg *discordgo.Session, host, port string) {
|
||||
}
|
||||
if curr == 0 {
|
||||
status = ""
|
||||
} else {
|
||||
if len(Bridge.MumbleUsers) > 0 {
|
||||
status = fmt.Sprintf("%v/%v users in Mumble\n", len(Bridge.MumbleUsers), curr)
|
||||
} else {
|
||||
status = fmt.Sprintf("%v users in Mumble\n", curr)
|
||||
}
|
||||
}
|
||||
dg.UpdateListeningStatus(status)
|
||||
}
|
||||
}
|
||||
|
14
handlers.go
14
handlers.go
@ -203,3 +203,17 @@ func mumbleConnect(e *gumble.ConnectEvent) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mumbleUserChange(e *gumble.UserChangeEvent) {
|
||||
if e.Type.Has(gumble.UserChangeConnected) || e.Type.Has(gumble.UserChangeChannel) || e.Type.Has(gumble.UserChangeDisconnected) {
|
||||
Bridge.MumbleUsers = make(map[string]bool)
|
||||
for _, user := range Bridge.Client.Self.Channel.Users {
|
||||
//note, this might be too slow for really really big channels?
|
||||
//event listeners block while processing
|
||||
//also probably bad to rebuild the set every user change.
|
||||
if user.Name != Bridge.Client.Self.Name {
|
||||
Bridge.MumbleUsers[user.Name] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user