use crate::config::{Auth, Config};
pub struct Builder {
config: Config,
}
impl Builder {
pub(crate) fn new(wiki_url: String) -> Self {
Self {
config: Config {
wiki_url: Some(wiki_url),
auth: None,
general: Default::default(),
edit: Default::default(),
..Default::default()
},
}
}
pub(crate) fn new_with_api_url(api_url: String, rest_url: String) -> Self {
Self {
config: Config {
api_url: Some(api_url),
rest_url: Some(rest_url),
auth: None,
general: Default::default(),
edit: Default::default(),
..Default::default()
},
}
}
pub fn set_botpassword(
mut self,
username: String,
password: String,
) -> Self {
self.config.auth = Some(Auth::BotPassword { username, password });
self
}
pub fn set_oauth2_token(mut self, username: String, token: String) -> Self {
self.config.auth = Some(Auth::OAuth2 {
username,
oauth2_token: token,
});
self
}
pub fn set_maxlag(mut self, maxlag: u32) -> Self {
self.config.general.maxlag = Some(maxlag);
self
}
pub fn set_retry_limit(mut self, retry_limit: u32) -> Self {
self.config.general.retry_limit = Some(retry_limit);
self
}
pub fn set_user_agent(mut self, user_agent: String) -> Self {
self.config.general.user_agent = Some(user_agent);
self
}
pub fn set_mark_as_bot(mut self, mark_as_bot: bool) -> Self {
self.config.edit.mark_as_bot = Some(mark_as_bot);
self
}
pub fn set_save_delay(mut self, save_delay: u64) -> Self {
self.config.edit.save_delay = Some(save_delay);
self
}
pub fn set_respect_nobots(mut self, respect_nobots: bool) -> Self {
self.config.edit.respect_nobots = Some(respect_nobots);
self
}
pub async fn build(self) -> Result<crate::Bot, crate::ConfigError> {
crate::Bot::from_config(self.config).await
}
}