Annotation For src/main.rs
Logged in as anonymous

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

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