Annotation For src/main.rs
Logged in as anonymous

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

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