Move username and password to config file

This commit is contained in:
Neshura 2023-12-29 14:35:07 +01:00
parent 654bc5c7f8
commit 8d75aaa4f7
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
6 changed files with 46 additions and 27 deletions
src/config

View file

@ -4,6 +4,8 @@ use crate::config::PostBody::Description;
#[derive(Serialize, Deserialize, Clone, Debug)]
pub(crate) struct Config {
pub(crate) instance: String,
pub(crate) username: String,
pub(crate) password: String,
pub(crate) status_post_url: Option<String>,
pub(crate) config_reload_seconds: u32,
pub(crate) protected_communities: Vec<String>,
@ -12,12 +14,21 @@ pub(crate) struct Config {
impl Config {
pub(crate) fn load() -> Result<Self, String> {
let cfg: Self = match confy::load_path("./config.toml") {
let cfg: Self = match confy::load(env!("CARGO_PKG_NAME"), "config") {
Ok(data) => data,
Err(_) => panic!("config.toml not found!"),
Err(e) => panic!("config.toml not found: {e}"),
};
if cfg.instance.is_empty() {
panic!("config.toml not found!")
panic!("bot instance not set!")
}
if cfg.username.is_empty() {
panic!("bot username not set!")
}
if cfg.password.is_empty() {
panic!("bot password not provided!")
}
cfg.series.iter().for_each(|series| {
@ -33,6 +44,8 @@ impl Default for Config {
fn default() -> Self {
Config {
instance: "".to_owned(),
username: "".to_owned(),
password: "".to_owned(),
status_post_url: None,
config_reload_seconds: 21600,
protected_communities: vec![],