From 8e5bb4b4794be8da144df8899235eaea92f64ada Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 7 Feb 2021 15:25:02 -0500 Subject: [PATCH] announce auto status change, respect what voice channel used for manual link --- bridge.go | 12 +++++++++--- discord-handlers.go | 6 ++++-- main.go | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bridge.go b/bridge.go index 6e6bac5..0c71c6c 100644 --- a/bridge.go +++ b/bridge.go @@ -73,7 +73,8 @@ type BridgeState struct { } // startBridge established the voice connection -func (b *BridgeState) startBridge() { +// if channelID is empty, use channelID from config +func (b *BridgeState) startBridge(channelID string) { b.lock.Lock() defer b.lock.Unlock() @@ -90,7 +91,12 @@ func (b *BridgeState) startBridge() { // DISCORD Connect Voice log.Println("Attempting to join Discord voice channel") - b.DiscordVoice, err = b.DiscordSession.ChannelVoiceJoin(b.BridgeConfig.GID, b.BridgeConfig.CID, false, false) + if channelID == "" { + b.DiscordVoice, err = b.DiscordSession.ChannelVoiceJoin(b.BridgeConfig.GID, b.BridgeConfig.CID, false, false) + } else { + b.DiscordVoice, err = b.DiscordSession.ChannelVoiceJoin(b.BridgeConfig.GID, channelID, false, false) + } + if err != nil { log.Println(err) b.DiscordVoice.Disconnect() @@ -241,7 +247,7 @@ func (b *BridgeState) AutoBridge() { if !b.Connected && b.MumbleUserCount > 0 && len(b.DiscordUsers) > 0 { log.Println("users detected in mumble and discord, bridging") - go b.startBridge() + go b.startBridge("") } if b.Connected && b.MumbleUserCount == 0 && len(b.DiscordUsers) <= 1 { log.Println("no one online, killing bridge") diff --git a/discord-handlers.go b/discord-handlers.go index ac46684..ea23ea2 100644 --- a/discord-handlers.go +++ b/discord-handlers.go @@ -88,7 +88,7 @@ func (l *DiscordListener) messageCreate(s *discordgo.Session, m *discordgo.Messa for _, vs := range g.VoiceStates { if vs.UserID == m.Author.ID { log.Printf("Trying to join GID %v and VID %v\n", g.ID, vs.ChannelID) - go l.Bridge.startBridge() + go l.Bridge.startBridge(vs.ChannelID) return } } @@ -114,7 +114,7 @@ func (l *DiscordListener) messageCreate(s *discordgo.Session, m *discordgo.Messa time.Sleep(5 * time.Second) - go l.Bridge.startBridge() + go l.Bridge.startBridge(vs.ChannelID) return } } @@ -122,10 +122,12 @@ func (l *DiscordListener) messageCreate(s *discordgo.Session, m *discordgo.Messa if strings.HasPrefix(m.Content, prefix+" auto") { if l.Bridge.Mode != bridgeModeAuto { + l.Bridge.DiscordSession.ChannelMessageSend(m.ChannelID, "Auto mode enabled") l.Bridge.Mode = bridgeModeAuto l.Bridge.AutoChanDie = make(chan bool) go l.Bridge.AutoBridge() } else { + l.Bridge.DiscordSession.ChannelMessageSend(m.ChannelID, "Auto mode disabled") l.Bridge.AutoChanDie <- true l.Bridge.Mode = bridgeModeManual } diff --git a/main.go b/main.go index b39e224..3627262 100644 --- a/main.go +++ b/main.go @@ -174,7 +174,7 @@ func main() { Bridge.Mode = bridgeModeConstant go func() { for { - Bridge.startBridge() + Bridge.startBridge("") log.Println("Bridge died. Restarting") } }()