Annotation For src/main.rs
Logged in as anonymous

Origin for each line in src/main.rs from check-in 614456ed35:

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