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 std::collections::HashMap;
|
||||||
|
|
||||||
use eyre::{eyre, OptionExt, Result};
|
use eyre::Result;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::{HttpClient, HttpClientExt};
|
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
|
// in future, we can add extra data to display in log analysis like Java version
|
||||||
pub enum Info {
|
pub enum Info {
|
||||||
Game,
|
Game,
|
||||||
Launcher
|
Launcher,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find(log: &str) -> Option<Info> {
|
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)
|
Some(Info::Launcher)
|
||||||
} else if looks_like_game_log(log) {
|
} else if looks_like_game_log(log) {
|
||||||
Some(Info::Game)
|
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()
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,13 @@ use crate::{
|
||||||
Data,
|
Data,
|
||||||
};
|
};
|
||||||
|
|
||||||
use color_eyre::owo_colors::OwoColorize;
|
|
||||||
use eyre::{eyre, OptionExt, Result};
|
use eyre::{eyre, OptionExt, Result};
|
||||||
use info::{find, Info};
|
use info::Info;
|
||||||
use log::{debug, trace};
|
use log::{debug, trace};
|
||||||
use poise::serenity_prelude::{
|
use poise::serenity_prelude::{
|
||||||
ButtonStyle, ComponentInteraction, Context, CreateAllowedMentions, CreateButton, CreateEmbed,
|
ButtonStyle, ComponentInteraction, Context, CreateAllowedMentions, CreateButton, CreateEmbed,
|
||||||
CreateInteractionResponse, CreateInteractionResponseMessage, CreateMessage, EditMessage,
|
CreateInteractionResponse, CreateInteractionResponseMessage, CreateMessage, EditMessage,
|
||||||
Message, MessageId, MessageType,
|
Message, MessageType,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod info;
|
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 attachment = first_text_attachment(message);
|
||||||
|
|
||||||
let log = match log {
|
let log = if let Some(log) = log {
|
||||||
Some(log) => log,
|
log
|
||||||
None => match attachment {
|
} else if let Some(attachment) = attachment {
|
||||||
Some(attachment) => {
|
data.http_client
|
||||||
data.http_client
|
.get_request(&attachment.url)
|
||||||
.get_request(&attachment.url)
|
.await?
|
||||||
.await?
|
.text()
|
||||||
.text()
|
.await?
|
||||||
.await?
|
} else {
|
||||||
}
|
debug!("No log found in message! Skipping analysis");
|
||||||
None => {
|
return Ok(());
|
||||||
debug!("No log found in message! Skipping analysis");
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let issues = issues::find(&log, data).await?;
|
let issues = issues::find(&log, data).await?;
|
||||||
|
@ -268,7 +263,7 @@ pub async fn handle_component_interaction(
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if embeds.len() == 0 {
|
if embeds.is_empty() {
|
||||||
interaction.message.delete(ctx).await?;
|
interaction.message.delete(ctx).await?;
|
||||||
} else {
|
} else {
|
||||||
ctx.http
|
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;
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
|
@ -19,6 +19,6 @@ impl super::LogProvider for MCLogs {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch(&self, http: &HttpClient, content: &str) -> Result<String> {
|
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> {
|
pub fn first_text_attachment(message: &Message) -> Option<&Attachment> {
|
||||||
message
|
message.attachments.iter().find(|a| {
|
||||||
.attachments
|
a.content_type
|
||||||
.iter()
|
.as_ref()
|
||||||
.filter(|a| {
|
.is_some_and(|content_type| content_type.starts_with("text/"))
|
||||||
a.content_type
|
})
|
||||||
.as_ref()
|
|
||||||
.is_some_and(|content_type| content_type.starts_with("text/"))
|
|
||||||
})
|
|
||||||
.nth(0)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue