Annotation For src/main.rs
Logged in as anonymous

Origin for each line in src/main.rs from check-in 1c444d34ff:

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