Clippy and cleanup
This commit is contained in:
parent
5ef9c3c674
commit
20db2b4fde
5 changed files with 26 additions and 34 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use eyre::{eyre, OptionExt, Result};
|
||||
use eyre::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{HttpClient, HttpClientExt};
|
||||
|
|
|
@ -6,11 +6,12 @@ use regex::Regex;
|
|||
// in future, we can add extra data to display in log analysis like Java version
|
||||
pub enum Info {
|
||||
Game,
|
||||
Launcher
|
||||
Launcher,
|
||||
}
|
||||
|
||||
pub fn find(log: &str) -> Option<Info> {
|
||||
if looks_like_launcher_log(log) { // launcher logs can sometimes seem like a game log
|
||||
if looks_like_launcher_log(log) {
|
||||
// launcher logs can sometimes seem like a game log
|
||||
Some(Info::Launcher)
|
||||
} else if looks_like_game_log(log) {
|
||||
Some(Info::Game)
|
||||
|
@ -61,7 +62,7 @@ fn looks_like_game_log(log: &str) -> bool {
|
|||
Regex::new(r"\[\d{2}:\d{2}:\d{2}\] \[.+?/(FATAL|ERROR|WARN|INFO|DEBUG|TRACE)\] ").unwrap()
|
||||
});
|
||||
|
||||
if log4j.is_match(&log) {
|
||||
if log4j.is_match(log) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,14 +5,13 @@ use crate::{
|
|||
Data,
|
||||
};
|
||||
|
||||
use color_eyre::owo_colors::OwoColorize;
|
||||
use eyre::{eyre, OptionExt, Result};
|
||||
use info::{find, Info};
|
||||
use info::Info;
|
||||
use log::{debug, trace};
|
||||
use poise::serenity_prelude::{
|
||||
ButtonStyle, ComponentInteraction, Context, CreateAllowedMentions, CreateButton, CreateEmbed,
|
||||
CreateInteractionResponse, CreateInteractionResponseMessage, CreateMessage, EditMessage,
|
||||
Message, MessageId, MessageType,
|
||||
Message, MessageType,
|
||||
};
|
||||
|
||||
mod info;
|
||||
|
@ -49,21 +48,17 @@ pub async fn handle_message(ctx: &Context, message: &Message, data: &Data) -> Re
|
|||
|
||||
let attachment = first_text_attachment(message);
|
||||
|
||||
let log = match log {
|
||||
Some(log) => log,
|
||||
None => match attachment {
|
||||
Some(attachment) => {
|
||||
data.http_client
|
||||
.get_request(&attachment.url)
|
||||
.await?
|
||||
.text()
|
||||
.await?
|
||||
}
|
||||
None => {
|
||||
debug!("No log found in message! Skipping analysis");
|
||||
return Ok(());
|
||||
}
|
||||
},
|
||||
let log = if let Some(log) = log {
|
||||
log
|
||||
} else if let Some(attachment) = attachment {
|
||||
data.http_client
|
||||
.get_request(&attachment.url)
|
||||
.await?
|
||||
.text()
|
||||
.await?
|
||||
} else {
|
||||
debug!("No log found in message! Skipping analysis");
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let issues = issues::find(&log, data).await?;
|
||||
|
@ -268,7 +263,7 @@ pub async fn handle_component_interaction(
|
|||
.await?;
|
||||
}
|
||||
|
||||
if embeds.len() == 0 {
|
||||
if embeds.is_empty() {
|
||||
interaction.message.delete(ctx).await?;
|
||||
} else {
|
||||
ctx.http
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::api::{mclogs::raw_log, HttpClient, HttpClientExt};
|
||||
use crate::api::{mclogs::raw_log, HttpClient};
|
||||
|
||||
use std::sync::OnceLock;
|
||||
|
||||
|
@ -19,6 +19,6 @@ impl super::LogProvider for MCLogs {
|
|||
}
|
||||
|
||||
async fn fetch(&self, http: &HttpClient, content: &str) -> Result<String> {
|
||||
Ok(raw_log(&http, content).await?)
|
||||
raw_log(http, content).await
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,13 +17,9 @@ pub fn semver_split(version: &str) -> Vec<u32> {
|
|||
}
|
||||
|
||||
pub fn first_text_attachment(message: &Message) -> Option<&Attachment> {
|
||||
message
|
||||
.attachments
|
||||
.iter()
|
||||
.filter(|a| {
|
||||
a.content_type
|
||||
.as_ref()
|
||||
.is_some_and(|content_type| content_type.starts_with("text/"))
|
||||
})
|
||||
.nth(0)
|
||||
message.attachments.iter().find(|a| {
|
||||
a.content_type
|
||||
.as_ref()
|
||||
.is_some_and(|content_type| content_type.starts_with("text/"))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue