From f63b9d005cc13053aede1f2850c7556962cc7dcb Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 3 Jan 2021 20:20:03 -0500 Subject: [PATCH] send message in mumble when user joins in discord --- bridge.go | 20 ++++++++++++++++++++ config.go | 9 +-------- handlers.go | 7 +++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/bridge.go b/bridge.go index a6bc1fc..571c0cf 100644 --- a/bridge.go +++ b/bridge.go @@ -14,6 +14,16 @@ import ( "layeh.com/gumble/gumble" ) +type BridgeState struct { + ActiveConn chan bool + Connected bool + Client *gumble.Client + CurrentChannel *gumble.Channel + MumbleUserCount int + DiscordUserCount int + AutoChan chan bool +} + func startBridge(discord *discordgo.Session, discordGID string, discordCID string, config *gumble.Config, mumbleAddr string, mumbleInsecure bool, die chan bool) { dgv, err := discord.ChannelVoiceJoin(discordGID, discordCID, false, false) if err != nil { @@ -43,6 +53,13 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin return } defer mumble.Disconnect() + Bridge.Client = mumble + if BridgeConf.MumbleChannel != "" { + //join specified channel + startingChannel := mumble.Channels.Find(BridgeConf.MumbleChannel) + mumble.Self.Move(startingChannel) + Bridge.CurrentChannel = startingChannel + } // Shared Channels // Shared channels pass PCM information in 10ms chunks [480]int16 @@ -97,6 +114,9 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin close(m.Close) close(toMumble) Bridge.Connected = false + Bridge.Client = nil + Bridge.MumbleUserCount = 0 + Bridge.DiscordUserCount = 0 } } diff --git a/config.go b/config.go index 295f809..b71d926 100644 --- a/config.go +++ b/config.go @@ -14,20 +14,13 @@ type BridgeConfig struct { Config *gumble.Config MumbleAddr string MumbleInsecure bool + MumbleChannel string Auto bool Command string GID string CID string } -type BridgeState struct { - ActiveConn chan bool - Connected bool - MumbleUserCount int - DiscordUserCount int - AutoChan chan bool -} - func lookupEnvOrString(key string, defaultVal string) string { if val, ok := os.LookupEnv(key); ok { return val diff --git a/handlers.go b/handlers.go index 4ce0c15..482ec08 100644 --- a/handlers.go +++ b/handlers.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "log" "strings" "time" @@ -139,6 +140,12 @@ func voiceUpdate(s *discordgo.Session, event *discordgo.VoiceStateUpdate) { if event.GuildID == BridgeConf.GID { if event.ChannelID == BridgeConf.CID { log.Println("user joined watched discord channel") + u, err := s.User(event.UserID) + if err != nil { + log.Printf("error looking up user for uid %v", event.UserID) + } else { + Bridge.CurrentChannel.Send(fmt.Sprintf("%v has joined Discord channel\n", u.Username), false) + } Bridge.DiscordUserCount = Bridge.DiscordUserCount + 1 } if event.ChannelID == "" {