From 2df391f0d9988ae401413c12fa307cf75667a51e Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 29 Dec 2020 15:23:43 -0500 Subject: [PATCH] less channel span, add refresh command --- handlers.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/handlers.go b/handlers.go index a8efb51..5a24737 100644 --- a/handlers.go +++ b/handlers.go @@ -3,6 +3,7 @@ package main import ( "log" "strings" + "time" "github.com/bwmarrin/discordgo" ) @@ -74,6 +75,34 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { } } } + + if strings.HasPrefix(m.Content, "!yammer refresh") { + + // Find the channel that the message came from. + c, err := s.State.Channel(m.ChannelID) + if err != nil { + // Could not find channel. + return + } + + // Find the guild for that channel. + g, err := s.State.Guild(c.GuildID) + if err != nil { + // Could not find guild. + return + } + + // Look for the message sender in that guild's current voice states. + for _, vs := range g.VoiceStates { + if vs.UserID == m.Author.ID { + log.Printf("Trying to refresh GID %v and VID %v\n", g.ID, vs.ChannelID) + YBConfig.ActiveConns[vs.ChannelID] <- true + time.Sleep(2 * time.Second) + go startBridge(s, g.ID, vs.ChannelID, YBConfig.Config, YBConfig.MumbleAddr, YBConfig.MumbleInsecure, YBConfig.ActiveConns[vs.ChannelID]) + return + } + } + } } func guildCreate(s *discordgo.Session, event *discordgo.GuildCreate) { @@ -84,7 +113,7 @@ func guildCreate(s *discordgo.Session, event *discordgo.GuildCreate) { for _, channel := range event.Guild.Channels { if channel.ID == event.Guild.ID { - _, _ = s.ChannelMessageSend(channel.ID, "Mumble-Discord bridge is active") + log.Println("Mumble-Discord bridge is active in new guild") return } }