Add HasPermission(), some formatting
This commit is contained in:
parent
7f6d764821
commit
369e1287ba
43
main.go
43
main.go
|
@ -16,11 +16,12 @@ import (
|
||||||
|
|
||||||
// MumbleDJ type declaration
|
// MumbleDJ type declaration
|
||||||
type mumbledj struct {
|
type mumbledj struct {
|
||||||
config gumble.Config
|
config gumble.Config
|
||||||
client *gumble.Client
|
client *gumble.Client
|
||||||
keepAlive chan bool
|
keepAlive chan bool
|
||||||
defaultChannel string
|
defaultChannel string
|
||||||
conf DjConfig
|
conf DjConfig
|
||||||
|
queue SongQueue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dj *mumbledj) OnConnect(e *gumble.ConnectEvent) {
|
func (dj *mumbledj) OnConnect(e *gumble.ConnectEvent) {
|
||||||
|
@ -29,7 +30,7 @@ func (dj *mumbledj) OnConnect(e *gumble.ConnectEvent) {
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("No channel specified, moving to root...")
|
fmt.Println("No channel specified, moving to root...")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := loadConfiguration()
|
err := loadConfiguration()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fmt.Println("Configuration successfully loaded!")
|
fmt.Println("Configuration successfully loaded!")
|
||||||
|
@ -44,11 +45,24 @@ func (dj *mumbledj) OnDisconnect(e *gumble.DisconnectEvent) {
|
||||||
|
|
||||||
func (dj *mumbledj) OnTextMessage(e *gumble.TextMessageEvent) {
|
func (dj *mumbledj) OnTextMessage(e *gumble.TextMessageEvent) {
|
||||||
if e.Message[0] == '!' {
|
if e.Message[0] == '!' {
|
||||||
parseCommand(e.Sender.Name(), e.Message[1:])
|
parseCommand(e.Sender, e.Sender.Name(), e.Message[1:])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var dj = mumbledj {
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var dj = mumbledj{
|
||||||
keepAlive: make(chan bool),
|
keepAlive: make(chan bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,28 +74,27 @@ func main() {
|
||||||
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.StringVar(&channel, "channel", "", "default channel for MumbleDJ")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
dj.client = gumble.NewClient(&dj.config)
|
dj.client = gumble.NewClient(&dj.config)
|
||||||
dj.config = gumble.Config{
|
dj.config = gumble.Config{
|
||||||
Username: username,
|
Username: username,
|
||||||
Password: password,
|
Password: password,
|
||||||
Address: address + ":" + port,
|
Address: address + ":" + port,
|
||||||
}
|
}
|
||||||
dj.defaultChannel = channel
|
dj.defaultChannel = channel
|
||||||
|
|
||||||
dj.client.Attach(gumbleutil.Listener{
|
dj.client.Attach(gumbleutil.Listener{
|
||||||
Connect: dj.OnConnect,
|
Connect: dj.OnConnect,
|
||||||
Disconnect: dj.OnDisconnect,
|
Disconnect: dj.OnDisconnect,
|
||||||
TextMessage: dj.OnTextMessage,
|
TextMessage: dj.OnTextMessage,
|
||||||
})
|
})
|
||||||
|
|
||||||
// IMPORTANT NOTE: This will be changed later once released. Not really safe at the
|
// IMPORTANT NOTE: This will be changed later once released. Not really safe at the
|
||||||
// moment.
|
// moment.
|
||||||
dj.config.TLSConfig.InsecureSkipVerify = true
|
dj.config.TLSConfig.InsecureSkipVerify = true
|
||||||
if err := dj.client.Connect(); err != nil {
|
if err := dj.client.Connect(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
<-dj.keepAlive
|
<-dj.keepAlive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue