Add log upload tip
This commit is contained in:
parent
e7ef2ca470
commit
104916464d
2 changed files with 48 additions and 18 deletions
|
@ -41,8 +41,9 @@ pub fn looks_like_mc_log(log: &str) -> bool {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let log4j = LOG4J_REGEX
|
let log4j = LOG4J_REGEX.get_or_init(|| {
|
||||||
.get_or_init(|| 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;
|
||||||
|
|
|
@ -1,8 +1,3 @@
|
||||||
use std::{
|
|
||||||
collections::HashSet,
|
|
||||||
sync::{Mutex, OnceLock},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{mclogs, HttpClientExt},
|
api::{mclogs, HttpClientExt},
|
||||||
consts::Colors,
|
consts::Colors,
|
||||||
|
@ -114,8 +109,11 @@ pub async fn handle_message(ctx: &Context, message: &Message, data: &Data) -> Re
|
||||||
message = message.add_embed(
|
message = message.add_embed(
|
||||||
CreateEmbed::new()
|
CreateEmbed::new()
|
||||||
.title("Upload log?")
|
.title("Upload log?")
|
||||||
.color(Colors::Blue)
|
.description(
|
||||||
.description("Discord attachments make it difficult for volunteers to view logs. Would you like me to upload your log to [mclo.gs](https://mclo.gs/)?"),
|
"Discord attachments make it difficult for volunteers to view logs. \
|
||||||
|
Would you like me to upload your log to [mclo.gs](https://mclo.gs/)?",
|
||||||
|
)
|
||||||
|
.color(Colors::Blue),
|
||||||
);
|
);
|
||||||
message = message
|
message = message
|
||||||
.button(
|
.button(
|
||||||
|
@ -186,7 +184,10 @@ pub async fn handle_component_interaction(
|
||||||
|
|
||||||
// prevent other members from clicking the buttons
|
// prevent other members from clicking the buttons
|
||||||
if interaction.user.id != referenced_message.author.id {
|
if interaction.user.id != referenced_message.author.id {
|
||||||
debug!("Ignoring component interaction by {} on reply to message by {}", interaction.user.id, referenced_message.author.id);
|
debug!(
|
||||||
|
"Ignoring component interaction by {} on reply to message by {}",
|
||||||
|
interaction.user.id, referenced_message.author.id
|
||||||
|
);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,8 +217,8 @@ pub async fn handle_component_interaction(
|
||||||
.embed(
|
.embed(
|
||||||
CreateEmbed::new()
|
CreateEmbed::new()
|
||||||
.title("Upload failed")
|
.title("Upload failed")
|
||||||
.color(Colors::Red)
|
.description(&error)
|
||||||
.description(&error),
|
.color(Colors::Red),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -234,15 +235,43 @@ pub async fn handle_component_interaction(
|
||||||
|
|
||||||
embeds[length - 1] = CreateEmbed::new()
|
embeds[length - 1] = CreateEmbed::new()
|
||||||
.title("Uploaded log")
|
.title("Uploaded log")
|
||||||
.color(Colors::Blue)
|
.description(url)
|
||||||
.description(url);
|
.color(Colors::Blue);
|
||||||
|
|
||||||
|
let display_upload_guide =
|
||||||
|
!heuristics::looks_like_launcher_log(&body) && heuristics::looks_like_mc_log(&body);
|
||||||
|
|
||||||
|
if display_upload_guide {
|
||||||
|
interaction
|
||||||
|
.create_response(
|
||||||
|
ctx,
|
||||||
|
CreateInteractionResponse::Message(
|
||||||
|
CreateInteractionResponseMessage::new()
|
||||||
|
.ephemeral(true)
|
||||||
|
.embed(
|
||||||
|
CreateEmbed::new()
|
||||||
|
.title("Tip")
|
||||||
|
.description(
|
||||||
|
"Logs can be uploaded directly within the launcher.",
|
||||||
|
)
|
||||||
|
.color(Colors::Yellow)
|
||||||
|
.image("https://cdn.discordapp.com/attachments/1031694870756204566/1156971972232740874/image.png"),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
} else {
|
||||||
|
interaction
|
||||||
|
.create_response(ctx, CreateInteractionResponse::Acknowledge)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
embeds.pop();
|
embeds.pop();
|
||||||
}
|
|
||||||
|
|
||||||
interaction
|
interaction
|
||||||
.create_response(ctx, CreateInteractionResponse::Acknowledge)
|
.create_response(ctx, CreateInteractionResponse::Acknowledge)
|
||||||
.await?;
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
if embeds.len() == 0 {
|
if embeds.len() == 0 {
|
||||||
interaction.message.delete(ctx).await?;
|
interaction.message.delete(ctx).await?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue