1use crate::config::{Auth, Config};
19
20pub struct Builder {
22 config: Config,
23}
24
25impl Builder {
26 pub(crate) fn new(api_url: String, rest_url: String) -> Self {
27 Self {
28 config: Config {
29 api_url,
30 rest_url,
31 auth: None,
32 general: Default::default(),
33 edit: Default::default(),
34 },
35 }
36 }
37
38 pub fn set_botpassword(
39 mut self,
40 username: String,
41 password: String,
42 ) -> Self {
43 self.config.auth = Some(Auth::BotPassword { username, password });
44 self
45 }
46
47 pub fn set_oauth2_token(mut self, username: String, token: String) -> Self {
48 self.config.auth = Some(Auth::OAuth2 {
49 username,
50 oauth2_token: token,
51 });
52 self
53 }
54
55 pub fn set_maxlag(mut self, maxlag: u32) -> Self {
56 self.config.general.maxlag = Some(maxlag);
57 self
58 }
59
60 pub fn set_retry_limit(mut self, retry_limit: u32) -> Self {
61 self.config.general.retry_limit = Some(retry_limit);
62 self
63 }
64
65 pub fn set_user_agent(mut self, user_agent: String) -> Self {
68 self.config.general.user_agent = Some(user_agent);
69 self
70 }
71
72 pub fn set_mark_as_bot(mut self, mark_as_bot: bool) -> Self {
73 self.config.edit.mark_as_bot = Some(mark_as_bot);
74 self
75 }
76
77 pub fn set_save_delay(mut self, save_delay: u64) -> Self {
78 self.config.edit.save_delay = Some(save_delay);
79 self
80 }
81
82 pub fn set_respect_nobots(mut self, respect_nobots: bool) -> Self {
83 self.config.edit.respect_nobots = Some(respect_nobots);
84 self
85 }
86
87 pub async fn build(self) -> Result<crate::Bot, crate::ConfigError> {
88 crate::Bot::from_config(self.config).await
89 }
90}