Annotation For src/main.rs
Logged in as anonymous

Lines of src/main.rs from check-in 3dc9cddd4d that are changed by the sequence of edits moving toward check-in 79c91a5357:

                         1: mod command;
                         2: mod core;
                         3: 
                         4: use anyhow::Result;
                         5: use async_std::task;
                         6: use async_std::stream::StreamExt;
                         7: 
                         8: fn main() -> Result<()> {
                         9: 	let settings = config::Config::builder()
                        10: 		.add_source(config::File::with_name("rsstg"))
                        11: 		.build()?;
                        12: 
                        13: 	let core = core::Core::new(settings)?;
                        14: 
                        15: 	let mut stream = core.stream();
                        16: 	stream.allowed_updates(&[telegram_bot::AllowedUpdate::Message]);
                        17: 
                        18: 	task::block_on(async {
                        19: 		let mut reply_to: Option<telegram_bot::UserId>;
                        20: 		loop {
                        21: 			reply_to = None;
                        22: 			match stream.next().await {
                        23: 				Some(update) => {
                        24: 					if let Err(err) = handle(update?, &core, &reply_to).await {
                        25: 						core.send(&format!("🛑 {:?}", err), reply_to, None).await?;
                        26: 					};
                        27: 				},
                        28: 				None => {
                        29: 					core.send("🛑 None error.", None, None).await?;
                        30: 				}
                        31: 			};
                        32: 		}
                        33: 	})
                        34: }
                        35: 
                        36: async fn handle(update: telegram_bot::Update, core: &core::Core, mut _reply_to: &Option<telegram_bot::UserId>) -> Result<()> {
                        37: 	if let telegram_bot::UpdateKind::Message(message) = update.kind {
                        38: 		if let telegram_bot::MessageKind::Text { ref data, .. } = message.kind {
3dc9cddd4d 2023-08-04   39: 			let sender = message.from.id;
3dc9cddd4d 2023-08-04   40: 			let words: Vec<&str> = data.split_whitespace().collect();
3dc9cddd4d 2023-08-04   41: 			if let Err(err) = match words[0] {
3dc9cddd4d 2023-08-04   42: 				"/check" | "/clean" | "/enable" | "/delete" | "/disable" => command::command(core, sender, words).await,
3dc9cddd4d 2023-08-04   43: 				"/start" => command::start(core, sender).await,
3dc9cddd4d 2023-08-04   44: 				"/list" => command::list(core, sender).await,
3dc9cddd4d 2023-08-04   45: 				"/add" | "/update" => command::update(core, sender, words).await,
3dc9cddd4d 2023-08-04   46: 				_ => Ok(()),
3dc9cddd4d 2023-08-04   47: 			} {
3dc9cddd4d 2023-08-04   48: 				core.send(format!("🛑 {:?}", err), Some(sender), None).await?;
                        49: 			};
                        50: 		};
                        51: 	};
                        52: 
                        53: 	Ok(())
                        54: }