mirror of
https://github.com/stryan/mumble-discord-bridge.git
synced 2024-11-22 21:35:44 -05:00
remove local mumble user list
This commit is contained in:
parent
16a66719e1
commit
1f0840bb74
22
bridge.go
22
bridge.go
@ -53,10 +53,6 @@ type BridgeState struct {
|
||||
DiscordUsers map[string]discordUser
|
||||
DiscordUsersMutex sync.Mutex
|
||||
|
||||
// Map of Mumble users tracked by this bridge
|
||||
MumbleUsers map[string]bool
|
||||
MumbleUsersMutex sync.Mutex
|
||||
|
||||
// Total Number of Mumble users
|
||||
MumbleUserCount int
|
||||
|
||||
@ -184,9 +180,6 @@ func (b *BridgeState) startBridge() {
|
||||
b.Connected = false
|
||||
wg.Wait()
|
||||
log.Println("Terminating Bridge")
|
||||
b.MumbleUsersMutex.Lock()
|
||||
b.MumbleUsers = make(map[string]bool)
|
||||
b.MumbleUsersMutex.Unlock()
|
||||
b.DiscordUsers = make(map[string]discordUser)
|
||||
}
|
||||
|
||||
@ -199,27 +192,26 @@ func (b *BridgeState) discordStatusUpdate() {
|
||||
|
||||
if err != nil {
|
||||
log.Printf("error pinging mumble server %v\n", err)
|
||||
b.DiscordSession.UpdateListeningStatus("an error pinging mumble")
|
||||
status = "an error polling mumble"
|
||||
} else {
|
||||
b.MumbleUsersMutex.Lock()
|
||||
b.MumbleUserCount = resp.ConnectedUsers
|
||||
if b.Connected {
|
||||
b.MumbleUserCount = b.MumbleUserCount - 1
|
||||
}
|
||||
|
||||
if b.MumbleUserCount == 0 {
|
||||
status = "No users in Mumble"
|
||||
} else {
|
||||
if len(b.MumbleUsers) > 0 {
|
||||
status = fmt.Sprintf("%v/%v users in Mumble\n", len(b.MumbleUsers), b.MumbleUserCount)
|
||||
channelCount := len(b.MumbleClient.Self.Channel.Users) - 1
|
||||
status = fmt.Sprintf("%v/%v users in Mumble\n", channelCount, b.MumbleUserCount)
|
||||
}
|
||||
} else {
|
||||
status = fmt.Sprintf("%v users in Mumble\n", b.MumbleUserCount)
|
||||
}
|
||||
}
|
||||
b.MumbleUsersMutex.Unlock()
|
||||
|
||||
b.DiscordSession.UpdateListeningStatus(status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AutoBridge starts a goroutine to check the number of users in discord and mumble
|
||||
// when there is at least one user on both, starts up the bridge
|
||||
@ -236,7 +228,6 @@ func (b *BridgeState) AutoBridge() {
|
||||
return
|
||||
}
|
||||
|
||||
b.MumbleUsersMutex.Lock()
|
||||
b.DiscordUsersMutex.Lock()
|
||||
|
||||
if !b.Connected && b.MumbleUserCount > 0 && len(b.DiscordUsers) > 0 {
|
||||
@ -248,7 +239,6 @@ func (b *BridgeState) AutoBridge() {
|
||||
b.BridgeDie <- true
|
||||
}
|
||||
|
||||
b.MumbleUsersMutex.Unlock()
|
||||
b.DiscordUsersMutex.Unlock()
|
||||
}
|
||||
}
|
||||
|
3
main.go
3
main.go
@ -39,7 +39,7 @@ func main() {
|
||||
mumbleUsername := flag.String("mumble-username", lookupEnvOrString("MUMBLE_USERNAME", "Discord"), "MUMBLE_USERNAME, mumble username, (default: discord)")
|
||||
mumblePassword := flag.String("mumble-password", lookupEnvOrString("MUMBLE_PASSWORD", ""), "MUMBLE_PASSWORD, mumble password, optional")
|
||||
mumbleInsecure := flag.Bool("mumble-insecure", lookupEnvOrBool("MUMBLE_INSECURE", false), " MUMBLE_INSECURE, mumble insecure, optional")
|
||||
mumbleChannel := flag.String("mumble-channel", lookupEnvOrString("MUMBLE_CHANNEL", ""), "MUMBLE_CHANNEL, mumble channel to start in, using '/' to seperate nested channels, optional")
|
||||
mumbleChannel := flag.String("mumble-channel", lookupEnvOrString("MUMBLE_CHANNEL", ""), "MUMBLE_CHANNEL, mumble channel to start in, using '/' to separate nested channels, optional")
|
||||
mumbleDisableText := flag.Bool("mumble-disable-text", lookupEnvOrBool("MUMBLE_DISABLE_TEXT", false), "MUMBLE_DISABLE_TEXT, disable sending text to mumble, (default false)")
|
||||
discordToken := flag.String("discord-token", lookupEnvOrString("DISCORD_TOKEN", ""), "DISCORD_TOKEN, discord bot token, required")
|
||||
discordGID := flag.String("discord-gid", lookupEnvOrString("DISCORD_GID", ""), "DISCORD_GID, discord gid, required")
|
||||
@ -110,7 +110,6 @@ func main() {
|
||||
},
|
||||
Connected: false,
|
||||
DiscordUsers: make(map[string]discordUser),
|
||||
MumbleUsers: make(map[string]bool),
|
||||
}
|
||||
|
||||
// MUMBLE SETUP
|
||||
|
@ -21,19 +21,6 @@ func (l *MumbleListener) mumbleConnect(e *gumble.ConnectEvent) {
|
||||
}
|
||||
|
||||
func (l *MumbleListener) mumbleUserChange(e *gumble.UserChangeEvent) {
|
||||
l.Bridge.MumbleUsersMutex.Lock()
|
||||
if e.Type.Has(gumble.UserChangeConnected) || e.Type.Has(gumble.UserChangeChannel) || e.Type.Has(gumble.UserChangeDisconnected) {
|
||||
l.Bridge.MumbleUsers = make(map[string]bool)
|
||||
for _, user := range l.Bridge.MumbleClient.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 != l.Bridge.MumbleClient.Self.Name {
|
||||
l.Bridge.MumbleUsers[user.Name] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
l.Bridge.MumbleUsersMutex.Unlock()
|
||||
|
||||
if e.Type.Has(gumble.UserChangeConnected) {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user