From 77cf32895506f1349597873f98ed09c79b11eb1a Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 3 Jan 2021 15:45:12 -0500 Subject: [PATCH] add auto_mode flag --- bridge.go | 3 ++- discord.go | 1 - main.go | 8 ++++++-- mumble.go | 3 +++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bridge.go b/bridge.go index 1884066..6efd2ca 100644 --- a/bridge.go +++ b/bridge.go @@ -135,10 +135,11 @@ func AutoBridge(s *discordgo.Session) { Bridge.ActiveConn = die go startBridge(s, BridgeConf.GID, BridgeConf.CID, BridgeConf.Config, BridgeConf.MumbleAddr, BridgeConf.MumbleInsecure, die) } - log.Printf("DU: %v MU %v\n", Bridge.DiscordUserCount, Bridge.MumbleUserCount) if Bridge.Connected && Bridge.MumbleUserCount == 0 && Bridge.DiscordUserCount <= 1 { log.Println("no one online, killing bridge") Bridge.ActiveConn <- true + MumbleReset() + DiscordReset() } } } diff --git a/discord.go b/discord.go index 966c66f..fb08488 100644 --- a/discord.go +++ b/discord.go @@ -68,7 +68,6 @@ func discordSendPCM(v *discordgo.VoiceConnection, pcm <-chan []int16, die chan b } <-ticker.C if len(pcm) > 1 { - log.Println("looking for speech") if !streaming { v.Speaking(true) streaming = true diff --git a/main.go b/main.go index 9d53808..8c85a40 100644 --- a/main.go +++ b/main.go @@ -31,6 +31,7 @@ func main() { discordGID := flag.String("discord-gid", lookupEnvOrString("DISCORD_GID", ""), "DISCORD_GID, discord gid") discordCID := flag.String("discord-cid", lookupEnvOrString("DISCORD_CID", ""), "DISCORD_CID, discord cid") discordCommand := flag.String("discord-command", lookupEnvOrString("DISCORD_COMMAND", "mumble-discord"), "Discord command string, env alt DISCORD_COMMAND, optional, defaults to mumble-discord") + autoMode := flag.Bool("auto", lookupEnvOrBool("AUTO_MODE", false), "bridge starts in auto mode") flag.Parse() log.Printf("app.config %v\n", getConfig(flag.CommandLine)) @@ -86,7 +87,7 @@ func main() { Config: config, MumbleAddr: *mumbleAddr + ":" + strconv.Itoa(*mumblePort), MumbleInsecure: *mumbleInsecure, - Auto: false, + Auto: *autoMode, Command: *discordCommand, GID: *discordGID, CID: *discordCID, @@ -100,7 +101,10 @@ func main() { userCount := make(chan int) go pingMumble(*mumbleAddr, strconv.Itoa(*mumblePort), userCount) go discordStatusUpdate(discord, userCount) - + if *autoMode { + Bridge.AutoChan = make(chan bool) + go AutoBridge(discord) + } sc := make(chan os.Signal, 1) signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill) <-sc diff --git a/mumble.go b/mumble.go index fbb12a0..09141bc 100644 --- a/mumble.go +++ b/mumble.go @@ -105,6 +105,9 @@ func (m MumbleDuplex) fromMumbleMixer(toDiscord chan []int16, die chan bool) { if sendAudio { select { case toDiscord <- outBuf: + case <-die: + log.Println("Killing fromMumbleMixer") + return default: log.Println("toDiscord buffer full. Dropping packet") }