use serde::Deserialize;
#[derive(Deserialize, Default)]
pub(crate) struct Config {
#[serde(default)]
pub(crate) wiki_url: Option<String>,
#[serde(default)]
pub(crate) api_url: Option<String>,
#[serde(default)]
pub(crate) rest_url: Option<String>,
pub(crate) auth: Option<Auth>,
#[serde(default)]
pub(crate) general: GeneralOptions,
#[serde(default)]
pub(crate) edit: EditOptions,
}
#[derive(Deserialize)]
#[serde(untagged)]
pub(crate) enum Auth {
BotPassword {
username: String,
password: String,
},
OAuth2 {
username: String,
oauth2_token: String,
},
}
impl Auth {
pub(crate) fn username(&self) -> &str {
match &self {
Auth::BotPassword { username, .. } => username,
Auth::OAuth2 { username, .. } => username,
}
}
}
#[derive(Default, Deserialize)]
pub(crate) struct GeneralOptions {
pub(crate) maxlag: Option<u32>,
pub(crate) retry_limit: Option<u32>,
pub(crate) user_agent: Option<String>,
}
#[derive(Default, Deserialize)]
pub(crate) struct EditOptions {
pub(crate) mark_as_bot: Option<bool>,
pub(crate) save_delay: Option<u64>,
pub(crate) respect_nobots: Option<bool>,
}