announce auto status change, respect what voice channel used for manual link

This commit is contained in:
stryan 2021-02-07 15:25:02 -05:00
parent 16a66719e1
commit 8e5bb4b479
3 changed files with 14 additions and 6 deletions

View File

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

View File

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

View File

@ -174,7 +174,7 @@ func main() {
Bridge.Mode = bridgeModeConstant
go func() {
for {
Bridge.startBridge()
Bridge.startBridge("")
log.Println("Bridge died. Restarting")
}
}()