1
0
mirror of https://github.com/stryan/mumble-discord-bridge.git synced 2024-11-22 21:35:44 -05:00

count how many users are actually in channel

This commit is contained in:
stryan 2021-01-05 19:00:28 -05:00
parent c469a65ed6
commit 1e8a0a4165
2 changed files with 22 additions and 2 deletions

View File

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

View File

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