Index: Cargo.toml ================================================================== --- Cargo.toml +++ Cargo.toml @@ -1,8 +1,8 @@ [package] name = "rsstg" -version = "0.2.0" +version = "0.2.1" authors = ["arcade"] edition = "2018" [dependencies] anyhow = "*" Index: src/command.rs ================================================================== --- src/command.rs +++ src/command.rs @@ -56,22 +56,19 @@ i_command.next().context(at_least)?, i_command.next().context(at_least)?, i_command.next(), i_command.next()); if ! RE_USERNAME.is_match(&channel) { - core.send(format!("Usernames should be something like \"@\\[a\\-zA\\-Z]\\[a\\-zA\\-Z0\\-9\\_]+\", aren't they?\nNot {:?}", &channel), Some(sender), None)?; - return Ok(()) - } + bail!("Usernames should be something like \"@\\[a\\-zA\\-Z]\\[a\\-zA\\-Z0\\-9\\_]+\", aren't they?\nNot {:?}", &channel); + }; if ! RE_LINK.is_match(&url) { - core.send(format!("Link should be a link to atom/rss feed, something like \"https://domain/path\".\nNot {:?}", &url), Some(sender), None)?; - return Ok(()) + bail!("Link should be a link to atom/rss feed, something like \"https://domain/path\".\nNot {:?}", &url); } let iv_hash = match iv_hash { Some(hash) => { if ! RE_IV_HASH.is_match(hash) { - core.send(format!("IV hash should be 14 hex digits.\nNot {:?}", hash), Some(sender), None)?; - return Ok(()) + bail!("IV hash should be 14 hex digits.\nNot {:?}", hash); }; Some(*hash) } None => None, }; @@ -78,20 +75,20 @@ if let Some(rex) = url_re { let _url_rex = ReplaceCommand::new(rex).context("Regexp parsing error:")?; }; let channel_id = i64::from(core.tg.send(telegram_bot::GetChat::new(telegram_bot::types::ChatRef::ChannelUsername(channel.to_string()))).await?.id()); let chan_adm = core.tg.send(telegram_bot::GetChatAdministrators::new(telegram_bot::types::ChatRef::ChannelUsername(channel.to_string()))).await - .context("Sorry, I have no access to that chat\\.")?; + .context("Sorry, I have no access to that chat.")?; let (mut me, mut user) = (false, false); for admin in chan_adm { if admin.user.id == core.my.id { me = true; }; if admin.user.id == sender { user = true; }; }; - if ! me { bail!("I need to be admin on that channel\\."); }; - if ! user { bail!("You should be admin on that channel\\."); }; + if ! me { bail!("I need to be admin on that channel."); }; + if ! user { bail!("You should be admin on that channel."); }; core.send(core.update(source_id, channel, channel_id, url, iv_hash, None, sender).await?, Some(sender), None)?; Ok(()) } Index: src/main.rs ================================================================== --- src/main.rs +++ src/main.rs @@ -44,17 +44,19 @@ telegram_bot::UpdateKind::Message(message) => { match message.kind { telegram_bot::MessageKind::Text { ref data, .. } => { let sender = message.from.id; let words: Vec<&str> = data.split_whitespace().collect(); - match words[0] { - "/check" | "/clean" | "/enable" | "/delete" | "/disable" => command::command(core, sender, words).await?, - "/start" => command::start(core, sender).await?, - "/list" => command::list(core, sender).await?, - "/add" | "/update" => command::update(core, sender, words).await?, - _ => { - }, + match match words[0] { + "/check" | "/clean" | "/enable" | "/delete" | "/disable" => command::command(core, sender, words).await, + "/start" => command::start(core, sender).await, + "/list" => command::list(core, sender).await, + "/add" | "/update" => command::update(core, sender, words).await, + _ => Ok(()), + } { + Err(err) => core.send(&format!("🛑 {:?}", err), Some(sender), None)?, + Ok(()) => {}, }; }, _ => { }, };