1
0
mirror of https://github.com/stryan/mumble-discord-bridge.git synced 2024-11-14 19:45:41 -05:00

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 // 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() b.lock.Lock()
defer b.lock.Unlock() defer b.lock.Unlock()
@ -90,7 +91,12 @@ func (b *BridgeState) startBridge() {
// DISCORD Connect Voice // DISCORD Connect Voice
log.Println("Attempting to join Discord voice channel") 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 { if err != nil {
log.Println(err) log.Println(err)
b.DiscordVoice.Disconnect() b.DiscordVoice.Disconnect()
@ -241,7 +247,7 @@ func (b *BridgeState) AutoBridge() {
if !b.Connected && b.MumbleUserCount > 0 && len(b.DiscordUsers) > 0 { if !b.Connected && b.MumbleUserCount > 0 && len(b.DiscordUsers) > 0 {
log.Println("users detected in mumble and discord, bridging") 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 { if b.Connected && b.MumbleUserCount == 0 && len(b.DiscordUsers) <= 1 {
log.Println("no one online, killing bridge") 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 { for _, vs := range g.VoiceStates {
if vs.UserID == m.Author.ID { if vs.UserID == m.Author.ID {
log.Printf("Trying to join GID %v and VID %v\n", g.ID, vs.ChannelID) 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 return
} }
} }
@ -114,7 +114,7 @@ func (l *DiscordListener) messageCreate(s *discordgo.Session, m *discordgo.Messa
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
go l.Bridge.startBridge() go l.Bridge.startBridge(vs.ChannelID)
return return
} }
} }
@ -122,10 +122,12 @@ func (l *DiscordListener) messageCreate(s *discordgo.Session, m *discordgo.Messa
if strings.HasPrefix(m.Content, prefix+" auto") { if strings.HasPrefix(m.Content, prefix+" auto") {
if l.Bridge.Mode != bridgeModeAuto { if l.Bridge.Mode != bridgeModeAuto {
l.Bridge.DiscordSession.ChannelMessageSend(m.ChannelID, "Auto mode enabled")
l.Bridge.Mode = bridgeModeAuto l.Bridge.Mode = bridgeModeAuto
l.Bridge.AutoChanDie = make(chan bool) l.Bridge.AutoChanDie = make(chan bool)
go l.Bridge.AutoBridge() go l.Bridge.AutoBridge()
} else { } else {
l.Bridge.DiscordSession.ChannelMessageSend(m.ChannelID, "Auto mode disabled")
l.Bridge.AutoChanDie <- true l.Bridge.AutoChanDie <- true
l.Bridge.Mode = bridgeModeManual l.Bridge.Mode = bridgeModeManual
} }

View File

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