2014-12-09 06:45:22 +01:00
|
|
|
/*
|
|
|
|
* MumbleDJ
|
|
|
|
* By Matthieu Grieger
|
|
|
|
* main.go
|
|
|
|
* Copyright (c) 2014 Matthieu Grieger (MIT License)
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-12-10 00:41:50 +01:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
2014-12-09 06:45:22 +01:00
|
|
|
"github.com/layeh/gumble/gumble"
|
|
|
|
"github.com/layeh/gumble/gumbleutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MumbleDJ type declaration
|
2014-12-13 00:42:59 +01:00
|
|
|
type mumbledj struct {
|
2014-12-16 01:40:31 +01:00
|
|
|
config gumble.Config
|
|
|
|
client *gumble.Client
|
|
|
|
keepAlive chan bool
|
2014-12-13 00:42:59 +01:00
|
|
|
defaultChannel string
|
2014-12-16 01:40:31 +01:00
|
|
|
conf DjConfig
|
2014-12-19 01:28:27 +01:00
|
|
|
queue *SongQueue
|
2014-12-13 00:42:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (dj *mumbledj) OnConnect(e *gumble.ConnectEvent) {
|
2014-12-15 05:35:44 +01:00
|
|
|
if dj.client.Channels().Find(dj.defaultChannel) != nil {
|
|
|
|
dj.client.Self().Move(dj.client.Channels().Find(dj.defaultChannel))
|
|
|
|
} else {
|
2014-12-20 06:56:30 +01:00
|
|
|
fmt.Println("Channel doesn't exist, staying in root channel...")
|
2014-12-15 05:35:44 +01:00
|
|
|
}
|
2014-12-16 01:40:31 +01:00
|
|
|
|
2014-12-15 05:35:44 +01:00
|
|
|
err := loadConfiguration()
|
2014-12-13 05:52:07 +01:00
|
|
|
if err == nil {
|
|
|
|
fmt.Println("Configuration successfully loaded!")
|
2014-12-13 18:22:30 +01:00
|
|
|
} else {
|
|
|
|
panic(err)
|
2014-12-13 05:52:07 +01:00
|
|
|
}
|
2014-12-19 01:28:27 +01:00
|
|
|
dj.queue = NewSongQueue()
|
2014-12-13 00:42:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (dj *mumbledj) OnDisconnect(e *gumble.DisconnectEvent) {
|
|
|
|
dj.keepAlive <- true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dj *mumbledj) OnTextMessage(e *gumble.TextMessageEvent) {
|
2014-12-13 05:52:07 +01:00
|
|
|
if e.Message[0] == '!' {
|
2014-12-16 01:40:31 +01:00
|
|
|
parseCommand(e.Sender, e.Sender.Name(), e.Message[1:])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dj *mumbledj) HasPermission(username string, command bool) bool {
|
|
|
|
if dj.conf.Permissions.AdminsEnabled && command {
|
|
|
|
for _, adminName := range dj.conf.Permissions.Admins {
|
|
|
|
if username == adminName {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
return true
|
2014-12-13 05:52:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-16 01:40:31 +01:00
|
|
|
var dj = mumbledj{
|
2014-12-13 05:52:07 +01:00
|
|
|
keepAlive: make(chan bool),
|
2014-12-19 01:28:27 +01:00
|
|
|
queue: NewSongQueue(),
|
2014-12-09 06:45:22 +01:00
|
|
|
}
|
2014-12-10 00:41:50 +01:00
|
|
|
|
|
|
|
func main() {
|
2014-12-20 06:57:48 +01:00
|
|
|
var address, port, username, password, channel string
|
2014-12-19 01:28:27 +01:00
|
|
|
|
2014-12-10 00:41:50 +01:00
|
|
|
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)")
|
2014-12-20 06:56:30 +01:00
|
|
|
flag.StringVar(&channel, "channel", "root", "default channel for MumbleDJ")
|
2014-12-10 00:41:50 +01:00
|
|
|
flag.Parse()
|
2014-12-16 01:40:31 +01:00
|
|
|
|
2014-12-13 00:42:59 +01:00
|
|
|
dj.client = gumble.NewClient(&dj.config)
|
|
|
|
dj.config = gumble.Config{
|
2014-12-10 00:41:50 +01:00
|
|
|
Username: username,
|
|
|
|
Password: password,
|
2014-12-16 01:40:31 +01:00
|
|
|
Address: address + ":" + port,
|
2014-12-10 00:41:50 +01:00
|
|
|
}
|
2014-12-13 00:42:59 +01:00
|
|
|
dj.defaultChannel = channel
|
2014-12-16 01:40:31 +01:00
|
|
|
|
2014-12-13 00:42:59 +01:00
|
|
|
dj.client.Attach(gumbleutil.Listener{
|
2014-12-16 01:40:31 +01:00
|
|
|
Connect: dj.OnConnect,
|
|
|
|
Disconnect: dj.OnDisconnect,
|
2014-12-13 00:42:59 +01:00
|
|
|
TextMessage: dj.OnTextMessage,
|
|
|
|
})
|
2014-12-16 01:40:31 +01:00
|
|
|
|
2014-12-13 00:42:59 +01:00
|
|
|
// 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 {
|
2014-12-10 00:41:50 +01:00
|
|
|
panic(err)
|
|
|
|
}
|
2014-12-16 01:40:31 +01:00
|
|
|
|
2014-12-13 00:42:59 +01:00
|
|
|
<-dj.keepAlive
|
2014-12-10 00:41:50 +01:00
|
|
|
}
|