Add config.toml, parseconfig.go

This commit is contained in:
Matthieu Grieger 2014-12-12 20:52:44 -08:00
parent 1e29473e86
commit d9014ccf65
2 changed files with 165 additions and 0 deletions

103
config.toml Normal file
View file

@ -0,0 +1,103 @@
# MumbleDJ
# By Matthieu Grieger
# config.toml
# Copyright (c) 2014 Matthieu Grieger (MIT License)
title = "MumbleDJ Configuration"
[general]
# Default channel
# DEFAULT VALUE: "Music"
default_channel = "Bot Testing"
# Command prefix
# DEFAULT VALUE: "!"
command_prefix = "!"
# Ratio that must be met or exceeded to trigger a song skip
# DEFAULT VALUE: 0.5
skip_ratio = 0.5
[volume]
# Default volume
# DEFAULT VALUE: 0.2
default_volume = 0.2
# Lowest volume allowed
# DEFAULT VALUE: 0.01
lowest_volume = 0.01
# Highest volume allowed
# DEFAULT VALUE: 0.8
highest_volume = 0.8
[command-aliases]
# Alias used for add command
# DEFAULT VALUE: "add"
add_alias = "add"
# Alias used for skip command
# DEFAULT VALUE: "skip"
skip_alias = "skip"
# Alias used for admin skip command
# DEFAULT VALUE: "forceskip"
admin_skip_alias = "forceskip"
# Alias used for volume command
# DEFAULT VALUE: "volume"
volume_alias = "volume"
# Alias used for move command
# DEFAULT VALUE: "move"
move_alias = "move"
# Alias used for reload command
# DEFAULT VALUE: "reload"
reload_alias = "reload"
# Alias used for kill command
# DEFAULT VALUE: "kill"
kill_alias = "kill"
[permissions]
# Enable admins
# DEFAULT VALUE: true
enable_admins = 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"]
# Make add an admin command?
# DEFAULT VALUE: false
admin_add = false
# Make skip an admin command?
# DEFAULT VALUE: false
admin_skip = false
# Make volume an admin command?
# DEFAULT VALUE: false
admin_volume = false
# Make move an admin command?
# DEFAULT VALUE: true
admin_move = true
# Make reload an admin command?
# DEFAULT VALUE: true
admin_reload = true
# Make kill an admin command?
# DEFAULT VALUE: true (I recommend never changing this to false)
admin_kill = true

62
parseconfig.go Normal file
View file

@ -0,0 +1,62 @@
/*
* MumbleDJ
* By Matthieu Grieger
* parseconfig.go
* Copyright (c) 2014 Matthieu Grieger (MIT License)
*/
package main
import (
"errors"
"github.com/BurntSushi/toml"
)
type config struct {
title string
general generalConfig
volume volumeConfig
aliases aliasConfig `toml:"command-aliases"`
permissions permissionsConfig
}
type generalConfig struct {
defaultChannel string `toml:"default_channel"`
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() (config, error) {
var conf config
if _, err := toml.Decode("config.toml", &conf); err != nil {
return conf, errors.New("Configuration load failed.")
}
return conf, nil
}