add auto_mode flag

This commit is contained in:
stryan 2021-01-03 15:45:12 -05:00
parent 4b8e6eea55
commit 77cf328955
4 changed files with 11 additions and 4 deletions

View File

@ -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()
}
}
}

View File

@ -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

View File

@ -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

View File

@ -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")
}