diff --git a/src/handlers/github_expansion.rs b/src/handlers/github_expansion.rs index e5137ec..405deed 100644 --- a/src/handlers/github_expansion.rs +++ b/src/handlers/github_expansion.rs @@ -1,10 +1,10 @@ use poise::serenity_prelude as serenity; -use anyhow::{anyhow, Result}; -use once_cell::sync::Lazy; +use crate::reqwest_client; use regex::Regex; -use crate::reqwest_client; +use anyhow::Result; +use once_cell::sync::Lazy; static GITHUB: Lazy = Lazy::new(|| { Regex::new(r"https?://github\.com/(?P[\w-]+/[\w.-]+)/blob/(?P.+?)/(?P.*\.(?:(?P\w+))?)#L(?P\d+)(?:[~-]L?(?P\d+)?)?").unwrap() @@ -15,29 +15,16 @@ pub async fn handle(message: &serenity::Message, ctx: &serenity::Context) -> Res let mut embeds: Vec = vec![]; for captures in GITHUB.captures_iter(&message.content) { - let repo = captures - .name("repo") - .ok_or_else(|| anyhow!("Could not obtain `repo`"))? - .as_str(); - let ref_ = captures - .name("ref") - .ok_or_else(|| anyhow!("Could not obtain `ref`"))? - .as_str(); - let file = captures - .name("file") - .ok_or_else(|| anyhow!("Could not obtain `file`"))? - .as_str(); + let repo = &captures["repo"]; + let ref_ = &captures["ref"]; + let file = &captures["file"]; let language = match captures.name("language") { Some(m) => m.as_str().to_owned(), None => "".to_owned(), }; - let start = captures - .name("start") - .ok_or_else(|| anyhow!("Could not obtain `start`"))? - .as_str() - .parse::()?; + let start = &captures["start"].parse::()?; let end = captures .name("end") .and_then(|end| end.as_str().parse::().ok());