Apply new config handling design

This commit is contained in:
hodasemi 2020-09-20 08:06:46 +02:00
parent db8c82578a
commit 767ced2df0
2 changed files with 11 additions and 45 deletions

View file

@ -7,7 +7,7 @@ authors = ["hodasemi <michaelh.95@t-online.de>"]
[dependencies]
typemap = "~0.3"
serde_json = "*"
utilities = { git = "http://dimov.cloud/hodasemi/utilities" }
utilities = { git = "http://gavania.de/hodasemi/context" }
rusqlite = { version = "*", features = ["bundled"] }
serenity = { version = "0.8", default-features = false, features = [ "builder", "cache", "client", "framework", "gateway", "model", "standard_framework", "utils", "voice", "rustls_backend"]}
parking_lot = "*"

View file

@ -27,21 +27,15 @@ use std::collections::HashSet;
use utilities::prelude::*;
struct Config {
create_settings_section!(
Config,
"Meta",
{
token: String,
prefix: String,
volume: f32,
}
impl Default for Config {
fn default() -> Self {
Self {
token: String::new(),
prefix: String::new(),
volume: 1.0,
}
}
}
},
);
#[group]
#[commands(ip, list, pause, play, remove, skip, stop, tag)]
@ -63,35 +57,7 @@ fn main() -> VerboseResult<()> {
// read config file
let config_file = ConfigHandler::read_config("bot.conf")?;
let mut config = Config::default();
match config_file.get("Meta") {
Some(info) => {
match info.get("token") {
Some(token_pair) => {
token_pair.set_value(&mut config.token)?;
}
None => {
create_error!("couldn't find token inside meta section");
}
}
match info.get("prefix") {
Some(prefix_pair) => {
prefix_pair.set_value(&mut config.prefix)?;
}
None => {
create_error!("couldn't find prefix inside meta section");
}
}
if let Some(volume) = info.get("volume") {
volume.set_value(&mut config.volume)?;
}
}
None => {
create_error!("couldn't find Meta section in config file");
}
};
let config = Config::load(&config_file)?;
let mut client = Client::new(&config.token, Handler).expect("Err creating client");