pull/54/head 2.6.5
Matthieu Grieger 2015-02-25 20:47:53 -08:00
parent f80ffbc745
commit d43dde1943
2 changed files with 25 additions and 1 deletions

View File

@ -1,6 +1,10 @@
MumbleDJ Changelog
==================
### February 25, 2015 -- `v2.6.5`
* Added automatic connection retries if the bot loses connection to the server. The bot will attempt to reconnect to the server every 30 seconds for a period of 15 seconds, then exit if
a connection cannot be made.
### February 20, 2015 -- `v2.6.4`
* Fixed failed audio downloads for YouTube videos with IDs beginning with "-".

22
main.go
View File

@ -17,6 +17,7 @@ import (
"github.com/layeh/gumble/gumbleutil"
"os"
"os/user"
"time"
)
// MumbleDJ type declaration
@ -68,7 +69,26 @@ func (dj *mumbledj) OnConnect(e *gumble.ConnectEvent) {
// OnDisconnect event. Terminates MumbleDJ thread.
func (dj *mumbledj) OnDisconnect(e *gumble.DisconnectEvent) {
dj.keepAlive <- true
if e.Type == gumble.DisconnectError || e.Type == gumble.DisconnectKicked {
fmt.Println("Disconnected from server... Will retry connection in 30 second intervals for 15 minutes.")
reconnectSuccess := false
for retries := 0; retries <= 30; retries++ {
fmt.Println("Retrying connection...")
if err := dj.client.Connect(); err == nil {
fmt.Println("Successfully reconnected to the server!")
reconnectSuccess = true
break
}
time.Sleep(30 * time.Second)
}
if !reconnectSuccess {
fmt.Println("Could not reconnect to server. Exiting...")
dj.keepAlive <- true
os.Exit(1)
}
} else {
dj.keepAlive <- true
}
}
// OnTextMessage event. Checks for command prefix, and calls parseCommand if it exists. Ignores