Annotation For src/main.rs
Logged in as anonymous

Origin for each line in src/main.rs from check-in 9171c791eb:

9171c791eb 2021-11-13    1: mod command;
9171c791eb 2021-11-13    2: mod core;
6ac5737a72 2020-11-18    3: 
61df933942 2020-11-18    4: use config;
b2297258c7 2021-11-06    5: use futures::StreamExt;
61df933942 2020-11-18    6: use tokio;
423cadd9c7 2020-11-27    7: 
423cadd9c7 2020-11-27    8: use telegram_bot::*;
61df933942 2020-11-18    9: 
4acdad1942 2020-11-26   10: #[macro_use]
4acdad1942 2020-11-26   11: extern crate lazy_static;
4acdad1942 2020-11-26   12: 
9171c791eb 2021-11-13   13: use anyhow::Result;
ec616a2a43 2020-11-19   14: 
ec616a2a43 2020-11-19   15: #[tokio::main]
61df933942 2020-11-18   16: async fn main() -> Result<()> {
61df933942 2020-11-18   17: 	let mut settings = config::Config::default();
61df933942 2020-11-18   18: 	settings.merge(config::File::with_name("rsstg"))?;
61df933942 2020-11-18   19: 
9171c791eb 2021-11-13   20: 	let core = core::Core::new(settings).await?;
a68576cc1b 2020-12-15   21: 
a68576cc1b 2020-12-15   22: 	let mut stream = core.stream();
fcf57ccb36 2021-07-25   23: 	stream.allowed_updates(&[AllowedUpdate::Message]);
b2b8005309 2020-12-18   24: 	let mut reply_to: Option<UserId>;
a68576cc1b 2020-12-15   25: 
a68576cc1b 2020-12-15   26: 	loop {
b2b8005309 2020-12-18   27: 		reply_to = None;
a68576cc1b 2020-12-15   28: 		match stream.next().await {
a68576cc1b 2020-12-15   29: 			Some(update) => {
b2b8005309 2020-12-18   30: 				if let Err(err) = handle(update?, &core, &mut reply_to).await {
9171c791eb 2021-11-13   31: 					core.send(&format!("🛑 {:?}", err), reply_to)?;
a68576cc1b 2020-12-15   32: 				};
a68576cc1b 2020-12-15   33: 			},
a68576cc1b 2020-12-15   34: 			None => {
9171c791eb 2021-11-13   35: 				core.send(&format!("🛑 None error."), None)?;
a68576cc1b 2020-12-15   36: 			}
a68576cc1b 2020-12-15   37: 		};
a68576cc1b 2020-12-15   38: 	}
a68576cc1b 2020-12-15   39: 
a68576cc1b 2020-12-15   40: 	//Ok(())
a68576cc1b 2020-12-15   41: }
a68576cc1b 2020-12-15   42: 
9171c791eb 2021-11-13   43: async fn handle(update: telegram_bot::Update, core: &core::Core, mut _reply_to: &Option<UserId>) -> Result<()> {
a68576cc1b 2020-12-15   44: 	match update.kind {
a68576cc1b 2020-12-15   45: 		UpdateKind::Message(message) => {
a68576cc1b 2020-12-15   46: 			match message.kind {
a68576cc1b 2020-12-15   47: 				MessageKind::Text { ref data, .. } => {
9171c791eb 2021-11-13   48: 					let sender = message.from.id;
9171c791eb 2021-11-13   49: 					let words: Vec<&str> = data.split_whitespace().collect();
9171c791eb 2021-11-13   50: 					match words[0] {
9171c791eb 2021-11-13   51: 						"/check" | "/clean" | "/enable" | "/delete" | "/disable" => command::command(core, sender, words).await?,
9171c791eb 2021-11-13   52: 						"/start" => command::start(core, sender).await?,
9171c791eb 2021-11-13   53: 						"/list" => command::list(core, sender).await?,
9171c791eb 2021-11-13   54: 						"/add" | "/update" => command::update(core, sender, words).await?,
4acdad1942 2020-11-26   55: 						_ => {
4acdad1942 2020-11-26   56: 						},
4acdad1942 2020-11-26   57: 					};
4acdad1942 2020-11-26   58: 				},
4acdad1942 2020-11-26   59: 				_ => {
4acdad1942 2020-11-26   60: 				},
4acdad1942 2020-11-26   61: 			};
4acdad1942 2020-11-26   62: 		},
4acdad1942 2020-11-26   63: 		_ => {},
4acdad1942 2020-11-26   64: 	};
61df933942 2020-11-18   65: 
61df933942 2020-11-18   66: 	Ok(())
61df933942 2020-11-18   67: }