From ba29c23caec1c042cd631ded24b0498bb2510aa3 Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 3 Jan 2021 19:49:12 -0500 Subject: [PATCH] remove legacy ping/status seperation --- bridge.go | 43 +++++++++++++++++++------------------------ main.go | 4 +--- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/bridge.go b/bridge.go index c3de13b..a6bc1fc 100644 --- a/bridge.go +++ b/bridge.go @@ -100,37 +100,32 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin } } -func pingMumble(host, port string, c chan int) { - m, _ := time.ParseDuration("30s") +func discordStatusUpdate(dg *discordgo.Session, host, port string) { + status := "" curr := 0 + m, _ := time.ParseDuration("30s") for { time.Sleep(3 * time.Second) resp, err := gumble.Ping(host+":"+port, -1, m) - curr = resp.ConnectedUsers - if err != nil { - panic(err) - } - if Bridge.Connected { - curr = curr - 1 - } - if curr != Bridge.MumbleUserCount { - Bridge.MumbleUserCount = curr - c <- Bridge.MumbleUserCount - } - } -} -func discordStatusUpdate(dg *discordgo.Session, c chan int) { - status := "" - curr := 0 - for { - curr = <-c - if curr == 0 { - status = "" + if err != nil { + log.Printf("error pinging mumble server %v\n", err) + dg.UpdateListeningStatus("an error pinging mumble") } else { - status = fmt.Sprintf("%v users in Mumble\n", curr) + curr = resp.ConnectedUsers + if Bridge.Connected { + curr = curr - 1 + } + if curr != Bridge.MumbleUserCount { + Bridge.MumbleUserCount = curr + } + if curr == 0 { + status = "" + } else { + status = fmt.Sprintf("%v users in Mumble\n", curr) + } + dg.UpdateListeningStatus(status) } - dg.UpdateListeningStatus(status) } } diff --git a/main.go b/main.go index 8c85a40..4a6442e 100644 --- a/main.go +++ b/main.go @@ -98,9 +98,7 @@ func main() { MumbleUserCount: 0, DiscordUserCount: 0, } - userCount := make(chan int) - go pingMumble(*mumbleAddr, strconv.Itoa(*mumblePort), userCount) - go discordStatusUpdate(discord, userCount) + go discordStatusUpdate(discord, *mumbleAddr, strconv.Itoa(*mumblePort)) if *autoMode { Bridge.AutoChan = make(chan bool) go AutoBridge(discord)