diff --git a/bridge.go b/bridge.go index d015741..1e6bffc 100644 --- a/bridge.go +++ b/bridge.go @@ -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 @@ -46,7 +47,8 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin tlsConfig.InsecureSkipVerify = true } config.Attach(gumbleutil.Listener{ - Connect: mumbleConnect, + Connect: mumbleConnect, + UserChange: mumbleUserChange, }) mumble, err := gumble.DialWithDialer(new(net.Dialer), mumbleAddr, config, &tlsConfig) @@ -158,7 +160,11 @@ func discordStatusUpdate(dg *discordgo.Session, host, port string) { if curr == 0 { status = "" } else { - status = fmt.Sprintf("%v users in Mumble\n", curr) + 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) } diff --git a/handlers.go b/handlers.go index 6e33cb7..cc7a652 100644 --- a/handlers.go +++ b/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 + } + } + } +}