Bot now successfully connects to server

This commit is contained in:
Matthieu Grieger 2014-12-12 15:42:59 -08:00
parent ad6e0e2017
commit 66f21f89ea

54
main.go
View file

@ -16,41 +16,59 @@ import (
)
// MumbleDJ type declaration
type MumbleDJ struct {
serverAddress string
serverPort int
username string
password string
type mumbledj struct {
config gumble.Config
client *gumble.Client
keepAlive chan bool
defaultChannel string
}
func (dj *mumbledj) OnConnect(e *gumble.ConnectEvent) {
dj.client.Self().Move(dj.client.Channels().Find(dj.defaultChannel))
}
func (dj *mumbledj) OnDisconnect(e *gumble.DisconnectEvent) {
dj.keepAlive <- true
}
func (dj *mumbledj) OnTextMessage(e *gumble.TextMessageEvent) {
fmt.Println(e.Message)
}
func main() {
var address, port, username, password string
var address, port, username, password, channel string
flag.StringVar(&address, "server", "localhost", "address for Mumble server")
flag.StringVar(&port, "port", "64738", "port for Mumble server")
flag.StringVar(&username, "username", "MumbleDJ", "username of MumbleDJ on server")
flag.StringVar(&password, "password", "", "password for Mumble server (if needed)")
flag.StringVar(&channel, "channel", "", "default channel for MumbleDJ")
flag.Parse()
// Just testing server connection, will implement this into MumbleDJ type later
listener := gumbleutil.Listener{
TextMessage: func(e *gumble.TextMessageEvent) {
fmt.Printf("Received text message: %s\n", e.Message)
},
dj := mumbledj {
keepAlive: make(chan bool),
}
config := gumble.Config{
dj.client = gumble.NewClient(&dj.config)
dj.config = gumble.Config{
Username: username,
Password: password,
Address: address + ":" + port,
Listener: listener,
}
dj.defaultChannel = channel
// Currently crashes on connect. Displays the following message:
// panic: x509: certificate is valid for Murmur Autogenerated Certificate v2
// Will investigate later.
client := gumble.NewClient(&config)
if err := client.Connect(); err != nil {
dj.client.Attach(gumbleutil.Listener{
Connect: dj.OnConnect,
Disconnect: dj.OnDisconnect,
TextMessage: dj.OnTextMessage,
})
// IMPORTANT NOTE: This will be changed later once released. Not really safe at the
// moment.
dj.config.TLSConfig.InsecureSkipVerify = true
if err := dj.client.Connect(); err != nil {
panic(err)
}
<-dj.keepAlive
}