Annotation For src/main.rs
Logged in as anonymous

Lines of src/main.rs from check-in 1c444d34ff that are changed by the sequence of edits moving toward check-in 614456ed35:

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