handlers::event: improve tracing
This commit is contained in:
parent
9d0c022c68
commit
af9938a3c6
9 changed files with 34 additions and 1 deletions
|
@ -1,12 +1,15 @@
|
||||||
use crate::Data;
|
use crate::Data;
|
||||||
|
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
|
use log::trace;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
pub type Issue = Option<(String, String)>;
|
pub type Issue = Option<(String, String)>;
|
||||||
|
|
||||||
pub async fn find(log: &str, data: &Data) -> Result<Vec<(String, String)>> {
|
pub async fn find(log: &str, data: &Data) -> Result<Vec<(String, String)>> {
|
||||||
|
trace!("Checking log for issues");
|
||||||
|
|
||||||
let issues = [
|
let issues = [
|
||||||
fabric_internal,
|
fabric_internal,
|
||||||
flatpak_nvidia,
|
flatpak_nvidia,
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::consts::COLORS;
|
||||||
use crate::Data;
|
use crate::Data;
|
||||||
|
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
use log::debug;
|
use log::{debug, trace};
|
||||||
use poise::serenity_prelude::{
|
use poise::serenity_prelude::{
|
||||||
Context, CreateAllowedMentions, CreateEmbed, CreateMessage, Message,
|
Context, CreateAllowedMentions, CreateEmbed, CreateMessage, Message,
|
||||||
};
|
};
|
||||||
|
@ -13,6 +13,11 @@ mod providers;
|
||||||
use providers::find_log;
|
use providers::find_log;
|
||||||
|
|
||||||
pub async fn handle(ctx: &Context, message: &Message, data: &Data) -> Result<()> {
|
pub async fn handle(ctx: &Context, message: &Message, data: &Data) -> Result<()> {
|
||||||
|
trace!(
|
||||||
|
"Checking message {} from {} for logs",
|
||||||
|
message.id,
|
||||||
|
message.author.id
|
||||||
|
);
|
||||||
let channel = message.channel_id;
|
let channel = message.channel_id;
|
||||||
|
|
||||||
let log = find_log(message).await;
|
let log = find_log(message).await;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::api::REQWEST_CLIENT;
|
use crate::api::REQWEST_CLIENT;
|
||||||
|
|
||||||
use eyre::{eyre, Result};
|
use eyre::{eyre, Result};
|
||||||
|
use log::trace;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
|
@ -8,6 +9,8 @@ use reqwest::StatusCode;
|
||||||
static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://0x0\.st/\w*\.\w*").unwrap());
|
static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://0x0\.st/\w*\.\w*").unwrap());
|
||||||
|
|
||||||
pub async fn find(content: &str) -> Result<Option<String>> {
|
pub async fn find(content: &str) -> Result<Option<String>> {
|
||||||
|
trace!("Checking if {content} is a 0x0 paste");
|
||||||
|
|
||||||
let Some(url) = REGEX.find(content).map(|m| &content[m.range()]) else {
|
let Some(url) = REGEX.find(content).map(|m| &content[m.range()]) else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
|
use log::trace;
|
||||||
use poise::serenity_prelude::Message;
|
use poise::serenity_prelude::Message;
|
||||||
|
|
||||||
pub async fn find(message: &Message) -> Result<Option<String>> {
|
pub async fn find(message: &Message) -> Result<Option<String>> {
|
||||||
|
trace!("Checking for text attachments in message {}", message.id);
|
||||||
|
|
||||||
// find first uploaded text file
|
// find first uploaded text file
|
||||||
if let Some(attachment) = message.attachments.iter().find(|a| {
|
if let Some(attachment) = message.attachments.iter().find(|a| {
|
||||||
a.content_type
|
a.content_type
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::api::REQWEST_CLIENT;
|
use crate::api::REQWEST_CLIENT;
|
||||||
|
|
||||||
use eyre::{eyre, Result};
|
use eyre::{eyre, Result};
|
||||||
|
use log::trace;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
|
@ -9,6 +10,8 @@ static REGEX: Lazy<Regex> =
|
||||||
Lazy::new(|| Regex::new(r"https://hst\.sh(?:/raw)?/(\w+(?:\.\w*)?)").unwrap());
|
Lazy::new(|| Regex::new(r"https://hst\.sh(?:/raw)?/(\w+(?:\.\w*)?)").unwrap());
|
||||||
|
|
||||||
pub async fn find(content: &str) -> Result<Option<String>> {
|
pub async fn find(content: &str) -> Result<Option<String>> {
|
||||||
|
trace!("Checking if {content} is a haste log");
|
||||||
|
|
||||||
let Some(captures) = REGEX.captures(content) else {
|
let Some(captures) = REGEX.captures(content) else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::api::REQWEST_CLIENT;
|
use crate::api::REQWEST_CLIENT;
|
||||||
|
|
||||||
use eyre::{eyre, Result};
|
use eyre::{eyre, Result};
|
||||||
|
use log::trace;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
|
@ -8,6 +9,8 @@ use reqwest::StatusCode;
|
||||||
static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://mclo\.gs/(\w+)").unwrap());
|
static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://mclo\.gs/(\w+)").unwrap());
|
||||||
|
|
||||||
pub async fn find(content: &str) -> Result<Option<String>> {
|
pub async fn find(content: &str) -> Result<Option<String>> {
|
||||||
|
trace!("Checking if {content} is an mclo.gs paste");
|
||||||
|
|
||||||
let Some(captures) = REGEX.captures(content) else {
|
let Some(captures) = REGEX.captures(content) else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::api::REQWEST_CLIENT;
|
use crate::api::REQWEST_CLIENT;
|
||||||
|
|
||||||
use eyre::{eyre, OptionExt, Result};
|
use eyre::{eyre, OptionExt, Result};
|
||||||
|
use log::trace;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
|
@ -27,6 +28,7 @@ struct PasteResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn find(content: &str) -> Result<Option<String>> {
|
pub async fn find(content: &str) -> Result<Option<String>> {
|
||||||
|
trace!("Checking if {content} is a paste.gg log");
|
||||||
let Some(captures) = REGEX.captures(content) else {
|
let Some(captures) = REGEX.captures(content) else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::api::REQWEST_CLIENT;
|
use crate::api::REQWEST_CLIENT;
|
||||||
|
|
||||||
use eyre::{eyre, Result};
|
use eyre::{eyre, Result};
|
||||||
|
use log::trace;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
|
@ -9,6 +10,7 @@ static REGEX: Lazy<Regex> =
|
||||||
Lazy::new(|| Regex::new(r"https://pastebin\.com(?:/raw)?/(\w+)").unwrap());
|
Lazy::new(|| Regex::new(r"https://pastebin\.com(?:/raw)?/(\w+)").unwrap());
|
||||||
|
|
||||||
pub async fn find(content: &str) -> Result<Option<String>> {
|
pub async fn find(content: &str) -> Result<Option<String>> {
|
||||||
|
trace!("Checking if {content} is a pastebin log");
|
||||||
let Some(captures) = REGEX.captures(content) else {
|
let Some(captures) = REGEX.captures(content) else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,6 +30,8 @@ pub async fn handle(
|
||||||
}
|
}
|
||||||
|
|
||||||
FullEvent::Message { new_message } => {
|
FullEvent::Message { new_message } => {
|
||||||
|
trace!("Recieved message {}", new_message.content);
|
||||||
|
|
||||||
// ignore new messages from bots
|
// ignore new messages from bots
|
||||||
// note: the webhook_id check allows us to still respond to PK users
|
// note: the webhook_id check allows us to still respond to PK users
|
||||||
if (new_message.author.bot && new_message.webhook_id.is_none())
|
if (new_message.author.bot && new_message.webhook_id.is_none())
|
||||||
|
@ -55,10 +57,17 @@ pub async fn handle(
|
||||||
}
|
}
|
||||||
|
|
||||||
FullEvent::ReactionAdd { add_reaction } => {
|
FullEvent::ReactionAdd { add_reaction } => {
|
||||||
|
trace!(
|
||||||
|
"Recieved reaction {} on message {} from {}",
|
||||||
|
add_reaction.emoji,
|
||||||
|
add_reaction.message_id.to_string(),
|
||||||
|
add_reaction.user_id.unwrap_or_default().to_string()
|
||||||
|
);
|
||||||
delete_on_reaction::handle(ctx, add_reaction).await?;
|
delete_on_reaction::handle(ctx, add_reaction).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
FullEvent::ThreadCreate { thread } => {
|
FullEvent::ThreadCreate { thread } => {
|
||||||
|
trace!("Recieved thread {}", thread.id);
|
||||||
support_onboard::handle(ctx, thread).await?;
|
support_onboard::handle(ctx, thread).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue