remove legacy ping/status seperation
This commit is contained in:
parent
70b0a691b6
commit
ba29c23cae
23
bridge.go
23
bridge.go
@ -100,31 +100,25 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func pingMumble(host, port string, c chan int) {
|
func discordStatusUpdate(dg *discordgo.Session, host, port string) {
|
||||||
m, _ := time.ParseDuration("30s")
|
status := ""
|
||||||
curr := 0
|
curr := 0
|
||||||
|
m, _ := time.ParseDuration("30s")
|
||||||
for {
|
for {
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
resp, err := gumble.Ping(host+":"+port, -1, m)
|
resp, err := gumble.Ping(host+":"+port, -1, m)
|
||||||
curr = resp.ConnectedUsers
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Printf("error pinging mumble server %v\n", err)
|
||||||
}
|
dg.UpdateListeningStatus("an error pinging mumble")
|
||||||
|
} else {
|
||||||
|
curr = resp.ConnectedUsers
|
||||||
if Bridge.Connected {
|
if Bridge.Connected {
|
||||||
curr = curr - 1
|
curr = curr - 1
|
||||||
}
|
}
|
||||||
if curr != Bridge.MumbleUserCount {
|
if curr != Bridge.MumbleUserCount {
|
||||||
Bridge.MumbleUserCount = curr
|
Bridge.MumbleUserCount = curr
|
||||||
c <- Bridge.MumbleUserCount
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func discordStatusUpdate(dg *discordgo.Session, c chan int) {
|
|
||||||
status := ""
|
|
||||||
curr := 0
|
|
||||||
for {
|
|
||||||
curr = <-c
|
|
||||||
if curr == 0 {
|
if curr == 0 {
|
||||||
status = ""
|
status = ""
|
||||||
} else {
|
} else {
|
||||||
@ -132,6 +126,7 @@ func discordStatusUpdate(dg *discordgo.Session, c chan int) {
|
|||||||
}
|
}
|
||||||
dg.UpdateListeningStatus(status)
|
dg.UpdateListeningStatus(status)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func AutoBridge(s *discordgo.Session) {
|
func AutoBridge(s *discordgo.Session) {
|
||||||
|
4
main.go
4
main.go
@ -98,9 +98,7 @@ func main() {
|
|||||||
MumbleUserCount: 0,
|
MumbleUserCount: 0,
|
||||||
DiscordUserCount: 0,
|
DiscordUserCount: 0,
|
||||||
}
|
}
|
||||||
userCount := make(chan int)
|
go discordStatusUpdate(discord, *mumbleAddr, strconv.Itoa(*mumblePort))
|
||||||
go pingMumble(*mumbleAddr, strconv.Itoa(*mumblePort), userCount)
|
|
||||||
go discordStatusUpdate(discord, userCount)
|
|
||||||
if *autoMode {
|
if *autoMode {
|
||||||
Bridge.AutoChan = make(chan bool)
|
Bridge.AutoChan = make(chan bool)
|
||||||
go AutoBridge(discord)
|
go AutoBridge(discord)
|
||||||
|
Loading…
Reference in New Issue
Block a user