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

This commit is contained in:
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 rm -f mumbledj
install: install:
sudo cp -f mumbledj /usr/local/bin/mumbledj
mkdir -p ~/.mumbledj/config mkdir -p ~/.mumbledj/config
mkdir -p ~/.mumbledj/songs mkdir -p ~/.mumbledj/songs
if [ -a ~/.mumbledj/config/config.toml ]; then mv ~/.mumbledj/config/config.toml ~/.mumbledj/config/config_backup.toml; fi; if [ -a ~/.mumbledj/config/mumbledj.gcfg ]; then mv ~/.mumbledj/config/mumbledj.gcfg ~/.mumbledj/config/mumbledj_backup.gcfg; fi;
cp -u config.toml ~/.mumbledj/config/config.toml cp -u mumbledj.gcfg ~/.mumbledj/config/mumbledj.gcfg
sudo cp -f mumbledj /usr/local/bin/mumbledj
install_deps: install_deps:
go get -u github.com/layeh/gumble/gumble go get -u github.com/layeh/gumble/gumble
go get -u github.com/layeh/gumble/gumbleutil go get -u github.com/layeh/gumble/gumbleutil
go get -u github.com/layeh/gumble/gumble_ffmpeg 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 { switch com {
case "add": case dj.conf.Aliases.AddAlias:
success := add(username, argument) success := add(username, argument)
if success { if success {
fmt.Println("Add successful!") fmt.Println("Add successful!")
} }
case "skip": case dj.conf.Aliases.SkipAlias:
success := skip(username, false) success := skip(username, false)
if success { if success {
fmt.Println("Skip successful!") fmt.Println("Skip successful!")
} }
case "forceskip": case dj.conf.Aliases.AdminSkipAlias:
success := skip(username, true) success := skip(username, true)
if success { if success {
fmt.Println("Forceskip successful!") fmt.Println("Forceskip successful!")
} }
case "volume": case dj.conf.Aliases.VolumeAlias:
success := volume(username, argument) success := volume(username, argument)
if success { if success {
fmt.Println("Volume change successful!") fmt.Println("Volume change successful!")
} }
case "move": case dj.conf.Aliases.MoveAlias:
success := move(username, argument) success := move(username, argument)
if success { if success {
fmt.Println("Move successful!") fmt.Println("Move successful!")
} }
case "reload": case dj.conf.Aliases.ReloadAlias:
conf, err := loadConfiguration() err := loadConfiguration()
if err == nil { if err == nil {
dj.conf = conf
fmt.Println("Reload successful!") fmt.Println("Reload successful!")
} }
case "kill": case dj.conf.Aliases.KillAlias:
success := kill(username) success := kill(username)
if success { if success {
fmt.Println("Kill successful!") fmt.Println("Kill successful!")
} }
case "test":
fmt.Printf("Title: %s\n", dj.conf.title)
} }
} }
func add(user, url string) bool { func add(user, url string) bool {
fmt.Println("Add requested!")
return true return true
} }
func skip(user string, admin bool) bool { func skip(user string, admin bool) bool {
if admin {
fmt.Println("Admin skip requested!")
} else {
fmt.Println("Skip requested!")
}
return true return true
} }
func volume(user, value string) bool { func volume(user, value string) bool {
fmt.Println("Volume change requested!")
return true return true
} }
func move(user, channel string) bool { func move(user, channel string) bool {
fmt.Println("Move requested!")
return true return true
} }
func kill(user string) bool { func kill(user string) bool {
fmt.Println("Kill requested!")
return true return true
} }

12
main.go
View file

@ -11,7 +11,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"github.com/layeh/gumble/gumble" "github.com/layeh/gumble/gumble"
//"github.com/layeh/gumble/gumble_ffmpeg"
"github.com/layeh/gumble/gumbleutil" "github.com/layeh/gumble/gumbleutil"
) )
@ -21,14 +20,17 @@ type mumbledj struct {
client *gumble.Client client *gumble.Client
keepAlive chan bool keepAlive chan bool
defaultChannel string defaultChannel string
conf djConfig conf DjConfig
} }
func (dj *mumbledj) OnConnect(e *gumble.ConnectEvent) { 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 err := loadConfiguration()
dj.conf, err = loadConfiguration()
if err == nil { if err == nil {
fmt.Println("Configuration successfully loaded!") fmt.Println("Configuration successfully loaded!")
} else { } else {

View file

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

View file

@ -8,54 +8,40 @@
package main package main
import ( import (
"errors" "code.google.com/p/gcfg"
"github.com/BurntSushi/toml"
) )
type djConfig struct { type DjConfig struct {
title string General struct {
general generalConfig CommandPrefix string
volume volumeConfig SkipRatio float32
aliases aliasConfig `toml:"command-aliases"` }
permissions permissionsConfig Volume struct {
} DefaultVolume float32
LowestVolume float32
type generalConfig struct { HighestVolume float32
commandPrefix string `toml:"command_prefix"` }
skipRatio float32 `toml:"skip_ratio"` Aliases struct {
} AddAlias string
SkipAlias string
type volumeConfig struct { AdminSkipAlias string
defaultVolume float32 `toml:"default_volume"` VolumeAlias string
lowestVolume float32 `toml:"lowest_volume"` MoveAlias string
highestVolume float32 `toml:"highest_volume"` ReloadAlias string
} KillAlias string
}
type aliasConfig struct { Permissions struct {
addAlias string `toml:"add_alias"` AdminsEnabled bool
skipAlias string `toml:"skip_alias"` Admins []string
adminSkipAlias string `toml:"admin_skip_alias"` AdminAdd bool
volumeAlias string `toml:"volume_alias"` AdminSkip bool
moveAlias string `toml:"move_alias"` AdminVolume bool
reloadAlias string `toml:"reload_alias"` AdminMove bool
killAlias string `toml:"kill_alias"` AdminReload bool
} AdminKill bool
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.")
} }
return conf, nil }
func loadConfiguration() (error) {
return gcfg.ReadFileInto(&dj.conf, "mumbledj.gcfg")
} }