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 = "*"
|
||||||
|
|
48
src/main.rs
48
src/main.rs
|
@ -27,21 +27,15 @@ use std::collections::HashSet;
|
||||||
|
|
||||||
use utilities::prelude::*;
|
use utilities::prelude::*;
|
||||||
|
|
||||||
struct Config {
|
create_settings_section!(
|
||||||
|
Config,
|
||||||
|
"Meta",
|
||||||
|
{
|
||||||
token: String,
|
token: String,
|
||||||
prefix: String,
|
prefix: String,
|
||||||
volume: f32,
|
volume: f32,
|
||||||
}
|
},
|
||||||
|
);
|
||||||
impl Default for Config {
|
|
||||||
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