mirror of
https://github.com/stryan/mumble-discord-bridge.git
synced 2024-11-22 21:35:44 -05:00
store channelid in state so other functions can use it
This commit is contained in:
parent
8e5bb4b479
commit
027d970c11
16
bridge.go
16
bridge.go
@ -70,11 +70,13 @@ type BridgeState struct {
|
|||||||
// Mumble Duplex and Event Listener
|
// Mumble Duplex and Event Listener
|
||||||
MumbleStream *MumbleDuplex
|
MumbleStream *MumbleDuplex
|
||||||
MumbleListener *MumbleListener
|
MumbleListener *MumbleListener
|
||||||
|
|
||||||
|
// Discord Voice channel to join
|
||||||
|
DiscordChannelID string
|
||||||
}
|
}
|
||||||
|
|
||||||
// startBridge established the voice connection
|
// startBridge established the voice connection
|
||||||
// if channelID is empty, use channelID from config
|
func (b *BridgeState) startBridge() {
|
||||||
func (b *BridgeState) startBridge(channelID string) {
|
|
||||||
b.lock.Lock()
|
b.lock.Lock()
|
||||||
defer b.lock.Unlock()
|
defer b.lock.Unlock()
|
||||||
|
|
||||||
@ -91,11 +93,11 @@ func (b *BridgeState) startBridge(channelID string) {
|
|||||||
|
|
||||||
// DISCORD Connect Voice
|
// DISCORD Connect Voice
|
||||||
log.Println("Attempting to join Discord voice channel")
|
log.Println("Attempting to join Discord voice channel")
|
||||||
if channelID == "" {
|
if b.DiscordChannelID == "" {
|
||||||
b.DiscordVoice, err = b.DiscordSession.ChannelVoiceJoin(b.BridgeConfig.GID, b.BridgeConfig.CID, false, false)
|
log.Println("Tried to start bridge but no Discord channel specified")
|
||||||
} else {
|
return
|
||||||
b.DiscordVoice, err = b.DiscordSession.ChannelVoiceJoin(b.BridgeConfig.GID, channelID, false, false)
|
|
||||||
}
|
}
|
||||||
|
b.DiscordVoice, err = b.DiscordSession.ChannelVoiceJoin(b.BridgeConfig.GID, b.DiscordChannelID, false, false)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -247,7 +249,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")
|
||||||
|
@ -24,7 +24,7 @@ func (l *DiscordListener) guildCreate(s *discordgo.Session, event *discordgo.Gui
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, vs := range event.VoiceStates {
|
for _, vs := range event.VoiceStates {
|
||||||
if vs.ChannelID == l.Bridge.BridgeConfig.CID {
|
if vs.ChannelID == l.Bridge.DiscordChannelID {
|
||||||
if s.State.User.ID == vs.UserID {
|
if s.State.User.ID == vs.UserID {
|
||||||
// Ignore bot
|
// Ignore bot
|
||||||
continue
|
continue
|
||||||
@ -88,7 +88,8 @@ 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(vs.ChannelID)
|
l.Bridge.DiscordChannelID = vs.ChannelID
|
||||||
|
go l.Bridge.startBridge()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,7 +115,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(vs.ChannelID)
|
go l.Bridge.startBridge()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,10 +125,12 @@ func (l *DiscordListener) messageCreate(s *discordgo.Session, m *discordgo.Messa
|
|||||||
if l.Bridge.Mode != bridgeModeAuto {
|
if l.Bridge.Mode != bridgeModeAuto {
|
||||||
l.Bridge.DiscordSession.ChannelMessageSend(m.ChannelID, "Auto mode enabled")
|
l.Bridge.DiscordSession.ChannelMessageSend(m.ChannelID, "Auto mode enabled")
|
||||||
l.Bridge.Mode = bridgeModeAuto
|
l.Bridge.Mode = bridgeModeAuto
|
||||||
|
l.Bridge.DiscordChannelID = l.Bridge.BridgeConfig.CID
|
||||||
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.DiscordSession.ChannelMessageSend(m.ChannelID, "Auto mode disabled")
|
||||||
|
l.Bridge.DiscordChannelID = ""
|
||||||
l.Bridge.AutoChanDie <- true
|
l.Bridge.AutoChanDie <- true
|
||||||
l.Bridge.Mode = bridgeModeManual
|
l.Bridge.Mode = bridgeModeManual
|
||||||
}
|
}
|
||||||
@ -154,7 +157,7 @@ func (l *DiscordListener) voiceUpdate(s *discordgo.Session, event *discordgo.Voi
|
|||||||
|
|
||||||
// Sync the channel voice states to the local discordUsersMap
|
// Sync the channel voice states to the local discordUsersMap
|
||||||
for _, vs := range g.VoiceStates {
|
for _, vs := range g.VoiceStates {
|
||||||
if vs.ChannelID == l.Bridge.BridgeConfig.CID {
|
if vs.ChannelID == l.Bridge.DiscordChannelID {
|
||||||
if s.State.User.ID == vs.UserID {
|
if s.State.User.ID == vs.UserID {
|
||||||
// Ignore bot
|
// Ignore bot
|
||||||
continue
|
continue
|
||||||
|
4
main.go
4
main.go
@ -165,6 +165,7 @@ func main() {
|
|||||||
log.Println("bridge starting in automatic mode")
|
log.Println("bridge starting in automatic mode")
|
||||||
Bridge.AutoChanDie = make(chan bool)
|
Bridge.AutoChanDie = make(chan bool)
|
||||||
Bridge.Mode = bridgeModeAuto
|
Bridge.Mode = bridgeModeAuto
|
||||||
|
Bridge.DiscordChannelID = Bridge.BridgeConfig.CID
|
||||||
go Bridge.AutoBridge()
|
go Bridge.AutoBridge()
|
||||||
case "manual":
|
case "manual":
|
||||||
log.Println("bridge starting in manual mode")
|
log.Println("bridge starting in manual mode")
|
||||||
@ -172,9 +173,10 @@ func main() {
|
|||||||
case "constant":
|
case "constant":
|
||||||
log.Println("bridge starting in constant mode")
|
log.Println("bridge starting in constant mode")
|
||||||
Bridge.Mode = bridgeModeConstant
|
Bridge.Mode = bridgeModeConstant
|
||||||
|
Bridge.DiscordChannelID = Bridge.BridgeConfig.CID
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
Bridge.startBridge("")
|
Bridge.startBridge()
|
||||||
log.Println("Bridge died. Restarting")
|
log.Println("Bridge died. Restarting")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
Loading…
Reference in New Issue
Block a user