mirror of
https://github.com/stryan/mumble-discord-bridge.git
synced 2024-11-23 05:45:41 -05:00
remove local mumble user list
This commit is contained in:
parent
16a66719e1
commit
1f0840bb74
30
bridge.go
30
bridge.go
@ -53,10 +53,6 @@ type BridgeState struct {
|
|||||||
DiscordUsers map[string]discordUser
|
DiscordUsers map[string]discordUser
|
||||||
DiscordUsersMutex sync.Mutex
|
DiscordUsersMutex sync.Mutex
|
||||||
|
|
||||||
// Map of Mumble users tracked by this bridge
|
|
||||||
MumbleUsers map[string]bool
|
|
||||||
MumbleUsersMutex sync.Mutex
|
|
||||||
|
|
||||||
// Total Number of Mumble users
|
// Total Number of Mumble users
|
||||||
MumbleUserCount int
|
MumbleUserCount int
|
||||||
|
|
||||||
@ -184,9 +180,6 @@ func (b *BridgeState) startBridge() {
|
|||||||
b.Connected = false
|
b.Connected = false
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
log.Println("Terminating Bridge")
|
log.Println("Terminating Bridge")
|
||||||
b.MumbleUsersMutex.Lock()
|
|
||||||
b.MumbleUsers = make(map[string]bool)
|
|
||||||
b.MumbleUsersMutex.Unlock()
|
|
||||||
b.DiscordUsers = make(map[string]discordUser)
|
b.DiscordUsers = make(map[string]discordUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,25 +192,24 @@ func (b *BridgeState) discordStatusUpdate() {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error pinging mumble server %v\n", err)
|
log.Printf("error pinging mumble server %v\n", err)
|
||||||
b.DiscordSession.UpdateListeningStatus("an error pinging mumble")
|
status = "an error polling mumble"
|
||||||
} else {
|
} else {
|
||||||
b.MumbleUsersMutex.Lock()
|
|
||||||
b.MumbleUserCount = resp.ConnectedUsers
|
b.MumbleUserCount = resp.ConnectedUsers
|
||||||
if b.Connected {
|
if b.Connected {
|
||||||
b.MumbleUserCount = b.MumbleUserCount - 1
|
b.MumbleUserCount = b.MumbleUserCount - 1
|
||||||
}
|
|
||||||
if b.MumbleUserCount == 0 {
|
if b.MumbleUserCount == 0 {
|
||||||
status = "No users in Mumble"
|
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)
|
|
||||||
} else {
|
} else {
|
||||||
status = fmt.Sprintf("%v users in Mumble\n", 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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b.DiscordSession.UpdateListeningStatus(status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +228,6 @@ func (b *BridgeState) AutoBridge() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
b.MumbleUsersMutex.Lock()
|
|
||||||
b.DiscordUsersMutex.Lock()
|
b.DiscordUsersMutex.Lock()
|
||||||
|
|
||||||
if !b.Connected && b.MumbleUserCount > 0 && len(b.DiscordUsers) > 0 {
|
if !b.Connected && b.MumbleUserCount > 0 && len(b.DiscordUsers) > 0 {
|
||||||
@ -248,7 +239,6 @@ func (b *BridgeState) AutoBridge() {
|
|||||||
b.BridgeDie <- true
|
b.BridgeDie <- true
|
||||||
}
|
}
|
||||||
|
|
||||||
b.MumbleUsersMutex.Unlock()
|
|
||||||
b.DiscordUsersMutex.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)")
|
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")
|
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")
|
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)")
|
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")
|
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")
|
discordGID := flag.String("discord-gid", lookupEnvOrString("DISCORD_GID", ""), "DISCORD_GID, discord gid, required")
|
||||||
@ -110,7 +110,6 @@ func main() {
|
|||||||
},
|
},
|
||||||
Connected: false,
|
Connected: false,
|
||||||
DiscordUsers: make(map[string]discordUser),
|
DiscordUsers: make(map[string]discordUser),
|
||||||
MumbleUsers: make(map[string]bool),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MUMBLE SETUP
|
// MUMBLE SETUP
|
||||||
|
@ -21,19 +21,6 @@ func (l *MumbleListener) mumbleConnect(e *gumble.ConnectEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *MumbleListener) mumbleUserChange(e *gumble.UserChangeEvent) {
|
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) {
|
if e.Type.Has(gumble.UserChangeConnected) {
|
||||||
|
|
||||||
@ -54,7 +41,7 @@ func (l *MumbleListener) mumbleUserChange(e *gumble.UserChangeEvent) {
|
|||||||
arr = append(arr, l.Bridge.DiscordUsers[u].username)
|
arr = append(arr, l.Bridge.DiscordUsers[u].username)
|
||||||
}
|
}
|
||||||
|
|
||||||
s = s + strings.Join(arr[:], ",")
|
s = s + strings.Join(arr[:], ", ")
|
||||||
|
|
||||||
l.Bridge.DiscordUsersMutex.Unlock()
|
l.Bridge.DiscordUsersMutex.Unlock()
|
||||||
e.User.Send(s)
|
e.User.Send(s)
|
||||||
|
Loading…
Reference in New Issue
Block a user