Refactor to use Info enum (in case we want to add more info like game & Java version)
This commit is contained in:
parent
104916464d
commit
28aa65d3be
2 changed files with 24 additions and 13 deletions
|
@ -3,7 +3,23 @@ use std::sync::OnceLock;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
pub fn looks_like_launcher_log(log: &str) -> bool {
|
// in future, we can add extra data to display in log analysis like Java version
|
||||||
|
pub enum Info {
|
||||||
|
Game,
|
||||||
|
Launcher
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn find(log: &str) -> Option<Info> {
|
||||||
|
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)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn looks_like_launcher_log(log: &str) -> bool {
|
||||||
static QT_LOG_REGEX: OnceLock<Regex> = OnceLock::new();
|
static QT_LOG_REGEX: OnceLock<Regex> = OnceLock::new();
|
||||||
|
|
||||||
trace!("Guessing whether log is launcher log");
|
trace!("Guessing whether log is launcher log");
|
||||||
|
@ -12,7 +28,7 @@ pub fn looks_like_launcher_log(log: &str) -> bool {
|
||||||
qt_log.is_match(log)
|
qt_log.is_match(log)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn looks_like_mc_log(log: &str) -> bool {
|
fn looks_like_game_log(log: &str) -> bool {
|
||||||
static LOG4J_REGEX: OnceLock<Regex> = OnceLock::new();
|
static LOG4J_REGEX: OnceLock<Regex> = OnceLock::new();
|
||||||
|
|
||||||
trace!("Guessing whether log is Minecraft log");
|
trace!("Guessing whether log is Minecraft log");
|
|
@ -7,6 +7,7 @@ use crate::{
|
||||||
|
|
||||||
use color_eyre::owo_colors::OwoColorize;
|
use color_eyre::owo_colors::OwoColorize;
|
||||||
use eyre::{eyre, OptionExt, Result};
|
use eyre::{eyre, OptionExt, Result};
|
||||||
|
use info::{find, 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,
|
||||||
|
@ -14,7 +15,7 @@ use poise::serenity_prelude::{
|
||||||
Message, MessageId, MessageType,
|
Message, MessageId, MessageType,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod heuristics;
|
mod info;
|
||||||
mod issues;
|
mod issues;
|
||||||
mod providers;
|
mod providers;
|
||||||
|
|
||||||
|
@ -66,13 +67,10 @@ pub async fn handle_message(ctx: &Context, message: &Message, data: &Data) -> Re
|
||||||
};
|
};
|
||||||
|
|
||||||
let issues = issues::find(&log, data).await?;
|
let issues = issues::find(&log, data).await?;
|
||||||
let launcher_log = heuristics::looks_like_launcher_log(&log);
|
let info = info::find(&log);
|
||||||
let mc_log = !launcher_log && heuristics::looks_like_mc_log(&log);
|
|
||||||
|
|
||||||
debug!("Detections: mc_log = {mc_log}, launcher_log = {launcher_log}");
|
let show_analysis = !issues.is_empty() || matches!(info, Some(Info::Game));
|
||||||
|
let show_upload_prompt = attachment.is_some() && info.is_some();
|
||||||
let show_analysis = !issues.is_empty() || mc_log;
|
|
||||||
let show_upload_prompt = attachment.is_some() && (mc_log || launcher_log);
|
|
||||||
|
|
||||||
if !show_analysis && !show_upload_prompt {
|
if !show_analysis && !show_upload_prompt {
|
||||||
debug!("Found log but there is nothing to respond with");
|
debug!("Found log but there is nothing to respond with");
|
||||||
|
@ -238,10 +236,7 @@ pub async fn handle_component_interaction(
|
||||||
.description(url)
|
.description(url)
|
||||||
.color(Colors::Blue);
|
.color(Colors::Blue);
|
||||||
|
|
||||||
let display_upload_guide =
|
if matches!(info::find(&body), Some(Info::Game)) {
|
||||||
!heuristics::looks_like_launcher_log(&body) && heuristics::looks_like_mc_log(&body);
|
|
||||||
|
|
||||||
if display_upload_guide {
|
|
||||||
interaction
|
interaction
|
||||||
.create_response(
|
.create_response(
|
||||||
ctx,
|
ctx,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue