From b7b1065abbdbe3181291299f24dc6024949ad6b2 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 5 Jan 2021 11:41:33 -0500 Subject: [PATCH] use mumble client more,finally get user count right --- bridge.go | 14 ++++++-------- handlers.go | 9 ++++++--- main.go | 5 +++++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/bridge.go b/bridge.go index 170bf8a..cd57238 100644 --- a/bridge.go +++ b/bridge.go @@ -18,7 +18,6 @@ type BridgeState struct { ActiveConn chan bool Connected bool Client *gumble.Client - CurrentChannel *gumble.Channel DiscordUsers map[string]bool MumbleUserCount int DiscordUserCount int @@ -33,7 +32,6 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin } defer dgv.Speaking(false) defer dgv.Close() - Bridge.Connected = true discord.ShouldReconnectOnError = true // MUMBLE Setup @@ -58,10 +56,10 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin if BridgeConf.MumbleChannel != "" { //join specified channel startingChannel := mumble.Channels.Find(BridgeConf.MumbleChannel) - mumble.Self.Move(startingChannel) - Bridge.CurrentChannel = startingChannel + if startingChannel != nil { + mumble.Self.Move(startingChannel) + } } - // Shared Channels // Shared channels pass PCM information in 10ms chunks [480]int16 var toMumble = mumble.AudioOutgoing() @@ -106,7 +104,6 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin //Setup initial discord state g, err := discord.State.Guild(discordGID) - Bridge.DiscordUsers = make(map[string]bool) if err != nil { log.Println("error finding guild") panic(err) @@ -118,10 +115,11 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin if err != nil { log.Println("error looking up username") Bridge.DiscordUsers[u.Username] = true - Bridge.CurrentChannel.Send(fmt.Sprintf("%v has joined Discord channel\n", u.Username), false) + Bridge.Client.Self.Channel.Send(fmt.Sprintf("%v has joined Discord channel\n", u.Username), false) } } } + Bridge.Connected = true select { case sig := <-c: @@ -137,7 +135,7 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin Bridge.Client = nil Bridge.MumbleUserCount = 0 Bridge.DiscordUserCount = 0 - Bridge.DiscordUsers = nil + Bridge.DiscordUsers = make(map[string]bool) } } diff --git a/handlers.go b/handlers.go index b7bcca0..90ad45d 100644 --- a/handlers.go +++ b/handlers.go @@ -151,9 +151,10 @@ func voiceUpdate(s *discordgo.Session, event *discordgo.VoiceStateUpdate) { } log.Println("user joined watched discord channel") if Bridge.Connected { - Bridge.CurrentChannel.Send(fmt.Sprintf("%v has joined Discord channel\n", u.Username), false) - Bridge.DiscordUsers[u.Username] = true + Bridge.Client.Self.Channel.Send(fmt.Sprintf("%v has joined Discord channel\n", u.Username), false) } + Bridge.DiscordUsers[u.Username] = true + log.Println(Bridge.DiscordUsers) Bridge.DiscordUserCount = Bridge.DiscordUserCount + 1 } if event.ChannelID == "" { @@ -179,7 +180,9 @@ func voiceUpdate(s *discordgo.Session, event *discordgo.VoiceStateUpdate) { } delete(Bridge.DiscordUsers, u.Username) log.Println("user left watched discord channel") - Bridge.CurrentChannel.Send(fmt.Sprintf("%v has left Discord channel\n", u.Username), false) + if Bridge.Connected { + Bridge.Client.Self.Channel.Send(fmt.Sprintf("%v has left Discord channel\n", u.Username), false) + } Bridge.DiscordUserCount = count } } diff --git a/main.go b/main.go index bd20318..8fca563 100644 --- a/main.go +++ b/main.go @@ -51,6 +51,10 @@ func main() { if *discordCID == "" { log.Fatalln("missing discord cid") } + err := syscall.Setpriority(syscall.PRIO_PROCESS, os.Getpid(), -5) + if err != nil { + log.Println("Unable to set priority. ", err) + } // DISCORD Setup @@ -98,6 +102,7 @@ func main() { Connected: false, MumbleUserCount: 0, DiscordUserCount: 0, + DiscordUsers: make(map[string]bool), } go discordStatusUpdate(discord, *mumbleAddr, strconv.Itoa(*mumblePort)) if *autoMode {