mirror of
https://github.com/stryan/mumble-discord-bridge.git
synced 2024-11-23 05:45:41 -05:00
count how many users are actually in channel
This commit is contained in:
parent
c469a65ed6
commit
1e8a0a4165
10
bridge.go
10
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)
|
||||
}
|
||||
|
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