diff --git a/src/utils/code_embed/url_parser.rs b/src/utils/code_embed/url_parser.rs index 3a970f6..154746f 100644 --- a/src/utils/code_embed/url_parser.rs +++ b/src/utils/code_embed/url_parser.rs @@ -48,12 +48,9 @@ impl CodeUrlParser for GitHubCodeUrl { } fn parse_code_url(&self) -> Result { - let mut segments = self - .url - .path_segments() - .ok_or(ParserError::ConversionError( - "Failed to convert path segments".to_string(), - ))?; + let mut segments = self.url.path_segments().ok_or_else(|| { + ParserError::ConversionError("Failed to convert path segments".to_string()) + })?; // parse the segments @@ -64,7 +61,7 @@ impl CodeUrlParser for GitHubCodeUrl { let mut path = String::new(); while let Ok(segment) = parse_segment!(segments, "path") { - if segment == "" { + if segment.is_empty() { continue; } path.push('/'); @@ -98,7 +95,7 @@ impl CodeUrlParser for GitHubCodeUrl { } let start = numbers.remove(0); - let end = numbers.pop().unwrap_or_else(|| start); + let end = numbers.pop().unwrap_or(start); code_url.relevant_lines = Some((start, end)); } @@ -130,7 +127,7 @@ impl CodeUrlParser for GitHubCodeUrl { .await .map_err(|_| ParserError::FailedToGetCode("Can't parse body".to_string()))?; - let preview = if let Some((start, end)) = code_url.relevant_lines.clone() { + let preview = if let Some((start, end)) = code_url.relevant_lines { let lines = code.lines().collect::>(); let start = start - 1; let end = end - 1; diff --git a/src/utils/code_embed/utils.rs b/src/utils/code_embed/utils.rs index 882a54d..b165110 100644 --- a/src/utils/code_embed/utils.rs +++ b/src/utils/code_embed/utils.rs @@ -1,7 +1,6 @@ use chrono::Utc; -use poise::serenity_prelude::{ButtonStyle, ReactionType}; use reqwest::Url; -use tracing::{debug, error, trace}; +use tracing::{debug, error}; use super::*; use crate::utils::bot::get_data_lock; @@ -21,9 +20,9 @@ pub async fn handle_code_url(ctx: &serenity::Context, new_message: &serenity::Me let new_slice = &slice[start..]; if let Some(end) = new_slice - .find(" ") - .or(new_slice.find("\n")) - .and_then(|slice_end| Some(start + slice_end)) + .find(' ') + .or_else(|| new_slice.find('\n')) + .map(|slice_end| start + slice_end) { debug!("HTTP url end: {}", end); @@ -124,5 +123,7 @@ pub async fn handle_code_url(ctx: &serenity::Context, new_message: &serenity::Me ); } - new_message.delete(&ctx.http).await; + if let Err(err) = new_message.delete(&ctx.http).await { + error!("Failed to delete the message. Error: {:?}", err); + } }