Annotation For src/main.rs
Logged in as anonymous

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

                         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;
a2880e5100 2025-04-19   10: use async_std::task;
a2880e5100 2025-04-19   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: 
a2880e5100 2025-04-19   19: 	let core = core::Core::new(settings)?;
a2880e5100 2025-04-19   20: 
a2880e5100 2025-04-19   21: 	let mut stream = core.stream();
a2880e5100 2025-04-19   22: 	stream.allowed_updates(&[telegram_bot::AllowedUpdate::Message]);
a2880e5100 2025-04-19   23: 
a2880e5100 2025-04-19   24: 	task::block_on(async {
a2880e5100 2025-04-19   25: 		let mut reply_to: Option<telegram_bot::UserId>;
a2880e5100 2025-04-19   26: 		loop {
a2880e5100 2025-04-19   27: 			reply_to = None;
a2880e5100 2025-04-19   28: 			match stream.next().await {
a2880e5100 2025-04-19   29: 				Some(update) => {
a2880e5100 2025-04-19   30: 					if let Err(err) = handle(update?, &core, &reply_to).await {
a2880e5100 2025-04-19   31: 						core.send(&format!("🛑 {err:?}"), reply_to, None).await?;
a2880e5100 2025-04-19   32: 					};
a2880e5100 2025-04-19   33: 				},
a2880e5100 2025-04-19   34: 				None => {
a2880e5100 2025-04-19   35: 					core.send("🛑 None error.", None, None).await?;
a2880e5100 2025-04-19   36: 				}
a2880e5100 2025-04-19   37: 			};
a2880e5100 2025-04-19   38: 		}
a2880e5100 2025-04-19   39: 	})
a2880e5100 2025-04-19   40: }
                        41: 
a2880e5100 2025-04-19   42: async fn handle(update: telegram_bot::Update, core: &core::Core, mut _reply_to: &Option<telegram_bot::UserId>) -> Result<()> {
a2880e5100 2025-04-19   43: 	if let telegram_bot::UpdateKind::Message(message) = update.kind {
a2880e5100 2025-04-19   44: 		if let Some(from) = message.from {
a2880e5100 2025-04-19   45: 			if let telegram_bot::MessageKind::Text{ ref data, .. } = message.kind {
a2880e5100 2025-04-19   46: 				let sender = from.id;
a2880e5100 2025-04-19   47: 				let words: Vec<&str> = data.split_whitespace().collect();
a2880e5100 2025-04-19   48: 				if let Err(err) = match words[0] {
a2880e5100 2025-04-19   49: 					"/check" | "/clean" | "/enable" | "/delete" | "/disable" => command::command(core, sender, words).await,
a2880e5100 2025-04-19   50: 					"/start" => command::start(core, sender).await,
a2880e5100 2025-04-19   51: 					"/list" => command::list(core, sender).await,
a2880e5100 2025-04-19   52: 					"/add" | "/update" => command::update(core, sender, words).await,
a2880e5100 2025-04-19   53: 					_ => Ok(()),
a2880e5100 2025-04-19   54: 				} {
a2880e5100 2025-04-19   55: 					core.send(format!("🛑 {:?}", err), Some(sender), None).await?;
a2880e5100 2025-04-19   56: 				};
a2880e5100 2025-04-19   57: 			};
a2880e5100 2025-04-19   58: 		};
a2880e5100 2025-04-19   59: 	};
                        60: 
                        61: 	Ok(())
                        62: }