Annotation For src/main.rs
Logged in as anonymous

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

                         1: use std::collections::BTreeMap;
                         2: 
                         3: use config;
                         4: 
                         5: use tokio;
                         6: use rss;
                         7: use chrono::DateTime;
                         8: 
                         9: use regex::Regex;
                        10: 
                        11: use tokio::stream::StreamExt;
                        12: use telegram_bot::*;
                        13: 
                        14: use sqlx::postgres::PgPoolOptions;
                        15: use sqlx::Row;
                        16: 
                        17: type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
                        18: 
                        19: #[derive(Clone)]
                        20: struct Core {
                        21: 	owner: i64,
                        22: 	api_key: String,
                        23: 	owner_chat: UserId,
                        24: 	tg: telegram_bot::Api,
                        25: 	my: User,
                        26: 	pool: sqlx::Pool<sqlx::Postgres>,
                        27: }
                        28: 
                        29: impl Core {
                        30: 	async fn new(settings: config::Config) -> Result<Core> {
                        31: 		let owner = settings.get_int("owner")?;
                        32: 		let api_key = settings.get_str("api_key")?;
                        33: 		let tg = Api::new(&api_key);
                        34: 		let core = Core {
                        35: 			owner: owner,
                        36: 			api_key: api_key.clone(),
                        37: 			my: tg.send(telegram_bot::GetMe).await?,
                        38: 			tg: tg,
                        39: 			owner_chat: UserId::new(owner),
                        40: 			pool: PgPoolOptions::new().max_connections(5).connect(&settings.get_str("pg")?).await?,
                        41: 		};
                        42: 		let clone = core.clone();
                        43: 		tokio::spawn(async move {
                        44: 			if let Err(err) = clone.autofetch().await {
                        45: 				eprintln!("connection error: {}", err);
                        46: 			}
                        47: 		});
                        48: 		Ok(core)
                        49: 	}
                        50: 
                        51: 	fn stream(&self) -> telegram_bot::UpdatesStream {
                        52: 		self.tg.stream()
                        53: 	}
                        54: 
                        55: 	fn debug(&self, msg: &str) -> Result<()> {
                        56: 		self.tg.spawn(SendMessage::new(self.owner_chat, msg));
                        57: 		Ok(())
                        58: 	}
                        59: 
                        60: 	async fn check(&self, id: &i32, real: Option<bool>) -> Result<()> {
                        61: 		match sqlx::query("select source_id, channel_id, url, iv_hash, owner from rsstg_source where source_id = $1")
                        62: 			.bind(id)
                        63: 			.fetch_one(&self.pool).await {
                        64: 			Ok(row) => {
                        65: 				let channel_id: i64 = row.try_get("channel_id")?;
                        66: 				let destination = match real {
                        67: 					Some(true) => UserId::new(channel_id),
                        68: 					Some(false) | None => UserId::new(row.try_get("owner")?),
                        69: 				};
                        70: 				let url: &str = row.try_get("url")?;
                        71: 				let mut this_fetch: Option<DateTime<chrono::FixedOffset>> = None;
                        72: 				let iv_hash: Option<&str> = row.try_get("iv_hash")?;
                        73: 				let mut posts: BTreeMap<DateTime<chrono::FixedOffset>, String> = BTreeMap::new();
                        74: 				match rss::Channel::from_url(url) {
                        75: 					Ok(feed) => {
6ac5737a72 2020-11-18   76: 						self.debug(&format!("# title:{:?} ttl:{:?} hours:{:?} days:{:?}", feed.title(), feed.ttl(), feed.skip_hours(), feed.skip_days()))?;
                        77: 						for item in feed.items() {
                        78: 							let date = match item.pub_date() {
                        79: 								Some(feed_date) => DateTime::parse_from_rfc2822(feed_date),
                        80: 								None => DateTime::parse_from_rfc3339(&item.dublin_core_ext().unwrap().dates()[0]),
                        81: 							}?;
                        82: 							let url = item.link().unwrap().to_string();
                        83: 							posts.insert(date.clone(), url.clone());
                        84: 						};
                        85: 						for (date, url) in posts.iter() {
                        86: 							match sqlx::query("select exists(select true from rsstg_post where url = $1 and source_id = $2) as exists;")
                        87: 								.bind(&url)
                        88: 								.bind(id)
                        89: 								.fetch_one(&self.pool).await {
                        90: 								Ok(row) => {
                        91: 									let exists: bool = row.try_get("exists")?;
                        92: 									if ! exists {
                        93: 										if this_fetch == None || *date > this_fetch.unwrap() {
                        94: 											this_fetch = Some(*date);
                        95: 										}
                        96: 										match self.tg.send( match iv_hash {
                        97: 												Some(x) => SendMessage::new(destination, format!("<a href=\"https://t.me/iv?url={}&rhash={}\"> </a>{0}", url, x)),
                        98: 												None => SendMessage::new(destination, format!("{}", url)),
                        99: 											}.parse_mode(types::ParseMode::Html)).await {
                       100: 											Ok(_) => {
                       101: 												match sqlx::query("insert into rsstg_post (source_id, posted, url) values ($1, $2, $3);")
                       102: 													.bind(id)
                       103: 													.bind(date)
                       104: 													.bind(url)
                       105: 													.execute(&self.pool).await {
                       106: 														Ok(_) => {},
                       107: 														Err(err) => {
                       108: 															self.debug(&err.to_string())?;
                       109: 														},
                       110: 												};
                       111: 											},
                       112: 											Err(err) => {
                       113: 												self.debug(&err.to_string())?;
                       114: 											},
                       115: 										};
                       116: 										tokio::time::delay_for(std::time::Duration::new(4, 0)).await;
                       117: 									}
                       118: 								},
                       119: 								Err(err) => {
                       120: 									self.debug(&err.to_string())?;
                       121: 								},
                       122: 							};
                       123: 						};
                       124: 						posts.clear();
                       125: 					},
                       126: 					Err(err) => {
6ac5737a72 2020-11-18  127: 						self.debug(&err.to_string())?;
                       128: 					},
                       129: 				};
                       130: 				match sqlx::query("update rsstg_source set last_scrape = now() where source_id = $1;")
                       131: 					.bind(id)
                       132: 					.execute(&self.pool).await {
                       133: 					Ok(_) => {},
                       134: 					Err(err) => {
                       135: 						self.debug(&err.to_string())?;
                       136: 					},
                       137: 				};
                       138: 			},
                       139: 			Err(err) => {
                       140: 				self.debug(&err.to_string())?;
                       141: 			},
                       142: 		};
                       143: 		Ok(())
                       144: 	}
                       145: 
                       146: 	async fn clean(&self, source_id: i32) -> Result<()> {
                       147: 		match sqlx::query("delete from rsstg_post where source_id = $1;")
                       148: 			.bind(source_id)
                       149: 			.execute(&self.pool).await {
                       150: 			Ok(_) => {},
                       151: 			Err(err) => {
                       152: 				self.debug(&err.to_string())?;
                       153: 			},
                       154: 		};
                       155: 		Ok(())
                       156: 	}
                       157: 
                       158: 	async fn enable(&self, source_id: &i32) -> Result<()> {
                       159: 		match sqlx::query("update rsstg_source set enabled = true where source_id = $1")
                       160: 			.bind(source_id)
                       161: 			.execute(&self.pool).await {
                       162: 			Ok(_) => {},
                       163: 			Err(err) => {
                       164: 				self.debug(&err.to_string())?;
                       165: 			},
                       166: 		}
                       167: 		Ok(())
                       168: 	}
                       169: 
                       170: 	async fn disable(&self, source_id: &i32) -> Result<()> {
                       171: 		match sqlx::query("update rsstg_source set enabled = false where source_id = $1")
                       172: 			.bind(source_id)
                       173: 			.execute(&self.pool).await {
                       174: 			Ok(_) => {},
                       175: 			Err(err) => {
                       176: 				self.debug(&err.to_string())?;
                       177: 			},
                       178: 		}
                       179: 		Ok(())
                       180: 	}
                       181: 
                       182: 	async fn autofetch(&self) -> Result<()> {
                       183: 		let mut delay = chrono::Duration::minutes(5);
                       184: 		let mut next_fetch: DateTime<chrono::Local>;
                       185: 		let mut now;
                       186: 		loop {
6ac5737a72 2020-11-18  187: 			self.debug("cycle")?;
                       188: 			now = chrono::Local::now();
                       189: 			let mut rows = sqlx::query("select source_id, next_fetch from rsstg_order natural left join rsstg_source natural left join rsstg_channel where next_fetch < now();")
                       190: 				.fetch(&self.pool);
                       191: 			while let Some(row) = rows.try_next().await.unwrap() {
                       192: 				let source_id: i32 = row.try_get("source_id")?;
                       193: 				next_fetch = row.try_get("next_fetch")?;
                       194: 				if next_fetch < now {
                       195: 					match sqlx::query("update rsstg_source set last_scrape = now() + interval '1 hour' where source_id = $1;")
                       196: 						.bind(source_id)
                       197: 						.execute(&self.pool).await {
                       198: 						Ok(_) => {},
                       199: 						Err(err) => {
                       200: 							self.debug(&err.to_string())?;
                       201: 						},
                       202: 					};
                       203: 					let clone = self.clone();
                       204: 					tokio::spawn(async move {
                       205: 						if let Err(err) = clone.check(&source_id.clone(), Some(true)).await {
                       206: 							eprintln!("connection error: {}", err);
                       207: 						}
                       208: 					});
                       209: 				} else {
                       210: 					if next_fetch - now < delay {
                       211: 						delay = next_fetch - now;
                       212: 					}
                       213: 				}
                       214: 			};
                       215: 			tokio::time::delay_for(delay.to_std()?).await;
                       216: 			delay = chrono::Duration::minutes(5);
                       217: 		}
                       218: 		//Ok(())
                       219: 	}
                       220: 
                       221: }
                       222: 
6ac5737a72 2020-11-18  223: #[tokio::main(basic_scheduler)]
                       224: async fn main() -> Result<()> {
                       225: 	let mut settings = config::Config::default();
                       226: 	settings.merge(config::File::with_name("rsstg"))?;
                       227: 
                       228: 	let re_username = Regex::new(r"^@[a-zA-Z][a-zA-Z0-9_]+$")?;
                       229: 	let re_link = Regex::new(r"^https?://[a-zA-Z.0-9-]+/[-_a-zA-Z.0-9/?=]+$")?;
                       230: 	let re_iv_hash = Regex::new(r"^[a-f0-9]{14}$")?;
                       231: 
                       232: 	let core = Core::new(settings).await?;
                       233: 
                       234: 	let mut stream = core.stream();
                       235: 
                       236: 	while let Some(update) = stream.next().await {
6ac5737a72 2020-11-18  237: 		let update = update?;
6ac5737a72 2020-11-18  238: 		match update.kind {
6ac5737a72 2020-11-18  239: 			UpdateKind::Message(message) => {
6ac5737a72 2020-11-18  240: 				let mut reply: Vec<String> = vec![];
6ac5737a72 2020-11-18  241: 				match message.kind {
6ac5737a72 2020-11-18  242: 					MessageKind::Text { ref data, .. } => {
6ac5737a72 2020-11-18  243: 						let mut words = data.split_whitespace();
6ac5737a72 2020-11-18  244: 						let cmd = words.next().unwrap();
6ac5737a72 2020-11-18  245: 						match cmd {
6ac5737a72 2020-11-18  246: 
6ac5737a72 2020-11-18  247: // start
6ac5737a72 2020-11-18  248: 
6ac5737a72 2020-11-18  249: 							"/start" => {
6ac5737a72 2020-11-18  250: 								reply.push("Not in service yet\\. Try later\\.".to_string());
6ac5737a72 2020-11-18  251: 							},
6ac5737a72 2020-11-18  252: 
6ac5737a72 2020-11-18  253: // list
6ac5737a72 2020-11-18  254: 
6ac5737a72 2020-11-18  255: 							"/list" => {
6ac5737a72 2020-11-18  256: 								reply.push("Channels:".to_string());
6ac5737a72 2020-11-18  257: 								let mut rows = sqlx::query("select source_id, username, enabled, url, iv_hash from rsstg_source left join rsstg_channel using (channel_id) where owner = $1 order by source_id")
6ac5737a72 2020-11-18  258: 									.bind(i64::from(message.from.id))
6ac5737a72 2020-11-18  259: 									.fetch(&core.pool);
6ac5737a72 2020-11-18  260: 								while let Some(row) = rows.try_next().await? {
6ac5737a72 2020-11-18  261: 									let source_id: i32 = row.try_get("source_id")?;
6ac5737a72 2020-11-18  262: 									let username: &str = row.try_get("username")?;
6ac5737a72 2020-11-18  263: 									let enabled: bool = row.try_get("enabled")?;
6ac5737a72 2020-11-18  264: 									let url: &str = row.try_get("url")?;
6ac5737a72 2020-11-18  265: 									let iv_hash: Option<&str> = row.try_get("iv_hash")?;
6ac5737a72 2020-11-18  266: 									reply.push(format!("\n\\#️⃣ {} \\*️⃣ `{}` {}\n🔗 `{}`", source_id, username,  
6ac5737a72 2020-11-18  267: 										match enabled {
6ac5737a72 2020-11-18  268: 											true  => "🔄 enabled",
6ac5737a72 2020-11-18  269: 											false => "⛔ disabled",
6ac5737a72 2020-11-18  270: 										}, url));
6ac5737a72 2020-11-18  271: 									if let Some(hash) = iv_hash {
6ac5737a72 2020-11-18  272: 										reply.push(format!("IV `{}`", hash));
6ac5737a72 2020-11-18  273: 									}
6ac5737a72 2020-11-18  274: 								}
6ac5737a72 2020-11-18  275: 							},
6ac5737a72 2020-11-18  276: 
6ac5737a72 2020-11-18  277: // add
6ac5737a72 2020-11-18  278: 
6ac5737a72 2020-11-18  279: 							"/add" | "/update" => {
6ac5737a72 2020-11-18  280: 								let mut source_id: i32 = 0;
6ac5737a72 2020-11-18  281: 								if cmd == "/update" {
6ac5737a72 2020-11-18  282: 									source_id = words.next().unwrap().parse::<i32>()?;
6ac5737a72 2020-11-18  283: 								}
6ac5737a72 2020-11-18  284: 								let (channel, url, iv_hash) = (words.next().unwrap(), words.next().unwrap(), words.next());
6ac5737a72 2020-11-18  285: 								let ok_link = re_link.is_match(&url);
6ac5737a72 2020-11-18  286: 								let ok_hash = match iv_hash {
6ac5737a72 2020-11-18  287: 									Some(hash) => re_iv_hash.is_match(&hash),
6ac5737a72 2020-11-18  288: 									None => true,
6ac5737a72 2020-11-18  289: 								};
6ac5737a72 2020-11-18  290: 								if ! ok_link {
6ac5737a72 2020-11-18  291: 									reply.push("Link should be link to atom/rss feed, something like \"https://domain/path\"\\.".to_string());
6ac5737a72 2020-11-18  292: 									core.debug(&format!("Url: {:?}", &url))?;
6ac5737a72 2020-11-18  293: 								}
6ac5737a72 2020-11-18  294: 								if ! ok_hash {
6ac5737a72 2020-11-18  295: 									reply.push("IV hash should be 14 hex digits.".to_string());
6ac5737a72 2020-11-18  296: 									core.debug(&format!("IV: {:?}", &iv_hash))?;
6ac5737a72 2020-11-18  297: 								}
6ac5737a72 2020-11-18  298: 								if ok_link && ok_hash {
6ac5737a72 2020-11-18  299: 									let chan: Option<i64> = match sqlx::query("select channel_id from rsstg_channel where username = $1")
6ac5737a72 2020-11-18  300: 										.bind(channel)
6ac5737a72 2020-11-18  301: 										.fetch_one(&core.pool).await {
6ac5737a72 2020-11-18  302: 											Ok(chan) => Some(chan.try_get("channel_id")?),
6ac5737a72 2020-11-18  303: 											Err(sqlx::Error::RowNotFound) => {
6ac5737a72 2020-11-18  304: 												reply.push("Sorry, I don't know about that channel. Please, add a channel with /addchan.".to_string());
6ac5737a72 2020-11-18  305: 												None
6ac5737a72 2020-11-18  306: 											},
6ac5737a72 2020-11-18  307: 											Err(err) => {
6ac5737a72 2020-11-18  308: 												reply.push("Sorry, unknown error\\.".to_string());
6ac5737a72 2020-11-18  309: 												core.debug(&format!("Sorry, unknown error: {:#?}\n", err))?;
6ac5737a72 2020-11-18  310: 												None
6ac5737a72 2020-11-18  311: 											},
6ac5737a72 2020-11-18  312: 									};
6ac5737a72 2020-11-18  313: 									if let Some(chan) = chan {
6ac5737a72 2020-11-18  314: 										match if cmd == "/update" {
6ac5737a72 2020-11-18  315: 												sqlx::query("update rsstg_source set channel_id = $2, url = $3, iv_hash = $4, owner = $4 where source_id = $1").bind(source_id)
6ac5737a72 2020-11-18  316: 											} else {
6ac5737a72 2020-11-18  317: 												sqlx::query("insert into rsstg_source (channel_id, url, iv_hash, owner) values ($1, $2, $3, $4)")
6ac5737a72 2020-11-18  318: 											}
6ac5737a72 2020-11-18  319: 											.bind(chan)
6ac5737a72 2020-11-18  320: 											.bind(url)
6ac5737a72 2020-11-18  321: 											.bind(iv_hash)
6ac5737a72 2020-11-18  322: 											.bind(i64::from(message.from.id))
6ac5737a72 2020-11-18  323: 											.execute(&core.pool).await {
6ac5737a72 2020-11-18  324: 											Ok(_) => reply.push("Channel added\\.".to_string()),
6ac5737a72 2020-11-18  325: 											Err(sqlx::Error::Database(err)) => {
6ac5737a72 2020-11-18  326: 												match err.downcast::<sqlx::postgres::PgDatabaseError>().routine() {
6ac5737a72 2020-11-18  327: 													Some("_bt_check_unique", ) => {
6ac5737a72 2020-11-18  328: 														reply.push("Duplicate key\\.".to_string());
6ac5737a72 2020-11-18  329: 													},
6ac5737a72 2020-11-18  330: 													Some(_) => {
6ac5737a72 2020-11-18  331: 														reply.push("Database error\\.".to_string());
6ac5737a72 2020-11-18  332: 													},
6ac5737a72 2020-11-18  333: 													None => {
6ac5737a72 2020-11-18  334: 														reply.push("No database error extracted\\.".to_string());
6ac5737a72 2020-11-18  335: 													},
6ac5737a72 2020-11-18  336: 												};
6ac5737a72 2020-11-18  337: 											},
6ac5737a72 2020-11-18  338: 											Err(err) => {
6ac5737a72 2020-11-18  339: 												reply.push("Sorry, unknown error\\.".to_string());
6ac5737a72 2020-11-18  340: 												core.debug(&format!("Sorry, unknown error: {:#?}\n", err))?;
6ac5737a72 2020-11-18  341: 											},
6ac5737a72 2020-11-18  342: 										};
6ac5737a72 2020-11-18  343: 									};
6ac5737a72 2020-11-18  344: 								};
6ac5737a72 2020-11-18  345: 							},
6ac5737a72 2020-11-18  346: 
6ac5737a72 2020-11-18  347: // addchan
6ac5737a72 2020-11-18  348: 
6ac5737a72 2020-11-18  349: 							"/addchan" => {
6ac5737a72 2020-11-18  350: 								let channel = words.next().unwrap();
6ac5737a72 2020-11-18  351: 								if ! re_username.is_match(&channel) {
6ac5737a72 2020-11-18  352: 									reply.push("Usernames should be something like \"@\\[a\\-zA\\-Z]\\[a\\-zA\\-Z0\\-9\\_]+\", aren't they?".to_string());
6ac5737a72 2020-11-18  353: 								} else {
6ac5737a72 2020-11-18  354: 									let chan: Option<i64> = match sqlx::query("select channel_id from rsstg_channel where username = $1")
6ac5737a72 2020-11-18  355: 										.bind(channel)
6ac5737a72 2020-11-18  356: 										.fetch_one(&core.pool).await {
6ac5737a72 2020-11-18  357: 											Ok(chan) => Some(chan.try_get("channel_id")?),
6ac5737a72 2020-11-18  358: 											Err(sqlx::Error::RowNotFound) => None,
6ac5737a72 2020-11-18  359: 											Err(err) => {
6ac5737a72 2020-11-18  360: 												reply.push("Sorry, unknown error\\.".to_string());
6ac5737a72 2020-11-18  361: 												core.debug(&format!("Sorry, unknown error: {:#?}\n", err))?;
6ac5737a72 2020-11-18  362: 												None
6ac5737a72 2020-11-18  363: 											},
6ac5737a72 2020-11-18  364: 									};
6ac5737a72 2020-11-18  365: 									match chan {
6ac5737a72 2020-11-18  366: 										Some(chan) => {
6ac5737a72 2020-11-18  367: 											let new_chan = core.tg.send(telegram_bot::GetChat::new(telegram_bot::types::ChatId::new(chan))).await?;
6ac5737a72 2020-11-18  368: 											if i64::from(new_chan.id()) == chan {
6ac5737a72 2020-11-18  369: 												reply.push("I already know that channel\\.".to_string());
6ac5737a72 2020-11-18  370: 											} else {
6ac5737a72 2020-11-18  371: 												reply.push("Hmm, channel has changed… I'll fix it later\\.".to_string());
6ac5737a72 2020-11-18  372: 											};
6ac5737a72 2020-11-18  373: 										},
6ac5737a72 2020-11-18  374: 										None => {
6ac5737a72 2020-11-18  375: 											match core.tg.send(telegram_bot::GetChatAdministrators::new(telegram_bot::types::ChatRef::ChannelUsername(channel.to_string()))).await {
6ac5737a72 2020-11-18  376: 												Ok(chan_adm) => {
6ac5737a72 2020-11-18  377: 													let (mut me, mut user) = (false, false);
6ac5737a72 2020-11-18  378: 													for admin in &chan_adm {
6ac5737a72 2020-11-18  379: 														if admin.user.id == core.my.id {
6ac5737a72 2020-11-18  380: 															me = true;
6ac5737a72 2020-11-18  381: 														};
6ac5737a72 2020-11-18  382: 														if admin.user.id == message.from.id {
6ac5737a72 2020-11-18  383: 															user = true;
6ac5737a72 2020-11-18  384: 														};
6ac5737a72 2020-11-18  385: 													};
6ac5737a72 2020-11-18  386: 													if ! me   { reply.push("I need to be admin on that channel\\.".to_string()); };
6ac5737a72 2020-11-18  387: 													if ! user { reply.push("You should be admin on that channel\\.".to_string()); };
6ac5737a72 2020-11-18  388: 													if me && user {
6ac5737a72 2020-11-18  389: 														let chan_id = core.tg.send(telegram_bot::GetChat::new(telegram_bot::types::ChatRef::ChannelUsername(channel.to_string()))).await?;
6ac5737a72 2020-11-18  390: 														sqlx::query("insert into rsstg_channel (channel_id, username) values ($1, $2);")
6ac5737a72 2020-11-18  391: 															.bind(i64::from(chan_id.id()))
6ac5737a72 2020-11-18  392: 															.bind(channel)
6ac5737a72 2020-11-18  393: 															.execute(&core.pool).await?;
6ac5737a72 2020-11-18  394: 														reply.push("Good, I know that channel now\\.\n".to_string());
6ac5737a72 2020-11-18  395: 													};
6ac5737a72 2020-11-18  396: 												},
6ac5737a72 2020-11-18  397: 												Err(_) => {
6ac5737a72 2020-11-18  398: 													reply.push("Sorry, I have no access to that chat\\.".to_string());
6ac5737a72 2020-11-18  399: 												},
6ac5737a72 2020-11-18  400: 											};
6ac5737a72 2020-11-18  401: 										},
6ac5737a72 2020-11-18  402: 									};
6ac5737a72 2020-11-18  403: 								};
6ac5737a72 2020-11-18  404: 							},
6ac5737a72 2020-11-18  405: 
6ac5737a72 2020-11-18  406: // check
6ac5737a72 2020-11-18  407: 
6ac5737a72 2020-11-18  408: 							"/check" => {
6ac5737a72 2020-11-18  409: 								&core.check(&words.next().unwrap().parse::<i32>()?, None).await?;
6ac5737a72 2020-11-18  410: 							},
6ac5737a72 2020-11-18  411: 
6ac5737a72 2020-11-18  412: // clear
6ac5737a72 2020-11-18  413: 
6ac5737a72 2020-11-18  414: 							"/clean" => {
6ac5737a72 2020-11-18  415: 								if core.owner != i64::from(message.from.id) {
6ac5737a72 2020-11-18  416: 									reply.push("Reserved for testing\\.".to_string());
6ac5737a72 2020-11-18  417: 								} else {
6ac5737a72 2020-11-18  418: 									let source_id = words.next().unwrap().parse::<i32>().unwrap_or(0);
6ac5737a72 2020-11-18  419: 									&core.clean(source_id).await?;
6ac5737a72 2020-11-18  420: 								}
6ac5737a72 2020-11-18  421: 							},
6ac5737a72 2020-11-18  422: 
6ac5737a72 2020-11-18  423: // enable
6ac5737a72 2020-11-18  424: 
6ac5737a72 2020-11-18  425: 							"/enable" => {
6ac5737a72 2020-11-18  426: 								match core.enable(&words.next().unwrap().parse::<i32>()?).await {
6ac5737a72 2020-11-18  427: 									Ok(_) => {
6ac5737a72 2020-11-18  428: 										reply.push("Channel enabled\\.".to_string());
6ac5737a72 2020-11-18  429: 									}
6ac5737a72 2020-11-18  430: 									Err(err) => {
6ac5737a72 2020-11-18  431: 										core.debug(&err.to_string())?;
6ac5737a72 2020-11-18  432: 									},
6ac5737a72 2020-11-18  433: 								};
6ac5737a72 2020-11-18  434: 							},
6ac5737a72 2020-11-18  435: 
6ac5737a72 2020-11-18  436: // disable
6ac5737a72 2020-11-18  437: 
6ac5737a72 2020-11-18  438: 							"/disable" => {
6ac5737a72 2020-11-18  439: 								match core.disable(&words.next().unwrap().parse::<i32>()?).await {
6ac5737a72 2020-11-18  440: 									Ok(_) => {
6ac5737a72 2020-11-18  441: 										reply.push("Channel disabled\\.".to_string());
6ac5737a72 2020-11-18  442: 									}
6ac5737a72 2020-11-18  443: 									Err(err) => {
6ac5737a72 2020-11-18  444: 										core.debug(&err.to_string())?;
6ac5737a72 2020-11-18  445: 									},
6ac5737a72 2020-11-18  446: 								};
6ac5737a72 2020-11-18  447: 							},
6ac5737a72 2020-11-18  448: 
6ac5737a72 2020-11-18  449: 							_ => {
6ac5737a72 2020-11-18  450: 							},
6ac5737a72 2020-11-18  451: 						};
6ac5737a72 2020-11-18  452: 					},
6ac5737a72 2020-11-18  453: 					_ => {
6ac5737a72 2020-11-18  454: 					},
6ac5737a72 2020-11-18  455: 				};
6ac5737a72 2020-11-18  456: 				if reply.len() > 0 {
6ac5737a72 2020-11-18  457: 					match core.tg.send(message.text_reply(reply.join("\n")).parse_mode(types::ParseMode::MarkdownV2)).await {
6ac5737a72 2020-11-18  458: 						Ok(_) => {},
6ac5737a72 2020-11-18  459: 						Err(err) => {
6ac5737a72 2020-11-18  460: 							dbg!(reply.join("\n"));
6ac5737a72 2020-11-18  461: 							println!("{}", err);
6ac5737a72 2020-11-18  462: 						},
6ac5737a72 2020-11-18  463: 					}
6ac5737a72 2020-11-18  464: 				}
6ac5737a72 2020-11-18  465: 			},
6ac5737a72 2020-11-18  466: 			_ => {},
                       467: 		};
                       468: 	}
                       469: 
                       470: 	Ok(())
                       471: }