Apply new config handling design
This commit is contained in:
parent
db8c82578a
commit
767ced2df0
2 changed files with 11 additions and 45 deletions
|
@ -7,7 +7,7 @@ authors = ["hodasemi <michaelh.95@t-online.de>"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
typemap = "~0.3"
|
typemap = "~0.3"
|
||||||
serde_json = "*"
|
serde_json = "*"
|
||||||
utilities = { git = "http://dimov.cloud/hodasemi/utilities" }
|
utilities = { git = "http://gavania.de/hodasemi/context" }
|
||||||
rusqlite = { version = "*", features = ["bundled"] }
|
rusqlite = { version = "*", features = ["bundled"] }
|
||||||
serenity = { version = "0.8", default-features = false, features = [ "builder", "cache", "client", "framework", "gateway", "model", "standard_framework", "utils", "voice", "rustls_backend"]}
|
serenity = { version = "0.8", default-features = false, features = [ "builder", "cache", "client", "framework", "gateway", "model", "standard_framework", "utils", "voice", "rustls_backend"]}
|
||||||
parking_lot = "*"
|
parking_lot = "*"
|
||||||
|
|
54
src/main.rs
54
src/main.rs
|
@ -27,21 +27,15 @@ use std::collections::HashSet;
|
||||||
|
|
||||||
use utilities::prelude::*;
|
use utilities::prelude::*;
|
||||||
|
|
||||||
struct Config {
|
create_settings_section!(
|
||||||
token: String,
|
Config,
|
||||||
prefix: String,
|
"Meta",
|
||||||
volume: f32,
|
{
|
||||||
}
|
token: String,
|
||||||
|
prefix: String,
|
||||||
impl Default for Config {
|
volume: f32,
|
||||||
fn default() -> Self {
|
},
|
||||||
Self {
|
);
|
||||||
token: String::new(),
|
|
||||||
prefix: String::new(),
|
|
||||||
volume: 1.0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[group]
|
#[group]
|
||||||
#[commands(ip, list, pause, play, remove, skip, stop, tag)]
|
#[commands(ip, list, pause, play, remove, skip, stop, tag)]
|
||||||
|
@ -63,35 +57,7 @@ fn main() -> VerboseResult<()> {
|
||||||
// read config file
|
// read config file
|
||||||
let config_file = ConfigHandler::read_config("bot.conf")?;
|
let config_file = ConfigHandler::read_config("bot.conf")?;
|
||||||
|
|
||||||
let mut config = Config::default();
|
let config = Config::load(&config_file)?;
|
||||||
|
|
||||||
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 mut client = Client::new(&config.token, Handler).expect("Err creating client");
|
let mut client = Client::new(&config.token, Handler).expect("Err creating client");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue