Annotation For src/main.rs
Logged in as anonymous

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

                         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 {
79c91a5357 2024-08-02   38: 		if let telegram_bot::MessageKind::Text { ref data, .. } = message.kind {
79c91a5357 2024-08-02   39: 			if let Some(from) = message.from {
                        40: 				let sender = from.id;
79c91a5357 2024-08-02   41: 				let words: Vec<&str> = data.split_whitespace().collect();
                        42: 				if let Err(err) = match words[0] {
                        43: 					"/check" | "/clean" | "/enable" | "/delete" | "/disable" => command::command(core, sender, words).await,
                        44: 					"/start" => command::start(core, sender).await,
                        45: 					"/list" => command::list(core, sender).await,
                        46: 					"/add" | "/update" => command::update(core, sender, words).await,
                        47: 					_ => Ok(()),
                        48: 				} {
                        49: 					core.send(format!("🛑 {:?}", err), Some(sender), None).await?;
                        50: 				};
                        51: 			};
                        52: 		};
                        53: 	};
                        54: 
                        55: 	Ok(())
                        56: }