Switched from TOML to GCFG for config file. Works now!

pull/18/head
Matthieu Grieger 2014-12-14 20:35:44 -08:00
parent a1e9d05cf2
commit 5a13fac882
5 changed files with 82 additions and 103 deletions

View File

@ -7,14 +7,14 @@ clean:
rm -f mumbledj
install:
sudo cp -f mumbledj /usr/local/bin/mumbledj
mkdir -p ~/.mumbledj/config
mkdir -p ~/.mumbledj/songs
if [ -a ~/.mumbledj/config/config.toml ]; then mv ~/.mumbledj/config/config.toml ~/.mumbledj/config/config_backup.toml; fi;
cp -u config.toml ~/.mumbledj/config/config.toml
if [ -a ~/.mumbledj/config/mumbledj.gcfg ]; then mv ~/.mumbledj/config/mumbledj.gcfg ~/.mumbledj/config/mumbledj_backup.gcfg; fi;
cp -u mumbledj.gcfg ~/.mumbledj/config/mumbledj.gcfg
sudo cp -f mumbledj /usr/local/bin/mumbledj
install_deps:
go get -u github.com/layeh/gumble/gumble
go get -u github.com/layeh/gumble/gumbleutil
go get -u github.com/layeh/gumble/gumble_ffmpeg
go get -u github.com/BurntSushi/toml
go get -u code.google.com/p/gcfg

View File

@ -23,72 +23,60 @@ func parseCommand(username, command string) {
}
switch com {
case "add":
case dj.conf.Aliases.AddAlias:
success := add(username, argument)
if success {
fmt.Println("Add successful!")
}
case "skip":
case dj.conf.Aliases.SkipAlias:
success := skip(username, false)
if success {
fmt.Println("Skip successful!")
}
case "forceskip":
case dj.conf.Aliases.AdminSkipAlias:
success := skip(username, true)
if success {
fmt.Println("Forceskip successful!")
}
case "volume":
case dj.conf.Aliases.VolumeAlias:
success := volume(username, argument)
if success {
fmt.Println("Volume change successful!")
}
case "move":
case dj.conf.Aliases.MoveAlias:
success := move(username, argument)
if success {
fmt.Println("Move successful!")
}
case "reload":
conf, err := loadConfiguration()
case dj.conf.Aliases.ReloadAlias:
err := loadConfiguration()
if err == nil {
dj.conf = conf
fmt.Println("Reload successful!")
}
case "kill":
case dj.conf.Aliases.KillAlias:
success := kill(username)
if success {
fmt.Println("Kill successful!")
}
case "test":
fmt.Printf("Title: %s\n", dj.conf.title)
}
}
func add(user, url string) bool {
fmt.Println("Add requested!")
return true
}
func skip(user string, admin bool) bool {
if admin {
fmt.Println("Admin skip requested!")
} else {
fmt.Println("Skip requested!")
}
return true
}
func volume(user, value string) bool {
fmt.Println("Volume change requested!")
return true
}
func move(user, channel string) bool {
fmt.Println("Move requested!")
return true
}
func kill(user string) bool {
fmt.Println("Kill requested!")
return true
}

12
main.go
View File

@ -11,7 +11,6 @@ import (
"flag"
"fmt"
"github.com/layeh/gumble/gumble"
//"github.com/layeh/gumble/gumble_ffmpeg"
"github.com/layeh/gumble/gumbleutil"
)
@ -21,14 +20,17 @@ type mumbledj struct {
client *gumble.Client
keepAlive chan bool
defaultChannel string
conf djConfig
conf DjConfig
}
func (dj *mumbledj) OnConnect(e *gumble.ConnectEvent) {
dj.client.Self().Move(dj.client.Channels().Find(dj.defaultChannel))
if dj.client.Channels().Find(dj.defaultChannel) != nil {
dj.client.Self().Move(dj.client.Channels().Find(dj.defaultChannel))
} else {
fmt.Println("No channel specified, moving to root...")
}
var err error
dj.conf, err = loadConfiguration()
err := loadConfiguration()
if err == nil {
fmt.Println("Configuration successfully loaded!")
} else {

View File

@ -3,97 +3,100 @@
# config.toml
# Copyright (c) 2014 Matthieu Grieger (MIT License)
title = "MumbleDJ Configuration"
[general]
[General]
# Command prefix
# DEFAULT VALUE: "!"
command_prefix = "!"
CommandPrefix = "!"
# Ratio that must be met or exceeded to trigger a song skip
# DEFAULT VALUE: 0.5
skip_ratio = 0.5
SkipRatio = 0.5
[volume]
[Volume]
# Default volume
# DEFAULT VALUE: 0.2
default_volume = 0.2
DefaultVolume = 0.2
# Lowest volume allowed
# DEFAULT VALUE: 0.01
lowest_volume = 0.01
LowestVolume = 0.01
# Highest volume allowed
# DEFAULT VALUE: 0.8
highest_volume = 0.8
HighestVolume = 0.8
[command-aliases]
[Aliases]
# Alias used for add command
# DEFAULT VALUE: "add"
add_alias = "add"
AddAlias = "add"
# Alias used for skip command
# DEFAULT VALUE: "skip"
skip_alias = "skip"
SkipAlias = "skip"
# Alias used for admin skip command
# DEFAULT VALUE: "forceskip"
admin_skip_alias = "forceskip"
AdminSkipAlias = "forceskip"
# Alias used for volume command
# DEFAULT VALUE: "volume"
volume_alias = "volume"
VolumeAlias = "volume"
# Alias used for move command
# DEFAULT VALUE: "move"
move_alias = "move"
MoveAlias = "move"
# Alias used for reload command
# DEFAULT VALUE: "reload"
reload_alias = "reload"
ReloadAlias = "reload"
# Alias used for kill command
# DEFAULT VALUE: "kill"
kill_alias = "kill"
KillAlias = "kill"
[permissions]
[Permissions]
# Enable admins
# DEFAULT VALUE: true
enable_admins = true
AdminsEnabled = true
# List of admins
# NOTE: I recommend only giving users admin privileges if they are registered
# on the server. Otherwise people can just take their username and issue admin
# commands.
admins = ["Matt"]
# SYNTAX: In order to specify multiple admins, repeat the Admins="username"
# line of code. Each line has one username, and an unlimited amount of usernames may
# be entered in this matter. This is shown below with these default values:
# Admins = "Matt"
# Admins = "Matthieu"
Admins = "Matt"
# Make add an admin command?
# DEFAULT VALUE: false
admin_add = false
AdminAdd = false
# Make skip an admin command?
# DEFAULT VALUE: false
admin_skip = false
AdminSkip = false
# Make volume an admin command?
# DEFAULT VALUE: false
admin_volume = false
AdminVolume = false
# Make move an admin command?
# DEFAULT VALUE: true
admin_move = true
AdminMove = true
# Make reload an admin command?
# DEFAULT VALUE: true
admin_reload = true
AdminReload = true
# Make kill an admin command?
# DEFAULT VALUE: true (I recommend never changing this to false)
admin_kill = true
AdminKill = true

View File

@ -8,54 +8,40 @@
package main
import (
"errors"
"github.com/BurntSushi/toml"
"code.google.com/p/gcfg"
)
type djConfig struct {
title string
general generalConfig
volume volumeConfig
aliases aliasConfig `toml:"command-aliases"`
permissions permissionsConfig
}
type generalConfig struct {
commandPrefix string `toml:"command_prefix"`
skipRatio float32 `toml:"skip_ratio"`
}
type volumeConfig struct {
defaultVolume float32 `toml:"default_volume"`
lowestVolume float32 `toml:"lowest_volume"`
highestVolume float32 `toml:"highest_volume"`
}
type aliasConfig struct {
addAlias string `toml:"add_alias"`
skipAlias string `toml:"skip_alias"`
adminSkipAlias string `toml:"admin_skip_alias"`
volumeAlias string `toml:"volume_alias"`
moveAlias string `toml:"move_alias"`
reloadAlias string `toml:"reload_alias"`
killAlias string `toml:"kill_alias"`
}
type permissionsConfig struct {
adminsEnabled bool `toml:"enable_admins"`
adminList []string `toml:"admins"`
adminAdd bool `toml:"admin_add"`
adminSkip bool `toml:"admin_skip"`
adminVolume bool `toml:"admin_volume"`
adminMove bool `toml:"admin_move"`
adminReload bool `toml:"admin_reload"`
adminKill bool `toml:"admin_kill"`
}
func loadConfiguration() (djConfig, error) {
var conf djConfig
if _, err := toml.DecodeFile("~/.mumbledj/config/config.toml", &conf); err != nil {
return conf, errors.New("Configuration load failed.")
type DjConfig struct {
General struct {
CommandPrefix string
SkipRatio float32
}
Volume struct {
DefaultVolume float32
LowestVolume float32
HighestVolume float32
}
Aliases struct {
AddAlias string
SkipAlias string
AdminSkipAlias string
VolumeAlias string
MoveAlias string
ReloadAlias string
KillAlias string
}
Permissions struct {
AdminsEnabled bool
Admins []string
AdminAdd bool
AdminSkip bool
AdminVolume bool
AdminMove bool
AdminReload bool
AdminKill bool
}
return conf, nil
}
func loadConfiguration() (error) {
return gcfg.ReadFileInto(&dj.conf, "mumbledj.gcfg")
}