Source code for my personal quote bot project.

Set up bot for hourly posting of regular quotes.

+30 -23
+30 -23
src/main.rs
··· 19 19 const DEFAULT_QUEUE: &str = "queue:default"; 20 20 const EVENT_QUEUE: &str = "queue:event"; 21 21 22 + // See https://cron.help for what these strings mean 23 + const POSTING_INTERVAL_CRON: &str = "00,30 * * * * * *"; 24 + const EVENT_UPDATE_INTERVAL: &str = "55 23 * * *"; 25 + 22 26 fn prepare_post<I: Into<String>>(text: I) -> post::RecordData { 23 27 post::RecordData { 24 28 text: text.into(), ··· 122 126 std::env::var("BLUESKY_USERNAME").unwrap_or_default(), 123 127 std::env::var("BLUESKY_PASSWORD").unwrap_or_default(), 124 128 ) 125 - .await; 129 + .await?; 126 130 127 131 let sched = JobScheduler::new().await?; 128 132 let agent = Arc::new(Mutex::new(agent)); 129 - let event_filter = Arc::new(QuoteFilter { 130 - content: r"\b(?i:mother|mommy|mama|mom)\b".to_string(), 131 - path: "quotes/**/*.txt".to_string(), 132 - dates: vec![], 133 - }); 133 + 134 + /* 135 + let event_filter = Arc::new(QuoteFilter { 136 + content: r"\b(?i:mother|mommy|mama|mom)\b".to_string(), 137 + path: "test/**/*.txt".to_string(), 138 + dates: vec![], 139 + }); 140 + */ 134 141 135 142 let regular_filter = Arc::new(QuoteFilter { 136 143 content: r".*".to_string(), 137 - path: "test/**/*.txt".to_string(), 144 + path: "quotes/**/*.txt".to_string(), 138 145 dates: vec![], 139 146 }); 140 147 ··· 143 150 144 151 // Add async job 145 152 sched 146 - .add(Job::new_async("0/10,5/10 * * * * *", move |_uuid, _| { 153 + .add(Job::new_async(POSTING_INTERVAL_CRON, move |_uuid, _| { 147 154 let filter = regular_filter.clone(); 148 155 let con = con_poster.clone(); 149 156 let agent = agent_poster.clone(); ··· 152 159 let text: String = get_quote(&filter, con).await.unwrap(); 153 160 let post = prepare_post(text.as_str()); 154 161 let agent = agent.lock().await; 155 - if let Err(_) = agent.create_record(post).await { 156 - println!("{}\n", text) 162 + if let Err(e) = agent.create_record(post).await { 163 + eprintln!("Could not post quote: {e}") 157 164 } 158 165 }) 159 166 })?) 160 167 .await?; 161 168 162 - sched 163 - .add(Job::new_async("32 * * * * *", move |_uuid, _| { 164 - let filter = event_filter.clone(); 165 - let con = con_event_monitor.clone(); 166 - let _agent = agent_event_monitor.clone(); // Can be used later to e.g. update profile 169 + // sched 170 + // .add(Job::new_async(EVENT_UPDATE_INTERVAL, move |_uuid, _| { 171 + // let filter = event_filter.clone(); 172 + // let con = con_event_monitor.clone(); 173 + // let _agent = agent_event_monitor.clone(); // Can be used later to e.g. update profile 167 174 168 - Box::pin(async move { 169 - // For testing purposes, let's always upload events 170 - reshuffle_quotes(&filter, con.clone(), EVENT_QUEUE) 171 - .await 172 - .unwrap(); 173 - }) 174 - })?) 175 - .await?; 175 + // Box::pin(async move { 176 + // // For testing purposes, let's always upload events 177 + // reshuffle_quotes(&filter, con.clone(), EVENT_QUEUE) 178 + // .await 179 + // .unwrap(); 180 + // }) 181 + // })?) 182 + // .await?; 176 183 177 184 sched.start().await.unwrap(); 178 185 loop {