Add HasPermission(), some formatting
This commit is contained in:
parent
7f6d764821
commit
369e1287ba
33
main.go
33
main.go
|
@ -16,11 +16,12 @@ import (
|
|||
|
||||
// MumbleDJ type declaration
|
||||
type mumbledj struct {
|
||||
config gumble.Config
|
||||
client *gumble.Client
|
||||
keepAlive chan bool
|
||||
config gumble.Config
|
||||
client *gumble.Client
|
||||
keepAlive chan bool
|
||||
defaultChannel string
|
||||
conf DjConfig
|
||||
conf DjConfig
|
||||
queue SongQueue
|
||||
}
|
||||
|
||||
func (dj *mumbledj) OnConnect(e *gumble.ConnectEvent) {
|
||||
|
@ -44,11 +45,24 @@ func (dj *mumbledj) OnDisconnect(e *gumble.DisconnectEvent) {
|
|||
|
||||
func (dj *mumbledj) OnTextMessage(e *gumble.TextMessageEvent) {
|
||||
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),
|
||||
}
|
||||
|
||||
|
@ -65,13 +79,13 @@ func main() {
|
|||
dj.config = gumble.Config{
|
||||
Username: username,
|
||||
Password: password,
|
||||
Address: address + ":" + port,
|
||||
Address: address + ":" + port,
|
||||
}
|
||||
dj.defaultChannel = channel
|
||||
|
||||
dj.client.Attach(gumbleutil.Listener{
|
||||
Connect: dj.OnConnect,
|
||||
Disconnect: dj.OnDisconnect,
|
||||
Connect: dj.OnConnect,
|
||||
Disconnect: dj.OnDisconnect,
|
||||
TextMessage: dj.OnTextMessage,
|
||||
})
|
||||
|
||||
|
@ -84,4 +98,3 @@ func main() {
|
|||
|
||||
<-dj.keepAlive
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue