Bot now successfully connects to server
This commit is contained in:
parent
ad6e0e2017
commit
66f21f89ea
54
main.go
54
main.go
|
@ -16,41 +16,59 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// MumbleDJ type declaration
|
// MumbleDJ type declaration
|
||||||
type MumbleDJ struct {
|
type mumbledj struct {
|
||||||
serverAddress string
|
config gumble.Config
|
||||||
serverPort int
|
client *gumble.Client
|
||||||
username string
|
keepAlive chan bool
|
||||||
password string
|
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() {
|
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(&address, "server", "localhost", "address for Mumble server")
|
||||||
flag.StringVar(&port, "port", "64738", "port for Mumble server")
|
flag.StringVar(&port, "port", "64738", "port for Mumble server")
|
||||||
flag.StringVar(&username, "username", "MumbleDJ", "username of MumbleDJ on server")
|
flag.StringVar(&username, "username", "MumbleDJ", "username of MumbleDJ on server")
|
||||||
flag.StringVar(&password, "password", "", "password for Mumble server (if needed)")
|
flag.StringVar(&password, "password", "", "password for Mumble server (if needed)")
|
||||||
|
flag.StringVar(&channel, "channel", "", "default channel for MumbleDJ")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Just testing server connection, will implement this into MumbleDJ type later
|
dj := mumbledj {
|
||||||
listener := gumbleutil.Listener{
|
keepAlive: make(chan bool),
|
||||||
TextMessage: func(e *gumble.TextMessageEvent) {
|
|
||||||
fmt.Printf("Received text message: %s\n", e.Message)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config := gumble.Config{
|
dj.client = gumble.NewClient(&dj.config)
|
||||||
|
dj.config = gumble.Config{
|
||||||
Username: username,
|
Username: username,
|
||||||
Password: password,
|
Password: password,
|
||||||
Address: address + ":" + port,
|
Address: address + ":" + port,
|
||||||
Listener: listener,
|
|
||||||
}
|
}
|
||||||
|
dj.defaultChannel = channel
|
||||||
|
|
||||||
// Currently crashes on connect. Displays the following message:
|
dj.client.Attach(gumbleutil.Listener{
|
||||||
// panic: x509: certificate is valid for Murmur Autogenerated Certificate v2
|
Connect: dj.OnConnect,
|
||||||
// Will investigate later.
|
Disconnect: dj.OnDisconnect,
|
||||||
client := gumble.NewClient(&config)
|
TextMessage: dj.OnTextMessage,
|
||||||
if err := client.Connect(); err != nil {
|
})
|
||||||
|
|
||||||
|
// 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)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<-dj.keepAlive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue