mirror of
https://github.com/revanced/revanced-discord-bot.git
synced 2025-05-02 07:24:25 +02:00
refactor: apply clippy suggestions
This commit is contained in:
parent
cdfbd438af
commit
f754cd3107
@ -48,12 +48,9 @@ impl CodeUrlParser for GitHubCodeUrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_code_url(&self) -> Result<CodeUrl, ParserError> {
|
fn parse_code_url(&self) -> Result<CodeUrl, ParserError> {
|
||||||
let mut segments = self
|
let mut segments = self.url.path_segments().ok_or_else(|| {
|
||||||
.url
|
ParserError::ConversionError("Failed to convert path segments".to_string())
|
||||||
.path_segments()
|
})?;
|
||||||
.ok_or(ParserError::ConversionError(
|
|
||||||
"Failed to convert path segments".to_string(),
|
|
||||||
))?;
|
|
||||||
|
|
||||||
// parse the segments
|
// parse the segments
|
||||||
|
|
||||||
@ -64,7 +61,7 @@ impl CodeUrlParser for GitHubCodeUrl {
|
|||||||
|
|
||||||
let mut path = String::new();
|
let mut path = String::new();
|
||||||
while let Ok(segment) = parse_segment!(segments, "path") {
|
while let Ok(segment) = parse_segment!(segments, "path") {
|
||||||
if segment == "" {
|
if segment.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
path.push('/');
|
path.push('/');
|
||||||
@ -98,7 +95,7 @@ impl CodeUrlParser for GitHubCodeUrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let start = numbers.remove(0);
|
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));
|
code_url.relevant_lines = Some((start, end));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +127,7 @@ impl CodeUrlParser for GitHubCodeUrl {
|
|||||||
.await
|
.await
|
||||||
.map_err(|_| ParserError::FailedToGetCode("Can't parse body".to_string()))?;
|
.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::<Vec<_>>();
|
let lines = code.lines().collect::<Vec<_>>();
|
||||||
let start = start - 1;
|
let start = start - 1;
|
||||||
let end = end - 1;
|
let end = end - 1;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use poise::serenity_prelude::{ButtonStyle, ReactionType};
|
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use tracing::{debug, error, trace};
|
use tracing::{debug, error};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::utils::bot::get_data_lock;
|
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..];
|
let new_slice = &slice[start..];
|
||||||
|
|
||||||
if let Some(end) = new_slice
|
if let Some(end) = new_slice
|
||||||
.find(" ")
|
.find(' ')
|
||||||
.or(new_slice.find("\n"))
|
.or_else(|| new_slice.find('\n'))
|
||||||
.and_then(|slice_end| Some(start + slice_end))
|
.map(|slice_end| start + slice_end)
|
||||||
{
|
{
|
||||||
debug!("HTTP url end: {}", 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user