From d9014ccf652b18611d9b210c6069f03ce9edbaf5 Mon Sep 17 00:00:00 2001 From: Matthieu Grieger Date: Fri, 12 Dec 2014 20:52:44 -0800 Subject: [PATCH] Add config.toml, parseconfig.go --- config.toml | 103 +++++++++++++++++++++++++++++++++++++++++++++++++ parseconfig.go | 62 +++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 config.toml create mode 100644 parseconfig.go diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..986954e --- /dev/null +++ b/config.toml @@ -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 diff --git a/parseconfig.go b/parseconfig.go new file mode 100644 index 0000000..a6157d9 --- /dev/null +++ b/parseconfig.go @@ -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 +}