handlers::event: improve tracing

This commit is contained in:
seth 2024-03-18 08:45:25 -04:00
parent 9d0c022c68
commit af9938a3c6
No known key found for this signature in database
GPG key ID: D31BD0D494BBEE86
9 changed files with 34 additions and 1 deletions

View file

@ -1,12 +1,15 @@
use crate::Data;
use eyre::Result;
use log::trace;
use once_cell::sync::Lazy;
use regex::Regex;
pub type Issue = Option<(String, String)>;
pub async fn find(log: &str, data: &Data) -> Result<Vec<(String, String)>> {
trace!("Checking log for issues");
let issues = [
fabric_internal,
flatpak_nvidia,

View file

@ -2,7 +2,7 @@ use crate::consts::COLORS;
use crate::Data;
use eyre::Result;
use log::debug;
use log::{debug, trace};
use poise::serenity_prelude::{
Context, CreateAllowedMentions, CreateEmbed, CreateMessage, Message,
};
@ -13,6 +13,11 @@ mod providers;
use providers::find_log;
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 log = find_log(message).await;

View file

@ -1,6 +1,7 @@
use crate::api::REQWEST_CLIENT;
use eyre::{eyre, Result};
use log::trace;
use once_cell::sync::Lazy;
use regex::Regex;
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());
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 {
return Ok(None);
};

View file

@ -1,7 +1,10 @@
use eyre::Result;
use log::trace;
use poise::serenity_prelude::Message;
pub async fn find(message: &Message) -> Result<Option<String>> {
trace!("Checking for text attachments in message {}", message.id);
// find first uploaded text file
if let Some(attachment) = message.attachments.iter().find(|a| {
a.content_type

View file

@ -1,6 +1,7 @@
use crate::api::REQWEST_CLIENT;
use eyre::{eyre, Result};
use log::trace;
use once_cell::sync::Lazy;
use regex::Regex;
use reqwest::StatusCode;
@ -9,6 +10,8 @@ static REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"https://hst\.sh(?:/raw)?/(\w+(?:\.\w*)?)").unwrap());
pub async fn find(content: &str) -> Result<Option<String>> {
trace!("Checking if {content} is a haste log");
let Some(captures) = REGEX.captures(content) else {
return Ok(None);
};

View file

@ -1,6 +1,7 @@
use crate::api::REQWEST_CLIENT;
use eyre::{eyre, Result};
use log::trace;
use once_cell::sync::Lazy;
use regex::Regex;
use reqwest::StatusCode;
@ -8,6 +9,8 @@ use reqwest::StatusCode;
static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://mclo\.gs/(\w+)").unwrap());
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 {
return Ok(None);
};

View file

@ -1,6 +1,7 @@
use crate::api::REQWEST_CLIENT;
use eyre::{eyre, OptionExt, Result};
use log::trace;
use once_cell::sync::Lazy;
use regex::Regex;
use reqwest::StatusCode;
@ -27,6 +28,7 @@ struct PasteResult {
}
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 {
return Ok(None);
};

View file

@ -1,6 +1,7 @@
use crate::api::REQWEST_CLIENT;
use eyre::{eyre, Result};
use log::trace;
use once_cell::sync::Lazy;
use regex::Regex;
use reqwest::StatusCode;
@ -9,6 +10,7 @@ static REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"https://pastebin\.com(?:/raw)?/(\w+)").unwrap());
pub async fn find(content: &str) -> Result<Option<String>> {
trace!("Checking if {content} is a pastebin log");
let Some(captures) = REGEX.captures(content) else {
return Ok(None);
};

View file

@ -30,6 +30,8 @@ pub async fn handle(
}
FullEvent::Message { new_message } => {
trace!("Recieved message {}", new_message.content);
// ignore new messages from bots
// note: the webhook_id check allows us to still respond to PK users
if (new_message.author.bot && new_message.webhook_id.is_none())
@ -55,10 +57,17 @@ pub async fn handle(
}
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?;
}
FullEvent::ThreadCreate { thread } => {
trace!("Recieved thread {}", thread.id);
support_onboard::handle(ctx, thread).await?;
}